diff --git a/src/pages/PublicAppointments/Success.tsx b/src/pages/PublicAppointments/Success.tsx index f5fa159efcb..e7dbf16c676 100644 --- a/src/pages/PublicAppointments/Success.tsx +++ b/src/pages/PublicAppointments/Success.tsx @@ -1,11 +1,14 @@ import { useQuery } from "@tanstack/react-query"; import { format } from "date-fns"; +import { navigate } from "raviger"; +import { useEffect } from "react"; import { useTranslation } from "react-i18next"; import { toast } from "sonner"; import CareIcon from "@/CAREUI/icons/CareIcon"; import Loading from "@/components/Common/Loading"; +import { Button } from "@/components/ui/button"; import { usePatientContext } from "@/hooks/usePatientUser"; @@ -33,18 +36,57 @@ export function AppointmentSuccess(props: { appointmentId: string }) { enabled: !!tokenData.token, }); - if (error) { - toast.error(t("appointment_not_found")); - } + useEffect(() => { + if (error) { + toast.error(t("page_load_error"), { + id: "appointment-success-load-error", + }); + } + }, [error, t]); const appointmentData = data?.results.find( (appointment) => appointment.id === appointmentId, ); - if (isLoading || !appointmentData) { + if (isLoading) { return ; } + if (error) { + return ( +
+ +

+ {t("page_load_error")} +

+

{t("could_not_load_page")}

+ +
+ ); + } + + if (!appointmentData) { + return ( +
+ +

+ {t("appointment_not_found")} +

+ +
+ ); + } + const appointmentTime = appointmentData.token_slot.start_datetime; const appointmentDate = format(appointmentTime, "do MMMM"); const appointmentTimeSlot = format(appointmentTime, "hh:mm a"); @@ -73,7 +115,7 @@ export function AppointmentSuccess(props: { appointmentId: string }) {

{t("patient")}:

-

{appointmentData?.patient.name}

+

{appointmentData.patient.name}