From 6ea0ac91b563ad492441794e94b2d6bf1e172721 Mon Sep 17 00:00:00 2001 From: Alex Santos Date: Wed, 29 Jun 2022 09:50:55 -0300 Subject: [PATCH] update forgotPassword --- src/pages/forgotPassword.tsx | 11 ++-------- src/pages/verifyEmail.tsx | 41 +++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/pages/forgotPassword.tsx b/src/pages/forgotPassword.tsx index 72c586d..48579b9 100644 --- a/src/pages/forgotPassword.tsx +++ b/src/pages/forgotPassword.tsx @@ -40,13 +40,7 @@ export default function ForgotPassword() { setOpenSnackSuccess(false); }; - function handleChangePassword() { - if (same) { - router.push('/') - } else { - null - } - } + useEffect(() => { if (password == confirmPassword && password != '') { @@ -66,7 +60,7 @@ export default function ForgotPassword() { } return ( - + Smart Energia @@ -103,7 +97,6 @@ export default function ForgotPassword() { } export const getServerSideProps: GetServerSideProps = async (ctx) => { - const apiClient = getAPIClient(ctx) const { ['@smartAuth-token']: token } = parseCookies(ctx) const { ['user-name']: userName } = parseCookies(ctx) if (!token) { diff --git a/src/pages/verifyEmail.tsx b/src/pages/verifyEmail.tsx index 99591f9..7c27e74 100644 --- a/src/pages/verifyEmail.tsx +++ b/src/pages/verifyEmail.tsx @@ -10,12 +10,18 @@ import Alert from '@mui/material/Alert'; import { VerifyEmailContainer, VerifyEmailView } from '../styles/layouts/forgotPassword/verifyEmail'; import RenderIf from '../utils/renderIf'; import Head from 'next/head'; +import { api } from '../services/api'; +import { GetServerSideProps } from 'next'; +import { parseCookies } from 'nookies'; export default function VerifyEmail() { const [sent, setSent]=useState(false); const [code, setCode]=useState('') const [codeStatus, setCodeStatus]=useState(null) - + const formData = new FormData(); + const [openSnackSuccess, setOpenSnackSuccess] = useState(false); + const [openSnackError, setOpenSnackError] = useState(false); + const [email, setEmail] = useState(); const [values, setValues] = React.useState({ password: '', showPassword: false, @@ -30,6 +36,15 @@ export default function VerifyEmail() { setCodeStatus(null) }, [rota]) + function handleSendEmail() { + formData.append('email', email) + api.post('/auth/forgot-password', formData).then(res => { + setOpenSnackSuccess(true) + }).catch(res => { + setOpenSnackError(true) + }) + } + function verifyConfirmationCode() { if (code === '0000') { setTimeout(() => { @@ -50,13 +65,10 @@ export default function VerifyEmail() {

Bem-Vindo

Estratégias Inteligentes em
Gestão de Energia

- - setSent(true)} /> + handleSendEmail()} /> - - setCode(value.target.value)} /> @@ -79,3 +91,22 @@ export default function VerifyEmail() { ) } + +export const getServerSideProps: GetServerSideProps = async (ctx) => { + const { ['@smartAuth-token']: token } = parseCookies(ctx) + const { ['user-name']: userName } = parseCookies(ctx) + if (!token) { + return { + redirect: { + destination: '/', + permanent: false + } + } + } + + return { + props: { + userName + } + } +}