peppa/apps/web/components/Onboarding.tsx

117 lines
6.6 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, skipTelegramStepAction, declineTelegramSuggestionAction } 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" /> : s.optional ? "·" : 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>}
{s.optional && !s.done && (
<form action={skipTelegramStepAction} className="self-start">
<Hidden fields={{ back: "/" }} />
<Button size="sm" variant="ghost">{t("Не сейчас")}</Button>
</form>
)}
{s.id === "telegram" ? (
// PEP-147: optional, never «current»: «Подключить» opens the bot steps, «Не сейчас» hides it.
!s.done && (
<details className="mt-1">
<summary className="inline-flex cursor-pointer list-none items-center gap-2">
<span className="inline-flex h-8 items-center rounded-md border bg-background px-3 text-sm font-medium">{t("Подключить")}</span>
</summary>
<div className="mt-2">
<OwnBotSteps botUsername={botUsername} back="/" bare />
</div>
</details>
)
) : 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>
);
}
/** PEP-147: one soft offer after the first accepted task. */
export async function TelegramSuggestion({ botUsername = null }: { botUsername?: string | null }) {
const t = await getT();
return (
<section aria-label={t("Хотите получать такие сообщения в Telegram?")} className="mb-8 rounded-xl border bg-card p-4">
<h2 className="m-0 text-base font-semibold">{t("Хотите получать такие сообщения в Telegram?")}</h2>
<p className="m-0 mt-1 text-sm text-muted-foreground">{t("Те же вопросы и готовые задачи — в телефоне, а новые задачи можно наговорить голосом. На сайте всё остаётся как есть.")}</p>
<div className="mt-3 flex flex-wrap items-start gap-2">
<details>
<summary className="inline-flex cursor-pointer list-none">
<span className="inline-flex h-8 items-center rounded-md border bg-background px-3 text-sm font-medium">{t("Подключить")}</span>
</summary>
<div className="mt-2">
<OwnBotSteps botUsername={botUsername} back="/" bare />
</div>
</details>
<form action={declineTelegramSuggestionAction}>
<Hidden fields={{ back: "/" }} />
<Button size="sm" variant="ghost">{t("Не нужно")}</Button>
</form>
</div>
</section>
);
}