Fakultas Ilmu Komputer UI

Commit 1a2aa114 authored by FadhilP's avatar FadhilP
Browse files

[REFACTOR] Add error message for invalid dates

parent 7b817f18
Pipeline #77512 failed with stages
in 3 minutes and 34 seconds
......@@ -26,11 +26,19 @@ const FormBatch = ({ onSubmit, initialData = null, error }) => {
const [startDate, setStartDate] = useState('');
const [endDate, setEndDate] = useState('');
const [errorMessage, setErrorMessage] = useState('');
return (
<form
data-testid="form-batch"
onSubmit={handleSubmit(onSubmit)}
onSubmit={(e) => {
e.preventDefault()
setErrorMessage("")
if (moment(startDate) <= moment(endDate))
handleSubmit(onSubmit)
else setErrorMessage("Tanggal Akhir tidak boleh lebih dulu dari Tanggal Mulai!")
}}
css={css`
display: flex;
flex-direction: column;
......@@ -119,6 +127,13 @@ const FormBatch = ({ onSubmit, initialData = null, error }) => {
</button>
</ErrorDiv>
)}
{errorMessage && (
<ErrorDiv>
<button className="btn btn-danger">
{errorMessage}
</button>
</ErrorDiv>
)}
</RowInput>
<RowInput>
<InputSubmitForm type="submit" data-testid="submit-batch" />
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment