import Link from "next/link"; import { notFound } from "next/navigation"; import { Gauge } from "lucide-react"; import { isSuperadmin, platformDashboard, platformDelayCounts, type DashboardCounts } from "@peppa/core"; import { ago, Empty, PageHeader, Section } from "@/components/common"; import { LiveRefresh } from "@/components/LiveRefresh"; import { Badge } from "@/components/ui/badge"; import { Card } from "@/components/ui/card"; import { Workspace } from "@/components/Workspace"; import { requireUser } from "@/lib/auth"; import { db } from "@/lib/db"; import { getT } from "@/lib/i18n"; import { m } from "@peppa/shared/i18n"; export async function generateMetadata() { const t = await getT(); return { title: t("Дашборд — Peppa FACTORY") }; } const SIGN_IN: Record = { egov: "eGov", google: "Google", gitea: "Gitea", local: m("пароль") }; /** «сделано / всего» with a thin bar. */ function Done({ c }: { c: DashboardCounts }) { const pct = c.total ? Math.round((c.done / c.total) * 100) : 0; return ( {c.done}/{c.total} ); } function Stat({ label, value, hint }: { label: string; value: number | string; hint?: string }) { return ( {label} {value} {hint && {hint}} ); } const th = "px-2 py-1.5 text-left text-xs font-medium whitespace-nowrap text-muted-foreground"; const td = "px-2 py-1.5 align-top whitespace-nowrap"; /** PEP-167: the superadmin's view of every user and project of the platform. */ export default async function Dashboard() { const user = await requireUser(); if (!(await isSuperadmin(db, user))) notFound(); const t = await getT(); const d = await platformDashboard(db); const x = d.totals; const delays = await platformDelayCounts(db); return ( {t("Дашборд платформы")}}> {t("Как идут дела у всех пользователей и во всех проектах. Видит только суперадмин.")}

{delays.total ? t("Задержки на платформе: {n}, требуют вас: {m}", { n: delays.total, m: delays.admin }) : t("Задержек на платформе нет")} →

{d.attention.length === 0 ? ( {t("Всё в порядке: ничего не зависло.")} ) : (
    {d.attention.map((a, i) => (
  • {a.who} {t.text(a.text)}
  • ))}
)}
{d.users.map((u) => ( ))}
{t("Пользователь")} {t("Вход")} {t("Проекты")} {t("Готово")} {t("В работе")} {t("Ждут «Принять»")} {t("Агенты")} {t("Вопросы")} {t("Принято за неделю")} {t("Активность")}
{u.name || u.login} {u.name && {u.login}}
{t("с {date}", { date: u.createdAt.toLocaleDateString("ru-RU") })}
{t.text(SIGN_IN[u.signIn] ?? u.signIn)} {u.telegram && Telegram} {u.projects.length ? ( {u.projects.map((k) => ( {k} ))} ) : ( {t("нет")} )} {u.inProgress} {u.review} {u.agentsNow} {u.openQuestions} {u.acceptedLast7d} {ago(u.lastActiveAt, t)}
{d.projects.map((p) => ( ))}
{t("Проект")} {t("Владелец")} {t("Готово")} {t("Бэклог")} {t("В работе")} {t("Ждут «Принять»")} {t("Агенты")} {t("Вопросы")} {t("Продукт")} {t("Активность")}
{p.key} {p.name} {p.warning &&
{t("Агенты не запустятся")}
}
{p.ownerLogin ?? "—"} {p.backlog} {p.inProgress} {p.review} {p.agentsNow} {p.openQuestions} {p.productUrl ? ( {t("открыть")} ) : ( — )} {ago(p.lastActiveAt, t)}
); }