From 1599098b6d827491a7dfbedf0b91e1bbbfb0fdf1 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Mon, 15 Jun 2026 00:00:16 +0330 Subject: [PATCH] feat(panel): connect dashboard page to representation monthly stats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit تبدیل صفحه dashboard پنل به Server Component که آمار ماهانه نماینده را از API می‌گیرد (year/month میلادی جاری) و با adaptRepresentationDashboard به propهای کامپوننت map می‌کند. حذف داده mock. Co-Authored-By: Claude Opus 4.8 --- app/panel/(layout)/dashboard/page.js | 38 +++++++++++++++++++++++++--- helper/index.js | 15 +++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/app/panel/(layout)/dashboard/page.js b/app/panel/(layout)/dashboard/page.js index dafec69..48322bc 100644 --- a/app/panel/(layout)/dashboard/page.js +++ b/app/panel/(layout)/dashboard/page.js @@ -1,8 +1,40 @@ import DashboardPage from "@/components/panel/dashboard"; -import Information from "@/data/information.json"; +import { cookies } from "next/headers"; +import { fetchReq } from "@/lib/req"; +import { safeJsonParse } from "@/lib/sanitize"; +import { adaptRepresentationDashboard } from "@/helper"; -function Dashboard() { - return ; +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 ; } export default Dashboard; diff --git a/helper/index.js b/helper/index.js index c87a3c7..9a6ec32 100644 --- a/helper/index.js +++ b/helper/index.js @@ -696,3 +696,18 @@ export function adaptRepresentationInfo(representationInfo) { chart_amount_income: [], }; } + +export function adaptRepresentationDashboard(dashboard) { + const stats = dashboard?.data?.stats ?? dashboard?.stats ?? {}; + const daily = Array.isArray(stats.daily) ? stats.daily : []; + + return { + number_of_patients: stats.total_appointments ?? 0, + today_turns: daily.length ? daily[daily.length - 1].appointments ?? 0 : 0, + payments: stats.total_revenue_rials ?? 0, + commission_rials: stats.commission_rials ?? 0, + chart_amount_income: daily.map((d) => d.revenue ?? 0), + list_of_doctors_appointments: [], + todays_activities: [], + }; +}