diff --git a/package-lock.json b/package-lock.json index 498c38dec08..fef9044fed8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8857,15 +8857,6 @@ "node": ">=8" } }, - "node_modules/css-box-model": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/css-box-model/-/css-box-model-1.2.1.tgz", - "integrity": "sha512-a7Vr4Q/kd/aw96bnJG332W9V9LkJO69JRcaCYDUqjp6/z0w6VcZjgAcTbgFxEPfBgdnAwlh3iwu+hLopa+flJw==", - "license": "MIT", - "dependencies": { - "tiny-invariant": "^1.0.6" - } - }, "node_modules/css-line-break": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/css-line-break/-/css-line-break-2.1.0.tgz", @@ -8980,9 +8971,9 @@ } }, "node_modules/cypress-split": { - "version": "1.24.7", - "resolved": "https://registry.npmjs.org/cypress-split/-/cypress-split-1.24.7.tgz", - "integrity": "sha512-JOxWgCQHi/JMOwznm6VF7V1GHYEM9Mxz6EipZu9WgQtqnRjk3QX6lBXJMjRXOPqArguL9S49OSFUQXDiC19hBg==", + "version": "1.24.8", + "resolved": "https://registry.npmjs.org/cypress-split/-/cypress-split-1.24.8.tgz", + "integrity": "sha512-gxsZg7Se3iy6eQuYP0w6munfRFBWP81OKc3WWTKQoxxafFWEp9gu173Nx3zoAEDUIEeYxUS1kwmZ7q5hhMN9og==", "dev": true, "license": "MIT", "dependencies": { @@ -15415,12 +15406,6 @@ "performance-now": "^2.1.0" } }, - "node_modules/raf-schd": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/raf-schd/-/raf-schd-4.0.3.tgz", - "integrity": "sha512-tQkJl2GRWh83ui2DiPTJz9wEiMN20syf+5oKfB03yYP7ioZcJwsIK8FjrtLwH1m7C7e+Tt2yYBlrOpdT+dyeIQ==", - "license": "MIT" - }, "node_modules/ramda": { "version": "0.29.1", "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.29.1.tgz", diff --git a/src/Utils/FiltersCache.tsx b/src/Utils/FiltersCache.tsx index e69fb14da58..d723a046549 100644 --- a/src/Utils/FiltersCache.tsx +++ b/src/Utils/FiltersCache.tsx @@ -58,7 +58,7 @@ const invalidate = (key?: string) => { /** * Removes all filters cache in the platform. */ -const invaldiateAll = () => { +const invalidateAll = () => { for (const key in localStorage) { if (key.startsWith("filters--")) { invalidate(key); @@ -70,7 +70,7 @@ export default { get, set, invalidate, - invaldiateAll, + invalidateAll, utils: { clean, }, diff --git a/src/components/Auth/Login.tsx b/src/components/Auth/Login.tsx index 55590bc1635..d049cee06d9 100644 --- a/src/components/Auth/Login.tsx +++ b/src/components/Auth/Login.tsx @@ -37,13 +37,9 @@ import FiltersCache from "@/Utils/FiltersCache"; import ViewCache from "@/Utils/ViewCache"; import routes from "@/Utils/request/api"; import mutate from "@/Utils/request/mutate"; +import { HTTPError } from "@/Utils/request/types"; import { TokenData } from "@/types/auth/otpToken"; -interface LoginFormData { - username: string; - password: string; -} - interface OtpLoginData { phone_number: string; otp: string; @@ -103,17 +99,6 @@ const Login = (props: LoginProps) => { localStorage.setItem(LocalStorageKeys.loginPreference, loginMode); }, [loginMode]); - // Staff Login Mutation - const staffLoginMutation = useMutation({ - mutationFn: async (data: LoginFormData) => { - FiltersCache.invaldiateAll(); - return await signIn(data); - }, - onError: (error) => { - setCaptcha(error.status == 429); - }, - }); - // Send OTP Mutation const { mutate: sendOtp, isPending: sendOtpPending } = useMutation({ mutationFn: mutate(routes.otp.sendOtp), @@ -233,7 +218,14 @@ const Login = (props: LoginProps) => { const validated = validateData(); if (!validated) return; - staffLoginMutation.mutate(validated); + FiltersCache.invalidateAll(); + try { + await signIn(validated); + } catch (error) { + if (error instanceof HTTPError) { + setCaptcha(error.status == 429); + } + } }; const validateForgetData = () => { @@ -278,19 +270,10 @@ const Login = (props: LoginProps) => { const handlePatientLogin = async (e: React.FormEvent) => { e.preventDefault(); - try { - if (!isOtpSent) { - await sendOtp({ phone_number: phone }); - setIsOtpSent(true); - } else { - await verifyOtp({ phone_number: phone, otp }); - } - } catch (error: any) { - if (!isOtpSent) { - setOtpError(error.message); - } else { - setOtpValidationError(error.message); - } + if (!isOtpSent) { + sendOtp({ phone_number: phone }); + } else { + verifyOtp({ phone_number: phone, otp }); } }; diff --git a/src/pages/Appointments/components/AppointmentTokenCard.tsx b/src/pages/Appointments/components/AppointmentTokenCard.tsx index 84df3ef362f..6e86b833821 100644 --- a/src/pages/Appointments/components/AppointmentTokenCard.tsx +++ b/src/pages/Appointments/components/AppointmentTokenCard.tsx @@ -52,7 +52,7 @@ const AppointmentTokenCard = ({ id, appointment, facility }: Props) => {

{patient.name}

- {formatPatientAge(patient as any, true)},{" "} + {formatPatientAge(patient, true)},{" "} {t(`GENDER__${patient.gender}`)}

diff --git a/src/pages/PublicAppointments/PatientRegistration.tsx b/src/pages/PublicAppointments/PatientRegistration.tsx index 1571cbd06fc..db9c0e2cdb0 100644 --- a/src/pages/PublicAppointments/PatientRegistration.tsx +++ b/src/pages/PublicAppointments/PatientRegistration.tsx @@ -1,7 +1,6 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { navigate, useNavigationPrompt } from "raviger"; -import { Fragment } from "react"; import { useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { toast } from "sonner"; @@ -24,13 +23,12 @@ import { Textarea } from "@/components/ui/textarea"; import { usePatientContext } from "@/hooks/usePatientUser"; -import { GENDER_TYPES } from "@/common/constants"; +import { GENDERS, GENDER_TYPES } from "@/common/constants"; import { validateName, validatePincode } from "@/common/validation"; import { usePubSub } from "@/Utils/pubsubContext"; import routes from "@/Utils/request/api"; import mutate from "@/Utils/request/mutate"; -import { HTTPError } from "@/Utils/request/types"; import { dateQueryString } from "@/Utils/utils"; import GovtOrganizationSelector from "@/pages/Organization/components/GovtOrganizationSelector"; import { AppointmentPatientRegister } from "@/pages/Patient/Utils"; @@ -42,19 +40,20 @@ import { TokenSlot, } from "@/types/scheduling/schedule"; -const initialForm: AppointmentPatientRegister & { - ageInputType: "age" | "date_of_birth"; -} = { - name: "", - gender: "1", - ageInputType: "date_of_birth", - year_of_birth: undefined, - date_of_birth: undefined, - phone_number: "", - address: "", - pincode: "", - geo_organization: undefined, -}; +// const initialForm: Omit & { +// ageInputType: "age" | "date_of_birth"; +// gender: "male" | "female" | "transgender" | "non_binary"; +// } = { +// name: "", +// gender: "male", +// ageInputType: "date_of_birth", +// year_of_birth: undefined, +// date_of_birth: undefined, +// phone_number: "", +// address: "", +// pincode: "", +// geo_organization: undefined, +// }; type PatientRegistrationProps = { facilityId: string; @@ -83,7 +82,7 @@ export function PatientRegistration(props: PatientRegistrationProps) { .string() .min(1, t("field_required")) .refine(validateName, t("min_char_length_error", { min_length: 3 })), - gender: z.string().min(1, t("field_required")), + gender: z.enum(GENDERS, { required_error: t("gender_is_required") }), address: z.string().min(1, t("field_required")), year_of_birth: z.string().optional(), date_of_birth: z.date().or(z.string()).optional(), @@ -131,7 +130,15 @@ export function PatientRegistration(props: PatientRegistrationProps) { const form = useForm({ resolver: formResolver, - defaultValues: initialForm, + defaultValues: { + name: "", + ageInputType: "date_of_birth", + year_of_birth: undefined, + date_of_birth: undefined, + address: "", + pincode: "", + geo_organization: undefined, + }, }); const { mutate: createAppointment, isPending: isCreatingAppointment } = @@ -159,9 +166,6 @@ export function PatientRegistration(props: PatientRegistrationProps) { }, ); }, - onError: (error) => { - toast.error(error?.message || t("failed_to_create_appointment")); - }, }); const { mutate: createPatient } = useMutation({ @@ -180,16 +184,6 @@ export function PatientRegistration(props: PatientRegistrationProps) { reason_for_visit: reason ?? "", }); }, - onError: (error: HTTPError) => { - const errorData = error.cause; - const errors = errorData?.errors; - if (Array.isArray(errors) && errors.length > 0) { - const firstError = errors[0]; - toast.error(firstError.msg); - } else { - toast.error(error.message); - } - }, }); const onSubmit = form.handleSubmit((data) => { @@ -361,7 +355,6 @@ export function PatientRegistration(props: PatientRegistrationProps) { @@ -396,7 +389,7 @@ export function PatientRegistration(props: PatientRegistrationProps) { name="pincode" render={({ field }) => ( - {t("pincode")} + {t("pincode")}