From 7a8700b09bbee20360aaba4abb0d8f9217336bd1 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Mon, 15 Jun 2026 15:41:22 +0330 Subject: [PATCH] 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 --- components/appointment/detail/SubmitData.js | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/components/appointment/detail/SubmitData.js b/components/appointment/detail/SubmitData.js index b2757b7..94a6221 100644 --- a/components/appointment/detail/SubmitData.js +++ b/components/appointment/detail/SubmitData.js @@ -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); }