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 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user