-
- {data?.phone?.value}
- تایید شده
-
+
+ {isForAnother ? (
+
+ ) : (
+
+ {data?.phone?.value}
+ تایید شده
+
+ )}
+ {isForAnother && (
+
+
+
+ )}
diff --git a/components/appointment/detail/SubmitData.js b/components/appointment/detail/SubmitData.js
index 94a6221..4bd4977 100644
--- a/components/appointment/detail/SubmitData.js
+++ b/components/appointment/detail/SubmitData.js
@@ -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;
}
diff --git a/components/appointment/detail/index.js b/components/appointment/detail/index.js
index e62b68c..de051d6 100644
--- a/components/appointment/detail/index.js
+++ b/components/appointment/detail/index.js
@@ -19,10 +19,12 @@ function Detail({
selectedSlot,
selectedDate,
setAppointmentId,
+ setAppointmentExpiresAt,
}) {
const [insurance, setInsurance] = useState();
const [supplementaryInsurance, setSupplementaryInsurance] = useState();
const [errors, setErrors] = useState({});
+ const [selfData, setSelfData] = useState(null);
const changeData = (value, type, name) =>
setData({
@@ -33,6 +35,28 @@ function Detail({
},
});
+ const emptyPatientData = () => ({
+ phone: { value: "", isEdit: true },
+ national_code: { value: "", isEdit: true },
+ name: { value: "", isEdit: true },
+ family: { value: "", isEdit: true },
+ gender: { value: "", isEdit: true },
+ patient_reason: { value: "", isEdit: true },
+ });
+
+ const switchToAnother = () => {
+ setSelfData(data);
+ setIsForAnother(true);
+ setErrors({});
+ setData(emptyPatientData());
+ };
+
+ const switchToSelf = () => {
+ setIsForAnother(false);
+ setErrors({});
+ if (selfData) setData(selfData);
+ };
+
useEffect(() => {
// دریافت لیست بیمه پایه
request.getInsuranceType().then((res) => {
@@ -78,33 +102,26 @@ function Detail({
isForAnother={isForAnother}
errors={errors}
/>
- {!isForAnother && (
-
- )}
+
diff --git a/components/appointment/index.js b/components/appointment/index.js
index eaa362f..267a622 100644
--- a/components/appointment/index.js
+++ b/components/appointment/index.js
@@ -56,6 +56,7 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) {
const [selectedSlot, setSelectedSlot] = useState(null);
const [selectedDate, setSelectedDate] = useState(null);
const [appointmentId, setAppointmentId] = useState(null);
+ const [appointmentExpiresAt, setAppointmentExpiresAt] = useState(null);
useEffect(() => {
const fetchUserData = async () => {
@@ -183,6 +184,8 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) {
setSelectedDate={setSelectedDate}
appointmentId={appointmentId}
setAppointmentId={setAppointmentId}
+ appointmentExpiresAt={appointmentExpiresAt}
+ setAppointmentExpiresAt={setAppointmentExpiresAt}
/>
);
}