From ac9a4ee6a60bce858e0eaa56a0f47380f8d255df Mon Sep 17 00:00:00 2001 From: Ashesh <3626859+Ashesh3@users.noreply.github.com> Date: Mon, 11 Sep 2023 19:19:44 +0530 Subject: [PATCH] Add validation for average working hours (#6243) * Add validation for average working hours * Fix error message --- src/Components/Users/ManageUsers.tsx | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Components/Users/ManageUsers.tsx b/src/Components/Users/ManageUsers.tsx index d2e0ca415e3..8625d442f52 100644 --- a/src/Components/Users/ManageUsers.tsx +++ b/src/Components/Users/ManageUsers.tsx @@ -73,6 +73,8 @@ export default function ManageUsers() { name: string; }>({ show: false, username: "", name: "" }); + const [weeklyHoursError, setWeeklyHoursError] = useState(""); + const extremeSmallScreenBreakpoint = 320; const isExtremeSmallScreen = width <= extremeSmallScreenBreakpoint ? true : false; @@ -144,7 +146,10 @@ export default function ManageUsers() { const handleWorkingHourSubmit = async () => { const username = selectedUser; - if (!username || weeklyHours < 0 || weeklyHours > 168) return; + if (!username || !weeklyHours || weeklyHours < 0 || weeklyHours > 168) { + setWeeklyHoursError("Value should be between 0 and 168"); + return; + } const res = await dispatch( partialUpdateUser(username, { weekly_working_hours: weeklyHours, @@ -163,6 +168,7 @@ export default function ManageUsers() { }); } setWeeklyHours(0); + setWeeklyHoursError(""); fetchData({ aborted: false }); }; @@ -493,13 +499,14 @@ export default function ManageUsers() { { + setExpandWorkingHours(state); + setWeeklyHours(0); + setWeeklyHoursError(""); + }} slideFrom="right" title="Average weekly working hours" dialogClass="md:w-[400px]" - onCloseClick={() => { - setWeeklyHours(0); - }} >
@@ -512,11 +519,7 @@ export default function ManageUsers() { onChange={(e) => { setWeeklyHours(e.value); }} - error={ - weeklyHours < 0 || weeklyHours > 168 - ? "Average weekly working hours should be between 0 and 168" - : "" - } + error={weeklyHoursError} required label="" type="number"