73 lines
4.2 KiB
TypeScript
73 lines
4.2 KiB
TypeScript
"use client";
|
||
|
||
import { useState, type ReactNode } from "react";
|
||
import { ChevronRight } from "lucide-react";
|
||
import { Input, Label } from "@/components/ui/input";
|
||
|
||
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 [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>
|
||
Как называется ваш продукт
|
||
<Input name="name" required placeholder="Например: Бронирование столиков" value={name} onChange={(e) => setName(e.target.value)} autoComplete="off" />
|
||
<span className="text-xs font-normal text-muted-foreground">
|
||
Сайт, бот, приложение или сервис — то, что будут делать агенты. Название можно поменять позже.
|
||
</span>
|
||
</Label>
|
||
<p className="m-0 rounded-md border bg-muted/40 px-3 py-2 text-sm text-muted-foreground">
|
||
Задачи проекта будут называться <span className="font-mono font-medium text-foreground">{key ?? autoKey}-1</span>,{" "}
|
||
<span className="font-mono font-medium text-foreground">{key ?? autoKey}-2</span> и так далее — по ним удобно говорить с агентами и ботом.
|
||
</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" /> Дополнительно — можно не трогать
|
||
</summary>
|
||
<div className="mt-3 flex flex-col gap-4">
|
||
<div className="flex flex-wrap gap-3">
|
||
<Label className="min-w-48 flex-1">
|
||
Адрес кода
|
||
<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">Латиница, цифры и дефис. Видно только в ссылке на код.</span>
|
||
</Label>
|
||
<Label className="w-36">
|
||
Код задач
|
||
<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">2–10 латинских букв.</span>
|
||
</Label>
|
||
</div>
|
||
{children}
|
||
</div>
|
||
</details>
|
||
</>
|
||
);
|
||
}
|