peppa/apps/web/components/ProjectBasics.tsx
Асель 1b0f6063cb Merge main into task/pep-98: PEP-94/97/100/101/102 texts through the dictionary
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 15:11:59 +05:00

75 lines
4.3 KiB
TypeScript
Raw 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.

"use client";
import { useState, type ReactNode } from "react";
import { ChevronRight } from "lucide-react";
import { Input, Label } from "@/components/ui/input";
import { useT } from "@/components/I18n";
const RU: Record<string, string> = {
а: "a", б: "b", в: "v", г: "g", д: "d", е: "e", ё: "e", ж: "zh", з: "z", и: "i", й: "y", к: "k", л: "l", м: "m", н: "n", о: "o", п: "p", р: "r", с: "s",
т: "t", у: "u", ф: "f", х: "h", ц: "ts", ч: "ch", ш: "sh", щ: "sch", ъ: "", ы: "y", ь: "", э: "e", ю: "yu", я: "ya",
ә: "a", ғ: "g", қ: "k", ң: "n", ө: "o", ұ: "u", ү: "u", һ: "h", і: "i",
};
const latin = (s: string) => [...s.toLowerCase()].map((c) => RU[c] ?? c).join("");
/** «Сервис бронирования столиков» → `servis-bronirovaniya-stolikov` (the code's address). */
export function slugFrom(name: string): string {
return latin(name).replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40).replace(/-+$/, "");
}
/** «Сервис бронирования столиков» → `SBS` (story numbers SBS-1, SBS-2…). */
export function keyFrom(name: string): string {
const words = latin(name).split(/[^a-z0-9]+/).filter(Boolean);
let key = words.length > 1 ? words.map((w) => w[0]).join("") : (words[0] ?? "").slice(0, 3);
key = key.replace(/^[0-9]+/, "").slice(0, 5).toUpperCase();
return key.length >= 2 ? key : (key + "PRJ").slice(0, 3);
}
/**
* PEP-102: a product manager types the product's name; the code's address and the short code of
* story numbers fill in by themselves (editable under «Дополнительно» until touched).
*/
export function ProjectBasics({ children }: { children?: ReactNode }) {
const t = useT();
const [name, setName] = useState("");
const [slug, setSlug] = useState<string | null>(null);
const [key, setKey] = useState<string | null>(null);
const autoSlug = slugFrom(name) || "my-product";
const autoKey = keyFrom(name);
return (
<>
<Label>
{t("Как называется ваш продукт")}
<Input name="name" required placeholder={t("Например: Бронирование столиков")} value={name} onChange={(e) => setName(e.target.value)} autoComplete="off" />
<span className="text-xs font-normal text-muted-foreground">
{t("Сайт, бот, приложение или сервис — то, что будут делать агенты. Название можно поменять позже.")}
</span>
</Label>
<p className="m-0 rounded-md border bg-muted/40 px-3 py-2 text-sm text-muted-foreground">
{t("Задачи проекта будут называться")} <span className="font-mono font-medium text-foreground">{key ?? autoKey}-1</span>,{" "}
<span className="font-mono font-medium text-foreground">{key ?? autoKey}-2</span> {t("и так далее — по ним удобно говорить с агентами и ботом.")}
</p>
<details className="group rounded-md border px-3 py-2">
<summary className="flex cursor-pointer list-none items-center gap-1.5 text-sm font-medium">
<ChevronRight className="size-4 transition-transform group-open:rotate-90" /> {t("Дополнительно — можно не трогать")}
</summary>
<div className="mt-3 flex flex-col gap-4">
<div className="flex flex-wrap gap-3">
<Label className="min-w-48 flex-1">
{t("Адрес кода")}
<Input name="slug" required pattern="[a-z0-9][a-z0-9-]*" value={slug ?? autoSlug} onChange={(e) => setSlug(e.target.value.toLowerCase())} className="font-mono" />
<span className="text-xs font-normal text-muted-foreground">{t("Латиница, цифры и дефис. Видно только в ссылке на код.")}</span>
</Label>
<Label className="w-36">
{t("Код задач")}
<Input name="key" required pattern="[A-Za-z][A-Za-z0-9]{1,9}" value={key ?? autoKey} onChange={(e) => setKey(e.target.value.toUpperCase())} className="font-mono uppercase" />
<span className="text-xs font-normal text-muted-foreground">{t("2–10 латинских букв.")}</span>
</Label>
</div>
{children}
</div>
</details>
</>
);
}