mirror of
https://github.com/hazemKrimi/crimson-quirks-ui.git
synced 2026-05-01 18:20:28 +00:00
Add form control and api logic
This commit is contained in:
@@ -1,9 +1,50 @@
|
|||||||
|
import * as Yup from 'yup';
|
||||||
|
import { useMutation } from '@apollo/client';
|
||||||
|
import { useFormik } from 'formik';
|
||||||
|
import { useState } from 'react';
|
||||||
import { Login as LoginIllustration, Logo } from '../../../assets';
|
import { Login as LoginIllustration, Logo } from '../../../assets';
|
||||||
import { Box, Button, Input, Link, Text } from '../../../components';
|
import { Box, Button, Input, Link, Text, Alert } from '../../../components';
|
||||||
|
import { RESET_PASSWORD } from '../../../graphql/auth.api';
|
||||||
|
import {
|
||||||
|
ResetPasswordMutation,
|
||||||
|
ResetPasswordMutationVariables,
|
||||||
|
} from '../../../graphql/types';
|
||||||
import { theme } from '../../../themes';
|
import { theme } from '../../../themes';
|
||||||
import { Wrapper } from './styles';
|
import { Wrapper } from './styles';
|
||||||
|
|
||||||
const ForgotPassword = () => {
|
const ForgotPassword = () => {
|
||||||
|
const [error, setError] = useState<string>('');
|
||||||
|
const [success, setSuccess] = useState<boolean>(false);
|
||||||
|
|
||||||
|
const [resetPassword, { loading }] = useMutation<
|
||||||
|
ResetPasswordMutation,
|
||||||
|
ResetPasswordMutationVariables
|
||||||
|
>(RESET_PASSWORD, {
|
||||||
|
onCompleted() {
|
||||||
|
setSuccess(true);
|
||||||
|
setTimeout(() => setSuccess(false), 3000);
|
||||||
|
},
|
||||||
|
onError({ graphQLErrors }) {
|
||||||
|
setError(graphQLErrors[0]?.extensions?.info);
|
||||||
|
setTimeout(() => setError(''), 3000);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const form = useFormik({
|
||||||
|
initialValues: {
|
||||||
|
email: '',
|
||||||
|
password: '',
|
||||||
|
},
|
||||||
|
validationSchema: Yup.object().shape({
|
||||||
|
email: Yup.string()
|
||||||
|
.required('Email is required')
|
||||||
|
.email('Email is invalid'),
|
||||||
|
}),
|
||||||
|
onSubmit: ({ email }) => {
|
||||||
|
resetPassword({ variables: { email } });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<Box
|
<Box
|
||||||
@@ -22,48 +63,70 @@ const ForgotPassword = () => {
|
|||||||
<Box marginRight='0.625rem'>
|
<Box marginRight='0.625rem'>
|
||||||
<Logo />
|
<Logo />
|
||||||
</Box>
|
</Box>
|
||||||
<Text variant='headline' weight='bold'>
|
|
||||||
astrobuild
|
|
||||||
</Text>
|
|
||||||
</Box>
|
</Box>
|
||||||
<Text variant='headline' weight='bold'>
|
|
||||||
Forgot Password
|
|
||||||
</Text>
|
|
||||||
<Box
|
<Box
|
||||||
display='grid'
|
display='grid'
|
||||||
gridTemplateColumns='auto'
|
gridTemplateColumns='auto 1fr'
|
||||||
|
columnGap='1rem'
|
||||||
alignItems='center'
|
alignItems='center'
|
||||||
rowGap='0.5rem'
|
|
||||||
padding='1.563rem 0rem'
|
|
||||||
>
|
>
|
||||||
<Input label='Email' name='email' value='' onChange={() => {}} />
|
<Text variant='headline' weight='bold'>
|
||||||
<Input label='Code' name='code' value='' onChange={() => {}} />
|
Forgot Password
|
||||||
|
</Text>
|
||||||
|
{error && <Alert color='error' text={error} />}
|
||||||
|
{success && (
|
||||||
|
<Alert
|
||||||
|
color='success'
|
||||||
|
text='Check your email to recover your account'
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
<form onSubmit={form.handleSubmit}>
|
||||||
<Box
|
<Box
|
||||||
display='grid'
|
display='grid'
|
||||||
gridTemplateColumns='auto'
|
gridTemplateColumns='auto'
|
||||||
rowGap='1rem'
|
alignItems='center'
|
||||||
marginTop='0.5rem'
|
rowGap='0.5rem'
|
||||||
|
padding='1.563rem 0rem'
|
||||||
>
|
>
|
||||||
<Button
|
<Input
|
||||||
variant='primary-action'
|
label='Email'
|
||||||
fullWidth
|
name='email'
|
||||||
color='client'
|
value={form.values.email}
|
||||||
text='Receive Code'
|
onChange={form.handleChange}
|
||||||
onClick={() => {}}
|
onBlur={form.handleBlur}
|
||||||
|
error={!!form.errors.email}
|
||||||
|
errorMessage={form.errors.email}
|
||||||
/>
|
/>
|
||||||
</Box>
|
<Box
|
||||||
<Box display='flex' flexDirection='row'>
|
display='grid'
|
||||||
<Box flexGrow='1'>
|
gridTemplateColumns='auto'
|
||||||
<Text variant='body' display='inline'>
|
rowGap='1rem'
|
||||||
Don’t have an account ?{' '}
|
marginTop='0.5rem'
|
||||||
</Text>
|
>
|
||||||
<Link href='/signup'>Signup</Link>
|
<Button
|
||||||
|
variant='primary-action'
|
||||||
|
fullWidth
|
||||||
|
color='client'
|
||||||
|
type='submit'
|
||||||
|
text='Send Reset Link'
|
||||||
|
loading={loading}
|
||||||
|
disabled={loading}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Box display='flex' flexDirection='row'>
|
||||||
|
<Box flexGrow='1'>
|
||||||
|
<Text variant='body' display='inline'>
|
||||||
|
Don’t have an account ?{' '}
|
||||||
|
</Text>
|
||||||
|
<Link href='/signup'>Signup</Link>
|
||||||
|
</Box>
|
||||||
|
<Link href='/' color='gray'>
|
||||||
|
Build a Project
|
||||||
|
</Link>
|
||||||
</Box>
|
</Box>
|
||||||
<Link href='/' color='gray'>
|
|
||||||
Build a Project
|
|
||||||
</Link>
|
|
||||||
</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