Skip to content

Commit

Permalink
Disable Unnecessary Browser Pop-up on Patient Registration Form (#10251)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaJ2305 authored Jan 28, 2025
1 parent 1568bfd commit 0c3342f
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions src/pages/PublicAppointments/PatientRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,36 +136,37 @@ export function PatientRegistration(props: PatientRegistrationProps) {
defaultValues: initialForm,
});

const { mutate: createAppointment } = useMutation({
mutationFn: (body: AppointmentCreateRequest) =>
mutate(PublicAppointmentApi.createAppointment, {
pathParams: { id: selectedSlot?.id },
body,
headers: {
Authorization: `Bearer ${tokenData.token}`,
},
})(body),
onSuccess: (data: Appointment) => {
toast.success(t("appointment_created_success"));
queryClient.invalidateQueries({
queryKey: [
["patients", tokenData.phoneNumber],
["appointment", tokenData.phoneNumber],
],
});
navigate(
`/facility/${props.facilityId}/appointments/${data.id}/success`,
{
replace: true,
},
);
},
onError: (error) => {
toast.error(error?.message || t("failed_to_create_appointment"));
},
});
const { mutate: createAppointment, isPending: isCreatingAppointment } =
useMutation({
mutationFn: (body: AppointmentCreateRequest) =>
mutate(PublicAppointmentApi.createAppointment, {
pathParams: { id: selectedSlot?.id },
body,
headers: {
Authorization: `Bearer ${tokenData.token}`,
},
})(body),
onSuccess: (data: Appointment) => {
toast.success(t("appointment_created_success"));
queryClient.invalidateQueries({
queryKey: [
["patients", tokenData.phoneNumber],
["appointment", tokenData.phoneNumber],
],
});
navigate(
`/facility/${props.facilityId}/appointments/${data.id}/success`,
{
replace: true,
},
);
},
onError: (error) => {
toast.error(error?.message || t("failed_to_create_appointment"));
},
});

const { mutate: createPatient, isPending: isCreatingPatient } = useMutation({
const { mutate: createPatient } = useMutation({
mutationFn: (body: Partial<AppointmentPatientRegister>) =>
mutate(routes.otp.createPatient, {
body: { ...body, phone_number: tokenData.phoneNumber },
Expand Down Expand Up @@ -214,7 +215,7 @@ export function PatientRegistration(props: PatientRegistrationProps) {
// 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,
form.formState.isDirty && !isCreatingAppointment,
t("unsaved_changes"),
);

Expand Down

0 comments on commit 0c3342f

Please sign in to comment.