peppa/apps/web/app/(app)/layout.tsx

49 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { ReactNode } from "react";
import { accountUsageForUser, agentsLine, getNotifyPrefs, isSuperadmin, pendingFeedbackCount } from "@peppa/core";
import { db } from "@/lib/db";
import { subscriptionRequestOffers } from "@peppa/runner";
import { requireUser, uiMode } from "@/lib/auth";
import { navCounts } from "@/lib/queries";
import { WordsProvider } from "@/components/Words";
import { Sidebar } from "@/components/Sidebar";
import { AttentionBadge } from "@/components/AttentionBadge";
import { CommandPalette } from "@/components/CommandPalette";
import { AgentsStrip, UsageStrip } from "@/components/Accounting";
import { VersionWatch } from "@/components/VersionWatch";
import { bootId } from "@/lib/boot";
import { FeedbackButton } from "@/components/FeedbackButton";
export const dynamic = "force-dynamic";
/** Console layout (PEP-38): navigation on the left, each page renders centre + right panel via <Workspace>. */
export default async function AppLayout({ children }: { children: ReactNode }) {
const user = await requireUser();
const counts = await navCounts(user.id);
const { sound } = await getNotifyPrefs(db, user.id);
const superadmin = await isSuperadmin(db, user);
const mode = await uiMode();
const engineer = mode === "engineer";
// PEP-5: subscription limit windows over every page — for «Инженер»; PEP-121: «Продакт»
// reads one line: agents work, or when they go on.
const accounts = engineer ? await accountUsageForUser(db, user).catch(() => []) : [];
const line = engineer ? null : await agentsLine(db, user).catch(() => ({ state: "working" as const }));
// PEP-186: agents stand — the owner may ask the superadmin for a subscription right from the strip.
const offers = line?.state === "paused" ? await subscriptionRequestOffers(db, user).catch(() => []) : [];
return (
<WordsProvider mode={mode}>
<div className="min-h-dvh md:grid md:grid-cols-[232px_minmax(0,1fr)]">
<AttentionBadge count={counts.questions + counts.waitingRunners} sound={sound} />
<Sidebar login={user.login} avatarUrl={user.avatarUrl} counts={{ ...counts, feedback: superadmin ? await pendingFeedbackCount(db) : 0 }} superadmin={superadmin} engineer={engineer} />
<div className="flex min-w-0 flex-col pb-16 md:pb-0">
<VersionWatch boot={bootId()} />
{line ? <AgentsStrip line={line} offers={offers} /> : <UsageStrip accounts={accounts} admin={superadmin} />}
{children}
</div>
<CommandPalette />
{/* PEP-143: «Сообщить о проблеме» on every page. */}
<FeedbackButton />
</div>
</WordsProvider>
);
}