Fakultas Ilmu Komputer UI

Commit b601cb8c authored by FadhilP's avatar FadhilP
Browse files

[REFACTOR] Rewrite error handling

parent 45896c2a
Pipeline #78104 failed with stages
in 3 minutes and 45 seconds
......@@ -14,7 +14,7 @@ import moment from "moment";
import DateTime from 'react-datetime';
import "react-datetime/css/react-datetime.css";
const FormBatch = ({ onSubmit, initialData = null, error }) => {
const FormBatch = ({ onSubmit, initialData = null, error, errorMessage }) => {
const { register, handleSubmit, errors } = useForm({
defaultValues: initialData !== null ? {
batch_name: initialData["batch_name"],
......@@ -26,19 +26,11 @@ 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={(e) => {
e.preventDefault()
setErrorMessage("")
if (moment(startDate) <= moment(endDate))
handleSubmit(onSubmit)
else setErrorMessage("Tanggal Mulai tidak boleh melebihi Tanggal Akhir!")
}}
onSubmit={handleSubmit(onSubmit)}
css={css`
display: flex;
flex-direction: column;
......
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