«Peppa FACTORY» → «FORGE» в экранах, сообщениях, словарях en/kk, шаблоне и тестах; «Пеппа» → «FORGE» в подсказках агентам и правилах; логотип, значок, версия кэша service worker; в словаре старые названия — в «Нельзя». Внутренние имена (CLI peppa, PEPPA_*, MCP-сервер peppa, ключи PEP-N) не меняются. Второй адрес — в mac-route.sh. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
182 lines
9.8 KiB
TypeScript
182 lines
9.8 KiB
TypeScript
import Link from "next/link";
|
||
import { notFound } from "next/navigation";
|
||
import { acceptAllSummary, acceptScreen, type AcceptItem } from "@peppa/core";
|
||
import { acceptAllAction, fixStoryAction } from "@/app/(app)/actions";
|
||
import { Empty, Flash, Key, Notice, PageHeader } from "@/components/common";
|
||
import { LiveRefresh } from "@/components/LiveRefresh";
|
||
import { Button } from "@/components/ui/button";
|
||
import { Textarea } from "@/components/ui/input";
|
||
import { Workspace } from "@/components/Workspace";
|
||
import { requireUser } from "@/lib/auth";
|
||
import { db } from "@/lib/db";
|
||
import { getT } from "@/lib/i18n";
|
||
import { projectForUserByKey } from "@/lib/queries";
|
||
|
||
export async function generateMetadata() {
|
||
const t = await getT();
|
||
return { title: t("Приёмка — FORGE") };
|
||
}
|
||
|
||
const BIG = "min-h-11"; // PEP-209: buttons at least 44 px on a phone
|
||
|
||
/**
|
||
* PEP-209: acceptance on one screen — every story waiting for «Принять», grouped by product page,
|
||
* with «было» / «стало», «Принять», «Поправить» and «Принять всё» on top.
|
||
*/
|
||
export default async function AcceptPage({ params, searchParams }: { params: Promise<{ key: string }>; searchParams: Promise<{ error?: string; ok?: string; pending?: string; failed?: string }> }) {
|
||
const user = await requireUser();
|
||
const { key } = await params;
|
||
const sp = await searchParams;
|
||
const t = await getT();
|
||
const p = await projectForUserByKey(user.id, key).catch(() => null);
|
||
if (!p) notFound();
|
||
const screen = await acceptScreen(db, p);
|
||
const back = `/p/${p.key}/accept`;
|
||
const all = screen.groups.flatMap((g) => g.items);
|
||
const done = sp.ok != null ? { accepted: Number(sp.ok) || 0, pending: Number(sp.pending) || 0, failed: Number(sp.failed) || 0 } : null;
|
||
return (
|
||
<Workspace>
|
||
<LiveRefresh scope={`project:${p.id}`} />
|
||
<Flash error={sp.error} />
|
||
<PageHeader crumbs={<Link href={`/p/${p.key}`} className="text-muted-foreground hover:text-foreground">{p.name}</Link>} title={t("Приёмка")}>
|
||
{screen.total ? t("Работа, которая ждёт вашего решения: посмотрите и примите или напишите, что поправить.") : t("Принимать пока нечего: агенты пришлют задачи, когда работа будет готова.")}
|
||
</PageHeader>
|
||
|
||
{done && (
|
||
<Notice>
|
||
<span data-accept-result>{t.text(acceptAllSummary(done))}</span>
|
||
{screen.liveUrl && done.accepted + done.pending > 0 && (
|
||
<a href={screen.liveUrl} target="_blank" rel="noreferrer" className="text-primary">{t("Открыть продукт")} →</a>
|
||
)}
|
||
</Notice>
|
||
)}
|
||
|
||
{screen.total > 0 && (
|
||
<div className="mb-6 flex flex-wrap items-start gap-2" data-accept-top>
|
||
{screen.checkUrl && (
|
||
<a href={screen.checkUrl} target="_blank" rel="noreferrer" className={`inline-flex items-center rounded-md border bg-card px-4 text-sm font-medium hover:bg-accent ${BIG}`}>
|
||
{t("Открыть версию для проверки")}
|
||
</a>
|
||
)}
|
||
<details className="group w-full rounded-lg border bg-card sm:w-auto" data-accept-all>
|
||
<summary className={`flex cursor-pointer list-none items-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground select-none [&::-webkit-details-marker]:hidden ${BIG}`}>
|
||
{t("Принять всё · {n}", { n: all.length })}
|
||
</summary>
|
||
<form action={acceptAllAction} className="flex flex-col gap-2 p-3">
|
||
<input type="hidden" name="project" value={p.key} />
|
||
<input type="hidden" name="back" value={back} />
|
||
<p className="m-0 text-sm">{t("Будут приняты по очереди:")}</p>
|
||
<ul className="m-0 flex list-none flex-col gap-1 p-0 text-sm">
|
||
{all.map((it) => (
|
||
<li key={it.key}>
|
||
<input type="hidden" name="taskKey" value={it.key} />
|
||
<Key>{it.key}</Key> {it.title}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
<p className="m-0 text-xs text-muted-foreground">{t("Если какая-то не примется, остальные всё равно примутся, а у неё будет написано почему.")}</p>
|
||
<Button variant="default" className={BIG} data-accept-all-confirm>
|
||
{t("Да, принять {n}", { n: all.length })}
|
||
</Button>
|
||
</form>
|
||
</details>
|
||
</div>
|
||
)}
|
||
|
||
{screen.total === 0 && !done && <Empty>{t("Задач на приёмке нет.")}</Empty>}
|
||
|
||
{screen.groups.map((g) => (
|
||
<section key={g.page || "-"} className="mb-8" data-accept-group={g.page || "-"}>
|
||
<h2 className="mb-3 text-base font-semibold">
|
||
{g.page ? t("Страница {page}", { page: g.page }) : t("Без снимков страниц")} <span className="text-muted-foreground">· {g.items.length}</span>
|
||
</h2>
|
||
<div className="flex flex-col gap-4">
|
||
{g.items.map((it) => <AcceptCard key={it.key} it={it} back={back} />)}
|
||
</div>
|
||
</section>
|
||
))}
|
||
</Workspace>
|
||
);
|
||
}
|
||
|
||
async function AcceptCard({ it, back }: { it: AcceptItem; back: string }) {
|
||
const t = await getT();
|
||
return (
|
||
<article className="rounded-lg border bg-card p-3 sm:p-4" data-accept-item={it.key}>
|
||
<div className="mb-1 flex flex-wrap items-center gap-2 text-sm">
|
||
<Link href={`/t/${it.key}`} className="hover:underline">
|
||
<Key>{it.key}</Key>
|
||
</Link>
|
||
<span className="font-medium">{it.title}</span>
|
||
</div>
|
||
{it.summary !== it.title && <p className="m-0 mb-3 text-sm" data-accept-summary>{t.text(it.summary)}</p>}
|
||
{it.failed && (
|
||
<p role="alert" className="m-0 mb-3 rounded-md border border-destructive/50 bg-destructive/10 px-3 py-2 text-sm" data-accept-failed>
|
||
{t("Не принялась: {reason}", { reason: t.text(it.failed) })}
|
||
</p>
|
||
)}
|
||
{it.pending && <p className="m-0 mb-3 text-sm text-muted-foreground">{t("Вы уже приняли — изменения обновляются, задача закроется сама.")}</p>}
|
||
{it.shots.length > 0 ? (
|
||
// Scrolls sideways on a phone: one page per screen, «было» above «стало».
|
||
<div className="-mx-3 mb-3 flex snap-x snap-mandatory gap-3 overflow-x-auto px-3 pb-2 sm:mx-0 sm:px-0" data-accept-shots>
|
||
{it.shots.map((s, i) => (
|
||
<figure key={i} className="m-0 w-[85%] shrink-0 snap-start sm:w-[calc(50%-0.375rem)]">
|
||
<figcaption className="mb-1 text-xs text-muted-foreground">{s.path}</figcaption>
|
||
<div className="grid grid-cols-1 gap-2">
|
||
<Shot src={s.before} label={t("Было")} empty={t("Снимка рабочей версии нет")} />
|
||
<Shot src={s.after} label={t("Стало")} empty={t("Снимка нет")} />
|
||
</div>
|
||
</figure>
|
||
))}
|
||
</div>
|
||
) : it.previewUrl ? (
|
||
<p className="m-0 mb-3 text-sm">
|
||
<a href={it.previewUrl} target="_blank" rel="noreferrer" className="inline-flex min-h-11 items-center text-primary">{t("Открыть в версии для проверки")} →</a>
|
||
</p>
|
||
) : (
|
||
<p className="m-0 mb-3 text-sm text-muted-foreground">{t("Снимков и версии для проверки нет — посмотрите описание задачи.")}</p>
|
||
)}
|
||
{it.shots.length > 0 && it.previewUrl && (
|
||
<p className="m-0 mb-3 text-sm">
|
||
<a href={it.previewUrl} target="_blank" rel="noreferrer" className="inline-flex min-h-11 items-center text-primary">{t("Открыть в версии для проверки")} →</a>
|
||
</p>
|
||
)}
|
||
{!it.pending && (
|
||
<div className="flex flex-col gap-2 sm:flex-row sm:items-start">
|
||
<form action={acceptAllAction}>
|
||
<input type="hidden" name="project" value={it.key.slice(0, it.key.lastIndexOf("-"))} />
|
||
<input type="hidden" name="back" value={back} />
|
||
<input type="hidden" name="taskKey" value={it.key} />
|
||
<Button variant="default" className={`${BIG} w-full sm:w-auto`} data-accept-one={it.key}>{t("Принять")}</Button>
|
||
</form>
|
||
<details className="w-full sm:w-auto">
|
||
<summary className={`flex cursor-pointer list-none items-center justify-center rounded-md border bg-card px-4 text-sm font-medium select-none hover:bg-accent [&::-webkit-details-marker]:hidden ${BIG}`}>{t("Поправить")}</summary>
|
||
<form action={fixStoryAction} className="mt-2 flex flex-col gap-2">
|
||
<input type="hidden" name="taskKey" value={it.key} />
|
||
<input type="hidden" name="back" value={back} />
|
||
<Textarea name="text" required rows={3} placeholder={t("Что поправить? Например: кнопка должна быть синей")} />
|
||
<Button className={BIG} data-accept-fix={it.key}>{t("Отправить агенту")}</Button>
|
||
</form>
|
||
</details>
|
||
</div>
|
||
)}
|
||
</article>
|
||
);
|
||
}
|
||
|
||
function Shot({ src, label, empty }: { src: string | null; label: string; empty: string }) {
|
||
return (
|
||
<div>
|
||
<div className="mb-0.5 text-xs font-medium">{label}</div>
|
||
{src ? (
|
||
<a href={src} target="_blank" rel="noreferrer">
|
||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||
<img src={src} alt={label} loading="lazy" className="block w-full rounded border" />
|
||
</a>
|
||
) : (
|
||
<div className="flex aspect-[16/10] items-center justify-center rounded border border-dashed text-xs text-muted-foreground">{empty}</div>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|