import { useState } from 'react'; import { toast } from 'sonner'; import { useNavigate } from 'react-router'; import { useClient } from 'hooks/useClient'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Card } from '@/components/Card'; import { useForm } from 'hooks/useForm'; import { useTranslation } from '@/lib/i18n'; export function Bootstrap() { const { t } = useTranslation(); const authClient = useClient('/api/auth'); const navigate = useNavigate(); const [isSubmitting, setIsSubmitting] = useState(false); const { formRef, state, isValid } = useForm( {}, (s) => !!s.email && !!s.name && !!s.username && !!s.password && s.password === s.confirmPassword, ); const handleBootstrap = async (ev: React.FormEvent) => { ev.preventDefault(); if (!isValid || isSubmitting) return; setIsSubmitting(true); try { await authClient.post('/bootstrap', { email: state.email.trim(), name: state.name.trim(), username: state.username.trim(), password: state.password, confirmPassword: state.confirmPassword, }); toast.success(t('auth.bootstrapOk')); navigate('/'); } catch (ex) { const error = ex as { message?: string }; toast.error(error.message || 'Bootstrap failed. Please try again.'); } finally { setIsSubmitting(false); } }; return (
{t('auth.bootstrapTitle')}
{t('auth.bootstrapSubtitle')}
); }