diff --git a/client/src/pages/Login.jsx b/client/src/pages/Login.jsx index e8f8078..27ceb2c 100644 --- a/client/src/pages/Login.jsx +++ b/client/src/pages/Login.jsx @@ -1,8 +1,9 @@ -import { useState } from 'react' +import { useState, useEffect } from 'react' import { useNavigate } from 'react-router-dom' import { useAuth } from '../contexts/AuthContext' import { useLanguage } from '../i18n/LanguageContext' -import { Megaphone, Lock, Mail, AlertCircle } from 'lucide-react' +import { Megaphone, Lock, Mail, AlertCircle, User, CheckCircle } from 'lucide-react' +import api from '../utils/api' export default function Login() { const navigate = useNavigate() @@ -13,6 +14,16 @@ export default function Login() { const [loading, setLoading] = useState(false) const [error, setError] = useState('') + const [needsSetup, setNeedsSetup] = useState(null) + const [setupName, setSetupName] = useState('') + const [setupEmail, setSetupEmail] = useState('') + const [setupPassword, setSetupPassword] = useState('') + const [setupDone, setSetupDone] = useState(false) + + useEffect(() => { + api.get('/setup/status').then(data => setNeedsSetup(data.needsSetup)).catch(() => setNeedsSetup(false)) + }, []) + const handleSubmit = async (e) => { e.preventDefault() setError('') @@ -28,6 +39,31 @@ export default function Login() { } } + const handleSetup = async (e) => { + e.preventDefault() + setError('') + setLoading(true) + + try { + await api.post('/setup', { name: setupName, email: setupEmail, password: setupPassword }) + setSetupDone(true) + setNeedsSetup(false) + setEmail(setupEmail) + } catch (err) { + setError(err.message || 'Setup failed') + } finally { + setLoading(false) + } + } + + if (needsSetup === null) { + return ( +
{t('login.subtitle')}
++ {needsSetup ? 'Create your superadmin account to get started' : t('login.subtitle')} +
Account created. You can now log in.
+