35 lines
1.5 KiB
TypeScript
35 lines
1.5 KiB
TypeScript
"use client";
|
||
// PEP-253: the secret name field with a live hint «это ключ <Сервис> — агенту лучше дать подключение».
|
||
// The rules come from the server (`secretNameHints`), so no core code reaches the browser.
|
||
import { useState } from "react";
|
||
import { Input } from "@/components/ui/input";
|
||
import { useT } from "@/components/I18n";
|
||
|
||
export function SecretNameHint({ hints, label }: { hints: Array<{ prefix: string; exact: boolean; service: string }>; label: string }) {
|
||
const t = useT();
|
||
const [name, setName] = useState("");
|
||
const n = name.trim().toUpperCase();
|
||
const hit = n ? hints.find((h) => (h.exact ? n === h.prefix : n.startsWith(h.prefix))) : undefined;
|
||
return (
|
||
<div className="flex flex-col gap-1">
|
||
<Input
|
||
name="name"
|
||
required
|
||
placeholder="MAPS_API_KEY"
|
||
aria-label={label}
|
||
pattern="[A-Z][A-Z0-9_]{0,63}"
|
||
className="font-mono"
|
||
autoComplete="off"
|
||
spellCheck={false}
|
||
value={name}
|
||
onChange={(e) => setName(e.target.value)}
|
||
/>
|
||
{hit && (
|
||
<p className="m-0 text-xs text-amber-600 dark:text-amber-400" role="status">
|
||
{t("Это ключ {service} — агенту лучше дать подключение: он будет работать с сервисом, не видя ключа. Сохраните ключ здесь «только продукту» и нажмите «Сделать подключением».", { service: hit.service })}
|
||
</p>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|