117 lines
6.2 KiB
TypeScript
117 lines
6.2 KiB
TypeScript
// PEP-120: the story page for a product manager — one card: what is happening now and
|
||
// «шаг N из M», the link to look at the result, what is needed from them, what comes next,
|
||
// «Принять» and «Поправить». Everything of a developer stays under «Подробнее» on the page.
|
||
import { Check, Eye, Pencil, Send } from "lucide-react";
|
||
import type { Question, ReviewPreview, StoryProductView } from "@peppa/core";
|
||
import { Hidden, QuestionCard } from "@/components/cards";
|
||
import { Button } from "@/components/ui/button";
|
||
import { Textarea } from "@/components/ui/input";
|
||
import { getT } from "@/lib/i18n";
|
||
import { cn } from "@/lib/utils";
|
||
import { acceptStoryAction, fixStoryAction } from "@/app/(app)/actions";
|
||
|
||
export async function StoryProduct({ view, taskKey, taskStatus, preview, questions, back, productUrl = null }: { view: StoryProductView; taskKey: string; taskStatus: string; preview: ReviewPreview; questions: Question[]; back: string; /** PEP-145: the project's product — where an accepted story is seen. */ productUrl?: string | null }) {
|
||
const t = await getT();
|
||
const pct = view.step ? Math.round(((view.step.n - 1) / view.step.m) * 100) : 0;
|
||
return (
|
||
<section aria-label={t("Что с задачей")} data-story-product className="flex flex-col gap-4 rounded-lg border bg-card p-4 md:p-5">
|
||
<div className="flex flex-col gap-2">
|
||
<p role="status" className="m-0 text-lg font-semibold [overflow-wrap:anywhere]">{t.text(view.now)}</p>
|
||
{view.step && (
|
||
<div className="flex flex-col gap-1">
|
||
<div className="flex items-center gap-3">
|
||
<span className="shrink-0 text-sm font-medium">
|
||
{t("Шаг {n} из {m}", { n: view.step.n, m: view.step.m })}
|
||
</span>
|
||
<div className="h-1.5 flex-1 overflow-hidden rounded-full bg-muted" aria-hidden>
|
||
<div className="h-full rounded-full bg-info" style={{ width: `${pct}%` }} />
|
||
</div>
|
||
</div>
|
||
{view.stepText && <p className="m-0 text-sm text-muted-foreground [overflow-wrap:anywhere]">{t("Сейчас: {step}", { step: view.stepText })}</p>}
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
{!preview.previewUrl && productUrl && taskStatus === "done" && (
|
||
<div className="flex flex-col gap-2">
|
||
<Button asChild variant="outline" className="self-start">
|
||
<a href={productUrl} target="_blank" rel="noreferrer">
|
||
<Eye />
|
||
{t("Посмотреть результат")}
|
||
</a>
|
||
</Button>
|
||
<p className="m-0 text-xs text-muted-foreground">{t("Откроется продукт проекта — в нём уже есть эта задача.")}</p>
|
||
</div>
|
||
)}
|
||
{preview.previewUrl && (
|
||
<div className="flex flex-col gap-2">
|
||
<Button asChild variant={view.canAccept ? "default" : "outline"} className="self-start">
|
||
<a href={preview.previewUrl} target="_blank" rel="noreferrer">
|
||
<Eye />
|
||
{t("Посмотреть")}
|
||
</a>
|
||
</Button>
|
||
<p className="m-0 text-xs text-muted-foreground">{t("Откроется версия для проверки — её видите только вы.")}</p>
|
||
{preview.releaseId != null && preview.screenshots.length > 0 && (
|
||
<div className="grid grid-cols-2 gap-2 sm:grid-cols-3">
|
||
{preview.screenshots.slice(0, 3).map((s) => {
|
||
const src = `/api/releases/${preview.releaseId}/shots/${s.n}`;
|
||
return (
|
||
<a key={s.n} href={src} target="_blank" rel="noreferrer" className="block overflow-hidden rounded border">
|
||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||
<img src={src} alt={t("Снимок экрана")} loading="lazy" className="block aspect-[16/10] w-full object-cover object-top" />
|
||
</a>
|
||
);
|
||
})}
|
||
</div>
|
||
)}
|
||
</div>
|
||
)}
|
||
|
||
<dl className="m-0 grid gap-x-4 gap-y-2 text-sm sm:grid-cols-[max-content_minmax(0,1fr)]">
|
||
<dt className="text-muted-foreground">{t("Что нужно от вас")}</dt>
|
||
<dd className={cn("m-0", view.need && "font-medium")}>{view.need ? t.text(view.need) : t("От вас сейчас ничего не нужно.")}</dd>
|
||
<dt className="text-muted-foreground">{t("Что дальше")}</dt>
|
||
<dd className="m-0">{t.text(view.next)}</dd>
|
||
</dl>
|
||
|
||
{questions.map((q) => (
|
||
<QuestionCard key={q.id} q={q} taskStatus={taskStatus} back={back} compact plain />
|
||
))}
|
||
|
||
{(view.canAccept || view.canFix) && (
|
||
<div className="flex flex-wrap items-start gap-2">
|
||
{view.canAccept && (
|
||
<form action={acceptStoryAction}>
|
||
<Hidden fields={{ taskKey, back }} />
|
||
<Button variant="default">
|
||
<Check />
|
||
{t("Принять")}
|
||
</Button>
|
||
</form>
|
||
)}
|
||
{view.canFix && (
|
||
<details className="group min-w-0 flex-[1_1_16rem]">
|
||
<summary className="inline-flex h-9 cursor-pointer list-none items-center gap-2 rounded-md border bg-background px-4 text-sm font-medium select-none hover:bg-accent [&::-webkit-details-marker]:hidden">
|
||
<Pencil className="size-4" />
|
||
{t("Поправить")}
|
||
</summary>
|
||
<form action={fixStoryAction} className="mt-2 flex flex-col gap-2">
|
||
<Hidden fields={{ taskKey, back }} />
|
||
<label htmlFor="story-fix" className="text-sm">
|
||
{t("Что поправить? Агент прочитает и доработает.")}
|
||
</label>
|
||
<Textarea id="story-fix" name="text" rows={3} required maxLength={60000} placeholder={t("Например: кнопка должна быть зелёной")} />
|
||
<Button size="sm" variant="outline" className="self-start">
|
||
<Send />
|
||
{t("Отправить агенту")}
|
||
</Button>
|
||
</form>
|
||
</details>
|
||
)}
|
||
</div>
|
||
)}
|
||
</section>
|
||
);
|
||
}
|