/* * SPDX-FileCopyrightText: 2020 Stalwart Labs LLC * * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL */ import { type FormEvent, useState } from 'react'; import { useLocation } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { ArrowRight, Loader2 } from 'lucide-react'; import Logo from '@/components/common/Logo'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Card, CardContent, CardHeader } from '@/components/ui/card'; import { startAuthFlow } from '@/services/auth/oauth'; export default function LoginPage() { const { t } = useTranslation(); const location = useLocation(); const originalPath = (location.state as { from?: string } | null)?.from ?? null; const [username, setUsername] = useState(''); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); async function handleSubmit(e: FormEvent) { e.preventDefault(); const trimmed = username.trim(); if (!trimmed) return; setError(null); setLoading(true); try { await startAuthFlow(trimmed, originalPath); } catch (err) { setError(err instanceof Error ? err.message : t('login.error', 'An unexpected error occurred')); setLoading(false); } } return (

{t('login.prompt', 'Enter your account name to continue')}

setUsername(e.target.value)} disabled={loading} aria-label={t('login.prompt', 'Enter your account name to continue')} />
{error && (

{error}

)}
); }