From b083604c7e1e14bc9b84d436ed70c10b51a958d3 Mon Sep 17 00:00:00 2001 From: Vinicius Gabriel Machado <vgm18@inf.ufpr.br> Date: Tue, 20 Apr 2021 09:18:12 -0300 Subject: [PATCH] Fixing bugs reported by Professor Todt --- src/Components/MenuBar.js | 31 ++++++++++-------- src/Components/MobileDrawerMenu.js | 31 ++++++++++-------- src/Components/SignUpContainerFunction.js | 40 ++++++++++++++++++++--- src/Components/SignUpModal.js | 8 +++-- 4 files changed, 74 insertions(+), 36 deletions(-) diff --git a/src/Components/MenuBar.js b/src/Components/MenuBar.js index 3f8dae23..f2fddb17 100644 --- a/src/Components/MenuBar.js +++ b/src/Components/MenuBar.js @@ -101,9 +101,6 @@ export default function MenuBar(props) { const { state } = useContext(Store) const buildMyAreaTabs = () => { - let canUserAdmin = false; - let index = 0; - const userRoles = [...state.currentUser.roles] const minhaArea = [ { name: "Perfil e Atividades", href: "/perfil", value: '0' }, { name: "Recursos Publicados", href: "/perfil", value: '1' }, @@ -113,19 +110,25 @@ export default function MenuBar(props) { { name: "Configurações", href: "/editarperfil", value: '5'}, ] - while (!canUserAdmin && index < userRoles.length) { - if(userRoles[index].id === 3 || userRoles[index].id === 7) - canUserAdmin = true - index++ + if (state.currentUser.roles) { + let canUserAdmin = false; + let index = 0; + const userRoles = [...state.currentUser.roles] + + while (!canUserAdmin && index < userRoles.length) { + if(userRoles[index].id === 3 || userRoles[index].id === 7) + canUserAdmin = true + index++ + } + + if(canUserAdmin) + minhaArea.push({ + name: "Administrador", + href: "/admin/home", + value: '6', + }) } - if(canUserAdmin) - minhaArea.push({ - name: "Administrador", - href: "/admin/home", - value: '6', - }) - return minhaArea; } diff --git a/src/Components/MobileDrawerMenu.js b/src/Components/MobileDrawerMenu.js index 0a615f6f..469fa378 100644 --- a/src/Components/MobileDrawerMenu.js +++ b/src/Components/MobileDrawerMenu.js @@ -38,9 +38,6 @@ export default function MobileDrawerMenu(props) { const { state, dispatch } = useContext(Store) const buildMyAreaTabs = () => { - let canUserAdmin = false; - let index = 0; - const userRoles = [...state.currentUser.roles] const minhaArea = [ { name: "Perfil e Atividades", href: "/perfil", value: '0' }, { name: "Recursos Publicados", href: "/perfil", value: '1' }, @@ -50,18 +47,24 @@ export default function MobileDrawerMenu(props) { { name: "Configurações", href: "/editarperfil", value: '5' }, ] - while (!canUserAdmin && index < userRoles.length) { - if (userRoles[index].id === 3 || userRoles[index].id === 7) - canUserAdmin = true - index++ - } + if (state.currentUser.roles) { + let canUserAdmin = false; + let index = 0; + const userRoles = [...state.currentUser.roles] - if (canUserAdmin) - minhaArea.push({ - name: "Administrador", - href: "/admin/home", - value: '6', - }) + while (!canUserAdmin && index < userRoles.length) { + if (userRoles[index].id === 3 || userRoles[index].id === 7) + canUserAdmin = true + index++ + } + + if (canUserAdmin) + minhaArea.push({ + name: "Administrador", + href: "/admin/home", + value: '6', + }) + } return minhaArea; } diff --git a/src/Components/SignUpContainerFunction.js b/src/Components/SignUpContainerFunction.js index d336d341..89343fe5 100644 --- a/src/Components/SignUpContainerFunction.js +++ b/src/Components/SignUpContainerFunction.js @@ -58,9 +58,16 @@ export default function SignUpContainer (props) { } ) - const handleChange = (e, type) => { + const [formConfirmation, setConfirmation] = useState( + { + key : false, + value : "" + } + ) + + const handleChange = (e, type, confirmation) => { const userInput = e.target.value - const flag = ValidateUserInput(type, userInput) + const flag = ValidateUserInput(type, userInput, confirmation) if (type === 'username') { setNome({...formNome, @@ -83,6 +90,13 @@ export default function SignUpContainer (props) { }) console.log(formSenha) } + else if(type === 'confirmation') { + setConfirmation({...formConfirmation, + key : flag, + value : userInput + }) + console.log(formConfirmation) + } } const limpaCamposForm = () => { @@ -100,6 +114,11 @@ export default function SignUpContainer (props) { key : false, value : '' }) + + setConfirmation({...formConfirmation, + key : false, + value : '' + }) } const switchModal = (e) => { @@ -110,9 +129,9 @@ export default function SignUpContainer (props) { const onSubmit = (e) => { e.preventDefault(); - const newLogin = {name : formNome.value, email : formEmail.value, password : formSenha.value} + const newLogin = {name : formNome.value, email : formEmail.value, password : formSenha.value, senha : formConfirmation.value} - if (!(formNome.key || formEmail.key || formSenha.key)) { + if (!(formNome.key || formEmail.key || formSenha.key || formConfirmation.key)) { props.handleLoginInfo(newLogin) limpaCamposForm() } @@ -178,6 +197,17 @@ export default function SignUpContainer (props) { help = {formSenha.key ? (formSenha.value.length === 0 ? "Faltou digitar sua senha." : "A senha precisa ter no mínimo 8 caracteres.") : ""} /> <br/> + <FormInput + inputType={"password"} + name={"confirmation"} + value={formConfirmation.value} + placeholder={"Confirme a Senha"} + handleChange={e => handleChange(e, 'confirmation', formSenha.value)} + required={true} + error={formConfirmation.key} + help = {formConfirmation.key ? (formConfirmation.value.length === 0 ? "Faltou digitar sua senha." : (formConfirmation.value !== formSenha.value ? "As senhas precisam ser iguais" : "A senha precisa ter no mínimo 8 caracteres.")) : ""} + /> + <br/> <ConfirmContainerStyled> <StyledSignUpButton type="submit" variant="contained"> <span @@ -192,7 +222,7 @@ export default function SignUpContainer (props) { <TermosDeUsoStyled> <p>Ao se cadastrar, você está aceitando os Termos de Uso e de Política - de Privacidade. <a href="./">Ler Termos</a>.</p> + de Privacidade. <a href="/termos">Ler Termos</a>.</p> </TermosDeUsoStyled> <DialogFooterStyled> diff --git a/src/Components/SignUpModal.js b/src/Components/SignUpModal.js index d3ed47c7..e0167807 100644 --- a/src/Components/SignUpModal.js +++ b/src/Components/SignUpModal.js @@ -23,6 +23,7 @@ import styled from 'styled-components' import SignUpContainer from './SignUpContainerFunction.js' import {Store} from '../Store.js' import {authentication} from './HelperFunctions/getAxiosConfig' +//import {postRequest} from './HelperFunctions/getAxiosConfig' export default function SignUpModal (props) { const { state, dispatch } = useContext(Store) @@ -41,11 +42,12 @@ export default function SignUpModal (props) { name : newLogin.name, email: newLogin.email, password : newLogin.password, - password_confirmation : newLogin.senha, - terms_of_service:true, - avatar: "" + password_confirmation : newLogin.senha //, + // terms_of_service : true, + // avatar: "" } authentication(url, payload, handleSuccess, (error) => {console.log(error)}) + //postRequest(url, payload, handleSuccess, (error) => {console.log(error)}) } return ( -- GitLab