Skip to content

Commit

Permalink
Replace all window.location.reload() with data refetch. (#6892)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sriharsh05 authored and Ashesh3 committed Jan 2, 2024
1 parent 77366d0 commit 923993e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
5 changes: 3 additions & 2 deletions src/Components/Assets/AssetImportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>();
const [preview, setPreview] =
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/Components/Assets/AssetsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -436,6 +436,7 @@ const AssetsList = () => {
return f;
});
}}
onUpdate={assetsFetch}
facility={facility}
/>
)}
Expand Down
2 changes: 0 additions & 2 deletions src/Components/Facility/CoverImageEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand All @@ -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();
Expand Down
7 changes: 2 additions & 5 deletions src/Components/Facility/DischargeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -163,7 +160,7 @@ const DischargeModal = ({
msg: "Patient Discharged Successfully",
});

afterSubmit();
afterSubmit?.();
}
};

Expand Down
31 changes: 16 additions & 15 deletions src/Components/Facility/FacilityHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 ? (
Expand Down
8 changes: 7 additions & 1 deletion src/Components/Patient/PatientInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,13 @@ export default function PatientInfoCard(props: {
/>
<DischargeModal
show={openDischargeDialog}
onClose={() => setOpenDischargeDialog(false)}
onClose={() => {
setOpenDischargeDialog(false);
}}
afterSubmit={() => {
setOpenDischargeDialog(false);
props.fetchPatientData?.({ aborted: false });
}}
consultationData={consultation}
/>
</>
Expand Down

0 comments on commit 923993e

Please sign in to comment.