diff --git a/src/Components/Facility/AddLocationForm.tsx b/src/Components/Facility/AddLocationForm.tsx index f4e8b3c1175..b468ded1fcd 100644 --- a/src/Components/Facility/AddLocationForm.tsx +++ b/src/Components/Facility/AddLocationForm.tsx @@ -15,6 +15,7 @@ import { Submit, Cancel } from "../Common/components/ButtonV2"; import TextFormField from "../Form/FormFields/TextFormField"; import TextAreaFormField from "../Form/FormFields/TextAreaFormField"; import { MultiSelectFormField } from "../Form/FormFields/SelectFormField"; +import { UserAssignedModel } from "../Users/models"; const Loading = loadable(() => import("../Common/Loading")); const PageTitle = loadable(() => import("../Common/PageTitle")); @@ -31,10 +32,10 @@ export const AddLocationForm = (props: LocationFormProps) => { const [description, setDescription] = useState(""); const [facilityName, setFacilityName] = useState(""); const [locationName, setLocationName] = useState(""); - const [doctorList, setDoctorList] = useState([]); - const [staffList, setStaffList] = useState([]); - const [doctors, setDoctors] = useState([]); - const [staff, setStaff] = useState([]); + const [doctorList, setDoctorList] = useState([]); + const [staffList, setStaffList] = useState([]); + const [doctors, setDoctors] = useState([]); + const [staff, setStaff] = useState([]); const [errors, setErrors] = useState({ name: "", description: "", @@ -70,8 +71,16 @@ export const AddLocationForm = (props: LocationFormProps) => { setName(res?.data?.name || ""); setLocationName(res?.data?.name || ""); setDescription(res?.data?.description || ""); - setDoctors(res?.data?.doctors || []); - setStaff(res?.data?.staff || []); + setDoctors( + res?.data?.duty_staff_objects + .filter((doc: UserAssignedModel) => doc.user_type === "Doctor") + .map((doc: UserAssignedModel) => doc.id) || [] + ); + setStaff( + res?.data?.duty_staff_objects + .filter((s: UserAssignedModel) => s.user_type === "Staff") + .map((s: UserAssignedModel) => s.id) || [] + ); } setIsLoading(false); } @@ -85,11 +94,11 @@ export const AddLocationForm = (props: LocationFormProps) => { }); e.preventDefault(); setIsLoading(true); + console.log(doctors, staff); const data = { name, description, - doctors, - staff, + duty_staff: [...doctors, ...staff], }; const res = await dispatchAction( diff --git a/src/Components/Facility/LocationManagement.tsx b/src/Components/Facility/LocationManagement.tsx index 2237ce3b856..6f8cd3a0c15 100644 --- a/src/Components/Facility/LocationManagement.tsx +++ b/src/Components/Facility/LocationManagement.tsx @@ -9,6 +9,7 @@ import { RoleButton } from "../Common/RoleButton"; import { LocationModel } from "./models"; import { ReactElement } from "react"; import { UserAssignedModel } from "../Users/models"; +import CareIcon from "../../CAREUI/icons/CareIcon"; const PageTitle = loadable(() => import("../Common/PageTitle")); const Loading = loadable(() => import("../Common/Loading")); @@ -34,16 +35,24 @@ const LocationRow = (props: LocationRowProps) => { className="w-full border-b lg:flex justify-between items-center py-4" >
-
-

{name}

-

{description}

-

- {doctors.map( - (doctor) => `${doctor.first_name} ${doctor.last_name}` - )} +

+

{name}

+

{description}

+

+ {doctors.map((doctor) => ( +

+ +
{`${doctor.first_name} ${doctor.last_name}`}
+
+ ))}

-

- {staff.map((s) => `${s.first_name} ${s.last_name}`)} +

+ {staff.map((s) => ( +

+ +
{`${s.first_name} ${s.last_name}`}
+
+ ))}

@@ -136,8 +145,16 @@ export const LocationManagement = (props: LocationManagementProps) => { facilityId={facilityId || ""} name={locationItem.name || ""} description={locationItem.description || ""} - doctors={locationItem.doctor_objects || []} - staff={locationItem.staff_objects || []} + doctors={ + locationItem.duty_staff_objects?.filter( + (doc: UserAssignedModel) => doc.user_type == "Doctor" + ) || [] + } + staff={ + locationItem.duty_staff_objects?.filter( + (s: UserAssignedModel) => s.user_type == "Staff" + ) || [] + } /> )); } else if (locations && locations.length === 0) { diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index e0395b8950b..578fbc2f8dc 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -185,8 +185,7 @@ export interface LocationModel { facility?: { name: string; }; - doctor_objects?: UserAssignedModel[]; - staff_objects?: UserAssignedModel[]; + duty_staff_objects?: UserAssignedModel[]; } export interface BedModel {