import { useRef, useEffect, SyntheticEvent, useState } from 'react' import { AppManager, UserManager } from '@app/managers' import { useUserData } from '@app/data' import { Button, LinearBottom, MarketingDrawer } from '@app/components/general' import { useRouter } from 'next/router' import { metaSetter } from '@app/utils' import type { PageProps } from '@app/types' import { MarketingShortTitle } from '@app/components/marketing' import { Header, Header2, Header3 } from '@app/components/general/header' import { FormControl } from '@app/components/general/form-control' import { TextField } from '@app/components/general/text-field' import { companyName } from '@app/configs' function ResetPassword({ name }: PageProps) { const router = useRouter() const { loading, forgotPassword, forgotPasswordData, resetPassword, resetPasswordData, } = useUserData(true) const emailRef = useRef(null) const resetRef = useRef(null) const [emailState, setEmailState] = useState('') const [resetState, setResetState] = useState('') const resetSent = forgotPasswordData?.forgotPassword?.email == 'true' const title = resetSent ? 'Enter Reset Code' : 'Reset Password' useEffect(() => { if (resetPasswordData?.resetPassword?.jwt) { UserManager.setUser(resetPasswordData.resetPassword) ;(async () => { await router.push('/dashboard') })() } }, [router, resetPasswordData]) useEffect(() => { if (resetSent) { AppManager.toggleSnack( true, 'Please check your email and enter the reset code.', 'message' ) } }, [resetSent]) const onEmailChange = ( e: SyntheticEvent ) => { e?.preventDefault() setEmailState(e?.currentTarget?.value) } const onResetEvent = ( e: SyntheticEvent ) => { e?.preventDefault() setResetState(e?.currentTarget?.value) } const submit = async (e: SyntheticEvent) => { e?.preventDefault() try { if (resetSent && resetRef?.current?.value) { await resetPassword({ variables: { email: emailState, resetCode: resetState, }, }) } else if (emailRef?.current?.value) { await forgotPassword({ variables: { email: emailState, }, }) } } catch (e) { console.error(e) } } const FormInputRender = () => { if (resetSent) { return ( <> Enter password Reset Code ) } return ( <> Enter Email ) } const FormRender = () => { return (
) } return (
{title}
Backup your password

After resetting your password, make sure to back it up using a secure password manager.

Issue with reset?

If you are having issues reseting your password please contact the support team.

) } export default metaSetter( { ResetPassword }, { description: `Reset your password to get back in action with the ${companyName} accessibility toolkit.`, gql: true, } )