Skip to content

Commit

Permalink
cleanup CarePatientTokenKey (#9827)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahendar0701 authored and khavinshankar committed Jan 8, 2025
1 parent 68cb994 commit 1652f5b
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/Providers/PatientUserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ 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";
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 = {
Expand Down
5 changes: 0 additions & 5 deletions src/common/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions src/hooks/usePatientSignOut.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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");
};

export const usePatientSignOut = () => {
const signOut = useCallback(async () => {
localStorage.removeItem(CarePatientTokenKey);
localStorage.removeItem(LocalStorageKeys.patientTokenKey);
localStorage.removeItem("selectedPatient");

const redirectURL = getRedirectURL();
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Appoinments/PatientRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Appoinments/PatientSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<string | null>(null);

Expand Down
4 changes: 2 additions & 2 deletions src/pages/Appoinments/Schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Appoinments/Success.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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") ?? "{}");

Expand Down
13 changes: 8 additions & 5 deletions src/pages/Appoinments/auth/PatientLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -66,7 +66,7 @@ export default function PatientLogin({
});

const tokenData: TokenData = JSON.parse(
localStorage.getItem(CarePatientTokenKey) || "{}",
localStorage.getItem(LocalStorageKeys.patientTokenKey) || "{}",
);

if (
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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`,
);
Expand Down Expand Up @@ -294,7 +297,7 @@ export default function PatientLogin({
}
>
<CareIcon icon="l-square-shape" className="h-4 w-4 mr-1" />
<span className="text-sm underline">Back</span>
<span className="text-sm underline">{t("back")}</span>
</Button>
{page === "send" ? renderPhoneNumberForm() : renderVerifyForm()}
</div>
Expand Down
9 changes: 5 additions & 4 deletions src/pages/Facility/components/UserCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dayjs from "dayjs";
import { t } from "i18next";
import { navigate } from "raviger";
import { useMemo } from "react";

Expand All @@ -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";
Expand All @@ -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(() => {
Expand Down Expand Up @@ -58,7 +59,7 @@ export function UserCard({ user, className, facilityId }: Props) {

{user.qualification && (
<>
<p className="text-xs mt-3">Education: </p>
<p className="text-xs mt-3">{t("education")}: </p>
<p className="text-sm text-muted-foreground">
{user.qualification}
</p>
Expand All @@ -77,7 +78,7 @@ export function UserCard({ user, className, facilityId }: Props) {
navigate(returnLink);
}}
>
Book Appointment
{t("book_appointment")}
</Button>
</div>
</div>
Expand Down

0 comments on commit 1652f5b

Please sign in to comment.