From 61c21136d2cd06c2bbd4aec3870596c472685501 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Mon, 15 Jun 2026 15:44:12 +0330 Subject: [PATCH] fix(appointment): read user profile from response envelope MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getUserProfile returns { success, data } (interceptor unwraps once), so the profile fields live under res.data, not res directly — the form was always populated empty. Extract a buildProfileData helper and use it in both the mount and step-3 effects, removing the duplicated mapping. Co-Authored-By: Claude Opus 4.8 --- components/appointment/index.js | 74 ++++++++++++--------------------- 1 file changed, 26 insertions(+), 48 deletions(-) diff --git a/components/appointment/index.js b/components/appointment/index.js index 60eb932..eaa362f 100644 --- a/components/appointment/index.js +++ b/components/appointment/index.js @@ -17,6 +17,28 @@ const defaultData = { supplementary_insurance: { value: "", isEdit: true }, }; +function buildProfileData(profile, phone) { + return { + uuid: profile.uuid, + phone: { value: phone, isEdit: false }, + national_code: { + value: profile.national_code || "", + isEdit: profile.national_code ? false : true, + }, + name: { value: profile.name || "", isEdit: true }, + family: { value: profile.family || "", isEdit: true }, + gender: { + value: profile.gender + ? { id: profile.gender, title: profile.gender === "male" ? "مرد" : "زن" } + : "", + isEdit: true, + }, + insurance_id: { value: profile.insurance_id || "", isEdit: true }, + basic_insurance: { value: profile.basic_insurance, isEdit: true }, + supplementary_insurance: { value: profile.supplementary_insurance, isEdit: true }, + }; +} + function AppointmentPage({ doctor, disabledDates, matchedCity }) { const [step, setStep] = useState(0); const [isForAnother, setIsForAnother] = useState(false); @@ -56,30 +78,8 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) { try { const res = await request.getUserProfile(parsedData.uuid); - if (res) { - const newData = { - uuid: res.uuid, - phone: { value: usernameFromCookie, isEdit: false }, - national_code: { - value: res.national_code || "", - isEdit: res.national_code ? false : true, // اگر کد ملی داره، غیرقابل ویرایش - }, - name: { value: res.name || "", isEdit: true }, - family: { value: res.family || "", 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, - }, - }; + if (res?.data) { + const newData = buildProfileData(res.data, usernameFromCookie); setData(newData); setPrevData(newData); } @@ -120,30 +120,8 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) { try { const res = await request.getUserProfile(parsedData.uuid); - if (res) { - const newData = { - uuid: res.uuid, - phone: { value: usernameFromCookie, isEdit: false }, - national_code: { - value: res.national_code || "", - isEdit: res.national_code ? false : true, - }, - name: { value: res.name || "", isEdit: true }, - family: { value: res.family || "", 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, - }, - }; + if (res?.data) { + const newData = buildProfileData(res.data, usernameFromCookie); setData(newData); setPrevData(newData); }