71 lines
3.8 KiB
TypeScript
71 lines
3.8 KiB
TypeScript
// PEP-198: «Фабрика решила за вас» — the analyst's product decisions of a story, right under its
|
||
// title (both views): each one with «Подходит» and «Нужно иначе» (a field «Как нужно?»); the
|
||
// split of a request — «Подходит» and «Не делить». Work does not wait for them.
|
||
import { decisionAction } from "@/app/(app)/actions";
|
||
import { Hidden } from "@/components/cards";
|
||
import { Badge } from "@/components/ui/badge";
|
||
import { Button } from "@/components/ui/button";
|
||
import { Textarea } from "@/components/ui/input";
|
||
import { getT } from "@/lib/i18n";
|
||
import { DECISION_STATUS_LABEL, type Decision } from "@peppa/core";
|
||
|
||
const VARIANT = { default: "muted", confirmed: "ok", changed: "info" } as const;
|
||
|
||
export async function TaskDecisions({ taskKey, decisions, back }: { taskKey: string; decisions: Decision[]; back: string }) {
|
||
if (!decisions.length) return null;
|
||
const t = await getT();
|
||
return (
|
||
<section data-decisions aria-labelledby="decisions-title" className="mb-4 flex flex-col gap-2 rounded-lg border bg-card p-3 sm:p-4">
|
||
<h2 id="decisions-title" className="m-0 text-sm font-semibold">
|
||
{t("Фабрика решила за вас")}
|
||
</h2>
|
||
<p className="m-0 text-xs text-muted-foreground">{t("Работа не ждёт: агент уже идёт по этим решениям. Если что-то нужно иначе — скажите здесь.")}</p>
|
||
<ul className="m-0 flex list-none flex-col gap-2 p-0">
|
||
{decisions.map((d) => (
|
||
<li key={d.id} data-decision={d.id} className="flex flex-col gap-2 rounded-md border p-2 text-sm">
|
||
<div className="flex flex-wrap items-start gap-2">
|
||
<span className="min-w-0 flex-1 break-words">{d.text}</span>
|
||
<Badge variant={VARIANT[d.status]} className="shrink-0">
|
||
{t(DECISION_STATUS_LABEL[d.status])}
|
||
</Badge>
|
||
</div>
|
||
{d.status === "changed" && d.was && <span className="text-xs break-words text-muted-foreground">{t("Было: {text}", { text: d.was })}</span>}
|
||
{d.status === "default" && (
|
||
<div className="flex flex-wrap items-start gap-2">
|
||
<form action={decisionAction}>
|
||
<Hidden fields={{ taskKey, id: d.id, back, choice: "confirm" }} />
|
||
<Button size="sm" variant="outline" className="min-h-11 min-w-11">
|
||
{t("Подходит")}
|
||
</Button>
|
||
</form>
|
||
{d.kind === "split" ? (
|
||
<form action={decisionAction}>
|
||
<Hidden fields={{ taskKey, id: d.id, back, choice: "unsplit" }} />
|
||
<Button size="sm" variant="outline" className="min-h-11 min-w-11">
|
||
{t("Не делить")}
|
||
</Button>
|
||
</form>
|
||
) : (
|
||
<details className="min-w-0 flex-1 basis-48">
|
||
<summary className="inline-flex min-h-11 cursor-pointer items-center rounded-md border px-3 text-sm">{t("Нужно иначе")}</summary>
|
||
<form action={decisionAction} className="mt-2 flex flex-col gap-2">
|
||
<Hidden fields={{ taskKey, id: d.id, back, choice: "change" }} />
|
||
<label className="flex flex-col gap-1 text-sm">
|
||
{t("Как нужно?")}
|
||
<Textarea name="how" rows={2} required />
|
||
</label>
|
||
<Button size="sm" className="min-h-11 self-start">
|
||
{t("Отправить")}
|
||
</Button>
|
||
</form>
|
||
</details>
|
||
)}
|
||
</div>
|
||
)}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
</section>
|
||
);
|
||
}
|