From 6a5f527552ac3f7af669988934acd1d103a9d10c Mon Sep 17 00:00:00 2001 From: cp-Coder Date: Sat, 22 Apr 2023 23:20:23 +0530 Subject: [PATCH] fix(location): updated UI of location view table --- src/Components/Facility/AddLocationForm.tsx | 25 ++++++++---- .../Facility/LocationManagement.tsx | 39 +++++++++++++------ src/Components/Facility/models.tsx | 3 +- 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/Components/Facility/AddLocationForm.tsx b/src/Components/Facility/AddLocationForm.tsx index 605595e06df..e7e18358f53 100644 --- a/src/Components/Facility/AddLocationForm.tsx +++ b/src/Components/Facility/AddLocationForm.tsx @@ -16,6 +16,7 @@ import TextAreaFormField from "../Form/FormFields/TextAreaFormField"; import TextFormField from "../Form/FormFields/TextFormField"; import { MultiSelectFormField } from "../Form/FormFields/SelectFormField"; +import { UserAssignedModel } from "../Users/models"; const Loading = loadable(() => import("../Common/Loading")); interface LocationFormProps { @@ -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 8645bca4e0f..4976409ddd7 100644 --- a/src/Components/Facility/LocationManagement.tsx +++ b/src/Components/Facility/LocationManagement.tsx @@ -34,16 +34,24 @@ const LocationRow = (props: LocationRowProps) => { className="w-full items-center justify-between border-b py-4 lg:flex" >
-
-

{ 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}` }
+
+ )) }

@@ -125,13 +133,20 @@ export const LocationManagement = (props: LocationManagementProps) => { if (locations?.length) { locationsList = locations.map((locationItem: LocationModel) => ( 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 7e6d4cab42c..92a9db5bcd9 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -183,8 +183,7 @@ export interface LocationModel { facility?: { name: string; }; - doctor_objects?: UserAssignedModel[]; - staff_objects?: UserAssignedModel[]; + duty_staff_objects?: UserAssignedModel[]; } export interface BedModel {