diff --git a/src/pages/Auth/ForgotPassword/index.tsx b/src/pages/Auth/ForgotPassword/index.tsx index 7d48c4e..f392146 100644 --- a/src/pages/Auth/ForgotPassword/index.tsx +++ b/src/pages/Auth/ForgotPassword/index.tsx @@ -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 { 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 { Wrapper } from './styles'; const ForgotPassword = () => { + const [error, setError] = useState(''); + const [success, setSuccess] = useState(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 ( { - - astrobuild - - - Forgot Password - - {}} /> - {}} /> + + Forgot Password + + {error && } + {success && ( + + )} + +
-