Skip to content

Commit

Permalink
Fix Merge Conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidSumra committed Jan 8, 2025
2 parents c1fdfe4 + 8bec8bc commit 06b5c15
Show file tree
Hide file tree
Showing 56 changed files with 2,592 additions and 1,093 deletions.
5 changes: 2 additions & 3 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
files:
- source: /public/locale/{{lang}}.json
translation: /public/locale/%two_letters_code%/%original_file_name%
- source: public/locale/en.json
translation: /public/locale/%two_letters_code%.json
bundles:
- 2

2 changes: 1 addition & 1 deletion cypress/e2e/patient_spec/patient_search.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("Patient Search", () => {

it("search patient with phone number and verifies details", () => {
patientSearch
.selectFacility("PHC Kakkanad -1")
.selectFacility("Arike")
.clickSearchPatients()
.searchPatient(TEST_PHONE)
.verifySearchResults(PATIENT_DETAILS);
Expand Down
6 changes: 2 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@
"all_changes_have_been_saved": "All changes have been saved",
"all_details": "All Details",
"all_patients": "All Patients",
"allergen": "Allergen",
"allergies": "Allergies",
"allow_transfer": "Allow Transfer",
"allowed_formats_are": "Allowed formats are",
Expand Down Expand Up @@ -651,6 +652,7 @@
"created_by": "Created By",
"created_date": "Created Date",
"created_on": "Created On",
"criticality": "Criticality",
"csv_file_in_the_specified_format": "Select a CSV file in the specified format",
"current_address": "Current Address",
"current_password": "Current Password",
Expand Down Expand Up @@ -832,6 +834,7 @@
"encounter_discharge_disposition__snf": "Skilled nursing facility",
"encounter_duration_confirmation": "The duration of this encounter would be",
"encounter_id": "Encounter ID",
"encounter_marked_as_complete": "Encounter Completed",
"encounter_notes__all_discussions": "All Discussions",
"encounter_notes__be_first_to_send": "Be the first to send a message",
"encounter_notes__choose_template": "Choose a template or enter a custom title",
Expand Down Expand Up @@ -902,6 +905,7 @@
"error_deleting_shifting": "Error while deleting Shifting record",
"error_fetching_slots_data": "Error while fetching slots data",
"error_sending_otp": "Error while sending OTP, Please try again later",
"error_updating_encounter": "Error to Updating Encounter",
"error_verifying_otp": "Error while verifying OTP, Please request a new OTP",
"error_while_deleting_record": "Error while deleting record",
"escape": "Escape",
Expand Down Expand Up @@ -1166,6 +1170,7 @@
"manufacturer": "Manufacturer",
"map_acronym": "M.A.P.",
"mark_all_as_read": "Mark all as Read",
"mark_as_complete": "Mark as Complete",
"mark_as_fulfilled": "Mark as Fullfilled",
"mark_as_noshow": "Mark as no-show",
"mark_as_read": "Mark as Read",
Expand Down Expand Up @@ -1633,6 +1638,7 @@
"select": "Select",
"select_all": "Select All",
"select_date": "Select date",
"select_department": "Select Department",
"select_diff_role": "Please select a different role",
"select_eligible_policy": "Select an Eligible Insurance Policy",
"select_facility": "Select Facility",
Expand Down
37 changes: 15 additions & 22 deletions src/Providers/AuthUserProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import careConfig from "@careConfig";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import dayjs from "dayjs";
import { navigate } from "raviger";
import { useCallback, useEffect, useState } from "react";

Expand All @@ -13,6 +12,7 @@ import { LocalStorageKeys } from "@/common/constants";
import routes from "@/Utils/request/api";
import query from "@/Utils/request/query";
import request from "@/Utils/request/request";
import { TokenData } from "@/types/auth/otpToken";

interface Props {
children: React.ReactNode;
Expand All @@ -29,8 +29,10 @@ export default function AuthUserProvider({
const [accessToken, setAccessToken] = useState(
localStorage.getItem(LocalStorageKeys.accessToken),
);
const [patientToken, setPatientToken] = useState(
JSON.parse(localStorage.getItem(LocalStorageKeys.patientTokenKey) || "{}"),
const [patientToken, setPatientToken] = useState<TokenData | null>(
JSON.parse(
localStorage.getItem(LocalStorageKeys.patientTokenKey) || "null",
),
);

const { data: user, isLoading } = useQuery({
Expand All @@ -40,16 +42,6 @@ export default function AuthUserProvider({
enabled: !!localStorage.getItem(LocalStorageKeys.accessToken),
});

useEffect(() => {
if (
patientToken.token &&
Object.keys(patientToken).length > 0 &&
dayjs(patientToken.createdAt).isAfter(dayjs().subtract(14, "minutes"))
) {
navigate("/patient/home");
}
}, [patientToken]);

useEffect(() => {
if (!user) {
return;
Expand Down Expand Up @@ -83,20 +75,20 @@ export default function AuthUserProvider({
[queryClient],
);

const patientLogin = useCallback(() => {
setPatientToken(
JSON.parse(
localStorage.getItem(LocalStorageKeys.patientTokenKey) || "{}",
),
const patientLogin = (tokenData: TokenData, redirectUrl: string) => {
setPatientToken(tokenData);
localStorage.setItem(
LocalStorageKeys.patientTokenKey,
JSON.stringify(tokenData),
);
navigate("/patient/home");
}, []);
navigate(redirectUrl);
};

const signOut = useCallback(async () => {
localStorage.removeItem(LocalStorageKeys.accessToken);
localStorage.removeItem(LocalStorageKeys.refreshToken);
localStorage.removeItem(LocalStorageKeys.patientTokenKey);
setPatientToken({});
setPatientToken(null);

await queryClient.resetQueries({ queryKey: ["currentUser"] });

Expand Down Expand Up @@ -134,7 +126,7 @@ export default function AuthUserProvider({
const SelectedRouter = () => {
if (user) {
return children;
} else if (patientToken.token) {
} else if (patientToken?.token) {
return otpAuthorized;
} else {
return unauthorized;
Expand All @@ -148,6 +140,7 @@ export default function AuthUserProvider({
signOut,
user,
patientLogin,
patientToken,
}}
>
<SelectedRouter />
Expand Down
54 changes: 23 additions & 31 deletions src/Providers/PatientUserProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
import { useQuery } from "@tanstack/react-query";
import { navigate } from "raviger";
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 { useAuthContext } from "@/hooks/useAuthUser";

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) || "{}",
);

export type PatientUserContextType = {
patients?: AppointmentPatient[];
selectedPatient: AppointmentPatient | null;
setSelectedPatient: (patient: AppointmentPatient) => void;
tokenData: TokenData;
};

export const PatientUserContext = createContext<PatientUserContextType>({
patients: undefined,
selectedPatient: null,
setSelectedPatient: () => {},
tokenData: tokenData,
});
export const PatientUserContext = createContext<PatientUserContextType | null>(
null,
);

interface Props {
children: React.ReactNode;
Expand All @@ -38,14 +29,16 @@ export default function PatientUserProvider({ children }: Props) {
const [selectedPatient, setSelectedPatient] =
useState<AppointmentPatient | null>(null);

const { patientToken: tokenData } = useAuthContext();

const { data: userData } = useQuery({
queryKey: ["patients", tokenData.phoneNumber],
queryKey: ["patients", tokenData],
queryFn: query(routes.otp.getPatient, {
headers: {
Authorization: `Bearer ${tokenData.token}`,
Authorization: `Bearer ${tokenData?.token}`,
},
}),
enabled: !!tokenData.token,
enabled: !!tokenData?.token,
});

useEffect(() => {
Expand All @@ -62,22 +55,21 @@ export default function PatientUserProvider({ children }: Props) {
}
}, [userData]);

const patientUserContext: PatientUserContextType = {
patients,
selectedPatient,
setSelectedPatient,
tokenData,
};
if (!tokenData) {
navigate("/");
return null;
}

return (
<PatientUserContext.Provider value={patientUserContext}>
<SidebarProvider>
<AppSidebar
patientUserContext={patientUserContext}
facilitySidebar={false}
/>
{children}
</SidebarProvider>
<PatientUserContext.Provider
value={{
patients,
selectedPatient,
setSelectedPatient,
tokenData: tokenData,
}}
>
{children}
</PatientUserContext.Provider>
);
}
Loading

0 comments on commit 06b5c15

Please sign in to comment.