import { useState } from "react"; import { post } from "../../api"; import { useT } from "../../i18n"; import { useStore } from "../../store"; import { GitAccount } from "./GitAccount"; import { ApiTokens } from "./ApiTokens"; import { CliInstall } from "./CliInstall"; import { Memory } from "./Memory"; import { Telegram } from "./Telegram"; export function Account() { const t = useT(); const me = useStore((s) => s.me); const [form, setForm] = useState({ current: "", next: "", repeat: "" }); const [notice, setNotice] = useState<{ ok: boolean; text: string }>(); const save = async () => { if (form.next !== form.repeat) return setNotice({ ok: false, text: t("login.mismatch") }); try { await post("/auth/password", { current: form.current || undefined, new: form.next }); setForm({ current: "", next: "", repeat: "" }); setNotice({ ok: true, text: t("account.changed") }); } catch (e: any) { setNotice({ ok: false, text: e.message }); } }; return ( <>