diff --git a/src/Routers/PatientRouter.tsx b/src/Routers/PatientRouter.tsx index 123c151350e..17388ffa74e 100644 --- a/src/Routers/PatientRouter.tsx +++ b/src/Routers/PatientRouter.tsx @@ -37,14 +37,14 @@ const tokenData: TokenData = JSON.parse( ); export const PatientUserContext = createContext<{ - users?: AppointmentPatient[]; - selectedUser: AppointmentPatient | null; - setSelectedUser: (user: AppointmentPatient) => void; + patients?: AppointmentPatient[]; + selectedPatient: AppointmentPatient | null; + setSelectedPatient: (patient: AppointmentPatient) => void; tokenData: TokenData; }>({ - users: undefined, - selectedUser: null, - setSelectedUser: () => {}, + patients: undefined, + selectedPatient: null, + setSelectedPatient: () => {}, tokenData: tokenData, }); @@ -53,10 +53,9 @@ export default function PatientRouter() { const path = usePath(); const [sidebarOpen, setSidebarOpen] = useState(false); - const [users, setUsers] = useState([]); - const [selectedUser, setSelectedUser] = useState( - null, - ); + const [patients, setPatients] = useState([]); + const [selectedPatient, setSelectedPatient] = + useState(null); const { data: userData } = useQuery({ queryKey: ["patients", tokenData.phoneNumber], @@ -70,8 +69,15 @@ export default function PatientRouter() { useEffect(() => { if (userData) { - setUsers(userData.results); - setSelectedUser(userData.results[0]); + setPatients(userData.results); + const localPatient: AppointmentPatient | undefined = JSON.parse( + localStorage.getItem("selectedPatient") || "{}", + ); + const selectedPatient = + userData.results.find((patient) => patient.id === localPatient?.id) || + userData.results[0]; + setSelectedPatient(selectedPatient); + localStorage.setItem("selectedPatient", JSON.stringify(selectedPatient)); } }, [userData]); @@ -98,7 +104,12 @@ export default function PatientRouter() { return (
diff --git a/src/components/Common/Sidebar/PatientSidebar.tsx b/src/components/Common/Sidebar/PatientSidebar.tsx index 5fdf8345d12..fc746ab8cba 100644 --- a/src/components/Common/Sidebar/PatientSidebar.tsx +++ b/src/components/Common/Sidebar/PatientSidebar.tsx @@ -115,16 +115,16 @@ export const PatientStatelessSidebar = ({ const [lastIndicatorPosition, setLastIndicatorPosition] = useState(0); const [isOverflowVisible, setOverflowVisisble] = useState(false); const { - users, - selectedUser, - setSelectedUser, + patients, + selectedPatient, + setSelectedPatient, }: { - users?: AppointmentPatient[] | undefined; - selectedUser: AppointmentPatient | null; - setSelectedUser: (user: AppointmentPatient) => void; + patients?: AppointmentPatient[] | undefined; + selectedPatient: AppointmentPatient | null; + setSelectedPatient: (patient: AppointmentPatient) => void; } = useContext(PatientUserContext); - const NavItems = GetNavItems(selectedUser); + const NavItems = GetNavItems(selectedPatient); const updateIndicator = () => { if (!indicatorRef.current) return; @@ -212,12 +212,16 @@ export const PatientStatelessSidebar = ({ )} >