refactor: add gender selection to Form component and update DefaultSelect for improved option handling
This commit is contained in:
@@ -10,19 +10,19 @@ function DefaultSelect({ list, value, updateData, label, error, name }) {
|
|||||||
value={value || ""}
|
value={value || ""}
|
||||||
getOptionLabel={(option) => {
|
getOptionLabel={(option) => {
|
||||||
if (typeof option === "string") return option;
|
if (typeof option === "string") return option;
|
||||||
return option?.name || option?.label || "";
|
return option?.title || option?.name || option?.label || "";
|
||||||
}}
|
}}
|
||||||
className="!w-full !rounded-lg auto-complete-selector"
|
className="!w-full !rounded-lg auto-complete-selector"
|
||||||
onChange={(_, newValue) => {
|
onChange={(_, newValue) => {
|
||||||
updateData(name, newValue?.label || newValue || "");
|
updateData(name, newValue?.id || newValue?.label || newValue || "");
|
||||||
}}
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
...styleTextSelectRight,
|
...styleTextSelectRight,
|
||||||
// Hide Icon Number
|
// Hide Icon Number
|
||||||
"& input::-webkit-outer-spin-button, & input::-webkit-inner-spin-button":
|
"& input::-webkit-outer-spin-button, & input::-webkit-inner-spin-button":
|
||||||
{
|
{
|
||||||
display: "none",
|
display: "none",
|
||||||
},
|
},
|
||||||
"& input[type=number]": {
|
"& input[type=number]": {
|
||||||
MozAppearance: "textfield",
|
MozAppearance: "textfield",
|
||||||
},
|
},
|
||||||
@@ -43,13 +43,13 @@ function DefaultSelect({ list, value, updateData, label, error, name }) {
|
|||||||
: "1px solid #D7D7D7 !important",
|
: "1px solid #D7D7D7 !important",
|
||||||
},
|
},
|
||||||
"& .MuiInput-underline:hover:not(.Mui-disabled):before, .MuiOutlinedInput-notchedOutline":
|
"& .MuiInput-underline:hover:not(.Mui-disabled):before, .MuiOutlinedInput-notchedOutline":
|
||||||
{
|
{
|
||||||
borderColor: error ? "red !important" : "#D7D7D7 !important",
|
borderColor: error ? "red !important" : "#D7D7D7 !important",
|
||||||
},
|
},
|
||||||
"& .muirtl-1kiro5a-MuiInputBase-root-MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline":
|
"& .muirtl-1kiro5a-MuiInputBase-root-MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline":
|
||||||
{
|
{
|
||||||
border: "1px solid #5559CE !important",
|
border: "1px solid #5559CE !important",
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
renderOption={(props, option) => (
|
renderOption={(props, option) => (
|
||||||
<Button
|
<Button
|
||||||
@@ -58,7 +58,7 @@ function DefaultSelect({ list, value, updateData, label, error, name }) {
|
|||||||
key={option.id || props.id}
|
key={option.id || props.id}
|
||||||
className="!flex !justify-start !p-[8px] !text-start !text-[#A1A1A1] hover:dark:!bg-[#35343D] !bg-[#FFF] dark:!bg-[#1F1D2B]"
|
className="!flex !justify-start !p-[8px] !text-start !text-[#A1A1A1] hover:dark:!bg-[#35343D] !bg-[#FFF] dark:!bg-[#1F1D2B]"
|
||||||
>
|
>
|
||||||
{option.name || option.label}
|
{option.title || option.name || option.label}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
renderInput={(params) => (
|
renderInput={(params) => (
|
||||||
|
|||||||
@@ -40,6 +40,22 @@ function Form({ changeData, insurance, supplementaryInsurance, data, isForAnothe
|
|||||||
<Content title="نام خانوادگی">
|
<Content title="نام خانوادگی">
|
||||||
<EditField changeData={changeData} data={data?.family} name="family" />
|
<EditField changeData={changeData} data={data?.family} name="family" />
|
||||||
</Content>
|
</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="نوع بیمه">
|
<Content title="نوع بیمه">
|
||||||
<DefaultSelect
|
<DefaultSelect
|
||||||
updateData={(name, val) => changeData(val, "value", name)}
|
updateData={(name, val) => changeData(val, "value", name)}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ const defaultData = {
|
|||||||
phone: { value: "", isEdit: false },
|
phone: { value: "", isEdit: false },
|
||||||
national_code: { value: "", isEdit: true },
|
national_code: { value: "", isEdit: true },
|
||||||
name: { value: "", isEdit: true },
|
name: { value: "", isEdit: true },
|
||||||
|
family: { value: "", isEdit: true },
|
||||||
|
gender: { value: "", isEdit: true },
|
||||||
basic_insurance: { value: "", isEdit: true },
|
basic_insurance: { value: "", isEdit: true },
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -58,7 +60,9 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) {
|
|||||||
value: res.national_code || "",
|
value: res.national_code || "",
|
||||||
isEdit: res.national_code ? false : true,
|
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: {
|
basic_insurance: {
|
||||||
value: res.basic_insurance,
|
value: res.basic_insurance,
|
||||||
isEdit: true,
|
isEdit: true,
|
||||||
@@ -68,7 +72,17 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) {
|
|||||||
setPrevData(newData);
|
setPrevData(newData);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} 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 {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
@@ -100,7 +114,9 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) {
|
|||||||
value: res.national_code || "",
|
value: res.national_code || "",
|
||||||
isEdit: res.national_code ? false : true,
|
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: {
|
basic_insurance: {
|
||||||
value: res.basic_insurance,
|
value: res.basic_insurance,
|
||||||
isEdit: true,
|
isEdit: true,
|
||||||
@@ -110,7 +126,17 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) {
|
|||||||
setPrevData(newData);
|
setPrevData(newData);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} 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 },
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user