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:
@@ -98,21 +98,16 @@ function SubmitData({ setStep, data, prevData, setErrors, doctor, selectedSlot,
|
|||||||
|
|
||||||
if (doctor && selectedSlot) {
|
if (doctor && selectedSlot) {
|
||||||
const appointmentPayload = {
|
const appointmentPayload = {
|
||||||
doctor_id: doctor.id,
|
doctor_uuid: doctor.uuid,
|
||||||
slot: {
|
slot_start: selectedSlot.start,
|
||||||
time: selectedSlot.time,
|
slot_end: selectedSlot.end,
|
||||||
status: selectedSlot.status,
|
note: "",
|
||||||
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: ""
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const appointmentResponse = await request.postAppointment(appointmentPayload);
|
const res = await request.postAppointment(appointmentPayload);
|
||||||
if (appointmentResponse?.id) {
|
const appointmentUuid = res?.data?.uuid;
|
||||||
setAppointmentId(appointmentResponse.id);
|
if (appointmentUuid) {
|
||||||
|
setAppointmentId(appointmentUuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +115,11 @@ function SubmitData({ setStep, data, prevData, setErrors, doctor, selectedSlot,
|
|||||||
newStep();
|
newStep();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
if (error?.response?.status === 409) {
|
||||||
|
alert("این نوبت پیشتر رزرو شده است. لطفاً ساعت دیگری انتخاب کنید.");
|
||||||
|
setStep(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (error?.response?.data) {
|
if (error?.response?.data) {
|
||||||
setErrors(error.response.data);
|
setErrors(error.response.data);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user