Files
kai f4619d22ed
release / which version (push) Successful in 6s
release / olares chart · sanity (push) Successful in 6s
release / app (push) Successful in 1m6s
release / tag and release (push) Successful in 2s
26.11.36: Startseiten mittig, saubere Umbrüche (#37)
2026-11-07 13:47:11 +00:00

55 lines
2.1 KiB
TypeScript

"use client";
import { useRouter } from "next/navigation";
import { useTranslations } from "next-intl";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { ErrorNotice } from "@/components/ui/notice";
import { register, type ErrorKey } from "./passkey";
export function SetupForm() {
const t = useTranslations("auth");
const router = useRouter();
const [error, setError] = useState<ErrorKey | null>(null);
const [busy, setBusy] = useState(false);
async function onSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
const form = new FormData(event.currentTarget);
setBusy(true);
setError(null);
const result = await register(
"/api/auth/setup/options",
{ code: form.get("code"), name: form.get("name"), household: form.get("household") },
"/api/auth/setup/verify",
);
setBusy(false);
if (result) setError(result);
else router.replace("/");
}
return (
<form onSubmit={onSubmit} className="flex flex-col gap-4">
<div className="flex flex-col gap-2">
<Label htmlFor="code">{t("setup.code")}</Label>
<Input id="code" name="code" required autoComplete="one-time-code" autoCapitalize="characters" spellCheck={false} placeholder="XXXX-XXXX-XXXX-XXXX" />
</div>
<div className="flex flex-col gap-2">
<Label htmlFor="name">{t("setup.name")}</Label>
<Input id="name" name="name" required maxLength={60} autoComplete="given-name" />
</div>
<div className="flex flex-col gap-2">
<Label htmlFor="household">{t("setup.household")}</Label>
<Input id="household" name="household" required maxLength={80} placeholder={t("setup.householdPlaceholder")} />
</div>
{error ? <ErrorNotice>{t(`errors.${error}`)}</ErrorNotice> : null}
<Button type="submit" size="lg" disabled={busy}>
{busy ? t("working") : t("setup.submit")}
</Button>
<p className="mx-auto max-w-[36ch] text-balance text-center text-sm text-muted-foreground">{t("setup.passkeyHint")}</p>
</form>
);
}