Merge branch 'administativePages' of https://gitlab.com/kluppsoftware/smart-energia-web into administativePages
This commit is contained in:
commit
faa8383383
@ -1,21 +1,29 @@
|
|||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
|
import FormData from 'form-data';
|
||||||
|
import Snackbar from '@mui/material/Snackbar';
|
||||||
import LoginButton from '../components/buttons/loginButton/LoginButton';
|
import LoginButton from '../components/buttons/loginButton/LoginButton';
|
||||||
import TextField from '@mui/material/TextField';
|
import TextField from '@mui/material/TextField';
|
||||||
import { ForgotPasswordContainer, ForgotPasswordView } from '../styles/layouts/forgotPassword/ForgotPasswordView';
|
import { ForgotPasswordContainer, ForgotPasswordView } from '../styles/layouts/forgotPassword/ForgotPasswordView';
|
||||||
import RenderIf from '../utils/renderIf';
|
import RenderIf from '../utils/renderIf';
|
||||||
import Alert from '@mui/material/Alert';
|
import Alert from '@mui/material/Alert';
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
|
import { GetServerSideProps } from 'next';
|
||||||
|
import { parseCookies } from 'nookies';
|
||||||
|
import getAPIClient from '../services/ssrApi';
|
||||||
|
import { api } from '../services/api';
|
||||||
|
|
||||||
export default function ForgotPassword() {
|
export default function ForgotPassword() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const rota = router.pathname
|
const rota = router.pathname
|
||||||
|
const formData = new FormData();
|
||||||
|
const [openSnackSuccess, setOpenSnackSuccess] = useState<boolean>(false);
|
||||||
|
const [openSnackError, setOpenSnackError] = useState<boolean>(false);
|
||||||
const [password, setPassword] = useState<string>('')
|
const [password, setPassword] = useState<string>('')
|
||||||
const [confirmPassword, setConfirmPassword] = useState<string>('')
|
const [confirmPassword, setConfirmPassword] = useState<string>('')
|
||||||
const [same, setSame] = useState<boolean>(false)
|
const [same, setSame] = useState<boolean>(false)
|
||||||
|
const [email, setEmail] = useState<any>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPassword('')
|
setPassword('')
|
||||||
@ -23,13 +31,16 @@ export default function ForgotPassword() {
|
|||||||
setSame(false)
|
setSame(false)
|
||||||
}, [rota])
|
}, [rota])
|
||||||
|
|
||||||
function handleChangePassword() {
|
|
||||||
if (same) {
|
const handleCloseSnack = (event?: React.SyntheticEvent | Event, reason?: string) => {
|
||||||
router.push('/')
|
if (reason === 'clickaway') {
|
||||||
} else {
|
return;
|
||||||
null
|
|
||||||
}
|
}
|
||||||
}
|
setOpenSnackError(false);
|
||||||
|
setOpenSnackSuccess(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (password == confirmPassword && password != '') {
|
if (password == confirmPassword && password != '') {
|
||||||
@ -39,8 +50,17 @@ export default function ForgotPassword() {
|
|||||||
}
|
}
|
||||||
}, [password])
|
}, [password])
|
||||||
|
|
||||||
|
function handleSendEmail() {
|
||||||
|
formData.append('email', email)
|
||||||
|
api.post('/auth/forgot-password', formData).then(res => {
|
||||||
|
setOpenSnackSuccess(true)
|
||||||
|
}).catch(res => {
|
||||||
|
setOpenSnackError(true)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ForgotPasswordView auth={rota} >
|
<ForgotPasswordView auth={rota}>
|
||||||
<Head>
|
<Head>
|
||||||
<title>Smart Energia</title>
|
<title>Smart Energia</title>
|
||||||
</Head>
|
</Head>
|
||||||
@ -52,7 +72,18 @@ export default function ForgotPassword() {
|
|||||||
<TextField id="outlined-basic" sx={{ m: 1, width: '90%' }} value={password} label="Senha" onChange={value => setPassword(value.target.value)} variant="outlined"/>
|
<TextField id="outlined-basic" sx={{ m: 1, width: '90%' }} value={password} label="Senha" onChange={value => setPassword(value.target.value)} variant="outlined"/>
|
||||||
<TextField id="outlined-basic" sx={{ m: 1, width: '90%' }} value={confirmPassword} label="Confirmar Senha" onChange={value => setConfirmPassword(value.target.value)} variant="outlined"/>
|
<TextField id="outlined-basic" sx={{ m: 1, width: '90%' }} value={confirmPassword} label="Confirmar Senha" onChange={value => setConfirmPassword(value.target.value)} variant="outlined"/>
|
||||||
|
|
||||||
<LoginButton title='Redefinir Senha' onClick={() => handleChangePassword()} />
|
<LoginButton title='Redefinir Senha' onClick={() => handleSendEmail()} />
|
||||||
|
|
||||||
|
<Snackbar open={openSnackSuccess} autoHideDuration={4000} onClose={handleCloseSnack}>
|
||||||
|
<Alert onClose={handleCloseSnack} severity="success" sx={{ width: '100%' }}>
|
||||||
|
PDF enviado com Sucesso!
|
||||||
|
</Alert>
|
||||||
|
</Snackbar>
|
||||||
|
<Snackbar open={openSnackError} autoHideDuration={4000} onClose={handleCloseSnack}>
|
||||||
|
<Alert onClose={handleCloseSnack} severity="error" sx={{ width: '100%' }}>
|
||||||
|
Falha ao enviar PDF!
|
||||||
|
</Alert>
|
||||||
|
</Snackbar>
|
||||||
|
|
||||||
<fieldset className="line">
|
<fieldset className="line">
|
||||||
<legend className="text">Ou</legend>
|
<legend className="text">Ou</legend>
|
||||||
@ -65,3 +96,21 @@ export default function ForgotPassword() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
|
import FormData from 'form-data';
|
||||||
import LoginButton from '../components/buttons/loginButton/LoginButton';
|
import LoginButton from '../components/buttons/loginButton/LoginButton';
|
||||||
import TextField from '@mui/material/TextField';
|
import TextField from '@mui/material/TextField';
|
||||||
|
|
||||||
@ -10,12 +10,18 @@ import Alert from '@mui/material/Alert';
|
|||||||
import { VerifyEmailContainer, VerifyEmailView } from '../styles/layouts/forgotPassword/verifyEmail';
|
import { VerifyEmailContainer, VerifyEmailView } from '../styles/layouts/forgotPassword/verifyEmail';
|
||||||
import RenderIf from '../utils/renderIf';
|
import RenderIf from '../utils/renderIf';
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
|
import { api } from '../services/api';
|
||||||
|
import { GetServerSideProps } from 'next';
|
||||||
|
import { parseCookies } from 'nookies';
|
||||||
|
|
||||||
export default function VerifyEmail() {
|
export default function VerifyEmail() {
|
||||||
const [sent, setSent]=useState(false);
|
const [sent, setSent]=useState(false);
|
||||||
const [code, setCode]=useState<string>('')
|
const [code, setCode]=useState<string>('')
|
||||||
const [codeStatus, setCodeStatus]=useState<boolean>(null)
|
const [codeStatus, setCodeStatus]=useState<boolean>(null)
|
||||||
|
const formData = new FormData();
|
||||||
|
const [openSnackSuccess, setOpenSnackSuccess] = useState<boolean>(false);
|
||||||
|
const [openSnackError, setOpenSnackError] = useState<boolean>(false);
|
||||||
|
const [email, setEmail] = useState<any>();
|
||||||
const [values, setValues] = React.useState({
|
const [values, setValues] = React.useState({
|
||||||
password: '',
|
password: '',
|
||||||
showPassword: false,
|
showPassword: false,
|
||||||
@ -30,6 +36,15 @@ export default function VerifyEmail() {
|
|||||||
setCodeStatus(null)
|
setCodeStatus(null)
|
||||||
}, [rota])
|
}, [rota])
|
||||||
|
|
||||||
|
function handleSendEmail() {
|
||||||
|
formData.append('email', email)
|
||||||
|
api.post('/auth/forgot-password', formData).then(res => {
|
||||||
|
setOpenSnackSuccess(true)
|
||||||
|
}).catch(res => {
|
||||||
|
setOpenSnackError(true)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function verifyConfirmationCode() {
|
function verifyConfirmationCode() {
|
||||||
if (code === '0000') {
|
if (code === '0000') {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -50,13 +65,10 @@ export default function VerifyEmail() {
|
|||||||
<VerifyEmailContainer>
|
<VerifyEmailContainer>
|
||||||
<h1>Bem-Vindo</h1>
|
<h1>Bem-Vindo</h1>
|
||||||
<h2>Estratégias Inteligentes em<br /> Gestão de Energia</h2>
|
<h2>Estratégias Inteligentes em<br /> Gestão de Energia</h2>
|
||||||
|
|
||||||
<TextField id="outlined-basic" sx={{ m: 1, width: '90%' }}label="Email" variant="outlined"/>
|
<TextField id="outlined-basic" sx={{ m: 1, width: '90%' }}label="Email" variant="outlined"/>
|
||||||
<RenderIf isTrue={sent? false : true}>
|
<RenderIf isTrue={sent? false : true}>
|
||||||
<LoginButton title='Enviar Email' onClick={() => setSent(true)} />
|
<LoginButton title='Enviar Email' onClick={() => handleSendEmail()} />
|
||||||
</RenderIf>
|
</RenderIf>
|
||||||
|
|
||||||
|
|
||||||
<RenderIf isTrue={sent? true : false}>
|
<RenderIf isTrue={sent? true : false}>
|
||||||
<TextField id="outlined-basic" sx={{ m: 1, width: '90%' }}label="Nova Senha" variant="outlined"/>
|
<TextField id="outlined-basic" sx={{ m: 1, width: '90%' }}label="Nova Senha" variant="outlined"/>
|
||||||
<TextField id="outlined-basic" sx={{ m: 1, width: '90%' }}label="Codigo de verificação" variant="outlined" onChange={value => setCode(value.target.value)} />
|
<TextField id="outlined-basic" sx={{ m: 1, width: '90%' }}label="Codigo de verificação" variant="outlined" onChange={value => setCode(value.target.value)} />
|
||||||
@ -79,3 +91,22 @@ export default function VerifyEmail() {
|
|||||||
</VerifyEmailView>
|
</VerifyEmailView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user