Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diet preference options with kebab case value #9821

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -650,6 +651,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 @@ -829,6 +831,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 @@ -899,6 +902,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 @@ -1163,6 +1167,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 @@ -1627,6 +1632,7 @@
"select": "Select",
"select_all": "Select All",
"select_date": "Select date",
"select_department": "Select Department",
"select_eligible_policy": "Select an Eligible Insurance Policy",
"select_facility_for_discharged_patients_warning": "Facility needs to be selected to view discharged patients.",
"select_for_administration": "Select for Administration",
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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical: PR changes do not match objectives.

The reviewed files contain significant changes related to navigation components, authentication handling, and UI updates, but none of these changes appear to be related to the stated PR objective of updating diet preference values from snake case to kebab case. This suggests either:

  1. The wrong files were provided for review
  2. The PR description needs to be updated
  3. The diet preference changes are missing from this PR

Please clarify the discrepancy between the PR objectives and the actual changes.

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
Loading