peppa/apps/web/components/Onboarding.tsx
2026-11-15 14:47:50 +05:00

79 lines
4.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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";
import { getT } from "@/lib/i18n";
export async function OnboardingChecklist({ data, botUsername = null }: { data: Onboarding; botUsername?: string | null }) {
const t = await getT();
const next = data.steps.find((s) => !s.done && !s.optional);
const fresh = data.done === 0;
return (
<section aria-label={t("С чего начать")} 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 ? t("Добро пожаловать! Запустим вашу фабрику за шесть шагов") : t("С чего начать")}</h2>
<p className="m-0 mt-1 text-sm text-muted-foreground">
{fresh
? t("Вы описываете задачу обычными словами — команда ИИ-агентов пишет код и показывает результат. Программировать не нужно. Идите по шагам сверху вниз.")
: t("Идите по шагам сверху вниз — на текущем шаге есть кнопка.")}
</p>
</div>
<form action={dismissOnboardingAction}>
<Hidden fields={{ back: "/" }} />
<Button size="sm" variant="ghost" title={t("Скрыть шаги")} aria-label={t("Скрыть шаги")}>
<X className="size-4" /> {t("Скрыть")}
</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={t("Сделано {done} из {total}", { done: data.done, total: 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">
{t("{done} из {total}", { done: data.done, total: 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")}>{t.text(s.title)}</span>
{!s.done && <span className="text-sm text-muted-foreground">{t.text(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}>
{t.text(s.action)} <ArrowRight />
</a>
</Button>
)}
</div>
</li>
);
})}
</ol>
</section>
);
}