Files
TradarrV2/frontend/src/pages/Login.tsx
Blomios 50bde816ed feat(accounts): add admin accounts and user preferences
Remove public registration, support administrator-managed accounts, and persist personal preferences.

Refs #2 #5

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-20 19:54:06 +01:00

96 lines
3.5 KiB
TypeScript

import { useState, type FormEvent } from 'react'
import { Navigate } from 'react-router-dom'
import { useAuth } from '@/lib/auth'
import { authApi } from '@/api/auth'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
export function Login() {
const { token, login } = useAuth()
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [error, setError] = useState('')
const [loading, setLoading] = useState(false)
if (token) return <Navigate to="/" replace />
async function handleSubmit(e: FormEvent) {
e.preventDefault()
setError('')
setLoading(true)
try {
const { token: t, user } = await authApi.login(email, password)
login(t, user)
} catch (err) {
setError(err instanceof Error ? err.message : 'Erreur de connexion')
} finally {
setLoading(false)
}
}
return (
<div className="flex min-h-screen items-center justify-center bg-background p-4">
{/* Motif de fond discret */}
<div className="absolute inset-0 opacity-[0.03] pointer-events-none"
style={{ backgroundImage: 'repeating-linear-gradient(0deg, hsl(20 15% 9%), hsl(20 15% 9%) 1px, transparent 1px, transparent 40px), repeating-linear-gradient(90deg, hsl(20 15% 9%), hsl(20 15% 9%) 1px, transparent 1px, transparent 40px)' }}
/>
<div className="relative w-full max-w-sm">
{/* En-tête */}
<div className="mb-8 text-center">
<h1 className="font-serif text-4xl font-bold text-foreground">
Financ<span className="text-primary">IA</span>l
</h1>
<p className="mt-2 text-sm text-muted-foreground tracking-wide">
Votre journal financier augmenté par l&apos;IA
</p>
</div>
{/* Carte formulaire */}
<div className="rounded-lg border bg-card shadow-sm p-6">
<form onSubmit={handleSubmit} className="space-y-4">
<div className="space-y-1.5">
<Label htmlFor="email">Adresse email</Label>
<Input
id="email"
type="email"
value={email}
onChange={e => setEmail(e.target.value)}
required
autoComplete="email"
placeholder="vous@exemple.com"
/>
</div>
<div className="space-y-1.5">
<Label htmlFor="password">Mot de passe</Label>
<Input
id="password"
type="password"
value={password}
onChange={e => setPassword(e.target.value)}
required
autoComplete="current-password"
placeholder="••••••••"
/>
</div>
{error && (
<p className="text-sm text-destructive border border-destructive/20 bg-destructive/5 rounded px-3 py-2">
{error}
</p>
)}
<Button type="submit" className="w-full mt-2" disabled={loading}>
{loading ? 'Connexion…' : 'Se connecter'}
</Button>
</form>
<p className="mt-4 text-sm text-muted-foreground">Pour obtenir un compte, contactez votre administrateur.</p>
</div>
<p className="mt-6 text-center text-xs text-muted-foreground">
© {new Date().getFullYear()} FinancIAl — Accès restreint
</p>
</div>
</div>
)
}