2024-02-26 09:39:09 -05:00
|
|
|
import React from 'react';
|
2024-01-23 11:48:56 -05:00
|
|
|
|
2024-02-26 09:39:09 -05:00
|
|
|
import { ViewIcon, ViewOffIcon } from '@chakra-ui/icons';
|
|
|
|
import { Button, Center, Container, FormControl, Icon, Image, Input, InputGroup, InputRightElement, Link, useBoolean } from '@chakra-ui/react';
|
|
|
|
import { SubmitHandler, useForm } from 'react-hook-form';
|
|
|
|
import { Link as ReactRouterLink, useNavigate } from 'react-router-dom';
|
2024-01-23 11:48:56 -05:00
|
|
|
|
2024-02-26 09:39:09 -05:00
|
|
|
import Logo from '../assets/images/fastapi-logo.svg';
|
|
|
|
import { Body_login_login_access_token as AccessToken } from '../client/models/Body_login_login_access_token';
|
|
|
|
import useAuth from '../hooks/useAuth';
|
2024-01-23 11:48:56 -05:00
|
|
|
|
|
|
|
const Login: React.FC = () => {
|
2024-02-15 17:17:26 -05:00
|
|
|
const [show, setShow] = useBoolean();
|
2024-01-23 11:48:56 -05:00
|
|
|
const navigate = useNavigate();
|
|
|
|
const { register, handleSubmit } = useForm<AccessToken>();
|
2024-02-26 09:39:09 -05:00
|
|
|
const { login } = useAuth();
|
|
|
|
|
2024-01-23 11:48:56 -05:00
|
|
|
const onSubmit: SubmitHandler<AccessToken> = async (data) => {
|
2024-02-26 09:39:09 -05:00
|
|
|
await login(data);
|
|
|
|
navigate('/');
|
2024-01-23 11:48:56 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2024-02-12 16:46:51 -05:00
|
|
|
<>
|
|
|
|
<Container
|
2024-02-26 09:39:09 -05:00
|
|
|
as='form'
|
2024-02-12 16:46:51 -05:00
|
|
|
onSubmit={handleSubmit(onSubmit)}
|
2024-02-26 09:39:09 -05:00
|
|
|
h='100vh'
|
|
|
|
maxW='sm'
|
|
|
|
alignItems='stretch'
|
|
|
|
justifyContent='center'
|
2024-02-12 16:46:51 -05:00
|
|
|
gap={4}
|
|
|
|
centerContent
|
|
|
|
>
|
2024-02-26 09:39:09 -05:00
|
|
|
<Image src={Logo} alt='FastAPI logo' height='auto' maxW='2xs' alignSelf='center' />
|
|
|
|
<FormControl id='email'>
|
|
|
|
<Input {...register('username')} placeholder='Email' type='text' />
|
2024-02-12 16:46:51 -05:00
|
|
|
</FormControl>
|
2024-02-26 09:39:09 -05:00
|
|
|
<FormControl id='password'>
|
2024-02-12 16:46:51 -05:00
|
|
|
<InputGroup>
|
|
|
|
<Input
|
2024-02-26 09:39:09 -05:00
|
|
|
{...register('password')}
|
|
|
|
type={show ? 'text' : 'password'}
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-02-26 09:39:09 -05:00
|
|
|
placeholder='Password'
|
2024-02-12 16:46:51 -05:00
|
|
|
/>
|
|
|
|
<InputRightElement
|
2024-02-26 09:39:09 -05:00
|
|
|
color='gray.400'
|
2024-02-12 16:46:51 -05:00
|
|
|
_hover={{
|
2024-02-26 09:39:09 -05:00
|
|
|
cursor: 'pointer',
|
2024-02-12 16:46:51 -05:00
|
|
|
}}
|
|
|
|
>
|
2024-02-26 09:39:09 -05:00
|
|
|
<Icon onClick={setShow.toggle} aria-label={show ? 'Hide password' : 'Show password'}>
|
2024-02-12 16:46:51 -05:00
|
|
|
{show ? <ViewOffIcon /> : <ViewIcon />}
|
|
|
|
</Icon>
|
|
|
|
</InputRightElement>
|
|
|
|
</InputGroup>
|
|
|
|
<Center>
|
2024-02-26 09:39:09 -05:00
|
|
|
<Link as={ReactRouterLink} to='/recover-password' color='blue.500' mt={2}>
|
2024-02-12 16:46:51 -05:00
|
|
|
Forgot password?
|
|
|
|
</Link>
|
|
|
|
</Center>
|
|
|
|
</FormControl>
|
2024-02-26 09:39:09 -05:00
|
|
|
<Button bg='ui.main' color='white' _hover={{ opacity: 0.8 }} type='submit'>
|
2024-02-12 16:46:51 -05:00
|
|
|
Log In
|
|
|
|
</Button>
|
|
|
|
</Container>
|
|
|
|
</>
|
2024-01-23 11:48:56 -05:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Login;
|