// R-P11b (P11 dashboard, 3 fixed role layouts) Interim-UI (AD-28) — composed // from ~/ui (D-DASH archetype "KPI + Widget-Compose"). Pure: renders the // permission-gated widget grid of the one layout the server derived from the // member's seat. The route owns the SSE stream and feeds the latest snapshot in // as the VM, so the page has no live-state controls of its own. No // useLoaderData. Final Subframe optics = tracked design-nachzug (D-DASH). import { lazy, Suspense, type ReactNode } from "react"; import { useTranslation } from "react-i18next"; import { FeatherActivity, FeatherCalendar, FeatherCheckSquare, FeatherCreditCard, FeatherFolder, FeatherHome, FeatherLayoutDashboard, FeatherPhoneCall, FeatherTrendingUp, FeatherUsers, } from "@subframe/core"; import type { DashboardPageVM, DashboardWidgetDomain, DashboardWidgetItemVM, DashboardWidgetVM } from "@hivegrid/view-models"; import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell"; import { Alert } from "~/ui/components/Alert"; import { Card } from "~/ui/components/Card"; import { EmptyState } from "~/ui/components/EmptyState"; import { Loader } from "~/ui/components/Loader"; import { StatsCard } from "~/ui/components/StatsCard"; import { APP_TIME_ZONE, createLocaleFormatters } from "~/locale/format"; import { formatMonthLabel } from "./dashboardFormatters"; import { AppLink } from "~/components/app/AppLink"; const DashboardStageDistributionChart = lazy(() => import("./DashboardStageDistributionChart")); const DashboardMonthlySeriesChart = lazy(() => import("./DashboardMonthlySeriesChart")); export type DashboardPageProps = { vm: DashboardPageVM; }; const sectionHeading = "text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary"; const mutedText = "text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary"; const metricValue = "text-subtitle-0 font-subtitle-0 text-text-neutral-primary"; const domainIcons: Record = { general: , sales: , finance: , projects: , tasks: , hr: , activity: , comms: , schedule: , }; /** Same currency/count rendering as the chart, for the screen-reader table. */ function formatSeriesValue(value: number, format: "currency" | "count", language: string): string { const formatters = createLocaleFormatters(language); return format === "currency" ? formatters.currency(value, "EUR", { maximumFractionDigits: 0 }) : formatters.number(value, { maximumFractionDigits: 0 }); } function formatDateTime(value: string | null, language: string): string { if (!value) return "—"; return new Intl.DateTimeFormat(language, { timeZone: APP_TIME_ZONE, dateStyle: "medium", timeStyle: "short" }).format(new Date(value)); } export function DashboardPage(props: DashboardPageProps) { const { t, i18n } = useTranslation(); const header = ( } title={t("app.dashboard.title")} /> ); if (props.vm.status === "loading" || props.vm.status === "idle") { return ( {header} {t("app.dashboard.loading")} ); } if (props.vm.status === "error") { return ( {header} ); } if (props.vm.status === "empty") { return ( {header} ); } const data = props.vm.data; const activeRole = data.layout; return ( } title={t("app.dashboard.title")} subtitle={t(activeRole.descriptionKey)} />
{activeRole.widgets.map((widget) => (
))}
); } function DashboardWidgetCard({ widget, language }: { widget: DashboardWidgetVM; language: string }) { const { t } = useTranslation(); if (!widget.visible) { return ( {t(widget.titleKey)} {t("app.dashboard.widgets.permissionHidden")} ); } if (widget.series) { const series = widget.series; const descriptionId = `dashboard-series-${widget.key.replace(/[^a-z0-9]+/gi, "-")}-description`; return (
{t(widget.titleKey)} {t(widget.descriptionKey)}
{widget.metrics.length > 0 ? (
{widget.metrics.map((metric) => (
{t(metric.labelKey)} {metric.value}
))}
) : null} } >
{series.hasComparison ? : null} {series.points.map((point) => ( {series.hasComparison ? ( ) : null} ))}
{t(widget.titleKey)}
{t("app.dashboard.series.monthColumn")} {t("app.dashboard.series.currentPeriod")}{t("app.dashboard.series.previousYear")}
{formatMonthLabel(point.id, language)} {formatSeriesValue(point.value, series.valueFormat, language)}{point.comparisonValue === undefined ? "—" : formatSeriesValue(point.comparisonValue, series.valueFormat, language)}
); } if (widget.kind === "chart") { const points = widget.chart?.points ?? []; const resolvedPoints = points.map((point) => ({ ...point, label: point.labelKey ? t(point.labelKey) : point.label ?? "—", })); const descriptionId = `dashboard-chart-${widget.key.replace(/[^a-z0-9]+/gi, "-")}-description`; return (
{t(widget.titleKey)} {t(widget.descriptionKey)}
{points.length > 0 ? ( <> }>

{t("app.dashboard.widgets.stageDistribution.a11ySummary", { count: points.reduce((sum, point) => sum + point.value, 0) })}

{resolvedPoints.map((point) => ( ))}
{t(widget.titleKey)}
{t("app.dashboard.widgets.stageDistribution.stageColumn")} {t("app.dashboard.widgets.stageDistribution.projectCountColumn")}
{point.label} {formatSeriesValue(point.value, widget.chart?.valueFormat ?? "count", language)}
) : ( {t("app.dashboard.widgets.stageDistribution.empty")} )}
); } if (widget.kind === "hero") { return ( {t(widget.titleKey)} {t(widget.descriptionKey)} {widget.metrics[0] ? ( {t(widget.metrics[0].labelKey)}: {formatDateTime(widget.metrics[0].value, language)} ) : null} ); } if (widget.metrics.length === 1 && widget.items.length === 0) { const card = ( ); return widget.href ? ( {card} ) : ( card ); } return (
{t(widget.titleKey)}
{t(widget.descriptionKey)} {widget.metrics.length > 0 ? (
{widget.metrics.map((metric) => (
{t(metric.labelKey)} {metric.value}
))}
) : null} {widget.kind === "list" ? ( widget.items.length > 0 ? (
{widget.items.map((item) => ( ))}
) : ( {t("app.dashboard.widgets.empty")} ) ) : null}
); } function dashboardWidgetGridClass(widget: DashboardWidgetVM): string { const widthClass = widget.size.w <= 3 ? "lg:col-span-3" : widget.size.w <= 4 ? "lg:col-span-4" : widget.size.w <= 6 ? "lg:col-span-6" : widget.size.w <= 8 ? "lg:col-span-8" : "lg:col-span-12"; const startClass = widget.position.x === 0 ? "lg:col-start-1" : widget.position.x === 3 ? "lg:col-start-4" : widget.position.x === 4 ? "lg:col-start-5" : widget.position.x === 6 ? "lg:col-start-7" : widget.position.x === 8 ? "lg:col-start-9" : ""; return `min-w-0 ${widthClass} ${startClass}`; } function SubframeIcon({ domain }: { domain: DashboardWidgetDomain }) { return {domainIcons[domain]}; } function DashboardWidgetItemRow({ item }: { item: DashboardWidgetItemVM }) { const { t, i18n } = useTranslation(); const label = item.labelKey ? t(item.labelKey) : item.label; const tooltip = item.tooltip ?? label; const meta = item.metaDateIso ? formatDateTime(item.metaDateIso, i18n.language) : item.meta; return (
{item.href ? ( {label} ) : ( {label} )} {meta ? {meta} : null}
); } export default DashboardPage;