fix(appointment): book with real payload and handle slot conflict

POST /api/v1/appointment expects { doctor_uuid, slot_start, slot_end,
note } with unix timestamps, and returns the appointment uuid at
data.uuid (not data.id). Send the right body, read the uuid, and on a
409 (slot already booked) alert the user and return to slot selection.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-06-15 15:41:22 +03:30
co-authored by Claude Opus 4.8
parent dcfdedd93c
commit 7a8700b09b
+13 -13
View File
@@ -98,21 +98,16 @@ function SubmitData({ setStep, data, prevData, setErrors, doctor, selectedSlot,
if (doctor && selectedSlot) {
const appointmentPayload = {
doctor_id: doctor.id,
slot: {
time: selectedSlot.time,
status: selectedSlot.status,
start_time_timestamp: selectedSlot.start_time_timestamp,
end_time_timestamp: selectedSlot.end_time_timestamp,
duration_per_patient: selectedSlot.duration_per_patient,
location_id: selectedSlot.location_id
},
info: ""
doctor_uuid: doctor.uuid,
slot_start: selectedSlot.start,
slot_end: selectedSlot.end,
note: "",
};
const appointmentResponse = await request.postAppointment(appointmentPayload);
if (appointmentResponse?.id) {
setAppointmentId(appointmentResponse.id);
const res = await request.postAppointment(appointmentPayload);
const appointmentUuid = res?.data?.uuid;
if (appointmentUuid) {
setAppointmentId(appointmentUuid);
}
}
@@ -120,6 +115,11 @@ function SubmitData({ setStep, data, prevData, setErrors, doctor, selectedSlot,
newStep();
} catch (error) {
setLoading(false);
if (error?.response?.status === 409) {
alert("این نوبت پیش‌تر رزرو شده است. لطفاً ساعت دیگری انتخاب کنید.");
setStep(0);
return;
}
if (error?.response?.data) {
setErrors(error.response.data);
}