From 3ed406e16078937ca8ee589c9d293a2d0c1480be Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Mon, 11 Sep 2023 17:02:00 +0530 Subject: [PATCH] Fix error message --- src/Components/Users/ManageUsers.tsx | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Components/Users/ManageUsers.tsx b/src/Components/Users/ManageUsers.tsx index f2862cbbbab..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,8 +146,10 @@ export default function ManageUsers() { const handleWorkingHourSubmit = async () => { const username = selectedUser; - if (!username || !weeklyHours || weeklyHours < 0 || weeklyHours > 168) + 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, @@ -164,6 +168,7 @@ export default function ManageUsers() { }); } setWeeklyHours(0); + setWeeklyHoursError(""); fetchData({ aborted: false }); }; @@ -494,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); - }} >
@@ -513,11 +519,7 @@ export default function ManageUsers() { onChange={(e) => { setWeeklyHours(e.value); }} - error={ - !weeklyHours || weeklyHours < 0 || weeklyHours > 168 - ? "Average weekly working hours should be between 0 and 168" - : "" - } + error={weeklyHoursError} required label="" type="number"