mirror of
https://github.com/hazemKrimi/crimson-quirks-ui.git
synced 2026-05-01 18:20:28 +00:00
Add form control
This commit is contained in:
@@ -1,9 +1,41 @@
|
|||||||
|
import * as Yup from 'yup';
|
||||||
|
import { useFormik } from 'formik';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
import { Google, Signup as SignupIllustration, Logo } from '../../../assets';
|
import { Google, Signup as SignupIllustration, Logo } from '../../../assets';
|
||||||
import { Box, Button, Input, Link, Text } from '../../../components';
|
import { Box, Button, Input, Link, Text, Alert } from '../../../components';
|
||||||
import { theme } from '../../../themes';
|
import { theme } from '../../../themes';
|
||||||
import { Wrapper } from './styles';
|
import { Wrapper } from './styles';
|
||||||
|
|
||||||
const Signup = () => {
|
const Signup = () => {
|
||||||
|
const history = useHistory();
|
||||||
|
const [error, setError] = useState<string>('');
|
||||||
|
|
||||||
|
const form = useFormik({
|
||||||
|
initialValues: {
|
||||||
|
email: '',
|
||||||
|
password: '',
|
||||||
|
},
|
||||||
|
validationSchema: Yup.object().shape({
|
||||||
|
email: Yup.string()
|
||||||
|
.required('Email is required')
|
||||||
|
.email('Email is invalid'),
|
||||||
|
password: Yup.string()
|
||||||
|
.required('Password is required')
|
||||||
|
.min(6, 'Password is 6 characters minimum'),
|
||||||
|
}),
|
||||||
|
onSubmit: ({ email, password }, { resetForm }) => {
|
||||||
|
try {
|
||||||
|
history.push(`/additional-info?email=${email}&password=${password}`);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err.message);
|
||||||
|
setTimeout(() => setError(''), 3000);
|
||||||
|
} finally {
|
||||||
|
resetForm();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<Box
|
<Box
|
||||||
@@ -22,13 +54,19 @@ const Signup = () => {
|
|||||||
<Box marginRight='0.625rem'>
|
<Box marginRight='0.625rem'>
|
||||||
<Logo />
|
<Logo />
|
||||||
</Box>
|
</Box>
|
||||||
<Text variant='headline' weight='bold'>
|
|
||||||
astrobuild
|
|
||||||
</Text>
|
|
||||||
</Box>
|
</Box>
|
||||||
|
<Box
|
||||||
|
display='grid'
|
||||||
|
gridTemplateColumns='auto 1fr'
|
||||||
|
columnGap='1rem'
|
||||||
|
alignItems='center'
|
||||||
|
>
|
||||||
<Text variant='headline' weight='bold'>
|
<Text variant='headline' weight='bold'>
|
||||||
Signup
|
Signup
|
||||||
</Text>
|
</Text>
|
||||||
|
{error && <Alert color='error' text={error} />}
|
||||||
|
</Box>
|
||||||
|
<form onSubmit={form.handleSubmit}>
|
||||||
<Box
|
<Box
|
||||||
display='grid'
|
display='grid'
|
||||||
gridTemplateColumns='auto'
|
gridTemplateColumns='auto'
|
||||||
@@ -36,13 +74,24 @@ const Signup = () => {
|
|||||||
rowGap='0.5rem'
|
rowGap='0.5rem'
|
||||||
padding='1.563rem 0rem'
|
padding='1.563rem 0rem'
|
||||||
>
|
>
|
||||||
<Input label='Email' name='email' value='' onChange={() => {}} />
|
<Input
|
||||||
|
label='Email'
|
||||||
|
name='email'
|
||||||
|
value={form.values.email}
|
||||||
|
onChange={form.handleChange}
|
||||||
|
onBlur={form.handleBlur}
|
||||||
|
error={!!form.errors.email}
|
||||||
|
errorMessage={form.errors.email}
|
||||||
|
/>
|
||||||
<Input
|
<Input
|
||||||
label='Password'
|
label='Password'
|
||||||
name='password'
|
name='password'
|
||||||
type='password'
|
type='password'
|
||||||
value=''
|
value={form.values.password}
|
||||||
onChange={() => {}}
|
onChange={form.handleChange}
|
||||||
|
onBlur={form.handleBlur}
|
||||||
|
error={!!form.errors.password}
|
||||||
|
errorMessage={form.errors.password}
|
||||||
/>
|
/>
|
||||||
<Box
|
<Box
|
||||||
display='grid'
|
display='grid'
|
||||||
@@ -53,9 +102,9 @@ const Signup = () => {
|
|||||||
<Button
|
<Button
|
||||||
variant='primary-action'
|
variant='primary-action'
|
||||||
fullWidth
|
fullWidth
|
||||||
|
type='submit'
|
||||||
color='client'
|
color='client'
|
||||||
text='Signup'
|
text='Signup'
|
||||||
onClick={() => {}}
|
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
variant='secondary-action'
|
variant='secondary-action'
|
||||||
@@ -63,7 +112,6 @@ const Signup = () => {
|
|||||||
color='client'
|
color='client'
|
||||||
text='Signup with Google'
|
text='Signup with Google'
|
||||||
iconLeft={<Google />}
|
iconLeft={<Google />}
|
||||||
onClick={() => {}}
|
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<Box display='flex' flexDirection='row'>
|
<Box display='flex' flexDirection='row'>
|
||||||
@@ -78,6 +126,7 @@ const Signup = () => {
|
|||||||
</Link>
|
</Link>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
</form>
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
<Box
|
||||||
background={theme.colors.client.main}
|
background={theme.colors.client.main}
|
||||||
|
|||||||
Reference in New Issue
Block a user