Files
nobat724_front/app/panel/(layout)/dashboard/page.js
T
hamedandClaude Opus 4.8 1599098b6d feat(panel): connect dashboard page to representation monthly stats
تبدیل صفحه dashboard پنل به Server Component که آمار ماهانه نماینده را
از API می‌گیرد (year/month میلادی جاری) و با adaptRepresentationDashboard
به propهای کامپوننت map می‌کند. حذف داده mock.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-15 00:00:16 +03:30

41 lines
1.3 KiB
JavaScript

import DashboardPage from "@/components/panel/dashboard";
import { cookies } from "next/headers";
import { fetchReq } from "@/lib/req";
import { safeJsonParse } from "@/lib/sanitize";
import { adaptRepresentationDashboard } from "@/helper";
export const dynamic = "force-dynamic";
async function Dashboard() {
const API_URL = process.env.NEXT_PUBLIC_API_URL;
let dashboard = null;
try {
const cookieStore = await cookies();
const userInfo = cookieStore.get("userInfo");
const accessToken = cookieStore.get("access_token");
if (userInfo && accessToken) {
const parsedUserInfo = safeJsonParse(userInfo.value);
const representationUuid = parsedUserInfo?.representation_uuid;
if (representationUuid) {
const now = new Date();
const year = now.getFullYear();
const month = now.getMonth() + 1;
dashboard = await fetchReq(
`${API_URL}/api/v1/representation/${representationUuid}/dashboard/monthly?year=${year}&month=${month}`,
{ headers: { Authorization: `Bearer ${accessToken.value}` } }
);
}
}
} catch (error) {
console.error("Error fetching representation dashboard:", error);
}
return <DashboardPage data={adaptRepresentationDashboard(dashboard)} />;
}
export default Dashboard;