Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#497 [FEAT] Adicionar confirmação de senha na hora de atualizar/criar… #510

Merged
merged 4 commits into from
Feb 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/pages/CreateUserPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function CreateUserPage(props) {
const submitNewUser = (e) => {
e.preventDefault();
const salt = process.env.REACT_APP_SALT;
const formData = serialize({ ...newUser, hash: hashSync(newUser.hash, salt) });
const formData = newUser.hash ? serialize({ ...newUser, hash: hashSync(newUser.hash, salt) }) : serialize({...newUser});
if (isEditing) {
axios
.put(`${baseUrl}api/user/updateUser/${userId || user.id}`, formData, {
Expand Down Expand Up @@ -277,7 +277,7 @@ function CreateUserPage(props) {
const generateRandomHash = () => {
//Random hash with special chars and exactly 12 characters
const randomHash = Array.from({ length: 12 }, () => String.fromCharCode(Math.floor(Math.random() * 93) + 33)).join('');
setNewUser((prev) => ({ ...prev, hash: randomHash }));
setNewUser((prev) => ({ ...prev, hash: randomHash , hashValidation: randomHash }));
};

if (error) {
Expand Down Expand Up @@ -397,7 +397,6 @@ function CreateUserPage(props) {
className="form-control rounded-4 bg-light-pastel-blue color-grey fw-medium fs-5 border-0"
autoComplete="new-password"
onChange={(e) => setNewUser({ ...newUser, hash: e.target.value })}
required
/>
</div>
<div className="col-auto">
Expand All @@ -412,6 +411,25 @@ function CreateUserPage(props) {
</div>
</div>
</div>
<div className="mb-3">
<label label="hash-validation" className="form-label color-steel-blue fs-5 fw-medium">
Confirmar senha:
</label>
<div className="row align-items-center gx-1">
<div className="col">
<input
type={passwordVisibility ? 'text' : 'password'}
name="hash"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name="hash"
name="hash-validation"

value={newUser.hashValidation || ''}
form="user-form"
id="hash"
className="form-control rounded-4 bg-light-pastel-blue color-grey fw-medium fs-5 border-0"
autoComplete="new-password"
onChange={(e) => setNewUser({ ...newUser, hashValidation: e.target.value })}
/>
</div>
</div>
</div>
{(user.role === 'ADMIN' || !isEditing) && (
<div className="mb-3">
<label label="role" className="form-label color-steel-blue fs-5 fw-medium">
Expand Down Expand Up @@ -577,16 +595,16 @@ function CreateUserPage(props) {
<TextButton
text={isEditing ? 'Concluir' : 'Criar'}
hsl={[97, 43, 70]}
onClick={() => {
onClick={ newUser.hash === newUser.hashValidation ? () => {
showAlert({
headerText: `Tem certeza que deseja ${isEditing ? 'editar' : 'criar'} o usuário?`,
primaryBtnHsl: [355, 78, 66],
primaryBtnLabel: 'Não',
secondaryBtnHsl: [97, 43, 70],
secondaryBtnLabel: 'Sim',
onSecondaryBtnClick: () => formRef.current.requestSubmit(),
});
}}
})
} : () => showAlert({ headerText: 'As senhas não coincidem'})}
/>
</div>
{isEditing && (
Expand Down