Skip to content

Commit

Permalink
removed unnecessary data fetch calls
Browse files Browse the repository at this point in the history
  • Loading branch information
sriharsh05 committed Dec 21, 2023
1 parent 754f34a commit 0daec4e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/Components/Assets/AssetImportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const AssetImportModal = ({ open, onClose, facility, onUpdate }: Props) => {
Notification.Success({ msg: "Assets imported successfully" });
await sleep(1000);
setIsImporting(false);
onUpdate && onUpdate();
onUpdate?.();
} else {
Notification.Error({ msg: "Error importing some assets" });
await sleep(1000);
Expand Down
48 changes: 18 additions & 30 deletions src/Components/Assets/AssetsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,16 @@ const AssetsList = () => {
},
});

const { data: facilityObject, refetch: facilityFetch } = useQuery(
routes.getAnyFacility,
{
pathParams: { id: qParams.facility },
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setFacility(data);
setSelectedFacility(data);
}
},
prefetch: !!qParams.facility,
}
);
const { data: facilityObject } = useQuery(routes.getAnyFacility, {
pathParams: { id: qParams.facility },
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setFacility(data);
setSelectedFacility(data);
}
},
prefetch: !!qParams.facility,
});

useEffect(() => {
setAssetType(qParams.asset_type);
Expand All @@ -105,16 +102,13 @@ const AssetsList = () => {
setAssetClass(qParams.asset_class);
}, [qParams.asset_class]);

const { data: locationObject, refetch: locationFetch } = useQuery(
routes.getFacilityAssetLocation,
{
pathParams: {
facility_external_id: String(qParams.facility),
external_id: String(qParams.location),
},
prefetch: !!(qParams.facility && qParams.location),
}
);
const { data: locationObject } = useQuery(routes.getFacilityAssetLocation, {
pathParams: {
facility_external_id: String(qParams.facility),
external_id: String(qParams.location),
},
prefetch: !!(qParams.facility && qParams.location),
});

const getAssetIdFromQR = async (assetUrl: string) => {
try {
Expand All @@ -134,12 +128,6 @@ const AssetsList = () => {
}
};

const handleUpdate = () => {
assetsFetch();
facilityFetch();
locationFetch();
};

const checkValidAssetId = async (assetId: string) => {
const { data: assetData } = await request(routes.getAsset, {
pathParams: { id: assetId },
Expand Down Expand Up @@ -448,7 +436,7 @@ const AssetsList = () => {
return f;
});
}}
onUpdate={handleUpdate}
onUpdate={assetsFetch}
facility={facility}
/>
)}
Expand Down
6 changes: 2 additions & 4 deletions src/Components/Facility/DischargeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ const DischargeModal = ({
show,
onClose,
consultationData,
afterSubmit = () => {
onClose();
},
afterSubmit,
discharge_reason = "",
discharge_notes = "",
discharge_date = dayjs().format("YYYY-MM-DDTHH:mm"),
Expand Down Expand Up @@ -162,7 +160,7 @@ const DischargeModal = ({
msg: "Patient Discharged Successfully",
});

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

Expand Down
6 changes: 4 additions & 2 deletions src/Components/Patient/PatientInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ export default function PatientInfoCard(props: {
show={openDischargeDialog}
onClose={() => {
setOpenDischargeDialog(false);
props.fetchPatientData &&
props.fetchPatientData({ aborted: false });
}}
afterSubmit={() => {
setOpenDischargeDialog(false);
props.fetchPatientData?.({ aborted: false });
}}
consultationData={consultation}
/>
Expand Down

0 comments on commit 0daec4e

Please sign in to comment.