refactor: enhance handling of supplementary insurance in Form and AppointmentPage components

This commit is contained in:
hamed
2025-11-18 10:35:35 +03:30
parent 3268b3c51e
commit 5c98b4de3e
4 changed files with 99 additions and 15 deletions
+23 -3
View File
@@ -13,6 +13,7 @@ const defaultData = {
gender: { value: "", isEdit: true },
insurance_id: { value: "", isEdit: true },
basic_insurance: { value: "", isEdit: true },
supplementary_insurance: { value: "", isEdit: true },
};
function AppointmentPage({ doctor, disabledDates, matchedCity }) {
@@ -53,23 +54,33 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) {
try {
console.log('📤 درخواست دریافت پروفایل کاربر - UUID:', parsedData.uuid);
const res = await request.getUserProfile(parsedData.uuid);
console.log('📥 پاسخ دریافتی از API:', res);
if (res) {
console.log('🏥 basic_insurance از API:', res.basic_insurance);
console.log('🏥 supplementary_insurance از API:', res.supplementary_insurance);
const newData = {
uuid: res.uuid,
phone: { value: usernameFromCookie, isEdit: false },
national_code: {
value: res.national_code || "",
isEdit: res.national_code ? false : true,
isEdit: res.national_code ? false : true, // اگر کد ملی داره، غیرقابل ویرایش
},
name: { value: res.name || "", isEdit: true },
family: { value: res.family || "", isEdit: true },
gender: { value: res.gender || "", isEdit: true },
gender: {
value: res.gender ? { id: res.gender, title: res.gender === "male" ? "مرد" : "زن" } : "",
isEdit: true
},
insurance_id: { value: res.insurance_id || "", isEdit: true },
basic_insurance: {
value: res.basic_insurance,
isEdit: true,
},
supplementary_insurance: {
value: res.supplementary_insurance,
isEdit: true,
},
};
setData(newData);
setPrevData(newData);
@@ -85,6 +96,7 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) {
gender: { value: "", isEdit: true },
insurance_id: { value: "", isEdit: true },
basic_insurance: { value: "", isEdit: true },
supplementary_insurance: { value: "", isEdit: true },
}));
}
} finally {
@@ -121,12 +133,19 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) {
},
name: { value: res.name || "", isEdit: true },
family: { value: res.family || "", isEdit: true },
gender: { value: res.gender || "", isEdit: true },
gender: {
value: res.gender ? { id: res.gender, title: res.gender === "male" ? "مرد" : "زن" } : "",
isEdit: true
},
insurance_id: { value: res.insurance_id || "", isEdit: true },
basic_insurance: {
value: res.basic_insurance,
isEdit: true,
},
supplementary_insurance: {
value: res.supplementary_insurance,
isEdit: true,
},
};
setData(newData);
setPrevData(newData);
@@ -142,6 +161,7 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) {
gender: { value: "", isEdit: true },
insurance_id: { value: "", isEdit: true },
basic_insurance: { value: "", isEdit: true },
supplementary_insurance: { value: "", isEdit: true },
}));
}
}