refactor: add gender selection to Form component and update DefaultSelect for improved option handling

This commit is contained in:
hamed
2025-11-18 08:32:41 +03:30
parent a3fd984894
commit ebc6c246b9
3 changed files with 58 additions and 16 deletions
+16
View File
@@ -40,6 +40,22 @@ function Form({ changeData, insurance, supplementaryInsurance, data, isForAnothe
<Content title="نام خانوادگی">
<EditField changeData={changeData} data={data?.family} name="family" />
</Content>
<Content title="جنسیت">
<DefaultSelect
updateData={(name, val) => changeData(val, "value", name)}
label="جنسیت"
name="gender"
list={[
{ id: "male", title: "مرد" },
{ id: "female", title: "زن" },
]}
value={
data?.gender?.value
? { id: data.gender.value, title: data.gender.value === "male" ? "مرد" : "زن" }
: null
}
/>
</Content>
<Content title="نوع بیمه">
<DefaultSelect
updateData={(name, val) => changeData(val, "value", name)}
+30 -4
View File
@@ -9,6 +9,8 @@ const defaultData = {
phone: { value: "", isEdit: false },
national_code: { value: "", isEdit: true },
name: { value: "", isEdit: true },
family: { value: "", isEdit: true },
gender: { value: "", isEdit: true },
basic_insurance: { value: "", isEdit: true },
};
@@ -58,7 +60,9 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) {
value: res.national_code || "",
isEdit: res.national_code ? false : true,
},
name: { value: `${res.name} ${res.family}`, isEdit: true },
name: { value: res.name || "", isEdit: true },
family: { value: res.family || "", isEdit: true },
gender: { value: res.gender || "", isEdit: true },
basic_insurance: {
value: res.basic_insurance,
isEdit: true,
@@ -68,7 +72,17 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) {
setPrevData(newData);
}
} catch (error) {
// خطا در دریافت پروفایل
// اگر 404 بود، فقط شماره موبایل را نگه می‌داریم و بقیه قابل ویرایش می‌شوند
if (error?.response?.status === 404) {
setData(prev => ({
...prev,
national_code: { value: "", isEdit: true },
name: { value: "", isEdit: true },
family: { value: "", isEdit: true },
gender: { value: "", isEdit: true },
basic_insurance: { value: "", isEdit: true },
}));
}
} finally {
setIsLoading(false);
}
@@ -100,7 +114,9 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) {
value: res.national_code || "",
isEdit: res.national_code ? false : true,
},
name: { value: `${res.name} ${res.family}`, isEdit: true },
name: { value: res.name || "", isEdit: true },
family: { value: res.family || "", isEdit: true },
gender: { value: res.gender || "", isEdit: true },
basic_insurance: {
value: res.basic_insurance,
isEdit: true,
@@ -110,7 +126,17 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) {
setPrevData(newData);
}
} catch (error) {
// خطا در دریافت پروفایل
// اگر 404 بود، فقط شماره موبایل را نگه می‌داریم و بقیه قابل ویرایش می‌شوند
if (error?.response?.status === 404) {
setData(prev => ({
...prev,
national_code: { value: "", isEdit: true },
name: { value: "", isEdit: true },
family: { value: "", isEdit: true },
gender: { value: "", isEdit: true },
basic_insurance: { value: "", isEdit: true },
}));
}
}
}
}