diff --git a/src/components/Assets/AssetsList.tsx b/src/components/Assets/AssetsList.tsx index 4212fae5d96..685d7dfa460 100644 --- a/src/components/Assets/AssetsList.tsx +++ b/src/components/Assets/AssetsList.tsx @@ -52,9 +52,7 @@ const AssetsList = () => { const [importAssetModalOpen, setImportAssetModalOpen] = useState(false); const assetsExist = assets.length > 0 && Object.keys(assets[0]).length > 0; const [showFacilityDialog, setShowFacilityDialog] = useState(false); - const [selectedFacility, setSelectedFacility] = useState({ - name: "", - }); + const [selectedFacility, setSelectedFacility] = useState(); const params = { limit: resultsPerPage, page: qParams.page, @@ -460,15 +458,11 @@ const AssetsList = () => { )} - {typeof facility === "undefined" && ( + {facility == null && ( setFacility(e)} - selectedFacility={ - facility ?? { - name: "", - } - } + selectedFacility={selectedFacility} handleOk={() => { return undefined; }} @@ -497,10 +491,16 @@ const AssetsList = () => { show={showFacilityDialog} setSelected={(e) => setSelectedFacility(e)} selectedFacility={selectedFacility} - handleOk={() => navigate(`facility/${selectedFacility.id}/assets/new`)} + handleOk={() => { + if (selectedFacility) { + navigate(`facility/${selectedFacility.id}/assets/new`); + } else { + Notification.Warn({ msg: "No facility selected" }); + } + }} handleCancel={() => { setShowFacilityDialog(false); - setSelectedFacility({ name: "" }); + setSelectedFacility(undefined); }} /> diff --git a/src/components/ExternalResult/FacilitiesSelectDialogue.tsx b/src/components/ExternalResult/FacilitiesSelectDialogue.tsx index 66e290c069d..9e8bb4fbf06 100644 --- a/src/components/ExternalResult/FacilitiesSelectDialogue.tsx +++ b/src/components/ExternalResult/FacilitiesSelectDialogue.tsx @@ -11,7 +11,7 @@ interface Props { show: boolean; handleOk: () => void; handleCancel: () => void; - selectedFacility: FacilityModel; + selectedFacility: FacilityModel | null | undefined; setSelected: (e: any) => void; } diff --git a/src/components/Patient/ManagePatients.tsx b/src/components/Patient/ManagePatients.tsx index 65fc0e73933..25a1f9166ed 100644 --- a/src/components/Patient/ManagePatients.tsx +++ b/src/components/Patient/ManagePatients.tsx @@ -100,9 +100,7 @@ export const PatientManager = () => { "emergency_phone_number", ], }); - const [selectedFacility, setSelectedFacility] = useState({ - name: "", - }); + const [selectedFacility, setSelectedFacility] = useState(); const authUser = useAuthUser(); const [diagnoses, setDiagnoses] = useState([]); const [showDialog, setShowDialog] = useState<"create" | "list-discharged">(); @@ -976,18 +974,22 @@ export const PatientManager = () => { setSelected={(e) => setSelectedFacility(e)} selectedFacility={selectedFacility} handleOk={() => { - switch (showDialog) { - case "create": - navigate(`facility/${selectedFacility.id}/patient`); - break; - case "list-discharged": - navigate(`facility/${selectedFacility.id}/discharged-patients`); - break; + if (selectedFacility) { + switch (showDialog) { + case "create": + navigate(`facility/${selectedFacility.id}/patient`); + break; + case "list-discharged": + navigate(`facility/${selectedFacility.id}/discharged-patients`); + break; + } + } else { + Notification.Error({ msg: "No facility selected" }); } }} handleCancel={() => { setShowDialog(undefined); - setSelectedFacility({ name: "" }); + setSelectedFacility(undefined); }} />