feat(appointment): real for-another-patient form and booking payload

Replace the mock for-another button with a real toggle: switching keeps
the user's own data, clears the form to editable patient fields (phone
becomes an input, adds علت مراجعه), and can switch back. SubmitData now
sends for_self plus patient_* only when booking for someone else, skips
the self-profile PATCH/POST in that case, stores the booking expires_at,
and surfaces a clearer 409 message. Thread appointmentExpiresAt through
the wizard to the payment step.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-06-15 18:07:10 +03:30
co-authored by Claude Opus 4.8
parent 969e915815
commit 08107d6ef2
6 changed files with 238 additions and 28 deletions
+15 -4
View File
@@ -5,7 +5,7 @@ import ArrowLeftB from "@/components/icons/ArrowLeftB";
import { request } from "@/services/response";
import Cookies from "js-cookie";
function SubmitData({ setStep, data, prevData, setErrors, doctor, selectedSlot, selectedDate, setAppointmentId }) {
function SubmitData({ setStep, data, prevData, setErrors, doctor, isForAnother, selectedSlot, selectedDate, setAppointmentId, setAppointmentExpiresAt }) {
const [loading, setLoading] = useState(false);
const newStep = () => setStep((prev) => prev + 1);
@@ -41,7 +41,7 @@ function SubmitData({ setStep, data, prevData, setErrors, doctor, selectedSlot,
setLoading(true);
try {
if (isChanged) {
if (!isForAnother && isChanged) {
const { basic_insurance, supplementary_insurance, name, family, national_code, gender, insurance_id, uuid } = data;
let payload = {};
@@ -101,13 +101,24 @@ function SubmitData({ setStep, data, prevData, setErrors, doctor, selectedSlot,
doctor_uuid: doctor.uuid,
slot_start: selectedSlot.start,
slot_end: selectedSlot.end,
note: "",
for_self: !isForAnother,
note: data?.patient_reason?.value || "",
...(isForAnother
? {
patient_name: [data?.name?.value, data?.family?.value].filter(Boolean).join(" ").trim(),
patient_mobile: data?.phone?.value,
patient_national_code: data?.national_code?.value || "",
patient_gender: data?.gender?.value?.id || data?.gender?.value || "",
patient_reason: data?.patient_reason?.value || "",
}
: {}),
};
const res = await request.postAppointment(appointmentPayload);
const appointmentUuid = res?.data?.uuid;
if (appointmentUuid) {
setAppointmentId(appointmentUuid);
setAppointmentExpiresAt?.(res?.data?.expires_at ?? null);
}
}
@@ -116,7 +127,7 @@ function SubmitData({ setStep, data, prevData, setErrors, doctor, selectedSlot,
} catch (error) {
setLoading(false);
if (error?.response?.status === 409) {
alert("این نوبت پیش‌تر رزرو شده است. لطفاً ساعت دیگری انتخاب کنید.");
alert("این زمان همین لحظه توسط کاربر دیگری رزرو شد. لطفاً ساعت دیگری انتخاب کنید.");
setStep(0);
return;
}