import { useEffect, useState } from "react"; import { del, get, post } from "../../api"; import { useT } from "../../i18n"; import { confirmDialog, toast } from "../../dialogs"; import { Icon } from "../Icon"; interface Key { id: string; name: string; public: string; fingerprint: string; } /** SSH keys of the user: used by agents, the terminal and the git panel to reach other servers. */ export function SshKeys() { const t = useT(); const [keys, setKeys] = useState(); const [name, setName] = useState(""); const [priv, setPriv] = useState(""); const [importing, setImporting] = useState(false); const [busy, setBusy] = useState(false); useEffect(() => { get("/account/ssh") .then(setKeys) .catch((e) => toast(e.message)); }, []); if (!keys) return null; const add = async () => { setBusy(true); try { setKeys(await post("/account/ssh", { name, private: importing ? priv : undefined })); setName(""); setPriv(""); toast(t("ssh.added"), "success"); } catch (e: any) { toast(e.message); } finally { setBusy(false); } }; const copy = (text: string) => navigator.clipboard?.writeText(text).then(() => toast(t("ssh.copied"), "success"), () => toast(t("ssh.copyFailed"))); return (

{t("ssh.title")}

{t("ssh.hint")}
{keys.length === 0 &&
{t("ssh.none")}
} {keys.map((k) => (
{k.name} {k.fingerprint}
e.currentTarget.select()} aria-label={t("ssh.public")} className="mono" />
))}
setName(e.target.value)} placeholder={t("ssh.name")} maxLength={60} aria-label={t("ssh.name")} style={{ flex: "1 1 160px" }} />
{importing && ( <>