77 lines
4.2 KiB
TypeScript
77 lines
4.2 KiB
TypeScript
// PEP-31/83: the first steps on the home page — for a product manager: what to do and why, in
|
||
// order, with one button on the current step.
|
||
import { ArrowRight, Check, X } from "lucide-react";
|
||
import type { Onboarding } from "@peppa/core";
|
||
import { dismissOnboardingAction } from "@/app/(app)/actions";
|
||
import { Hidden } from "@/components/cards";
|
||
import { Button } from "@/components/ui/button";
|
||
import { OwnBotSteps } from "@/components/OwnBotSteps";
|
||
import { cn } from "@/lib/utils";
|
||
|
||
export function OnboardingChecklist({ data, botUsername = null }: { data: Onboarding; botUsername?: string | null }) {
|
||
const next = data.steps.find((s) => !s.done && !s.optional);
|
||
const fresh = data.done === 0;
|
||
return (
|
||
<section aria-label="С чего начать" className="mb-8 rounded-xl border bg-card p-5">
|
||
<div className="mb-1 flex flex-wrap items-start gap-3">
|
||
<div className="min-w-0 flex-1">
|
||
<h2 className="m-0 text-lg font-semibold">{fresh ? "Добро пожаловать! Запустим вашу фабрику за шесть шагов" : "С чего начать"}</h2>
|
||
<p className="m-0 mt-1 text-sm text-muted-foreground">
|
||
{fresh
|
||
? "Вы описываете задачу обычными словами — команда ИИ-агентов пишет код и показывает результат. Программировать не нужно. Идите по шагам сверху вниз."
|
||
: "Идите по шагам сверху вниз — на текущем шаге есть кнопка."}
|
||
</p>
|
||
</div>
|
||
<form action={dismissOnboardingAction}>
|
||
<Hidden fields={{ back: "/" }} />
|
||
<Button size="sm" variant="ghost" title="Скрыть шаги" aria-label="Скрыть шаги">
|
||
<X className="size-4" /> Скрыть
|
||
</Button>
|
||
</form>
|
||
</div>
|
||
<div className="mb-4 flex items-center gap-3">
|
||
<div className="h-1.5 min-w-24 flex-1 overflow-hidden rounded-full bg-muted" role="progressbar" aria-valuemin={0} aria-valuemax={data.total} aria-valuenow={data.done} aria-label={`Сделано ${data.done} из ${data.total}`}>
|
||
<div className="h-full rounded-full bg-primary" style={{ width: `${Math.round((data.done / Math.max(1, data.total)) * 100)}%` }} />
|
||
</div>
|
||
<span className="text-xs text-muted-foreground tabular-nums">
|
||
{data.done} из {data.total}
|
||
</span>
|
||
</div>
|
||
<ol className="m-0 flex list-none flex-col gap-1.5 p-0">
|
||
{data.steps.map((s, i) => {
|
||
const current = s === next;
|
||
return (
|
||
<li key={s.id} data-step={s.id} aria-current={current ? "step" : undefined} className={cn("flex items-start gap-3 rounded-lg px-3 py-2.5", current && "border border-primary/40 bg-primary/8")}>
|
||
<span
|
||
aria-hidden
|
||
className={cn(
|
||
"mt-0.5 grid size-6 shrink-0 place-items-center rounded-full text-xs font-semibold",
|
||
s.done ? "bg-ok/20 text-ok" : current ? "bg-primary text-primary-foreground" : "bg-muted text-muted-foreground",
|
||
)}
|
||
>
|
||
{s.done ? <Check className="size-3.5" /> : i + 1}
|
||
</span>
|
||
<div className="flex min-w-0 flex-1 flex-col gap-1">
|
||
<span className={cn("text-sm font-medium", s.done && "text-muted-foreground line-through")}>{s.title}</span>
|
||
{!s.done && <span className="text-sm text-muted-foreground">{s.hint}</span>}
|
||
{current && s.id === "telegram" ? (
|
||
// PEP-85: the first thing to do — right here, not behind a link to Settings.
|
||
<div className="mt-1">
|
||
<OwnBotSteps botUsername={botUsername} back="/" bare />
|
||
</div>
|
||
) : current && (
|
||
<Button asChild variant="default" size="sm" className="mt-1 self-start">
|
||
<a href={s.href}>
|
||
{s.action} <ArrowRight />
|
||
</a>
|
||
</Button>
|
||
)}
|
||
</div>
|
||
</li>
|
||
);
|
||
})}
|
||
</ol>
|
||
</section>
|
||
);
|
||
}
|