fix(user-profile): consume profile from double-nested 200 response

With the backend now returning 200 (lazy-created profile) instead of
404, align the consumers: the profile lives at res.data.data (the
endpoint double-nests), so the booking detail and dashboard read that
instead of res.data / the raw envelope. Drop the obsolete 404 special
handling (empty editable form now comes from the 200 payload), seed the
dashboard empty state when the profile has no real data yet, and make
the profile POST fall back to PATCH on 409 (already lazy-created).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-06-15 19:06:38 +03:30
co-authored by Claude Opus 4.8
parent 83b2ec21b7
commit fbb2279b49
4 changed files with 129 additions and 40 deletions
@@ -27,17 +27,19 @@ function Information({ information, setInformation }) {
.getUserProfile(parsedUserInfo.uuid)
.then((res) => {
setLoadingInfo(false);
let changedData = res;
const profile = res?.data?.data;
changedData.basic_insurance = [Number(res?.basic_insurance?.id)];
changedData.prev_data = true;
changedData = changeDateType(changedData, false);
const hasProfileData = Boolean(
profile && (profile.label || profile.family || profile.national_code)
);
setInformation(changedData);
})
.catch((err) => {
setLoadingInfo(false);
if (err?.response?.data === "Entity not found") {
if (hasProfileData) {
let changedData = { ...profile };
changedData.basic_insurance = [Number(profile?.basic_insurance?.id)];
changedData.prev_data = true;
changedData = changeDateType(changedData, false);
setInformation(changedData);
} else {
setInformation({
prev_data: false,
other: {
@@ -50,6 +52,20 @@ function Information({ information, setInformation }) {
},
});
}
})
.catch(() => {
setLoadingInfo(false);
setInformation({
prev_data: false,
other: {
disease: disease,
allergies: [],
medications: [],
surgeries: [],
family_history: [],
relatives: [],
},
});
});
} else {
setLoadingInfo(false);