From 4274cd61dcc04321ed515afd1464e120c5990e7d Mon Sep 17 00:00:00 2001 From: Gitead Date: Wed, 3 Jun 2026 00:15:44 -0400 Subject: [PATCH] fix: ensure appointment is created before saving claim from claims page - mutationFn now throws on non-ok responses so failed appointment creation (409 no slots, 400 validation) properly rejects instead of silently calling onSuccess with no id - handleAppointmentSubmit rejects if server returns success but no id - invalidate QK_APPOINTMENTS_BASE cache after successful appointment creation so the appointments page refreshes automatically Co-Authored-By: Claude Sonnet 4.6 --- apps/Frontend/src/pages/claims-page.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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); }, }