-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from fga-eps-mds/151-criarUsuario
📝 #151 Adicionando Criacao doUsuáro
- Loading branch information
Showing
26 changed files
with
2,420 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
import { yupResolver } from "@hookform/resolvers/yup"; | ||
import React, { useEffect, useState } from "react"; | ||
import { useForm } from "react-hook-form"; | ||
import * as yup from "yup"; | ||
import { getLotacoes } from "../../services/lotacaoService"; | ||
import { createUser } from "../../services/userService"; | ||
import "../../style/components/signupForms.css"; | ||
import elipse6 from '../../assets/elipse6.svg'; | ||
|
||
|
||
const signupSchema = yup.object().shape({ | ||
nome: yup.string().required('Nome é obrigatório'), | ||
email: yup | ||
.string() | ||
.email('Email inválido') | ||
.required('Email é obrigatório'), | ||
emailConfirmar: yup | ||
.string() | ||
.oneOf([yup.ref('email'), null], 'Os emails devem coincidir') | ||
.required('Email é obrigatória'), | ||
senha: yup.string().required('Senha é obrigatória') | ||
.matches( | ||
/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/, | ||
'A senha não segue o padrão a baixo' | ||
), | ||
senhaConfirmar: yup | ||
.string() | ||
.oneOf([yup.ref('senha'), null], 'As senhas devem coincidir') | ||
.required('Senha é obrigatória'), | ||
documento: yup.string() | ||
.matches(/^(\d{11}|\d{14})$/, 'CPF ou CNPJ inválido') | ||
.test('cpfOrCnpj', 'CPF ou CNPJ inválido', value => { | ||
return value.length === 11 || value.length === 14; | ||
}), | ||
lotacao_id: yup.string().required('Lotação é obrigatória'), | ||
isAdmin: yup.boolean(), | ||
}); | ||
|
||
export default function SignupForm(){ | ||
const [lotacao, setLotacao] = useState([]); | ||
|
||
useEffect( () => { | ||
async function setLotacoes() { | ||
try { | ||
const data = await getLotacoes(); | ||
if (data.type ==='success') { | ||
setLotacao(data.data); | ||
} | ||
} catch (error) { | ||
console.error('Erro ao obter opções do serviço:', error); | ||
} | ||
} | ||
setLotacoes(); | ||
}, []); | ||
|
||
|
||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors, isValid }, | ||
reset | ||
} = useForm({resolver: yupResolver(signupSchema), mode: "onChange"}) | ||
|
||
const onSubmit = async (data) => { | ||
data.cargos = ["USER"]; | ||
if (data.isAdmin) { | ||
data.cargos.push("ADMIN"); | ||
} | ||
await createUser(data); | ||
reset() | ||
} | ||
|
||
return( | ||
<div id="signup-card"> | ||
<header id="form-header"> | ||
Cadastro | ||
</header> | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<div id="input-group"> | ||
<div id="input-line"> | ||
<div id="input-box"> | ||
<label>Nome<span>*</span></label> | ||
<input {...register("nome", {required: true} )} placeholder="Nome" /> | ||
<span>{errors.nome?.message}</span> | ||
</div> | ||
|
||
<div id="input-box"> | ||
<label>Documento<span>*</span></label> | ||
<input {...register("documento", {required: true})} placeholder="CPF ou CNPF" /> | ||
<span>{errors.documento?.message}</span> | ||
</div> | ||
</div> | ||
<div id="input-line"> | ||
<div id="input-box"> | ||
<label>E-mail<span>*</span></label> | ||
<input {...register("email", {required: true} )} type="email" placeholder="Email" /> | ||
<span>{errors.email?.message}</span> | ||
</div> | ||
|
||
<div id="input-box"> | ||
<label>Confirmar E-mail<span>*</span></label> | ||
<input {...register("emailConfirmar", {required: true})} placeholder="Confirmar Email" /> | ||
<span>{errors.emailConfirmar?.message}</span> | ||
</div> | ||
</div> | ||
|
||
<div id="input-line"> | ||
<div id="input-box"> | ||
<label>Senha<span>*</span></label> | ||
<input {...register("senha", {required: true})} placeholder="Senha" type="password"/> | ||
<span>{errors.senha?.message}</span> | ||
<p id="input-description">A senha deve conter pelo menos 8 caracteres, 1 letra maiúscula, 1 minuscula, 1 número e um caractere especial</p> | ||
</div> | ||
<div id="input-box"> | ||
<label>Confirmar Senha<span>*</span></label> | ||
<input {...register("senhaConfirmar", {required: true})} placeholder="Confirmar Senha" type="password"/> | ||
<span>{errors.senhaConfirmar?.message}</span> | ||
</div> | ||
</div> | ||
<div id="input-line"> | ||
<div id="input-box"> | ||
<label>Lotação <span>*</span></label> | ||
<select {...register("lotacao_id", {required: "Lotação é obrigatória"})}> | ||
<option value="">Selecione a Lotação</option> | ||
{lotacao?.map((lotacao) => ( | ||
<option key={lotacao.id} value={lotacao.id}> | ||
{lotacao.nome} | ||
</option> | ||
))} | ||
</select> | ||
<span>{errors.lotacao_id?.message}</span> | ||
</div> | ||
</div> | ||
<div id="input-line"> | ||
<div id="input-box"> | ||
<div id="input-checkbox"> | ||
<input | ||
id="checkbox" | ||
type="checkbox" | ||
{...register("isAdmin")} | ||
/> | ||
<label id="label-checkbox">Usuário é administrador?</label> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div id="buttons"> | ||
<button className="form-button" type="button" id="cancelar-bnt" >CANCELAR</button> | ||
<button className="form-button" type="submit" id="registrar-bnt" disabled={!isValid}>REGISTRAR</button> | ||
</div> | ||
</form> | ||
<div className="elipse-signup"> | ||
<img alt= "elipse" src={elipse6}></img> | ||
</div> | ||
</div> | ||
); | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import axios from 'axios'; | ||
|
||
export const api = axios.create({ | ||
baseURL: process.env.API_URL || 'http://localhost:8000', | ||
timeout: 5000, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import "../style/pages/createUser.css"; | ||
import React from "react"; | ||
import SignupForm from "../components/forms/SignupForm"; | ||
import signup_image from "../assets/signup_image.svg"; | ||
|
||
export default function CreateUserPage(){ | ||
return( | ||
<div id="signup-container"> | ||
<img alt="" src={signup_image} /> | ||
<SignupForm/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { api } from '../lib/api/config'; | ||
|
||
export const createLotacao = async (lotacoa) => { | ||
try { | ||
const response = await api.post('/lotacao/create', lotacoa); | ||
return {type: 'success', data:response.data}; | ||
} catch (error) { | ||
return { type: 'error', error }; | ||
} | ||
}; | ||
|
||
export const getLotacoes = async () => { | ||
try { | ||
const response = await api.get('/lotacao'); | ||
return { type: 'success', data: response.data}; | ||
} catch (error) { | ||
return { type: 'error', error }; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { api } from '../lib/api/config'; | ||
|
||
export const createUser = async (user) => { | ||
try { | ||
const response = await api.post('/user/create', user); | ||
return { type: 'success', data: response.data}; | ||
} catch (error) { | ||
return { type: 'error', error }; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/* CustomButton.css */ | ||
.button { | ||
width: 17vw; | ||
height: 8vh; | ||
|
Oops, something went wrong.
e20f2e1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
2023-2-print-go – ./
2023-2-print-go.vercel.app
2023-2-print-go-git-main-guilhermes-projects-0cbdcfe2.vercel.app
2023-2-print-go-guilhermes-projects-0cbdcfe2.vercel.app