mirror of
https://github.com/hazemKrimi/crimson-quirks-ui.git
synced 2026-05-02 02:30:29 +00:00
Add form control and api logic
This commit is contained in:
@@ -1,9 +1,58 @@
|
|||||||
|
import * as Yup from 'yup';
|
||||||
|
import { useMutation } from '@apollo/client';
|
||||||
|
import { useFormik } from 'formik';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
import { Login as LoginIllustration, Logo } from '../../../assets';
|
import { Login as LoginIllustration, Logo } from '../../../assets';
|
||||||
import { Box, Button, Input, Text } from '../../../components';
|
import { Box, Button, Input, Text, Alert } from '../../../components';
|
||||||
|
import { CONFIRM_USER_RESET_PASSWORD } from '../../../graphql/auth.api';
|
||||||
|
import {
|
||||||
|
ConfirmUserResetPasswordMutation,
|
||||||
|
ConfirmUserResetPasswordMutationVariables,
|
||||||
|
} from '../../../graphql/types';
|
||||||
import { theme } from '../../../themes';
|
import { theme } from '../../../themes';
|
||||||
import { Wrapper } from './styles';
|
import { Wrapper } from './styles';
|
||||||
|
|
||||||
const RecoverAccount = () => {
|
const RecoverAccount = () => {
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
const history = useHistory();
|
||||||
|
const [error, setError] = useState<string>('');
|
||||||
|
|
||||||
|
const [confirmResetPassword, { loading }] = useMutation<
|
||||||
|
ConfirmUserResetPasswordMutation,
|
||||||
|
ConfirmUserResetPasswordMutationVariables
|
||||||
|
>(CONFIRM_USER_RESET_PASSWORD, {
|
||||||
|
onCompleted() {
|
||||||
|
history.push('/login');
|
||||||
|
},
|
||||||
|
onError({ graphQLErrors }) {
|
||||||
|
setError(graphQLErrors[0]?.extensions?.info);
|
||||||
|
setTimeout(() => setError(''), 3000);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const form = useFormik({
|
||||||
|
initialValues: {
|
||||||
|
newPassword: '',
|
||||||
|
confirmNewPassword: '',
|
||||||
|
},
|
||||||
|
validationSchema: Yup.object().shape({
|
||||||
|
newPassword: Yup.string()
|
||||||
|
.required('New password is required')
|
||||||
|
.min(6, 'new Password is 6 characters minimum'),
|
||||||
|
confirmNewPassword: Yup.string().oneOf(
|
||||||
|
[Yup.ref('newPassword')],
|
||||||
|
"Passwords don't match"
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
onSubmit: ({ newPassword }) => {
|
||||||
|
confirmResetPassword({
|
||||||
|
// eslint-disable-next-line
|
||||||
|
variables: { id: params.get('code')!, password: newPassword },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<Box
|
<Box
|
||||||
@@ -22,47 +71,62 @@ const RecoverAccount = () => {
|
|||||||
<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'>
|
|
||||||
Recover Account
|
|
||||||
</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
|
<Text variant='headline' weight='bold'>
|
||||||
label='New Password'
|
Recover Account
|
||||||
name='newPassword'
|
</Text>
|
||||||
value=''
|
{error && <Alert color='error' text={error} />}
|
||||||
onChange={() => {}}
|
</Box>
|
||||||
/>
|
<form onSubmit={form.handleSubmit}>
|
||||||
<Input
|
|
||||||
label='Confirm New Password'
|
|
||||||
name='confirmNewPassword'
|
|
||||||
value=''
|
|
||||||
onChange={() => {}}
|
|
||||||
/>
|
|
||||||
<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='New Password'
|
||||||
fullWidth
|
name='newPassword'
|
||||||
color='client'
|
value={form.values.newPassword}
|
||||||
text='Recover Account'
|
onChange={form.handleChange}
|
||||||
onClick={() => {}}
|
onBlur={form.handleBlur}
|
||||||
|
error={!!form.errors.newPassword}
|
||||||
|
errorMessage={form.errors.newPassword}
|
||||||
/>
|
/>
|
||||||
|
<Input
|
||||||
|
label='Confirm New Password'
|
||||||
|
name='confirmNewPassword'
|
||||||
|
value={form.values.confirmNewPassword}
|
||||||
|
onChange={form.handleChange}
|
||||||
|
onBlur={form.handleBlur}
|
||||||
|
error={!!form.errors.confirmNewPassword}
|
||||||
|
errorMessage={form.errors.confirmNewPassword}
|
||||||
|
/>
|
||||||
|
<Box
|
||||||
|
display='grid'
|
||||||
|
gridTemplateColumns='auto'
|
||||||
|
rowGap='1rem'
|
||||||
|
marginTop='0.5rem'
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
variant='primary-action'
|
||||||
|
fullWidth
|
||||||
|
color='client'
|
||||||
|
text='Recover Account'
|
||||||
|
type='submit'
|
||||||
|
loading={loading}
|
||||||
|
disabled={loading}
|
||||||
|
/>
|
||||||
|
</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