From 25c8e0bd021ea5f7965743d8a3893918658ab200 Mon Sep 17 00:00:00 2001 From: Anvesh Nalimela <151531961+AnveshNalimela@users.noreply.github.com> Date: Mon, 11 Nov 2024 19:10:58 +0530 Subject: [PATCH] Update for List View in Shifting from Gird LayOut to List Layout (#8882) --- .env | 2 +- public/locale/en.json | 1 + src/components/Shifting/ShiftingList.tsx | 267 ++++++++++++++++++----- 3 files changed, 216 insertions(+), 54 deletions(-) diff --git a/.env b/.env index b5db3d0088f..77e4641b8b2 100644 --- a/.env +++ b/.env @@ -14,4 +14,4 @@ ESLINT_NO_DEV_ERRORS=true CARE_CDN_URL="https://egov-s3-facility-10bedicu.s3.amazonaws.com https://egov-s3-patient-data-10bedicu.s3.amazonaws.com http://localhost:4566" REACT_ALLOWED_LOCALES="en,hi,ta,ml,mr,kn" -REACT_ENABLED_APPS="" +REACT_ENABLED_APPS="" \ No newline at end of file diff --git a/public/locale/en.json b/public/locale/en.json index ce1d79aa3dd..d686fa181a5 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -487,6 +487,7 @@ "consultation_not_filed_description": "Please file a consultation for this patient to continue.", "consultation_notes": "General Instructions (Advice)", "consultation_updates": "Consultation updates", + "contact_info": "Contact Info", "contact_number": "Contact Number", "contact_person": "Name of Contact Person at Facility", "contact_person_at_the_facility": "Contact person at the current facility", diff --git a/src/components/Shifting/ShiftingList.tsx b/src/components/Shifting/ShiftingList.tsx index 3af77809d7c..d4746ad434b 100644 --- a/src/components/Shifting/ShiftingList.tsx +++ b/src/components/Shifting/ShiftingList.tsx @@ -1,3 +1,4 @@ +import careConfig from "@careConfig"; import { navigate } from "raviger"; import { useState } from "react"; import { useTranslation } from "react-i18next"; @@ -13,15 +14,16 @@ import Page from "@/components/Common/Page"; import { ShiftingModel } from "@/components/Facility/models"; import SearchInput from "@/components/Form/SearchInput"; import BadgesList from "@/components/Shifting/ShiftingBadges"; -import ShiftingBlock from "@/components/Shifting/ShiftingBlock"; import { formatFilter } from "@/components/Shifting/ShiftingCommons"; import ListFilter from "@/components/Shifting/ShiftingFilters"; +import useAuthUser from "@/hooks/useAuthUser"; import useFilters from "@/hooks/useFilters"; import routes from "@/Utils/request/api"; import request from "@/Utils/request/request"; import useQuery from "@/Utils/request/useQuery"; +import { formatDateTime } from "@/Utils/utils"; export default function ListView() { const { @@ -31,19 +33,31 @@ export default function ListView() { FilterBadges, advancedFilter, resultsPerPage, - } = useFilters({ cacheBlacklist: ["patient_name"], limit: 12 }); + } = useFilters({ cacheBlacklist: ["patient_name"] }); - const [modalFor, setModalFor] = useState(); + const [modalFor, setModalFor] = useState<{ + externalId: string | undefined; + loading: boolean; + }>({ + externalId: undefined, + loading: false, + }); + + const authUser = useAuthUser(); const { t } = useTranslation(); - const handleTransferComplete = async (shift?: ShiftingModel) => { - if (!shift) return; - await request(routes.completeTransfer, { - pathParams: { externalId: shift.external_id }, - }); - navigate( - `/facility/${shift.assigned_facility}/patient/${shift.patient}/consultation`, - ); + const handleTransferComplete = async (shift: ShiftingModel) => { + setModalFor({ ...modalFor, loading: true }); + try { + await request(routes.completeTransfer, { + pathParams: { externalId: shift.external_id }, + }); + navigate( + `/facility/${shift.assigned_facility}/patient/${shift.patient}/consultation`, + ); + } catch (error) { + setModalFor({ externalId: undefined, loading: false }); + } }; const { @@ -53,7 +67,6 @@ export default function ListView() { } = useQuery(routes.listShiftRequests, { query: formatFilter({ ...qParams, - limit: resultsPerPage, offset: (qParams.page ? qParams.page - 1 : 0) * resultsPerPage, }), }); @@ -62,42 +75,173 @@ export default function ListView() { if (loading) { return ; } - - if (!data || data.length === 0) { + if (data && !data.length) { return ( -
-
- {t("no_patients_to_show")} -
+
+ {t("no_patients_to_show")}
); } - return ( -
-
- {data.map((shift, i) => ( -
- setModalFor(shift)} - shift={shift} - /> + return data.map((shift: ShiftingModel) => ( +
+
+
+
+ {shift.patient_object.name} +
+
+ {shift.patient_object.age} +
+
+ +
+
+
+ +
+ {shift.patient_object.phone_number || ""} +
+
- ))} +
+
+ +
+ {shift.patient_object.address || "--"} +
+ +
+
+ +
+
+
+ +
{shift.status}
+ + +
+ {shift.emergency && ( + + {t("emergency")} + + )} +
+
+ +
+
+ +
+ {formatDateTime(shift.modified_date) || "--"} +
+ +
+
+ +
+
+ +
+ {shift.origin_facility_object?.name} +
+ + + {careConfig.wartimeShifting && ( +
+ +
+ {shift.shifting_approving_facility_object?.name} +
+ + )} + +
+ +
+ {shift.assigned_facility_external || + shift.assigned_facility_object?.name || + t("yet_to_be_decided")} +
+ +
+
+ navigate(`/shifting/${shift.external_id}`)} + variant="secondary" + border + className="w-full" + > + {t("all_details")} + + {shift.status === "COMPLETED" && shift.assigned_facility && ( +
+ + setModalFor({ + externalId: shift.external_id, + loading: false, + }) + } + > + {t("transfer_to_receiving_facility")} + + + setModalFor({ externalId: undefined, loading: false }) + } + onConfirm={() => handleTransferComplete(shift)} + /> +
+ )} +
- setModalFor(undefined)} - onConfirm={() => handleTransferComplete(modalFor)} - />
- ); + )); }; return ( @@ -118,7 +262,9 @@ export default function ListView() { breadcrumbs={false} options={ <> -
+
+ +
-
- {/* dummy div to align space as per board view */} -
-
+ +
+ advancedFilter.setShow(true)} + /> navigate("/shifting/board", { query: qParams })} @@ -137,10 +284,6 @@ export default function ListView() { {t("board_view")} - - advancedFilter.setShow(true)} - />
} @@ -151,9 +294,9 @@ export default function ListView() { ) : (
-
+
- - {showShiftingCardList(shiftData?.results || [])} +
+
+
+ {t("patients")} +
+
+ {t("contact_info")} +
+
+ {t("consent__status")} +
+
+ {t("facilities")} +
+
+ {t("LOG_UPDATE_FIELD_LABEL__action")} +
+
+
{showShiftingCardList(shiftData?.results || [])}
+