45 lines
2.3 KiB
TypeScript
45 lines
2.3 KiB
TypeScript
import Link from "next/link";
|
|
import { KeyRound } from "lucide-react";
|
|
import type { AccessRequestView } from "@peppa/core";
|
|
import type { Translator } from "@peppa/shared/i18n";
|
|
import { ago } from "@/components/common";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { Card } from "@/components/ui/card";
|
|
|
|
/** «читать» / «читать и менять». */
|
|
export function accessModeText(mode: AccessRequestView["mode"], t: Translator): string {
|
|
return mode === "write" ? t("читать и менять") : t("только читать");
|
|
}
|
|
|
|
export function AccessStatus({ r, t }: { r: AccessRequestView; t: Translator }) {
|
|
if (r.status === "open") return <Badge variant="warn">{t("ждёт вашего решения")}</Badge>;
|
|
if (r.status === "granted") return <Badge variant="ok">{t("доступ выдан")}</Badge>;
|
|
if (r.status === "denied") return <Badge variant="danger">{t("отказано")}</Badge>;
|
|
return <Badge variant="outline">{t("агент отменил запрос")}</Badge>;
|
|
}
|
|
|
|
/** PEP-250: «Агенты просят доступ» on «Подключения» — the owner's open requests. */
|
|
export function AccessRequestList({ list, t }: { list: AccessRequestView[]; t: Translator }) {
|
|
return (
|
|
<ul className="m-0 flex list-none flex-col gap-2 p-0">
|
|
{list.map((r) => (
|
|
<li key={r.id}>
|
|
<Card className="flex flex-wrap items-center gap-x-3 gap-y-1 p-3 text-sm">
|
|
<KeyRound className="size-4 text-primary" />
|
|
<span className="font-medium">{r.service}</span>
|
|
<span className="text-muted-foreground">· {accessModeText(r.mode, t)}</span>
|
|
<span className="text-muted-foreground">
|
|
· {r.agentName ? t("агент {name}", { name: r.agentName }) : t("агент")} · {r.taskKey ?? r.projectKey}
|
|
</span>
|
|
<span className="basis-full truncate text-muted-foreground">{r.purpose}</span>
|
|
<span className="text-xs text-muted-foreground">{ago(r.updatedAt, t)}</span>
|
|
<Link href={`/connections/requests/${r.id}`} className="ml-auto text-primary underline-offset-2 hover:underline">
|
|
{t("Посмотреть и решить")}
|
|
</Link>
|
|
</Card>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
);
|
|
}
|