From ebc6c246b97aae46ce8f5a16a9bc71f1e0710650 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Tue, 18 Nov 2025 08:32:41 +0330 Subject: [PATCH] refactor: add gender selection to Form component and update DefaultSelect for improved option handling --- app/component/selectors/DefaultSelect.js | 24 ++++++++--------- components/appointment/detail/Form.js | 16 +++++++++++ components/appointment/index.js | 34 +++++++++++++++++++++--- 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/app/component/selectors/DefaultSelect.js b/app/component/selectors/DefaultSelect.js index 5198b5d..54f2245 100644 --- a/app/component/selectors/DefaultSelect.js +++ b/app/component/selectors/DefaultSelect.js @@ -10,19 +10,19 @@ function DefaultSelect({ list, value, updateData, label, error, name }) { value={value || ""} getOptionLabel={(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" onChange={(_, newValue) => { - updateData(name, newValue?.label || newValue || ""); + updateData(name, newValue?.id || newValue?.label || newValue || ""); }} sx={{ ...styleTextSelectRight, // Hide Icon Number "& input::-webkit-outer-spin-button, & input::-webkit-inner-spin-button": - { - display: "none", - }, + { + display: "none", + }, "& input[type=number]": { MozAppearance: "textfield", }, @@ -43,13 +43,13 @@ function DefaultSelect({ list, value, updateData, label, error, name }) { : "1px solid #D7D7D7 !important", }, "& .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": - { - border: "1px solid #5559CE !important", - }, + { + border: "1px solid #5559CE !important", + }, }} renderOption={(props, option) => ( )} renderInput={(params) => ( diff --git a/components/appointment/detail/Form.js b/components/appointment/detail/Form.js index d1fe8b9..f8ec331 100644 --- a/components/appointment/detail/Form.js +++ b/components/appointment/detail/Form.js @@ -40,6 +40,22 @@ function Form({ changeData, insurance, supplementaryInsurance, data, isForAnothe + + 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 + } + /> + changeData(val, "value", name)} diff --git a/components/appointment/index.js b/components/appointment/index.js index ff75f9a..0dc5df0 100644 --- a/components/appointment/index.js +++ b/components/appointment/index.js @@ -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 }, + })); + } } } }