fix(appointment): read user profile from response envelope
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 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,28 @@ const defaultData = {
|
|||||||
supplementary_insurance: { value: "", isEdit: true },
|
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 }) {
|
function AppointmentPage({ doctor, disabledDates, matchedCity }) {
|
||||||
const [step, setStep] = useState(0);
|
const [step, setStep] = useState(0);
|
||||||
const [isForAnother, setIsForAnother] = useState(false);
|
const [isForAnother, setIsForAnother] = useState(false);
|
||||||
@@ -56,30 +78,8 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) {
|
|||||||
try {
|
try {
|
||||||
const res = await request.getUserProfile(parsedData.uuid);
|
const res = await request.getUserProfile(parsedData.uuid);
|
||||||
|
|
||||||
if (res) {
|
if (res?.data) {
|
||||||
const newData = {
|
const newData = buildProfileData(res.data, usernameFromCookie);
|
||||||
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,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
setData(newData);
|
setData(newData);
|
||||||
setPrevData(newData);
|
setPrevData(newData);
|
||||||
}
|
}
|
||||||
@@ -120,30 +120,8 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) {
|
|||||||
try {
|
try {
|
||||||
const res = await request.getUserProfile(parsedData.uuid);
|
const res = await request.getUserProfile(parsedData.uuid);
|
||||||
|
|
||||||
if (res) {
|
if (res?.data) {
|
||||||
const newData = {
|
const newData = buildProfileData(res.data, usernameFromCookie);
|
||||||
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,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
setData(newData);
|
setData(newData);
|
||||||
setPrevData(newData);
|
setPrevData(newData);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user