diff --git a/src/Components/Users/ManageUsers.tsx b/src/Components/Users/ManageUsers.tsx index 9ef0b5b3cc9..e7b9fa8ad67 100644 --- a/src/Components/Users/ManageUsers.tsx +++ b/src/Components/Users/ManageUsers.tsx @@ -14,7 +14,7 @@ import { useCallback, useEffect, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import { AdvancedFilterButton } from "../../CAREUI/interactive/FiltersSlideover"; -import ButtonV2 from "../Common/components/ButtonV2"; +import ButtonV2, { Submit } from "../Common/components/ButtonV2"; import CareIcon from "../../CAREUI/icons/CareIcon"; import ConfirmHomeFacilityUpdateDialog from "./ConfirmHomeFacilityUpdateDialog"; import CountBlock from "../../CAREUI/display/Count"; @@ -36,6 +36,7 @@ import useFilters from "../../Common/hooks/useFilters"; import useWindowDimensions from "../../Common/hooks/useWindowDimensions"; import CircularProgress from "../Common/components/CircularProgress.js"; import Page from "../Common/components/Page.js"; +import TextFormField from "../Form/FormFields/TextFormField.js"; const Loading = loadable(() => import("../Common/Loading")); @@ -59,10 +60,12 @@ export default function ManageUsers() { const [districtName, setDistrictName] = useState(); const [expandFacilityList, setExpandFacilityList] = useState(false); const [selectedUser, setSelectedUser] = useState(null); + const [expandWorkingHours, setExpandWorkingHours] = useState(false); const state: any = useSelector((state) => state); const { currentUser } = state; const isSuperuser = currentUser.data.is_superuser; const userType = currentUser.data.user_type; + const [weeklyHours, setWeeklyHours] = useState(0); const userIndex = USER_TYPES.indexOf(userType); const userTypes = isSuperuser ? [...USER_TYPES] @@ -143,6 +146,30 @@ export default function ManageUsers() { setUserData({ show: false, username: "", name: "" }); }; + const handleWorkingHourSubmit = async () => { + const username = selectedUser; + if (!username || weeklyHours < 0 || weeklyHours > 168) return; + const res = await dispatch( + partialUpdateUser(username, { + weekly_working_hours: weeklyHours, + }) + ); + + if (res?.data) { + Notification.Success({ + msg: "Working hours updated successfully", + }); + setExpandWorkingHours(false); + setSelectedUser(null); + } else { + Notification.Error({ + msg: "Error while updating working hours: " + (res.data.detail || ""), + }); + } + setWeeklyHours(0); + fetchData({ aborted: false }); + }; + const handleSubmit = async () => { const username = userData.username; const res = await dispatch(deleteUser(username)); @@ -194,10 +221,13 @@ export default function ManageUsers() { id={`usr_${idx}`} className=" mt-6 w-full md:px-4 lg:w-1/2 xl:w-1/3" > -
-
+
+
-
+
{user.username && (
handleDelete(user)} > Delete @@ -259,10 +290,10 @@ export default function ManageUsers() { isExtremeSmallScreen ? " flex-wrap " : " flex-col justify-between md:flex-row " - } gap-2 md:grid md:grid-cols-4`} + } gap-2 md:grid md:grid-cols-2`} > {user.user_type && ( -
+
{user.user_type} @@ -271,7 +302,7 @@ export default function ManageUsers() {
)} {user.district_object && ( -
+
{user.district_object.name} @@ -281,7 +312,7 @@ export default function ManageUsers() { )} {user.user_type === "Doctor" && ( <> -
+
-
+
{user.doctor_experience_commenced_on ? ( @@ -339,11 +370,11 @@ export default function ManageUsers() { className={`${ isExtremeSmallScreen ? "flex flex-wrap " - : "grid grid-cols-4 " + : "grid grid-cols-2 " }`} > {user.created_by && ( -
+
{user.created_by} @@ -352,7 +383,7 @@ export default function ManageUsers() {
)} {user.username && ( -
+
{user.home_facility_object?.name || @@ -362,8 +393,21 @@ export default function ManageUsers() {
)}
- {user.username && ( -
+
+ + {user.weekly_working_hours ? ( + + {user.weekly_working_hours} hours + + ) : ( + - + )} + +
+
+ {user.username && ( +
+

Linked Facilities

+
Linked Skills

- )} -
+ {["DistrictAdmin", "StateAdmin"].includes(userType) && ( +
+ { + setExpandWorkingHours(true); + setSelectedUser(user.username); + setWeeklyHours(user.weekly_working_hours); + }} + > + +

Set weekly working hours

+
+
+ )} +
+ )}
@@ -397,7 +458,7 @@ export default function ManageUsers() { if (isLoading || !users) { manageUsers = ; - } else if (users && users.length) { + } else if (users?.length) { manageUsers = (
{userList}
@@ -433,6 +494,43 @@ export default function ManageUsers() { > + { + setWeeklyHours(0); + }} + > +
+
+ Set weekly working hours for {selectedUser} +
+ { + setWeeklyHours(e.value); + }} + error={ + weeklyHours < 0 || weeklyHours > 168 + ? "Weekly working hours should be between 0 and 168" + : "" + } + required + label="" + type="number" + min={0} + max={168} + /> +
+ +
+
+
Home Facility
-
+
{user?.home_facility_object?.name}
@@ -672,7 +770,7 @@ function UserFacilities(props: { user: any }) { id={`facility_${i}`} key={`facility_${i}`} className={classNames( - "relative cursor-pointer rounded p-2 transition hover:bg-gray-200 focus:bg-gray-200 md:rounded-lg" + "relative rounded p-2 transition hover:bg-gray-200 focus:bg-gray-200 md:rounded-lg" )} >
diff --git a/src/Components/Users/UserProfile.tsx b/src/Components/Users/UserProfile.tsx index 618f2dec369..6e53d2fed5f 100644 --- a/src/Components/Users/UserProfile.tsx +++ b/src/Components/Users/UserProfile.tsx @@ -37,6 +37,7 @@ type EditForm = { doctor_qualification: string | undefined; doctor_experience_commenced_on: number | string | undefined; doctor_medical_council_registration: string | undefined; + weekly_working_hours: string | undefined; }; type State = { form: EditForm; @@ -57,6 +58,7 @@ const initForm: EditForm = { doctor_qualification: undefined, doctor_experience_commenced_on: undefined, doctor_medical_council_registration: undefined, + weekly_working_hours: undefined, }; const initError: EditForm = Object.assign( @@ -151,6 +153,7 @@ export default function UserProfile() { ), doctor_medical_council_registration: res.data.doctor_medical_council_registration, + weekly_working_hours: res.data.weekly_working_hours, }; dispatch({ type: "set_form", @@ -251,6 +254,20 @@ export default function UserProfile() { invalidForm = true; } return; + case "weekly_working_hours": + if (!states.form[field]) { + errors[field] = "This field is required"; + invalidForm = true; + } else if ( + Number(states.form[field]) < 0 || + Number(states.form[field]) > 168 || + !/^\d+$/.test(states.form[field] ?? "") + ) { + errors[field] = + "Weekly working hours must be a number between 0 and 168"; + invalidForm = true; + } + return; } }); dispatch({ type: "set_error", errors }); @@ -306,6 +323,7 @@ export default function UserProfile() { details.user_type === "Doctor" ? states.form.doctor_medical_council_registration : undefined, + weekly_working_hours: states.form.weekly_working_hours, }; const res = await dispatchAction(partialUpdateUser(username, data)); if (res && res.data) { @@ -513,25 +531,33 @@ export default function UserProfile() { {details.state_object?.name || "-"}
+
+
+ Skills +
+
+
+ {details.skills && details.skills.length + ? details.skills?.map((skill: SkillObjectModel) => { + return ( + +

{skill.name}

+
+ ); + }) + : "-"} +
+
+
+
+
+ Weekly working hours +
+
+ {details.weekly_working_hours ?? "-"} +
+
-
-
- Skills -
-
-
- {details.skills && details.skills.length - ? details.skills?.map((skill: SkillObjectModel) => { - return ( - -

{skill.name}

-
- ); - }) - : "-"} -
-
-
)} @@ -622,6 +648,15 @@ export default function UserProfile() { /> )} +