Skip to content

Commit

Permalink
Merge branch 'develop' into issue/10215/newline-questionnaire
Browse files Browse the repository at this point in the history
  • Loading branch information
rajku-dev authored Jan 28, 2025
2 parents 179f696 + 6834157 commit 4e0892b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
9 changes: 6 additions & 3 deletions src/components/Patient/PatientIndex.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useQuery } from "@tanstack/react-query";
import { navigate } from "raviger";
import { navigate, useQueryParams } from "raviger";
import { useCallback, useState } from "react";
import { useTranslation } from "react-i18next";
import { toast } from "sonner";
Expand Down Expand Up @@ -39,7 +39,8 @@ import { parsePhoneNumber } from "@/Utils/utils";
import { PartialPatientModel } from "@/types/emr/newPatient";

export default function PatientIndex({ facilityId }: { facilityId: string }) {
const [phoneNumber, setPhoneNumber] = useState("");
const [{ phone_number: phoneNumber = "" }, setPhoneNumberQuery] =
useQueryParams();
const [yearOfBirth, setYearOfBirth] = useState("");
const [selectedPatient, setSelectedPatient] =
useState<PartialPatientModel | null>(null);
Expand Down Expand Up @@ -91,7 +92,9 @@ export default function PatientIndex({ facilityId }: { facilityId: string }) {

const handleSearch = useCallback((key: string, value: string) => {
if (key === "phone_number") {
setPhoneNumber(value.length >= 13 || value === "" ? value : "");
setPhoneNumberQuery({
phone_number: value.length >= 13 || value === "" ? value : "",
});
}
}, []);

Expand Down
44 changes: 30 additions & 14 deletions src/components/Patient/PatientRegistration.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { useMutation, useQuery } from "@tanstack/react-query";
import { navigate, useQueryParams } from "raviger";
import { navigate, useNavigationPrompt, useQueryParams } from "raviger";
import { useEffect, useMemo, useState } from "react";
import { useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -297,6 +297,22 @@ export default function PatientRegistration(
}
}, [patientQuery.data]); // eslint-disable-line react-hooks/exhaustive-deps

const showDuplicate =
!patientPhoneSearch.isLoading &&
!!duplicatePatients?.length &&
!!parsePhoneNumber(form.watch("phone_number") || "") &&
!suppressDuplicateWarning;

// TODO: Use useBlocker hook after switching to tanstack router
// https://tanstack.com/router/latest/docs/framework/react/guide/navigation-blocking#how-do-i-use-navigation-blocking
useNavigationPrompt(
form.formState.isDirty &&
!isCreatingPatient &&
!isUpdatingPatient &&
!showDuplicate,
t("unsaved_changes"),
);

if (patientId && patientQuery.isLoading) {
return <Loading />;
}
Expand Down Expand Up @@ -672,7 +688,7 @@ export default function PatientRegistration(
)}
/>

<div className="grid grid-cols-2 gap-4">
<div className="grid grid-cols-1 gap-4">
<FormField
control={form.control}
name="nationality"
Expand All @@ -696,6 +712,9 @@ export default function PatientRegistration(
</FormItem>
)}
/>
</div>

<div className="grid grid-cols-2 gap-4">
{form.watch("nationality") === "India" && (
<FormField
control={form.control}
Expand Down Expand Up @@ -740,18 +759,15 @@ export default function PatientRegistration(
</form>
</Form>
</div>
{!patientPhoneSearch.isLoading &&
!!duplicatePatients?.length &&
!!parsePhoneNumber(form.watch("phone_number") || "") &&
!suppressDuplicateWarning && (
<DuplicatePatientDialog
patientList={duplicatePatients}
handleOk={handleDialogClose}
handleCancel={() => {
handleDialogClose("close");
}}
/>
)}
{showDuplicate && (
<DuplicatePatientDialog
patientList={duplicatePatients}
handleOk={handleDialogClose}
handleCancel={() => {
handleDialogClose("close");
}}
/>
)}
</Page>
);
}
11 changes: 9 additions & 2 deletions src/pages/PublicAppointments/PatientRegistration.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { navigate } from "raviger";
import { navigate, useNavigationPrompt } from "raviger";
import { Fragment } from "react";
import { useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -165,7 +165,7 @@ export function PatientRegistration(props: PatientRegistrationProps) {
},
});

const { mutate: createPatient } = useMutation({
const { mutate: createPatient, isPending: isCreatingPatient } = useMutation({
mutationFn: (body: Partial<AppointmentPatientRegister>) =>
mutate(routes.otp.createPatient, {
body: { ...body, phone_number: tokenData.phoneNumber },
Expand Down Expand Up @@ -211,6 +211,13 @@ export function PatientRegistration(props: PatientRegistrationProps) {
createPatient(formattedData);
});

// TODO: Use useBlocker hook after switching to tanstack router
// https://tanstack.com/router/latest/docs/framework/react/guide/navigation-blocking#how-do-i-use-navigation-blocking
useNavigationPrompt(
form.formState.isDirty && !isCreatingPatient,
t("unsaved_changes"),
);

// const [showAutoFilledPincode, setShowAutoFilledPincode] = useState(false);

return (
Expand Down

0 comments on commit 4e0892b

Please sign in to comment.