From 283504d89f1171207e5529cc6e552fc706ba4b5a Mon Sep 17 00:00:00 2001 From: Gampa Sri Harsh <114745442+sriharsh05@users.noreply.github.com> Date: Thu, 28 Dec 2023 06:40:44 +0530 Subject: [PATCH] Replace all window.location.reload() with data refetch. (#6892) * replaced window.location.reload with appropriate fetchdata function in patient discharge * replaced window.location.reload with appropriate refetch while updating facility cover image * replaced window.location.reload with appropriate refetch in assetImportModal * replaced wimdow.location.reload with appropriate refecth in update app * Reverted changes made related to UpdatableApp * removed unnecessary data fetch calls --- src/Components/Assets/AssetImportModal.tsx | 5 +-- src/Components/Assets/AssetsList.tsx | 3 +- .../Facility/CoverImageEditModal.tsx | 2 -- src/Components/Facility/DischargeModal.tsx | 7 ++--- src/Components/Facility/FacilityHome.tsx | 31 ++++++++++--------- src/Components/Patient/PatientInfoCard.tsx | 8 ++++- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/Components/Assets/AssetImportModal.tsx b/src/Components/Assets/AssetImportModal.tsx index 02fe1d90265..adab83c744c 100644 --- a/src/Components/Assets/AssetImportModal.tsx +++ b/src/Components/Assets/AssetImportModal.tsx @@ -22,9 +22,10 @@ interface Props { open: boolean; onClose: (() => void) | undefined; facility: FacilityModel; + onUpdate?: (() => void) | undefined; } -const AssetImportModal = ({ open, onClose, facility }: Props) => { +const AssetImportModal = ({ open, onClose, facility, onUpdate }: Props) => { const [isImporting, setIsImporting] = useState(false); const [selectedFile, setSelectedFile] = useState(); const [preview, setPreview] = @@ -170,7 +171,7 @@ const AssetImportModal = ({ open, onClose, facility }: Props) => { Notification.Success({ msg: "Assets imported successfully" }); await sleep(1000); setIsImporting(false); - window.location.reload(); + onUpdate?.(); } else { Notification.Error({ msg: "Error importing some assets" }); await sleep(1000); diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx index 447bff1c1d0..3fc9c9f9f14 100644 --- a/src/Components/Assets/AssetsList.tsx +++ b/src/Components/Assets/AssetsList.tsx @@ -69,7 +69,7 @@ const AssetsList = () => { qParams.warranty_amc_end_of_validity_after || "", }; - const { loading } = useQuery(routes.listAssets, { + const { refetch: assetsFetch, loading } = useQuery(routes.listAssets, { query: params, onResponse: ({ res, data }) => { if (res?.status === 200 && data) { @@ -436,6 +436,7 @@ const AssetsList = () => { return f; }); }} + onUpdate={assetsFetch} facility={facility} /> )} diff --git a/src/Components/Facility/CoverImageEditModal.tsx b/src/Components/Facility/CoverImageEditModal.tsx index a1394c6441f..4d723214604 100644 --- a/src/Components/Facility/CoverImageEditModal.tsx +++ b/src/Components/Facility/CoverImageEditModal.tsx @@ -123,7 +123,6 @@ const CoverImageEditModal = ({ ); if (response.status === 200) { Success({ msg: "Cover image updated." }); - window.location.reload(); } else { Notification.Error({ msg: "Something went wrong!", @@ -148,7 +147,6 @@ const CoverImageEditModal = ({ const res = await dispatch(deleteFacilityCoverImage(facility.id as any)); if (res.statusCode === 204) { Success({ msg: "Cover image deleted" }); - window.location.reload(); } onDelete && onDelete(); diff --git a/src/Components/Facility/DischargeModal.tsx b/src/Components/Facility/DischargeModal.tsx index 46bdf866e90..a15af4d3883 100644 --- a/src/Components/Facility/DischargeModal.tsx +++ b/src/Components/Facility/DischargeModal.tsx @@ -50,10 +50,7 @@ const DischargeModal = ({ show, onClose, consultationData, - afterSubmit = () => { - onClose(); - window.location.reload(); - }, + afterSubmit, discharge_reason = "", discharge_notes = "", discharge_date = dayjs().format("YYYY-MM-DDTHH:mm"), @@ -163,7 +160,7 @@ const DischargeModal = ({ msg: "Patient Discharged Successfully", }); - afterSubmit(); + afterSubmit?.(); } }; diff --git a/src/Components/Facility/FacilityHome.tsx b/src/Components/Facility/FacilityHome.tsx index b36a3a7b36d..2341d231675 100644 --- a/src/Components/Facility/FacilityHome.tsx +++ b/src/Components/Facility/FacilityHome.tsx @@ -54,19 +54,20 @@ export const FacilityHome = (props: any) => { useMessageListener((data) => console.log(data)); - const { data: facilityData, loading: isLoading } = useQuery( - routes.getPermittedFacility, - { - pathParams: { - id: facilityId, - }, - onResponse: ({ res }) => { - if (!res?.ok) { - navigate("/not-found"); - } - }, - } - ); + const { + data: facilityData, + loading: isLoading, + refetch: facilityFetch, + } = useQuery(routes.getPermittedFacility, { + pathParams: { + id: facilityId, + }, + onResponse: ({ res }) => { + if (!res?.ok) { + navigate("/not-found"); + } + }, + }); const handleDeleteClose = () => { setOpenDeleteDialog(false); @@ -139,10 +140,10 @@ export const FacilityHome = (props: any) => { onSave={() => facilityData?.read_cover_image_url ? setImageKey(Date.now()) - : window.location.reload() + : facilityFetch() } onClose={() => setEditCoverImage(false)} - onDelete={() => window.location.reload()} + onDelete={() => facilityFetch()} facility={facilityData ?? ({} as FacilityModel)} /> {hasCoverImage ? ( diff --git a/src/Components/Patient/PatientInfoCard.tsx b/src/Components/Patient/PatientInfoCard.tsx index b9d1d256566..c5087f13dda 100644 --- a/src/Components/Patient/PatientInfoCard.tsx +++ b/src/Components/Patient/PatientInfoCard.tsx @@ -141,7 +141,13 @@ export default function PatientInfoCard(props: { /> setOpenDischargeDialog(false)} + onClose={() => { + setOpenDischargeDialog(false); + }} + afterSubmit={() => { + setOpenDischargeDialog(false); + props.fetchPatientData?.({ aborted: false }); + }} consultationData={consultation} />