Files
speedBB/resources/js/pages/Login.jsx
tracer ef84b73cb5
All checks were successful
CI/CD Pipeline / deploy (push) Successful in 31s
CI/CD Pipeline / promote_stable (push) Successful in 2s
Refine ACP general settings navigation and tabbed layout
2026-02-28 19:13:33 +01:00

76 lines
3.3 KiB
JavaScript

import { useState } from 'react'
import { Button, Card, Container, Form } from 'react-bootstrap'
import { Link, useNavigate } from 'react-router-dom'
import { useAuth } from '../context/AuthContext'
import { useTranslation } from 'react-i18next'
export default function Login() {
const { login } = useAuth()
const navigate = useNavigate()
const [loginValue, setLoginValue] = useState('')
const [password, setPassword] = useState('')
const [error, setError] = useState('')
const [loading, setLoading] = useState(false)
const { t } = useTranslation()
const handleSubmit = async (event) => {
event.preventDefault()
setError('')
setLoading(true)
try {
await login(loginValue, password)
navigate('/')
} catch (err) {
setError(err.message)
} finally {
setLoading(false)
}
}
return (
<Container fluid className="py-5">
<Card className="bb-card mx-auto" style={{ maxWidth: '480px' }}>
<Card.Body>
<Card.Title className="mb-3">{t('auth.login_title')}</Card.Title>
<Card.Text className="bb-muted">{t('auth.login_hint')}</Card.Text>
{error && <p className="text-danger">{error}</p>}
<Form onSubmit={handleSubmit}>
<Form.Group className="mb-3">
<Form.Label>{t('auth.login_identifier')}</Form.Label>
<Form.Control
type="text"
value={loginValue}
onChange={(event) => setLoginValue(event.target.value)}
placeholder={t('auth.login_placeholder')}
required
/>
</Form.Group>
<Form.Group className="mb-4">
<Form.Label>{t('form.password')}</Form.Label>
<Form.Control
type="password"
value={password}
onChange={(event) => setPassword(event.target.value)}
required
/>
<div className="mt-2 text-end">
<Link to="/reset-password">{t('auth.forgot_password')}</Link>
</div>
</Form.Group>
<div className="d-flex w-100 align-items-center gap-2">
<Button as={Link} to="/" type="button" variant="outline-secondary" disabled={loading}>
<i className="bi bi-x-circle me-2" aria-hidden="true" />
{t('acp.cancel')}
</Button>
<Button type="submit" className="ms-auto bb-accent-button" disabled={loading}>
<i className="bi bi-box-arrow-in-right me-2" aria-hidden="true" />
{loading ? t('form.signing_in') : t('form.sign_in')}
</Button>
</div>
</Form>
</Card.Body>
</Card>
</Container>
)
}