From fcfb2f2137cca5538cb00eede706622fc4e568f4 Mon Sep 17 00:00:00 2001 From: Shaurya Gupta Date: Sat, 5 Oct 2024 16:39:34 +0530 Subject: [PATCH] Fix: Error Messages Persist in UserAdd Component --- src/Components/Users/UserAdd.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Components/Users/UserAdd.tsx b/src/Components/Users/UserAdd.tsx index 73c7fb63c26..409a3660f13 100644 --- a/src/Components/Users/UserAdd.tsx +++ b/src/Components/Users/UserAdd.tsx @@ -294,6 +294,7 @@ export const UserAdd = (props: UserProps) => { const handleDateChange = (e: FieldChangeEvent) => { if (dayjs(e.value).isValid()) { + const errors = { ...state.errors, [e.name]: "" }; dispatch({ type: "set_form", form: { @@ -301,10 +302,12 @@ export const UserAdd = (props: UserProps) => { [e.name]: dayjs(e.value).format("YYYY-MM-DD"), }, }); + dispatch({ type: "set_errors", errors }); } }; const handleFieldChange = (event: FieldChangeEvent) => { + const errors = { ...state.errors, [event.name]: "" }; dispatch({ type: "set_form", form: { @@ -312,6 +315,7 @@ export const UserAdd = (props: UserProps) => { [event.name]: event.value, }, }); + dispatch({ type: "set_errors", errors }); }; useAbortableEffect(() => {