parent
395b6c2d89
commit
619fd952a5
55
front/src/components/AuthForm.tsx
Normal file
55
front/src/components/AuthForm.tsx
Normal file
@ -0,0 +1,55 @@
|
||||
import { FormEventHandler } from "react"
|
||||
import { Button, Form } from "react-bootstrap"
|
||||
|
||||
type AuthFormProps = {
|
||||
register: boolean
|
||||
handleAuth: FormEventHandler<HTMLFormElement>,
|
||||
loading: boolean,
|
||||
error: string
|
||||
}
|
||||
|
||||
const AuthForm = ({ handleAuth, register, loading, error }: AuthFormProps) => {
|
||||
const buttonText = loading ? "Загрузка..." : (error || (register ? "Зарегистрироваться" : "Войти"))
|
||||
return (
|
||||
<Form onSubmit={handleAuth}>
|
||||
<Form.Group className="mb-3" controlId="email">
|
||||
<Form.Label>Почта</Form.Label>
|
||||
<Form.Control type="email" required />
|
||||
</Form.Group>
|
||||
|
||||
{register && <>
|
||||
<Form.Group className="mb-3" controlId="name">
|
||||
<Form.Label>Имя</Form.Label>
|
||||
<Form.Control type="text" required />
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group className="mb-3" controlId="surname">
|
||||
<Form.Label>Фамилия</Form.Label>
|
||||
<Form.Control type="text" required />
|
||||
</Form.Group>
|
||||
</>}
|
||||
|
||||
<Form.Group className="mb-3" controlId="password">
|
||||
<Form.Label>Пароль</Form.Label>
|
||||
<Form.Control type="password" required />
|
||||
</Form.Group>
|
||||
|
||||
{register &&
|
||||
<Form.Group className="mb-3" controlId="privacyPolicyConsent">
|
||||
<Form.Check label="<a>условиями обработки персональных данных</a>">
|
||||
<Form.Check.Input type="checkbox" required />
|
||||
<Form.Check.Label>
|
||||
Я согласен с <a href={`${document.location.origin}/privacy_policy.pdf`} target="_blank" rel="noopener noreferrer">условиями обработки персональных данных</a>
|
||||
</Form.Check.Label>
|
||||
</Form.Check>
|
||||
</Form.Group>
|
||||
}
|
||||
|
||||
<Button variant="success" type="submit">
|
||||
{buttonText}
|
||||
</Button>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
|
||||
export default AuthForm
|
@ -6,6 +6,7 @@ import LocationMarker from './LocationMarker'
|
||||
import TrashboxMarkers from './TrashboxMarkers'
|
||||
import WithToken from './WithToken'
|
||||
import ClickHandler from './ClickHandler'
|
||||
import AuthForm from "./AuthForm"
|
||||
|
||||
export {
|
||||
AnnouncementDetails,
|
||||
@ -16,4 +17,5 @@ export {
|
||||
TrashboxMarkers,
|
||||
WithToken,
|
||||
ClickHandler,
|
||||
AuthForm,
|
||||
}
|
||||
|
@ -1,14 +1,15 @@
|
||||
import { FormEventHandler } from 'react'
|
||||
import { Form, Button, Card, Tabs, Tab } from "react-bootstrap"
|
||||
import { Card, Tabs, Tab } from "react-bootstrap"
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
import { useAuth } from "../hooks/api";
|
||||
import { setToken } from "../utils/auth";
|
||||
import { AuthForm } from '../components';
|
||||
|
||||
function LoginPage() {
|
||||
const navigate = useNavigate()
|
||||
|
||||
const { doAuth } = useAuth() // TODO: Add loading and error handling
|
||||
const { doAuth, loading, error } = useAuth()
|
||||
|
||||
const handleAuth = (newAccount: boolean): FormEventHandler<HTMLFormElement> => async (event) => {
|
||||
event.preventDefault();
|
||||
@ -36,57 +37,10 @@ function LoginPage() {
|
||||
<Card.Body>
|
||||
<Tabs defaultActiveKey="register" fill justify className="mb-3">
|
||||
<Tab eventKey="register" title="Регистрация">
|
||||
<Form onSubmit={handleAuth(true)}>
|
||||
<Form.Group className="mb-3" controlId="email">
|
||||
<Form.Label>Почта</Form.Label>
|
||||
<Form.Control type="email" required />
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group className="mb-3" controlId="name">
|
||||
<Form.Label>Имя</Form.Label>
|
||||
<Form.Control type="text" required />
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group className="mb-3" controlId="surname">
|
||||
<Form.Label>Фамилия</Form.Label>
|
||||
<Form.Control type="text" required />
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group className="mb-3" controlId="password">
|
||||
<Form.Label>Пароль</Form.Label>
|
||||
<Form.Control type="password" required />
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group className="mb-3" controlId="privacyPolicyConsent">
|
||||
<Form.Check label="<a>условиями обработки персональных данных</a>">
|
||||
<Form.Check.Input type="checkbox" required />
|
||||
<Form.Check.Label>
|
||||
Я согласен с <a href={`${document.location.origin}/privacy_policy.pdf`} target="_blank" rel="noopener noreferrer">условиями обработки персональных данных</a>
|
||||
</Form.Check.Label>
|
||||
</Form.Check>
|
||||
</Form.Group>
|
||||
|
||||
<Button variant="success" type="submit">
|
||||
Зарегистрироваться
|
||||
</Button>
|
||||
</Form>
|
||||
<AuthForm handleAuth={handleAuth(true)} register={true} loading={loading} error={error} />
|
||||
</Tab>
|
||||
<Tab eventKey="login" title="Вход">
|
||||
<Form onSubmit={handleAuth(false)}>
|
||||
<Form.Group className="mb-3" controlId="email">
|
||||
<Form.Label>Почта</Form.Label>
|
||||
<Form.Control type="email" required />
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group className="mb-3" controlId="password">
|
||||
<Form.Label>Пароль</Form.Label>
|
||||
<Form.Control type="password" required />
|
||||
</Form.Group>
|
||||
|
||||
<Button variant="success" type="submit">
|
||||
Войти
|
||||
</Button>
|
||||
</Form>
|
||||
<AuthForm handleAuth={handleAuth(false)} register={false} loading={loading} error={error} />
|
||||
</Tab>
|
||||
</Tabs>
|
||||
</Card.Body>
|
||||
|
Loading…
x
Reference in New Issue
Block a user