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, 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 as string); 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 ( Forgot Password {error && } {success && ( )}