211 lines
12 KiB
TypeScript
211 lines
12 KiB
TypeScript
import Link from "next/link";
|
||
import { ExternalLink, Hourglass, KeyRound, Rocket, Wrench, X } from "lucide-react";
|
||
import type { ProductNeedView, ProductReview, ProjectProduct, PublishMode } from "@peppa/core";
|
||
import { Hidden } from "@/components/cards";
|
||
import { ago } from "@/components/common";
|
||
import { Button } from "@/components/ui/button";
|
||
import { Input } from "@/components/ui/input";
|
||
import { getT } from "@/lib/i18n";
|
||
import { deployProdAction, removeNeedAction, saveProjectSecretAction, setNeedDoneAction } from "@/app/(app)/actions";
|
||
import { wording } from "@peppa/shared/wording";
|
||
|
||
const host = (url: string) => url.replace(/^https?:\/\//, "");
|
||
|
||
/**
|
||
* PEP-111: «Ваш продукт» on the project page — where the result is and what to do next, for a
|
||
* product manager who asks «где это работает?». PEP-145: one big «Открыть продукт»; without a
|
||
* link — the honest status («Готовим ссылку», the system story), never «попросите аналитика».
|
||
*/
|
||
export async function ProductCard({
|
||
product,
|
||
projectKey,
|
||
chat = true,
|
||
engineer = false,
|
||
projectId,
|
||
needs = [],
|
||
review = null,
|
||
back,
|
||
publish = "button",
|
||
}: {
|
||
product: ProjectProduct;
|
||
projectKey: string;
|
||
chat?: boolean;
|
||
/** PEP-119: «Инженер» gets the link to the releases tab, «Продакт» — the button right here. */
|
||
engineer?: boolean;
|
||
projectId?: number;
|
||
/** PEP-112: what the owner has to give before the product is real. */
|
||
needs?: ProductNeedView[];
|
||
/** PEP-112: the product agent's last acceptance. */
|
||
review?: ProductReview | null;
|
||
back?: string;
|
||
/** PEP-145: «Показывать всем: сам» — no button, Peppa shows the version to everyone itself. */
|
||
publish?: PublishMode;
|
||
}) {
|
||
const t = await getT();
|
||
// «Показать всем»: the same action as the button in «Релизы», without sending a product manager there.
|
||
const showAll = engineer ? (
|
||
<>
|
||
{t("показать её всем можно в")} <Link href={`/p/${projectKey}?tab=releases`}>{t("Релизах")}</Link>.
|
||
</>
|
||
) : (
|
||
<form action={deployProdAction} className="inline">
|
||
<Hidden fields={{ projectKey, back: back ?? `/p/${projectKey}` }} />
|
||
<Button size="sm" variant="default">{t("Показать всем")}</Button>
|
||
</form>
|
||
);
|
||
const { task } = wording(engineer ? "engineer" : "product", t.locale);
|
||
const { live, check, doneStories } = product;
|
||
const open = needs.filter((n) => n.open);
|
||
if (!live && !check && doneStories === 0 && !open.length && !product.preparing) return null;
|
||
// PEP-145: one big button — the working product, else the version to check.
|
||
const link = live ?? check;
|
||
const deployed = !!(live || check);
|
||
const mayEdit = chat && projectId != null && !!back;
|
||
const next = chat && (
|
||
<p className="m-0 text-sm text-muted-foreground">
|
||
{t("Что дальше: опишите следующую задачу")} <Link href={`/chats/${projectKey}`}>{t("аналитику в чате")}</Link> — {t("он поможет сформулировать {task}, агенты сделают.", { task: task("acc") })}
|
||
</p>
|
||
);
|
||
return (
|
||
<section aria-label={t("Ваш продукт")} className={`mb-5 flex flex-col gap-3 rounded-xl border p-4 ${open.length ? "border-warn/50 bg-warn/5" : link ? "border-ok/40 bg-ok/5" : "border-info/40 bg-info/5"}`}>
|
||
{link ? (
|
||
<div className="flex flex-wrap items-center gap-x-4 gap-y-3">
|
||
<div className="flex min-w-0 flex-1 basis-full flex-col gap-0.5 sm:basis-0">
|
||
<span className="text-[15px] font-semibold">{live ? t("Ваш продукт работает") : t("Ваш продукт готов — пока его видите только вы")}</span>
|
||
<span className="text-sm text-muted-foreground">
|
||
{live ? t("Открыт для всех по адресу") : t("Адрес:")} <span className="font-mono text-foreground [overflow-wrap:anywhere]">{host(link.url)}</span> · {t("обновлён {when}", { when: ago(link.at, t) })}
|
||
{link.stories.length > 0 && <> · {t("вошли {tasks} {keys}", { tasks: task("pl"), keys: link.stories.slice(0, 6).join(", ") })}</>}
|
||
</span>
|
||
{!live && (
|
||
<span className="text-sm text-muted-foreground">
|
||
{publish === "auto" ? t("Когда задачи этой версии будут приняты, Peppa FACTORY сама покажет её всем.") : <>{t("Посмотрите — и, если всё хорошо,")} {showAll}</>}
|
||
</span>
|
||
)}
|
||
</div>
|
||
{product.shot && (
|
||
<a href={link.url} target="_blank" rel="noreferrer" className="hidden overflow-hidden rounded border sm:block" aria-hidden tabIndex={-1}>
|
||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||
<img src={`/api/releases/${product.shot.releaseId}/shots/${product.shot.n}`} alt="" loading="lazy" className="block h-20 w-32 object-cover object-top" />
|
||
</a>
|
||
)}
|
||
<Button asChild variant="default" size="lg">
|
||
<a href={link.url} target="_blank" rel="noreferrer">
|
||
<ExternalLink /> {t("Открыть продукт")}
|
||
</a>
|
||
</Button>
|
||
</div>
|
||
) : product.preparing || doneStories > 0 ? (
|
||
<div className="flex flex-col gap-0.5" role="status">
|
||
<span className="flex items-center gap-2 text-[15px] font-semibold">
|
||
<Hourglass className="size-4 text-info" /> {t("Готовим ссылку на продукт")}
|
||
</span>
|
||
<span className="text-sm text-muted-foreground">
|
||
{product.fix ? (
|
||
<>
|
||
{product.fix.working ? t("Агент уже этим занят:") : t("Агент возьмёт это первым:")} <Link href={`/t/${product.fix.key}`}>{product.fix.key}</Link>. {t("Ссылка появится здесь, делать ничего не нужно.")}
|
||
</>
|
||
) : product.preparing ? (
|
||
t("Продукт запускается — ссылка появится здесь через несколько минут.")
|
||
) : (
|
||
t("Ссылка появится здесь сама — делать ничего не нужно. Что уже получилось — на странице каждой готовой {task}.", { task: task("gen") })
|
||
)}
|
||
</span>
|
||
</div>
|
||
) : null}
|
||
{link && product.broken && (
|
||
<p className="m-0 text-sm" role="status">
|
||
<Wrench className="mr-1.5 inline size-4 align-text-bottom text-warn" />
|
||
{t("Последнее обновление не запустилось — по ссылке открывается прежняя версия. Чиним.")}{" "}
|
||
{product.fix && <Link href={`/t/${product.fix.key}`}>{product.fix.key}</Link>}
|
||
</p>
|
||
)}
|
||
{live && check && (
|
||
<p className="m-0 flex flex-wrap items-center gap-2 text-sm">
|
||
<Rocket className="size-4 text-primary" />
|
||
{t("Есть новая версия для проверки:")}{" "}
|
||
<a href={check.url} target="_blank" rel="noreferrer">
|
||
{host(check.url)}
|
||
</a>
|
||
{check.stories.length > 0 && <span className="text-muted-foreground">({check.stories.slice(0, 6).join(", ")})</span>} — {publish === "auto" ? t("Peppa FACTORY покажет её всем сама, когда задачи будут приняты.") : showAll}
|
||
</p>
|
||
)}
|
||
{open.length > 0 && (
|
||
<div role="note" aria-label={t("Демо-режим")} className="flex flex-col gap-2 rounded-lg border border-warn/40 bg-warn/10 p-3">
|
||
<span className="text-sm font-semibold">
|
||
{deployed ? t("Работает в демо-режиме — чтобы заработало по-настоящему, нужно от вас:") : t("Продукт будет работать в демо-режиме — чтобы заработало по-настоящему, нужно от вас:")}
|
||
</span>
|
||
<span className="text-sm text-muted-foreground">
|
||
{t("Пока этого нет, продукт показывает примеры вместо настоящей работы. Ключи хранятся зашифрованными; Peppa FACTORY сама передаст их продукту и перезапустит его — через пару минут после сохранения.")}
|
||
</span>
|
||
<ul className="m-0 flex list-none flex-col gap-2 p-0">
|
||
{open.map((n) => (
|
||
<li key={n.id} className="flex flex-col gap-1.5 rounded-md border bg-background/60 p-2.5 text-sm">
|
||
<div className="flex items-start gap-2">
|
||
<KeyRound className="mt-0.5 size-4 shrink-0 text-warn" />
|
||
<div className="flex min-w-0 flex-1 flex-col gap-0.5">
|
||
<span className="font-medium">{n.title}</span>
|
||
{n.why && <span className="text-muted-foreground">{t("Зачем: {why}", { why: n.why })}</span>}
|
||
{n.how && <span className="text-muted-foreground">{t("Где взять: {how}", { how: n.how })}</span>}
|
||
</div>
|
||
{mayEdit && (
|
||
<form action={removeNeedAction}>
|
||
<Hidden fields={{ projectId, id: n.id, back }} />
|
||
<Button variant="ghost" size="icon" aria-label={t("Не нужно: {title}", { title: n.title })} title={t("Не нужно — убрать пункт")}>
|
||
<X />
|
||
</Button>
|
||
</form>
|
||
)}
|
||
</div>
|
||
{mayEdit &&
|
||
(n.secret ? (
|
||
<form action={saveProjectSecretAction} className="flex flex-wrap items-center gap-2" autoComplete="off">
|
||
<Hidden fields={{ projectId, name: n.secret, back }} />
|
||
<Input name="value" type="password" required placeholder={t("Вставьте ключ сюда")} aria-label={t("Ключ: {title}", { title: n.title })} className="min-w-0 flex-1 font-mono" autoComplete="off" spellCheck={false} />
|
||
<Button size="sm">{t("Сохранить")}</Button>
|
||
</form>
|
||
) : (
|
||
<form action={setNeedDoneAction}>
|
||
<Hidden fields={{ projectId, id: n.id, done: 1, back }} />
|
||
<Button size="sm" variant="outline">
|
||
{t("Сделано")}
|
||
</Button>
|
||
</form>
|
||
))}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
</div>
|
||
)}
|
||
{review && deployed && (review.howto.length > 0 || review.notReal.length > 0) && (
|
||
<details className="text-sm">
|
||
<summary className="cursor-pointer font-medium">{t("Как пользоваться продуктом")}</summary>
|
||
<div className="mt-2 flex flex-col gap-2">
|
||
<p className="m-0 text-muted-foreground">{review.summary}</p>
|
||
{review.howto.length > 0 && (
|
||
<ol className="m-0 flex list-decimal flex-col gap-1 pl-5">
|
||
{review.howto.map((step, i) => (
|
||
<li key={i}>{step}</li>
|
||
))}
|
||
</ol>
|
||
)}
|
||
{review.notReal.length > 0 && (
|
||
<div className="flex flex-col gap-1">
|
||
<span className="font-medium">{t("Пока не настоящее")}</span>
|
||
<ul className="m-0 flex list-disc flex-col gap-1 pl-5 text-muted-foreground">
|
||
{review.notReal.map((x, i) => (
|
||
<li key={i}>{x}</li>
|
||
))}
|
||
</ul>
|
||
</div>
|
||
)}
|
||
<p className="m-0 text-xs text-muted-foreground">
|
||
{t("Продукт посмотрел продакт-агент {when} — подробности в", { when: ago(new Date(review.at), t) })} <Link href={`/chats/${projectKey}`}>{t("обсуждении проекта")}</Link>.
|
||
</p>
|
||
</div>
|
||
</details>
|
||
)}
|
||
{next}
|
||
</section>
|
||
);
|
||
}
|