- 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>
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
import Content from "@/components/dashboard/Content";
|
|
import { defineAbilitiesFor } from "@/lib/ability";
|
|
import { getUser } from "@/lib/auth";
|
|
import { getStateInfo } from "@/lib/getStateInfo";
|
|
import { removeToken } from "@/utils";
|
|
import { cookies } from "next/headers";
|
|
import { redirect } from "next/navigation";
|
|
import { fetchReq } from "@/lib/req";
|
|
import { buildPatientUser } from "@/lib/representationAdapters";
|
|
|
|
export default async function Dashboard({ searchParams }) {
|
|
const awaitedSearchParams = await searchParams;
|
|
const { matchedCity } = await getStateInfo();
|
|
const user = await getUser();
|
|
|
|
const ability = defineAbilitiesFor(user);
|
|
const cookieStore = await cookies();
|
|
const token = cookieStore.get("access_token");
|
|
|
|
if (!ability.can("access", "Dashboard")) {
|
|
removeToken();
|
|
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 (
|
|
<Content
|
|
logged={token.value}
|
|
params={awaitedSearchParams}
|
|
matchedCity={matchedCity}
|
|
user={buildPatientUser(profile)}
|
|
/>
|
|
);
|
|
}
|