Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation for average working hours #6243

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/Components/Users/ManageUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export default function ManageUsers() {
name: string;
}>({ show: false, username: "", name: "" });

const [weeklyHoursError, setWeeklyHoursError] = useState<string>("");

const extremeSmallScreenBreakpoint = 320;
const isExtremeSmallScreen =
width <= extremeSmallScreenBreakpoint ? true : false;
Expand Down Expand Up @@ -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,
Expand All @@ -163,6 +168,7 @@ export default function ManageUsers() {
});
}
setWeeklyHours(0);
setWeeklyHoursError("");
fetchData({ aborted: false });
};

Expand Down Expand Up @@ -493,13 +499,14 @@ export default function ManageUsers() {
</SlideOverCustom>
<SlideOverCustom
open={expandWorkingHours}
setOpen={setExpandWorkingHours}
setOpen={(state) => {
setExpandWorkingHours(state);
setWeeklyHours(0);
setWeeklyHoursError("");
}}
slideFrom="right"
title="Average weekly working hours"
dialogClass="md:w-[400px]"
onCloseClick={() => {
setWeeklyHours(0);
}}
>
<div className="px-2">
<dt className="mb-3 text-sm font-medium leading-5 text-black">
Expand All @@ -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"
Expand Down