2025-04-02 19:57:04 -04:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2025-02-21 14:48:21 -05:00
|
|
|
import { Link } from 'react-router-dom';
|
2025-04-02 19:57:04 -04:00
|
|
|
import { TextField, Button, CircularProgress } from '@mui/material';
|
|
|
|
|
import LoginContainer from '../../../../components/LoginContainer/LoginContainer';
|
2025-02-21 14:48:21 -05:00
|
|
|
import ApiService from '../../../../services/ApiService';
|
2025-04-02 19:57:04 -04:00
|
|
|
import 'bootstrap/dist/css/bootstrap.min.css';
|
2025-02-21 14:48:21 -05:00
|
|
|
|
|
|
|
|
const SimpleLogin: React.FC = () => {
|
|
|
|
|
const [email, setEmail] = useState('');
|
|
|
|
|
const [password, setPassword] = useState('');
|
|
|
|
|
const [connectionError, setConnectionError] = useState<string>('');
|
2025-04-02 19:57:04 -04:00
|
|
|
const [isConnecting, setIsConnecting] = useState<boolean>(false);
|
2025-02-21 14:48:21 -05:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
return () => {
|
2025-04-02 19:57:04 -04:00
|
|
|
// Cleanup if needed
|
2025-02-21 14:48:21 -05:00
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const login = async () => {
|
2025-04-02 19:57:04 -04:00
|
|
|
setIsConnecting(true);
|
2025-02-21 14:48:21 -05:00
|
|
|
const result = await ApiService.login(email, password);
|
2025-04-02 19:57:04 -04:00
|
|
|
setIsConnecting(false);
|
|
|
|
|
|
2025-02-21 14:48:21 -05:00
|
|
|
if (result !== true) {
|
|
|
|
|
setConnectionError(result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2025-04-02 19:57:04 -04:00
|
|
|
<LoginContainer title='' error={connectionError}>
|
|
|
|
|
{/* Email Input */}
|
2025-02-21 14:48:21 -05:00
|
|
|
<TextField
|
|
|
|
|
label="Email"
|
|
|
|
|
variant="outlined"
|
2025-04-02 19:57:04 -04:00
|
|
|
className="mb-3 w-100" // Bootstrap classes for spacing and width
|
2025-02-21 14:48:21 -05:00
|
|
|
value={email}
|
|
|
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
|
|
|
placeholder="Nom d'utilisateur"
|
2025-04-02 19:57:04 -04:00
|
|
|
fullWidth // Material-UI fullWidth
|
2025-02-21 14:48:21 -05:00
|
|
|
/>
|
|
|
|
|
|
2025-04-02 19:57:04 -04:00
|
|
|
{/* Password Input */}
|
2025-02-21 14:48:21 -05:00
|
|
|
<TextField
|
|
|
|
|
label="Mot de passe"
|
|
|
|
|
variant="outlined"
|
|
|
|
|
type="password"
|
2025-04-02 19:57:04 -04:00
|
|
|
className="mb-3 w-100" // Bootstrap classes
|
2025-02-21 14:48:21 -05:00
|
|
|
value={password}
|
|
|
|
|
onChange={(e) => setPassword(e.target.value)}
|
2025-04-02 19:57:04 -04:00
|
|
|
placeholder="Mot de passe"
|
2025-02-21 14:48:21 -05:00
|
|
|
fullWidth
|
|
|
|
|
/>
|
|
|
|
|
|
2025-04-02 19:57:04 -04:00
|
|
|
{/* Login Button */}
|
|
|
|
|
<Button
|
2025-02-21 14:48:21 -05:00
|
|
|
variant="contained"
|
2025-04-02 19:57:04 -04:00
|
|
|
className={`w-100 mb-${connectionError ? '4' : '3'}`} // Dynamic margin-bottom
|
|
|
|
|
onClick={login}
|
|
|
|
|
disabled={!email || !password || isConnecting}
|
|
|
|
|
startIcon={isConnecting ? <CircularProgress size={20} /> : null}
|
|
|
|
|
size="large"
|
2025-02-21 14:48:21 -05:00
|
|
|
>
|
|
|
|
|
Login
|
2025-04-02 19:57:04 -04:00
|
|
|
</Button>
|
|
|
|
|
|
|
|
|
|
{/* Links Section */}
|
|
|
|
|
<div className="d-flex flex-column align-items-center pt-3">
|
|
|
|
|
<del className="py-1 text-muted">Réinitialiser le mot de passe</del>
|
|
|
|
|
<Link
|
|
|
|
|
to="/register"
|
|
|
|
|
className="py-1 text-decoration-none text-primary"
|
|
|
|
|
>
|
2025-02-21 14:48:21 -05:00
|
|
|
Créer un compte
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
</LoginContainer>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-02 19:57:04 -04:00
|
|
|
export default SimpleLogin;
|