From 35355e4b2b3bdbccc362bfa21ce5327e02208e5b Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Mon, 26 Oct 2020 00:16:51 -0300 Subject: [PATCH] WIP Forgot Password --- components/auth/ForgotPassword.tsx | 89 ++++++++++++++++++++++++++++++ pages/forgot-password.tsx | 33 ----------- 2 files changed, 89 insertions(+), 33 deletions(-) create mode 100644 components/auth/ForgotPassword.tsx delete mode 100644 pages/forgot-password.tsx diff --git a/components/auth/ForgotPassword.tsx b/components/auth/ForgotPassword.tsx new file mode 100644 index 000000000..c7d507701 --- /dev/null +++ b/components/auth/ForgotPassword.tsx @@ -0,0 +1,89 @@ +import { FC, useEffect, useState, useCallback } from 'react' +import { validate } from 'email-validator' +import { Info } from '@components/icon' +import { useUI } from '@components/ui/context' +import { Logo, Button, Input } from '@components/ui' +import useSignup from '@lib/bigcommerce/use-signup' + +interface Props {} + +const ForgotPassword: FC = () => { + // Form State + const [email, setEmail] = useState('') + const [loading, setLoading] = useState(false) + const [message, setMessage] = useState('') + const [dirty, setDirty] = useState(false) + const [disabled, setDisabled] = useState(false) + + const signup = useSignup() + const { setModalView, closeModal } = useUI() + + const handleSignup = async () => { + if (!dirty && !disabled) { + setDirty(true) + handleValidation() + } + + // try { + // setLoading(true) + // setMessage('') + // await signup({ + // email, + // }) + // setLoading(false) + // closeModal() + // } catch ({ errors }) { + // setMessage(errors[0].message) + // setLoading(false) + // } + } + + const handleValidation = useCallback(() => { + // Unable to send form unless fields are valid. + if (dirty) { + setDisabled(!validate(email)) + } + }, [email, dirty]) + + useEffect(() => { + handleValidation() + }, [handleValidation]) + + return ( +
+
+ +
+
+ {message && ( +
{message}
+ )} + + +
+ +
+ + + Do you have an account? + {` `} + setModalView('LOGIN_VIEW')} + > + Log In + + +
+
+ ) +} + +export default ForgotPassword diff --git a/pages/forgot-password.tsx b/pages/forgot-password.tsx deleted file mode 100644 index 5ff128cc6..000000000 --- a/pages/forgot-password.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import { Layout } from '@components/core' -import { Logo, Modal, Button } from '@components/ui' -export default function ForgotPassword() { - return ( -
- {}}> -
-
- -
-
-
- -
- - - Don't have an account? - {` `} - - Sign Up - - -
-
-
-
- ) -} - -ForgotPassword.Layout = Layout