diff --git a/apps/Frontend/src/pages/claims-page.tsx b/apps/Frontend/src/pages/claims-page.tsx index 2d718733..b133a208 100755 --- a/apps/Frontend/src/pages/claims-page.tsx +++ b/apps/Frontend/src/pages/claims-page.tsx @@ -113,9 +113,14 @@ export default function ClaimsPage() { "/api/appointments/upsert", appointment ); - return await res.json(); + const data = await res.json(); + if (!res.ok) { + throw new Error(data?.message || "Failed to create appointment"); + } + return data; }, onSuccess: (appointment) => { + queryClient.invalidateQueries({ queryKey: QK_APPOINTMENTS_BASE }); toast({ title: "Appointment Scheduled", description: appointment.message || "Appointment created successfully.", @@ -319,14 +324,13 @@ export default function ClaimsPage() { }, { onSuccess: (appointment) => { + if (!appointment?.id) { + reject(new Error("Appointment was created but returned no ID")); + return; + } resolve(appointment.id); }, onError: (error) => { - toast({ - title: "Error", - description: "Could not schedule appointment", - variant: "destructive", - }); reject(error); }, }