From 1652f5b211893d582b959917dfec56cdc15ceaa3 Mon Sep 17 00:00:00 2001 From: Mahendar Chikolla <119734520+Mahendar0701@users.noreply.github.com> Date: Tue, 7 Jan 2025 19:46:34 +0530 Subject: [PATCH] cleanup CarePatientTokenKey (#9827) --- src/Providers/PatientUserProvider.tsx | 4 ++-- src/common/constants.tsx | 5 ----- src/hooks/usePatientSignOut.ts | 4 ++-- src/pages/Appoinments/PatientRegistration.tsx | 4 ++-- src/pages/Appoinments/PatientSelect.tsx | 4 ++-- src/pages/Appoinments/Schedule.tsx | 4 ++-- src/pages/Appoinments/Success.tsx | 4 ++-- src/pages/Appoinments/auth/PatientLogin.tsx | 13 ++++++++----- src/pages/Facility/components/UserCard.tsx | 9 +++++---- 9 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/Providers/PatientUserProvider.tsx b/src/Providers/PatientUserProvider.tsx index e7705b1b797..3ec0c5f038a 100644 --- a/src/Providers/PatientUserProvider.tsx +++ b/src/Providers/PatientUserProvider.tsx @@ -4,7 +4,7 @@ import { createContext, useEffect, useState } from "react"; import { SidebarProvider } from "@/components/ui/sidebar"; import { AppSidebar } from "@/components/ui/sidebar/app-sidebar"; -import { CarePatientTokenKey } from "@/common/constants"; +import { LocalStorageKeys } from "@/common/constants"; import routes from "@/Utils/request/api"; import query from "@/Utils/request/query"; @@ -12,7 +12,7 @@ import { AppointmentPatient } from "@/pages/Patient/Utils"; import { TokenData } from "@/types/auth/otpToken"; const tokenData: TokenData = JSON.parse( - localStorage.getItem(CarePatientTokenKey) || "{}", + localStorage.getItem(LocalStorageKeys.patientTokenKey) || "{}", ); export type PatientUserContextType = { diff --git a/src/common/constants.tsx b/src/common/constants.tsx index 39fe769520c..64af8d373ac 100644 --- a/src/common/constants.tsx +++ b/src/common/constants.tsx @@ -1757,8 +1757,3 @@ export const HEADER_CONTENT_TYPES = { } as const; export const ADMIN_USER_TYPES = ["DistrictAdmin", "StateAdmin"] as const; - -/** - * @deprecated use `LocalStorageKeys.patientTokenKey` instead - */ -export const CarePatientTokenKey = LocalStorageKeys.patientTokenKey; diff --git a/src/hooks/usePatientSignOut.ts b/src/hooks/usePatientSignOut.ts index 1f10d2c5234..4b48b2886bc 100644 --- a/src/hooks/usePatientSignOut.ts +++ b/src/hooks/usePatientSignOut.ts @@ -1,7 +1,7 @@ import { navigate } from "raviger"; import { useCallback } from "react"; -import { CarePatientTokenKey } from "@/common/constants"; +import { LocalStorageKeys } from "@/common/constants"; const getRedirectURL = () => { return new URLSearchParams(window.location.search).get("redirect"); @@ -9,7 +9,7 @@ const getRedirectURL = () => { export const usePatientSignOut = () => { const signOut = useCallback(async () => { - localStorage.removeItem(CarePatientTokenKey); + localStorage.removeItem(LocalStorageKeys.patientTokenKey); localStorage.removeItem("selectedPatient"); const redirectURL = getRedirectURL(); diff --git a/src/pages/Appoinments/PatientRegistration.tsx b/src/pages/Appoinments/PatientRegistration.tsx index 0e4ada8b57f..cbbd2ce5fe6 100644 --- a/src/pages/Appoinments/PatientRegistration.tsx +++ b/src/pages/Appoinments/PatientRegistration.tsx @@ -29,7 +29,7 @@ import { SlotAvailability, } from "@/components/Schedule/types"; -import { CarePatientTokenKey, GENDER_TYPES } from "@/common/constants"; +import { GENDER_TYPES, LocalStorageKeys } from "@/common/constants"; import { validateName, validatePincode } from "@/common/validation"; import * as Notification from "@/Utils/Notifications"; @@ -73,7 +73,7 @@ export function PatientRegistration(props: PatientRegistrationProps) { ) as SlotAvailability; const reason = localStorage.getItem("reason"); const tokenData: TokenData = JSON.parse( - localStorage.getItem(CarePatientTokenKey) || "{}", + localStorage.getItem(LocalStorageKeys.patientTokenKey) || "{}", ); const { t } = useTranslation(); diff --git a/src/pages/Appoinments/PatientSelect.tsx b/src/pages/Appoinments/PatientSelect.tsx index 1dd8d75f626..d3379d6c000 100644 --- a/src/pages/Appoinments/PatientSelect.tsx +++ b/src/pages/Appoinments/PatientSelect.tsx @@ -15,7 +15,7 @@ import { SlotAvailability, } from "@/components/Schedule/types"; -import { CarePatientTokenKey } from "@/common/constants"; +import { LocalStorageKeys } from "@/common/constants"; import * as Notification from "@/Utils/Notifications"; import routes from "@/Utils/request/api"; @@ -39,7 +39,7 @@ export default function PatientSelect({ ) as SlotAvailability; const reason = localStorage.getItem("reason"); const tokenData: TokenData = JSON.parse( - localStorage.getItem(CarePatientTokenKey) || "{}", + localStorage.getItem(LocalStorageKeys.patientTokenKey) || "{}", ); const [selectedPatient, setSelectedPatient] = useState(null); diff --git a/src/pages/Appoinments/Schedule.tsx b/src/pages/Appoinments/Schedule.tsx index e31b63a71a8..1b0423afcd7 100644 --- a/src/pages/Appoinments/Schedule.tsx +++ b/src/pages/Appoinments/Schedule.tsx @@ -20,7 +20,7 @@ import { FacilityModel } from "@/components/Facility/models"; import { groupSlotsByAvailability } from "@/components/Schedule/Appointments/utils"; import { SlotAvailability } from "@/components/Schedule/types"; -import { CarePatientTokenKey } from "@/common/constants"; +import { LocalStorageKeys } from "@/common/constants"; import * as Notification from "@/Utils/Notifications"; import routes from "@/Utils/request/api"; @@ -45,7 +45,7 @@ export function ScheduleAppointment(props: AppointmentsProps) { const [reason, setReason] = useState(""); const tokenData: TokenData = JSON.parse( - localStorage.getItem(CarePatientTokenKey) || "{}", + localStorage.getItem(LocalStorageKeys.patientTokenKey) || "{}", ); if (!staffId) { diff --git a/src/pages/Appoinments/Success.tsx b/src/pages/Appoinments/Success.tsx index ff3e63c3d32..14ce2cb209a 100644 --- a/src/pages/Appoinments/Success.tsx +++ b/src/pages/Appoinments/Success.tsx @@ -7,7 +7,7 @@ import CareIcon from "@/CAREUI/icons/CareIcon"; import Loading from "@/components/Common/Loading"; import { UserModel } from "@/components/Users/models"; -import { CarePatientTokenKey } from "@/common/constants"; +import { LocalStorageKeys } from "@/common/constants"; import * as Notification from "@/Utils/Notifications"; import query from "@/Utils/request/query"; @@ -19,7 +19,7 @@ export function AppointmentSuccess(props: { appointmentId: string }) { const { appointmentId } = props; const { t } = useTranslation(); const tokenData: TokenData = JSON.parse( - localStorage.getItem(CarePatientTokenKey) || "{}", + localStorage.getItem(LocalStorageKeys.patientTokenKey) || "{}", ); const userData: UserModel = JSON.parse(localStorage.getItem("user") ?? "{}"); diff --git a/src/pages/Appoinments/auth/PatientLogin.tsx b/src/pages/Appoinments/auth/PatientLogin.tsx index 5b1ae45f76e..e8d22387090 100644 --- a/src/pages/Appoinments/auth/PatientLogin.tsx +++ b/src/pages/Appoinments/auth/PatientLogin.tsx @@ -29,7 +29,7 @@ import PhoneNumberFormField from "@/components/Form/FormFields/PhoneNumberFormFi import useAppHistory from "@/hooks/useAppHistory"; -import { CarePatientTokenKey } from "@/common/constants"; +import { LocalStorageKeys } from "@/common/constants"; import * as Notification from "@/Utils/Notifications"; import routes from "@/Utils/request/api"; @@ -66,7 +66,7 @@ export default function PatientLogin({ }); const tokenData: TokenData = JSON.parse( - localStorage.getItem(CarePatientTokenKey) || "{}", + localStorage.getItem(LocalStorageKeys.patientTokenKey) || "{}", ); if ( @@ -101,7 +101,7 @@ export default function PatientLogin({ onSuccess: () => { if (page === "send") { const tokenData: TokenData = JSON.parse( - localStorage.getItem(CarePatientTokenKey) || "{}", + localStorage.getItem(LocalStorageKeys.patientTokenKey) || "{}", ); if ( Object.keys(tokenData).length > 0 && @@ -160,7 +160,10 @@ export default function PatientLogin({ phoneNumber: phoneNumber, createdAt: new Date().toISOString(), }; - localStorage.setItem(CarePatientTokenKey, JSON.stringify(tokenData)); + localStorage.setItem( + LocalStorageKeys.patientTokenKey, + JSON.stringify(tokenData), + ); navigate( `/facility/${facilityId}/appointments/${staffId}/book-appointment`, ); @@ -294,7 +297,7 @@ export default function PatientLogin({ } > - Back + {t("back")} {page === "send" ? renderPhoneNumberForm() : renderVerifyForm()} diff --git a/src/pages/Facility/components/UserCard.tsx b/src/pages/Facility/components/UserCard.tsx index 7ae0221e4ff..29798a96d62 100644 --- a/src/pages/Facility/components/UserCard.tsx +++ b/src/pages/Facility/components/UserCard.tsx @@ -1,4 +1,5 @@ import dayjs from "dayjs"; +import { t } from "i18next"; import { navigate } from "raviger"; import { useMemo } from "react"; @@ -10,7 +11,7 @@ import { Card } from "@/components/ui/card"; import { Avatar } from "@/components/Common/Avatar"; import { UserAssignedModel } from "@/components/Users/models"; -import { CarePatientTokenKey } from "@/common/constants"; +import { LocalStorageKeys } from "@/common/constants"; import { formatName } from "@/Utils/utils"; import { TokenData } from "@/types/auth/otpToken"; @@ -28,7 +29,7 @@ export function UserCard({ user, className, facilityId }: Props) { }); const tokenData: TokenData = JSON.parse( - localStorage.getItem(CarePatientTokenKey) || "{}", + localStorage.getItem(LocalStorageKeys.patientTokenKey) || "{}", ); const returnLink = useMemo(() => { @@ -58,7 +59,7 @@ export function UserCard({ user, className, facilityId }: Props) { {user.qualification && ( <> -

Education:

+

{t("education")}:

{user.qualification}

@@ -77,7 +78,7 @@ export function UserCard({ user, className, facilityId }: Props) { navigate(returnLink); }} > - Book Appointment + {t("book_appointment")}