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); }