feat(dashboard): connect patient dashboard to real user profile
- buildPatientUser: ساخت آبجکت user از user-profile واقعی با کلیدهای
مورد انتظار کامپوننتها؛ comments/messages خالی و اعداد هدر صفر
(بدون داده ساختگی، چون endpoint ندارند)
- app/dashboard/page.js پروفایل را server-side از user-profile/{uuid} میگیرد
- حذف import userData.json mock از Content داشبورد
- نوبت/تراکنش/تب اطلاعات از قبل به API واقعی وصل بودند (بدون تغییر)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,8 @@ import { getStateInfo } from "@/lib/getStateInfo";
|
|||||||
import { removeToken } from "@/utils";
|
import { removeToken } from "@/utils";
|
||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
import { fetchReq } from "@/lib/req";
|
||||||
|
import { buildPatientUser } from "@/lib/representationAdapters";
|
||||||
|
|
||||||
export default async function Dashboard({ searchParams }) {
|
export default async function Dashboard({ searchParams }) {
|
||||||
const awaitedSearchParams = await searchParams;
|
const awaitedSearchParams = await searchParams;
|
||||||
@@ -20,11 +22,21 @@ export default async function Dashboard({ searchParams }) {
|
|||||||
return redirect("/login");
|
return redirect("/login");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uuid = cookieStore.get("uuid")?.value;
|
||||||
|
let profile = null;
|
||||||
|
if (uuid) {
|
||||||
|
profile = await fetchReq(
|
||||||
|
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/user-profile/${uuid}`,
|
||||||
|
{ headers: { Authorization: `Bearer ${token.value}` } }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Content
|
<Content
|
||||||
logged={token.value}
|
logged={token.value}
|
||||||
params={awaitedSearchParams}
|
params={awaitedSearchParams}
|
||||||
matchedCity={matchedCity}
|
matchedCity={matchedCity}
|
||||||
|
user={buildPatientUser(profile)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,10 @@
|
|||||||
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
import userData from "@/data/userData.json";
|
|
||||||
import DashboardPage from "@/components/dashboard";
|
import DashboardPage from "@/components/dashboard";
|
||||||
import UserAccountPage from "./userAccount";
|
import UserAccountPage from "./userAccount";
|
||||||
|
|
||||||
function Content({ matchedCity, params, logged }) {
|
function Content({ matchedCity, params, logged, user }) {
|
||||||
const [value, setValue] = useState(Number(params?.sidebar) || 0);
|
const [value, setValue] = useState(Number(params?.sidebar) || 0);
|
||||||
const [isOpenSide, setIsOpenSide] = useState();
|
const [isOpenSide, setIsOpenSide] = useState();
|
||||||
const [isTurnsDetails, setIsTurnsDetails] = useState(null);
|
const [isTurnsDetails, setIsTurnsDetails] = useState(null);
|
||||||
@@ -16,7 +15,7 @@ function Content({ matchedCity, params, logged }) {
|
|||||||
value={value}
|
value={value}
|
||||||
logged={logged}
|
logged={logged}
|
||||||
setValue={setValue}
|
setValue={setValue}
|
||||||
user={userData.data}
|
user={user}
|
||||||
isOpenSide={isOpenSide}
|
isOpenSide={isOpenSide}
|
||||||
matchedCity={matchedCity}
|
matchedCity={matchedCity}
|
||||||
setIsOpenSide={setIsOpenSide}
|
setIsOpenSide={setIsOpenSide}
|
||||||
@@ -25,7 +24,7 @@ function Content({ matchedCity, params, logged }) {
|
|||||||
>
|
>
|
||||||
<UserAccountPage
|
<UserAccountPage
|
||||||
value={value}
|
value={value}
|
||||||
user={userData.data}
|
user={user}
|
||||||
setIsOpenSide={setIsOpenSide}
|
setIsOpenSide={setIsOpenSide}
|
||||||
isTurnsDetails={isTurnsDetails}
|
isTurnsDetails={isTurnsDetails}
|
||||||
setIsTurnsDetails={setIsTurnsDetails}
|
setIsTurnsDetails={setIsTurnsDetails}
|
||||||
|
|||||||
@@ -51,6 +51,33 @@ export function adaptRepresentationDashboard(dashboard) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function buildPatientUser(profile) {
|
||||||
|
const data = profile?.data ?? profile ?? {};
|
||||||
|
|
||||||
|
return {
|
||||||
|
profile: data.avatar ?? "/assets/images/profile-user.png",
|
||||||
|
name: [data.name, data.family].filter(Boolean).join(" ").trim(),
|
||||||
|
phone: data.phone ?? data.mobile ?? "",
|
||||||
|
total_transactions: 0,
|
||||||
|
number_of_turns: 0,
|
||||||
|
national_code: data.national_code ?? "",
|
||||||
|
gender: data.gender ?? "",
|
||||||
|
date_of_birth: data.birthday ?? "",
|
||||||
|
father_name: data.fathers_name ?? "",
|
||||||
|
insurance: data.basic_insurance ?? "",
|
||||||
|
insurance_number: "",
|
||||||
|
blood_group: data.blood_type ?? "",
|
||||||
|
marital_status: data.marital_status ?? "",
|
||||||
|
home_phone: data.home_phone ?? "",
|
||||||
|
education: data.education ?? "",
|
||||||
|
job: data.job ?? "",
|
||||||
|
work_phone: data.work_phone ?? "",
|
||||||
|
turns: { current: [], done: [] },
|
||||||
|
comments: [],
|
||||||
|
messages: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function adaptBankAccount(bankAccount) {
|
export function adaptBankAccount(bankAccount) {
|
||||||
if (!bankAccount) return [];
|
if (!bankAccount) return [];
|
||||||
return [
|
return [
|
||||||
|
|||||||
Reference in New Issue
Block a user