import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Card, CardContent, CardHeader, CardTitle, CardDescription, } from '@/components/ui/card'; import { LanguageSelector } from '@/components/ui/language-selector'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import * as z from 'zod'; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from '@/components/ui/form'; import { useEffect, useState } from 'react'; import { httpClient } from '@/app/infra/http/HttpClient'; import { useNavigate } from 'react-router-dom'; import { Mail, Lock, Loader2, Info } from 'lucide-react'; import { Popover, PopoverContent, PopoverTrigger, } from '@/components/ui/popover'; import langbotIcon from '@/app/assets/langbot-logo.webp'; import { toast } from 'sonner'; import { useTranslation } from 'react-i18next'; import { ThemeToggle } from '@/components/ui/theme-toggle'; import { CustomApiError } from '@/app/infra/entities/common'; const formSchema = (t: (key: string) => string) => z.object({ email: z.string().email(t('common.invalidEmail')), password: z.string().min(1, t('common.emptyPassword')), }); export default function Register() { const navigate = useNavigate(); const { t } = useTranslation(); const [spaceLoading, setSpaceLoading] = useState(false); const form = useForm>>({ resolver: zodResolver(formSchema(t)), defaultValues: { email: '', password: '', }, }); useEffect(() => { getIsInitialized(); }, []); function getIsInitialized() { httpClient .checkIfInited() .then((res) => { if (res.initialized) { navigate('/login'); } }) .catch(() => {}); } function onSubmit(values: z.infer>) { handleRegister(values.email, values.password); } function handleRegister(username: string, password: string) { httpClient .initUser(username, password) .then(() => { toast.success(t('register.initSuccess')); navigate('/login'); }) .catch((err: Error) => { toast.error(t('register.initFailed') + (err as CustomApiError).msg); }); } // Space OAuth redirect handler const handleSpaceLoginClick = async () => { setSpaceLoading(true); try { // Build the redirect URI to the OAuth callback page const currentOrigin = window.location.origin; const redirectUri = `${currentOrigin}/auth/space/callback`; // Get the authorization URL from backend const response = await httpClient.getSpaceAuthorizeUrl(redirectUri); // Redirect to Space authorization page window.location.href = response.authorize_url; } catch { toast.error(t('common.spaceLoginFailed')); setSpaceLoading(false); } }; return (
LangBot {t('register.title')} {t('register.description')}
{t('register.adminAccountNote')}
{/* Space Login - Recommended */}

{t('register.spaceRecommended')}

  • {t('register.spaceInfoTip1')}
  • {t('register.spaceInfoTip2')}
  • {t('register.spaceInfoTip3')}

{t('common.or')}
{/* Local Account Registration */}
( {t('common.email')}
)} /> ( {t('common.password')}
)} />

{t('common.agreementNotice')}{' '} {t('common.privacyPolicy')} {' '} {t('common.and')}{' '} {t('common.dataCollectionPolicy')}

); }