import { FormEventHandler, useCallback } from 'react' import { Button, Form } from 'react-bootstrap' import { useSignIn, useSignUp } from '../hooks/api' import { composeSignUpBody } from '../api/signup' import { composeSignInBody } from '../api/token' type AuthFormProps = { register: boolean goBack: () => void, } function AuthForm({ goBack, register }: AuthFormProps) { const { handleSignUp, signUpButton } = useSignUp() const { handleSignIn, signInButton } = useSignIn() const handleAuth: FormEventHandler = useCallback((e) => { e.preventDefault() e.stopPropagation() const formData = new FormData(e.currentTarget) void (async () => { const accountCreated = register ? ( await handleSignUp(composeSignUpBody(formData)) ) : true if (accountCreated) { if (await handleSignIn(composeSignInBody(formData))) { goBack() } } })() }, [register, goBack, handleSignUp, handleSignIn]) return (
Почта {register && <> Имя Фамилия } Пароль {register && Я согласен с условиями обработки персональных данных }