feat(userAccount): enhance user profile handling with avatar upload and additional user data

This commit is contained in:
hamed
2026-06-19 10:19:52 +03:30
parent f6a3082ac8
commit ea2c0c29ec
7 changed files with 94 additions and 20 deletions
+25 -8
View File
@@ -27,20 +27,37 @@ export default async function Dashboard({ searchParams }) {
// may still carry the OTP uuid, which 404s against user-profile.
const userInfo = safeJsonParse(cookieStore.get("userInfo")?.value);
const userUuid = userInfo?.uuid || cookieStore.get("uuid")?.value;
let profile = null;
if (userUuid) {
profile = await fetchReq(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/user-profile/${userUuid}`,
{ headers: { Authorization: `Bearer ${token.value}` } }
);
}
const authHeader = { headers: { Authorization: `Bearer ${token.value}` } };
const API = process.env.NEXT_PUBLIC_API_URL;
const [profile, appointmentsRes, paymentsRes] = await Promise.all([
userUuid
? fetchReq(`${API}/api/v1/user-profile/${userUuid}`, authHeader)
: Promise.resolve(null),
fetchReq(`${API}/api/v1/my/appointments?page=1&limit=1`, authHeader),
fetchReq(`${API}/api/v1/my/payments?page=1&limit=200`, authHeader),
]);
const numberOfTurns = appointmentsRes?.meta?.totalRecords ?? 0;
const payments = paymentsRes?.data ?? [];
const totalRials = payments
.filter((p) => p.status === "success")
.reduce((sum, p) => sum + (Number(p.amount_rials) || 0), 0);
const totalTransactions = Math.round(totalRials / 10); // ریال → تومان
const extras = {
mobile: userInfo?.mobile_number ?? "",
realName: userInfo?.realName ?? "",
number_of_turns: numberOfTurns,
total_transactions: totalTransactions,
};
return (
<Content
logged={token.value}
params={awaitedSearchParams}
matchedCity={matchedCity}
user={buildPatientUser(profile)}
user={buildPatientUser(profile, extras)}
/>
);
}