175 lines
8.8 KiB
TypeScript
175 lines
8.8 KiB
TypeScript
import { connectedApps, isLocalUser, isSuperadmin, maskIin, MIN_PASSWORD } from "@peppa/core";
|
||
import { Hidden } from "@/components/cards";
|
||
import { ago, Empty, Flash, Notice, PageHeader, Section } from "@/components/common";
|
||
import { Button } from "@/components/ui/button";
|
||
import { Card } from "@/components/ui/card";
|
||
import { Input, Label } from "@/components/ui/input";
|
||
import { EgovSign } from "@/components/EgovSign";
|
||
import { Workspace } from "@/components/Workspace";
|
||
import { publicOrigin, requireUser } from "@/lib/auth";
|
||
import { db } from "@/lib/db";
|
||
import { changePasswordAction, pairTelegram, revokeConnectedApp, unlinkEgov, unpairTelegramAction } from "../actions";
|
||
|
||
const back = { back: "/settings" };
|
||
|
||
/** A connected thing: title + details on the left, actions on the right. */
|
||
function Row({ title, children, actions }: { title: React.ReactNode; children?: React.ReactNode; actions?: React.ReactNode }) {
|
||
return (
|
||
<Card className="flex-row flex-wrap items-center gap-3">
|
||
<div className="min-w-0 flex-[1_1_16rem]">
|
||
<div className="font-medium">{title}</div>
|
||
{children && <div className="text-sm text-muted-foreground">{children}</div>}
|
||
</div>
|
||
{actions && <div className="flex gap-2">{actions}</div>}
|
||
</Card>
|
||
);
|
||
}
|
||
|
||
export default async function Settings({ searchParams }: { searchParams: Promise<{ error?: string; egov?: string; password?: string }> }) {
|
||
const user = await requireUser();
|
||
const { error, egov, password } = await searchParams;
|
||
const local = isLocalUser(user);
|
||
const superadmin = await isSuperadmin(db, user);
|
||
const apps = await connectedApps(db, user.id);
|
||
const origin = await publicOrigin();
|
||
return (
|
||
<Workspace>
|
||
<div className="max-w-2xl">
|
||
<Flash error={error} />
|
||
<PageHeader title="Настройки" />
|
||
<Section title="Учётная запись">
|
||
{password === "changed" && <Notice>Пароль изменён</Notice>}
|
||
{local ? (
|
||
<Card>
|
||
<p className="m-0 text-sm">
|
||
<span className="font-mono">{user.login}</span> — локальный пользователь Пеппы, <b>нет аккаунта Gitea</b>. Доступ к коду проектов — только через Пеппу
|
||
(агенты, PR, проверки); соавтором репозитория в Gitea вас добавить нельзя, новые проекты создаются в пространстве{" "}
|
||
<span className="font-mono">peppa-bot</span>.
|
||
</p>
|
||
<form action={changePasswordAction} className="flex flex-col gap-3" aria-label="Смена пароля">
|
||
<Hidden fields={back} />
|
||
<input type="text" name="username" value={user.login} autoComplete="username" readOnly hidden />
|
||
<div className="flex flex-wrap gap-3">
|
||
<Label className="min-w-40 flex-1">
|
||
Текущий пароль
|
||
<Input name="current" type="password" required autoComplete="current-password" />
|
||
</Label>
|
||
<Label className="min-w-40 flex-1">
|
||
Новый пароль
|
||
<Input name="newPassword" type="password" required minLength={MIN_PASSWORD} autoComplete="new-password" />
|
||
</Label>
|
||
<Label className="min-w-40 flex-1">
|
||
Повтор
|
||
<Input name="confirm" type="password" required minLength={MIN_PASSWORD} autoComplete="new-password" />
|
||
</Label>
|
||
</div>
|
||
<Button variant="default" className="self-start">Сменить пароль</Button>
|
||
</form>
|
||
</Card>
|
||
) : (
|
||
<Row title={`Gitea: ${user.login}`}>Вы входите через Gitea{user.egovIin ? " или eGov" : ""}; пароль Пеппы не нужен.</Row>
|
||
)}
|
||
{superadmin && (
|
||
<Row
|
||
title="Суперадмин"
|
||
actions={
|
||
<>
|
||
<Button asChild size="sm">
|
||
<a href="/users">Пользователи</a>
|
||
</Button>
|
||
<Button asChild size="sm">
|
||
<a href="/subscriptions">Подписки</a>
|
||
</Button>
|
||
</>
|
||
}
|
||
>
|
||
Локальные пользователи без Gitea: создать, сбросить пароль, отключить. Подписки агентов и пулы для ротации.
|
||
</Row>
|
||
)}
|
||
</Section>
|
||
<Section title="Агенты">
|
||
<p className="m-0 text-sm text-muted-foreground">
|
||
Подписки Claude Code, Codex и OpenCode, на которых работают агенты, ведёт суперадмин в разделе «Подписки»; проект запускает раннеры на своём пуле подписок.
|
||
</p>
|
||
</Section>
|
||
<Section title="eGov">
|
||
{egov === "linked" && <Notice>eGov привязан — теперь можно входить по QR</Notice>}
|
||
{user.egovIin ? (
|
||
<Card>
|
||
<p className="m-0 text-sm">
|
||
Привязан ИИН <span className="font-mono">{maskIin(user.egovIin)}</span> — на странице входа можно войти через eGov QR.
|
||
</p>
|
||
<form action={unlinkEgov}>
|
||
<Hidden fields={back} />
|
||
<Button variant="destructive" size="sm">Отвязать</Button>
|
||
</form>
|
||
</Card>
|
||
) : (
|
||
<Card>
|
||
<p className="m-0 text-sm">Привяжите свой ИИН: отсканируйте QR в eGov Mobile и подпишите. После этого можно входить в Пеппу через eGov.</p>
|
||
<div className="max-w-xs">
|
||
<EgovSign purpose="link" label="Привязать eGov" />
|
||
</div>
|
||
</Card>
|
||
)}
|
||
</Section>
|
||
|
||
<Section title="Telegram">
|
||
{user.telegramChatId ? (
|
||
<Row
|
||
title={`Telegram привязан${user.telegramUsername ? ` (@${user.telegramUsername})` : ""}`}
|
||
actions={
|
||
<form action={unpairTelegramAction}>
|
||
<Hidden fields={back} />
|
||
<Button size="sm" variant="destructive">Отвязать</Button>
|
||
</form>
|
||
}
|
||
>
|
||
Вопросы агентов из ваших и общих проектов приходят в этот чат.
|
||
</Row>
|
||
) : (
|
||
<Row
|
||
title="Telegram не привязан"
|
||
actions={
|
||
<form action={pairTelegram}>
|
||
<Hidden fields={back} />
|
||
<Button variant="default" size="sm">Привязать Telegram</Button>
|
||
</form>
|
||
}
|
||
>
|
||
Бот присылает вопросы агентов и «готово к ревью» с кнопками. Нажмите кнопку — откроется бот, в нём нажмите Start.
|
||
</Row>
|
||
)}
|
||
</Section>
|
||
<Section title="MCP для ChatGPT и других клиентов">
|
||
<p className="m-0 text-sm">Адрес сервера — подключите его как MCP-коннектор с авторизацией OAuth. Клиент зарегистрируется сам, вы подтвердите доступ на экране Пеппы.</p>
|
||
<code className="block overflow-x-auto rounded-md border bg-muted px-3 py-2 font-mono text-sm">{origin}/mcp</code>
|
||
<p className="m-0 text-sm text-muted-foreground">
|
||
Как подключить и что спрашивать — в <a href="/help" className="text-primary">Помощи</a>.
|
||
</p>
|
||
</Section>
|
||
<Section title="Подключённые приложения">
|
||
{apps.length === 0 ? (
|
||
<Empty>Нет подключённых приложений.</Empty>
|
||
) : (
|
||
apps.map((a) => (
|
||
<Row
|
||
key={a.clientId}
|
||
title={a.name}
|
||
actions={
|
||
<form action={revokeConnectedApp}>
|
||
<Hidden fields={{ clientId: a.clientId, ...back }} />
|
||
<Button size="sm" variant="destructive">Отозвать</Button>
|
||
</form>
|
||
}
|
||
>
|
||
с {a.since.toLocaleDateString("ru-RU")} · последний запрос {ago(a.lastUsedAt)}
|
||
</Row>
|
||
))
|
||
)}
|
||
</Section>
|
||
</div>
|
||
</Workspace>
|
||
);
|
||
}
|