70 lines
3.4 KiB
TypeScript
70 lines
3.4 KiB
TypeScript
// PEP-174: a project on pause — the plaque on the project page, the «Поставить на паузу» /
|
||
// «Продолжить» buttons (page and «⋯ Настройки проекта») and the mark on project cards.
|
||
import { Pause, Play } from "lucide-react";
|
||
import { pauseProjectAction, resumeProjectAction } from "@/app/(app)/actions";
|
||
import { LocalTime } from "@/components/LocalTime";
|
||
import { PendingButton } from "@/components/PendingButton";
|
||
import { Badge } from "@/components/ui/badge";
|
||
import { getT } from "@/lib/i18n";
|
||
|
||
/** Pause or continue; pausing asks once more in one phrase (native <details>: no client JS). */
|
||
export async function PauseControl({ projectId, back, paused, popover }: { projectId: number; back: string; paused: boolean; popover?: boolean }) {
|
||
const t = await getT();
|
||
if (paused) {
|
||
return (
|
||
<form action={resumeProjectAction}>
|
||
<input type="hidden" name="projectId" value={projectId} />
|
||
<input type="hidden" name="back" value={back} />
|
||
<PendingButton pendingText={t("Продолжаем…")}>
|
||
<Play />
|
||
{t("Продолжить")}
|
||
</PendingButton>
|
||
</form>
|
||
);
|
||
}
|
||
return (
|
||
<details className={popover ? "group relative" : "group"}>
|
||
<summary className="inline-flex cursor-pointer list-none items-center gap-1.5 rounded-md border px-3 py-1.5 text-sm font-medium select-none hover:bg-muted [&::-webkit-details-marker]:hidden">
|
||
<Pause className="size-4" />
|
||
{t("Поставить на паузу")}
|
||
</summary>
|
||
<div className={popover ? "absolute right-0 z-30 mt-2 flex w-72 max-w-[calc(100vw-2rem)] flex-col gap-2 rounded-lg border bg-card p-3 text-sm shadow-lg" : "mt-2 flex flex-col gap-2 rounded-lg border bg-card p-3 text-sm"}>
|
||
<p className="m-0">{t("Агенты остановятся, уведомлений не будет, пока вы не нажмёте «Продолжить».")}</p>
|
||
<form action={pauseProjectAction}>
|
||
<input type="hidden" name="projectId" value={projectId} />
|
||
<input type="hidden" name="back" value={back} />
|
||
<PendingButton pendingText={t("Ставим на паузу…")}>{t("Да, поставить на паузу")}</PendingButton>
|
||
</form>
|
||
</div>
|
||
</details>
|
||
);
|
||
}
|
||
|
||
/** The plaque on the project page while it is on pause. */
|
||
export async function PauseBanner({ projectId, back, since }: { projectId: number; back: string; since: number }) {
|
||
const t = await getT();
|
||
return (
|
||
<div role="status" className="mb-4 flex flex-col items-start gap-3 rounded-lg border border-warn/50 bg-warn/15 px-4 py-3 text-sm sm:flex-row sm:items-center">
|
||
<span className="min-w-0 flex-1">
|
||
<Pause className="mr-1.5 inline size-4 align-[-3px]" />
|
||
<span className="font-medium">
|
||
{t("Проект на паузе с")} <LocalTime iso={new Date(since).toISOString()} />.
|
||
</span>{" "}
|
||
{t("Агенты не работают, уведомлений нет. Нажмите «Продолжить», чтобы агенты вернулись к работе.")}
|
||
</span>
|
||
<PauseControl projectId={projectId} back={back} paused />
|
||
</div>
|
||
);
|
||
}
|
||
|
||
/** Mark on a project card in lists and on the home page. */
|
||
export async function PausedBadge() {
|
||
const t = await getT();
|
||
return (
|
||
<Badge variant="warn">
|
||
<Pause className="size-3" />
|
||
{t("На паузе")}
|
||
</Badge>
|
||
);
|
||
}
|