diff --git a/src/Components/Common/components/SwitchTabs.tsx b/src/Components/Common/components/SwitchTabs.tsx index a7872d5a400..6bf510c085e 100644 --- a/src/Components/Common/components/SwitchTabs.tsx +++ b/src/Components/Common/components/SwitchTabs.tsx @@ -4,8 +4,8 @@ import { classNames } from "../../../Utils/utils"; export default function SwitchTabs(props: { className?: string; isTab2Active: boolean; - onClickTab1: () => void; - onClickTab2: () => void; + onClickTab1?: () => void; + onClickTab2?: () => void; tab1: ReactNode; tab2: ReactNode; }) { diff --git a/src/Components/Facility/DischargedPatientsList.tsx b/src/Components/Facility/DischargedPatientsList.tsx index 3ca965a435f..2d4c262c0e7 100644 --- a/src/Components/Facility/DischargedPatientsList.tsx +++ b/src/Components/Facility/DischargedPatientsList.tsx @@ -35,7 +35,7 @@ const DischargedPatientsList = ({ options={ <> - navigate(`/patients?facility=${facility_external_id}`) - } - onClickTab2={() => { - // Voluntarily doing nothing since we are already in the dedicated discharged patients list page... - }} + onClickTab1={() => navigate("/patients")} isTab2Active /> diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index 212be41b36a..710b2ca067f 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -103,7 +103,7 @@ export const PatientManager = () => { }); const authUser = useAuthUser(); const [diagnoses, setDiagnoses] = useState([]); - const [showDialog, setShowDialog] = useState(false); + const [showDialog, setShowDialog] = useState<"create" | "list-discharged">(); const [showDoctors, setShowDoctors] = useState(false); const [showDoctorConnect, setShowDoctorConnect] = useState(false); const [phone_number, setPhoneNumber] = useState(""); @@ -743,7 +743,7 @@ export const PatientManager = () => { navigate(`/facility/${qParams.facility}/patient`); else if (onlyAccessibleFacility) navigate(`/facility/${onlyAccessibleFacility.id}/patient`); - else setShowDialog(true); + else setShowDialog("create"); }} className="w-full lg:w-fit" > @@ -754,40 +754,30 @@ export const PatientManager = () => {
- {(authUser.user_type === "StateAdmin" || - authUser.user_type === "StateReadOnlyAdmin" || - permittedFacilities?.count === 1 || - qParams.facility) && ( - updateQuery({ is_active: "True" })} - onClickTab2={() => { - if (qParams.facility) { - navigate( - `facility/${qParams.facility}/discharged-patients` - ); - return; - } + updateQuery({ is_active: "True" })} + onClickTab2={() => { + // Navigate to dedicated discharged list page if filtered by a facility or user has access only to one facility. + const id = qParams.facility || onlyAccessibleFacility?.id; + if (id) { + navigate(`facility/${id}/discharged-patients`); + return; + } - if (onlyAccessibleFacility) { - navigate( - `facility/${onlyAccessibleFacility.id}/discharged-patients` - ); - return; - } + if ( + authUser.user_type === "StateAdmin" || + authUser.user_type === "StateReadOnlyAdmin" + ) { + updateQuery({ is_active: "False" }); + return; + } - if ( - authUser.user_type === "StateAdmin" || - authUser.user_type === "StateReadOnlyAdmin" - ) { - updateQuery({ is_active: "False" }); - return; - } - }} - isTab2Active={tabValue ? true : false} - /> - )} + setShowDialog("list-discharged"); + }} + isTab2Active={!!tabValue} + /> {showDoctorConnect && ( { } > setSelectedFacility(e)} selectedFacility={selectedFacility} - handleOk={() => navigate(`facility/${selectedFacility.id}/patient`)} + handleOk={() => { + switch (showDialog) { + case "create": + navigate(`facility/${selectedFacility.id}/patient`); + break; + case "list-discharged": + navigate(`facility/${selectedFacility.id}/discharged-patients`); + break; + } + }} handleCancel={() => { - setShowDialog(false); + setShowDialog(undefined); setSelectedFacility({ name: "" }); }} />