Skip to content
Merged
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
10 changes: 9 additions & 1 deletion public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,13 @@
"verify_bio": "Verify Biometrics",
"capture_fingerprint": "Capture Fingerprint",
"initiate_face_auth": "Initiate Face Authentication",
"retry_face_auth": "Retry Face Authentication"
"retry_face_auth": "Retry Face Authentication",
"error_verifying_aadhaar_demographics": "Error verifying Aadhaar demographics.",
"error_verifying_aadhaar_face": "Error verifying Aadhaar face.",
"error_capturing_pid_via_face": "Error capturing PID via face.",
"error_linking_abha_number": "Error linking ABHA number.",
"otp_sent_successfully": "OTP has been sent successfully.",
"otp_verified_successfully": "OTP has been verified successfully.",
"otp_resend_successfully": "OTP has been resend successfully.",
"abha_address_created_successfully": "ABHA Address has been created successfully."
}
42 changes: 32 additions & 10 deletions src/components/LinkAbhaNumber/CreateWithAadhaar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,18 @@ const EnterAadhaar: FC<EnterAadhaarProps> = ({ setMemory, goTo }) => {
},
});

const handleCheckAllDisclaimers = () => {
Array.from({ length: 6 }).forEach((_, index) => {
const fieldName = `disclaimer_${index + 1}` as keyof EnterAadhaarFormValues;
form.setValue(fieldName, true, { shouldValidate: true });
});
};

const sendAadhaarOtpMutation = useMutation({
mutationFn: apis.healthId.abhaCreateSendAadhaarOtp,
onSuccess: (data) => {
if (data) {
toast.success(data.detail);
toast.success(data.detail || t("otp_sent_successfully"));
setMemory((prev) => ({
...prev,
transactionId: data.transaction_id,
Expand Down Expand Up @@ -293,6 +300,20 @@ const EnterAadhaar: FC<EnterAadhaarProps> = ({ setMemory, goTo }) => {
)}
/>
))}

<div className="flex justify-end">
<Button
type="button"
variant="outline"
size="sm"
onClick={(e) => {
e.stopPropagation();
handleCheckAllDisclaimers();
}}
>
Check all terms
</Button>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<Button
type="submit"
Expand Down Expand Up @@ -405,7 +426,7 @@ const VerifyAadhaarWithOtp: FC<VerifyAadhaarWithOtpProps> = ({
mutationFn: apis.healthId.abhaCreateVerifyAadhaarOtp,
onSuccess: (data) => {
if (data) {
toast.success(data.detail);
toast.success(data.detail || t("otp_verified_successfully"));
setMemory((prev) => ({
...prev,
transactionId: data.transaction_id,
Expand All @@ -421,7 +442,7 @@ const VerifyAadhaarWithOtp: FC<VerifyAadhaarWithOtpProps> = ({
mutationFn: apis.healthId.abhaCreateSendAadhaarOtp,
onSuccess: (data) => {
if (data) {
toast.success(data.detail);
toast.success(data.detail || t("otp_resend_successfully"));
form.setValue("otp", "");
setMemory((prev) => ({
...prev,
Expand Down Expand Up @@ -620,7 +641,7 @@ const VerifyAadhaarWithDemographics: FC<VerifyAadhaarWithDemographicsProps> = ({
form.setError("_aadhaar", {
message: error.message,
});
toast.error(error.message);
toast.error(error.message || t("error_verifying_aadhaar_demographics"));
},
});

Expand Down Expand Up @@ -923,7 +944,7 @@ const VerifyAadhaarWithFace: FC<VerifyAadhaarWithFaceProps> = ({
}
},
onError: (error) => {
toast.error(error.message);
toast.error(error.message || t("error_verifying_aadhaar_face"));
setMemory((prev) => ({
...prev,
transactionId: "",
Expand Down Expand Up @@ -963,7 +984,7 @@ const VerifyAadhaarWithFace: FC<VerifyAadhaarWithFaceProps> = ({
...prev,
error: error.message,
}));
toast.error(error.message);
toast.error(error.message || t("error_capturing_pid_via_face"));
},
});

Expand All @@ -990,6 +1011,7 @@ const VerifyAadhaarWithFace: FC<VerifyAadhaarWithFaceProps> = ({
}
}, [isPolling]);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function onSubmit(_values: VerifyAadhaarWithFaceFormValues) {
authInitViaFaceMutation.mutate();
}
Expand Down Expand Up @@ -1423,7 +1445,7 @@ const LinkMobile: FC<LinkMobileProps> = ({ memory, setMemory, goTo }) => {
mutationFn: apis.healthId.abhaCreateLinkMobileNumber,
onSuccess: (data) => {
if (data) {
toast.success(data.detail);
toast.success(data.detail || t("otp_sent_successfully"));
setMemory((prev) => ({
...prev,
transactionId: data.transaction_id,
Expand Down Expand Up @@ -1511,7 +1533,7 @@ const VerifyMobile: FC<VerifyMobileProps> = ({ memory, setMemory, goTo }) => {
mutationFn: apis.healthId.abhaCreateVerifyMobileNumber,
onSuccess: (data) => {
if (data) {
toast.success(data.detail);
toast.success(data.detail || t("otp_verified_successfully"));
setMemory((prev) => ({
...prev,
transactionId: data.transaction_id,
Expand All @@ -1525,7 +1547,7 @@ const VerifyMobile: FC<VerifyMobileProps> = ({ memory, setMemory, goTo }) => {
mutationFn: apis.healthId.abhaCreateLinkMobileNumber,
onSuccess: (data) => {
if (data) {
toast.success(data.detail);
toast.success(data.detail || t("otp_resend_successfully"));
form.setValue("otp", "");
setMemory((prev) => ({
...prev,
Expand Down Expand Up @@ -1714,7 +1736,7 @@ export const ChooseAbhaAddress: FC<ChooseAbhaAddressProps> = ({
transactionId: data.transaction_id,
abhaNumber: data.abha_number,
}));
toast.success("ABHA Address created successfully");
toast.success(t("abha_address_created_successfully"));
goTo("show-abha-profile");
}
},
Expand Down
31 changes: 26 additions & 5 deletions src/components/LinkAbhaNumber/LinkWithOtp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import { Input } from "@/components/ui/input";
import { apis } from "@/apis";
import { toast } from "@/lib/utils";
import { useForm } from "react-hook-form";
import { useLinkAbhaNumberContext } from ".";
import { useMutation } from "@tanstack/react-query";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import { useLinkAbhaNumberContext } from ".";

type LinkWithOtpProps = {
onSuccess: (abhaNumber: AbhaNumber) => void;
Expand Down Expand Up @@ -113,7 +113,7 @@ const enterIdFormSchema = z.object({

type EnterIdFormValues = z.infer<typeof enterIdFormSchema>;

const EnterId: FC<EnterIdProps> = ({ memory, setMemory, goTo }) => {
const EnterId: FC<EnterIdProps> = ({ setMemory, goTo }) => {
const { t } = useTranslation(I18NNAMESPACE);
const { currentUser } = useLinkAbhaNumberContext();

Expand All @@ -134,6 +134,13 @@ const EnterId: FC<EnterIdProps> = ({ memory, setMemory, goTo }) => {
},
});

const handleCheckAllDisclaimers = () => {
Array.from({ length: 5 }).forEach((_, index) => {
const fieldName = `disclaimer_${index + 1}` as keyof EnterIdFormValues;
form.setValue(fieldName, true, { shouldValidate: true });
});
};

const checkAuthMethodsMutation = useMutation({
mutationFn: apis.healthId.abhaLoginCheckAuthMethods,
onSuccess: (data) => {
Expand Down Expand Up @@ -170,7 +177,7 @@ const EnterId: FC<EnterIdProps> = ({ memory, setMemory, goTo }) => {
mutationFn: apis.healthId.abhaLoginSendOtp,
onSuccess: (data) => {
if (data) {
toast.success(data.detail);
toast.success(data.detail || t("otp_sent_successfully"));
setMemory((prev) => ({
...prev,
transactionId: data.transaction_id,
Expand Down Expand Up @@ -249,6 +256,20 @@ const EnterId: FC<EnterIdProps> = ({ memory, setMemory, goTo }) => {
/>
))}

<div className="flex justify-end">
<Button
type="button"
variant="outline"
size="sm"
onClick={(e) => {
e.stopPropagation();
handleCheckAllDisclaimers();
}}
>
Check all terms
</Button>
</div>

<Popover
open={showAuthMethods}
onOpenChange={(open) => !open && setShowAuthMethods(false)}
Expand Down Expand Up @@ -339,7 +360,7 @@ const VerifyId: FC<VerifyIdProps> = ({ memory, setMemory, onSuccess }) => {
mutationFn: apis.healthId.abhaLoginVerifyOtp,
onSuccess: (data) => {
if (data) {
toast.success(t("verify_otp_success"));
toast.success(t("otp_verified_successfully"));
onSuccess(data.abha_number);
}
},
Expand All @@ -349,7 +370,7 @@ const VerifyId: FC<VerifyIdProps> = ({ memory, setMemory, onSuccess }) => {
mutationFn: apis.healthId.abhaLoginSendOtp,
onSuccess: (data) => {
if (data) {
toast.success(data.detail);
toast.success(data.detail || t("otp_resend_successfully"));
form.setValue("otp", "");
setMemory((prev) => ({
...prev,
Expand Down
7 changes: 5 additions & 2 deletions src/components/pluggables/PatientHomeActions.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useMutation, useQuery } from "@tanstack/react-query";

import { FC } from "react";
import { I18NNAMESPACE } from "@/lib/constants";
import { LinkAbhaNumber } from "@/components/LinkAbhaNumber";
import { Patient } from "@/types/patient";
import { apis } from "@/apis";
import { toast } from "@/lib/utils";
import { useTranslation } from "react-i18next";

type PatientHomeActionsProps = {
patient: Patient;
Expand All @@ -17,6 +19,7 @@ const PatientHomeActions: FC<PatientHomeActionsProps> = ({
facilityId,
className,
}) => {
const { t } = useTranslation(I18NNAMESPACE);
const { data: abhaNumber, refetch } = useQuery({
queryKey: ["abhaNumber", patient.id],
queryFn: () => apis.abhaNumber.get(patient.id),
Expand All @@ -27,12 +30,12 @@ const PatientHomeActions: FC<PatientHomeActionsProps> = ({
mutationFn: apis.healthId.linkAbhaNumberAndPatient,
onSuccess: (data) => {
if (data) {
toast.success(data.detail);
toast.success(data.detail || t("abha_number_linked_successfully"));
refetch();
}
},
onError: (error) => {
toast.error(error.message);
toast.error(error.message || t("error_linking_abha_number"));
},
});

Expand Down
7 changes: 5 additions & 2 deletions src/components/pluggables/PatientRegistrationForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FC, useEffect } from "react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";

import { I18NNAMESPACE } from "@/lib/constants";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { LinkAbhaNumber } from "../LinkAbhaNumber";
Expand All @@ -9,6 +10,7 @@ import { UseFormReturn } from "react-hook-form";
import { apis } from "@/apis";
import { enforceAbhaNumberLinking } from "@/config";
import { toast } from "@/lib/utils";
import { useTranslation } from "react-i18next";

type PatientRegistrationFormProps = {
form: UseFormReturn;
Expand All @@ -22,6 +24,7 @@ const PatientRegistrationForm: FC<PatientRegistrationFormProps> = ({
patientId,
}) => {
const queryClient = useQueryClient();
const { t } = useTranslation(I18NNAMESPACE);

const { data: abhaNumber, refetch } = useQuery({
queryKey: ["abhaNumber", patientId],
Expand All @@ -41,12 +44,12 @@ const PatientRegistrationForm: FC<PatientRegistrationFormProps> = ({
mutationFn: apis.healthId.linkAbhaNumberAndPatient,
onSuccess: (data) => {
if (data) {
toast.success(data.detail);
toast.success(data.detail || t("abha_number_linked_successfully"));
refetch();
}
},
onError: (error) => {
toast.error(error.message);
toast.error(error.message || t("error_linking_abha_number"));
},
});

Expand Down
Loading