Skip to content

Commit

Permalink
Merge branch 'main' into issue-285
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaam authored Aug 30, 2024
2 parents f7af03b + bc4dc91 commit a5dd765
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 24 deletions.
16 changes: 4 additions & 12 deletions src/components/ChangePassword/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component } from 'pet-dex-utilities';
import { isPasswordValid } from '../../utils/validations';
import TextInput from '../TextInput';
import Button from '../Button';
import './index.scss';
Expand Down Expand Up @@ -28,22 +29,13 @@ const html = `
<span data-select="confirm-password-error-match" class="change-password__error">As senhas não coincidem</span>
<ul class="change-password__tips">
<li>Insira no mínimo 6 caracteres</li>
<li>Insira no mínimo 10 caracteres</li>
<li>A senha deve conter uma letra maiúscula</li>
<li>Deve conter um caractere especial</li>
</ul>
</form>
`;

const validatePassword = (password) => {
const hasMinLength = password.length >= 10;
const hasUppercase = /[A-Z]/g.test(password);
const hasNumber = /[0-9]/g.test(password);
const hasSpecialCharacter = /[!@#$%^&*(),.?":{}|<>]/g.test(password);

return hasMinLength && hasUppercase && hasNumber && hasSpecialCharacter;
};

export default function ChangePassword() {
Component.call(this, { html, events });
const $changePasswordForm = this.selected.get('change-password');
Expand Down Expand Up @@ -123,8 +115,8 @@ export default function ChangePassword() {
confirmPasswordInput.selected.get('input-text').value;

const showErrorMessage = (field, error) => {
const fieldValue = field.selected.get('input-text').value;
if (!validatePassword(fieldValue)) {
const password = field.selected.get('input-text').value;
if (!isPasswordValid(password)) {
validPasswords = false;
error.classList.add('show-error');
field.inputError();
Expand Down
12 changes: 3 additions & 9 deletions src/components/LoginForm/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component } from 'pet-dex-utilities';
import { isPasswordValid } from '../../utils/validations';
import TextInput from '../TextInput';
import Button from '../Button';
import Toggle from '../Toggle';
Expand Down Expand Up @@ -112,7 +113,7 @@ export default function LoginForm() {
emailInput.inputError();
}

if (!this.validatePassword(password)) {
if (!this.isPasswordValid(password)) {
validPassword = false;
$passwordErrorMessage.classList.add('show-error');
$passwordErrorMessage.innerText =
Expand All @@ -138,12 +139,5 @@ LoginForm.prototype = Object.assign(LoginForm.prototype, Component.prototype, {

return emailRegex.test(email);
},
validatePassword(password) {
const hasMinLength = password.length >= 10;
const hasUppercase = /[A-Z]/g.test(password);
const hasNumber = /[0-9]/g.test(password);
const hasSpecialCharacter = /[!@#$%^&*(),.?":{}|<>]/g.test(password);

return hasMinLength && hasUppercase && hasNumber && hasSpecialCharacter;
},
isPasswordValid,
});
13 changes: 12 additions & 1 deletion src/components/RegisterForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import googleIcon from './images/google-icon.svg';
import facebookIcon from './images/facebook-icon.svg';
import './index.scss';
import { UserService } from '../../services/userService';

const events = ['register'];

Expand Down Expand Up @@ -151,7 +152,7 @@ export default function RegisterForm() {
repeatPassword.mount($fields);
registerButton.mount($formButton);

registerButton.listen('click', () => {
registerButton.listen('click', async () => {
const nameValue = name.getContent().getValue();
const surnameValue = surname.getContent().getValue();
const birthValue = birth.getContent().getValue();
Expand Down Expand Up @@ -270,6 +271,16 @@ export default function RegisterForm() {
passwordValid &&
repeatPasswordValid
) {
await UserService.registerUser({
name: nameValue,
surname: surnameValue,
birth: birthValue,
local: localValue,
email: emailValue,
phone: phoneValue,
password: passwordValue,
});

this.register();
}
});
Expand Down
21 changes: 19 additions & 2 deletions src/layouts/app/components/SideMenu/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,28 @@
}

&__avatars-yourpet {
max-height: calc(8.5rem * 2 + 2rem);
overflow-y: auto;

display: grid;
grid-template-columns: repeat(3, 6rem);
grid-gap: 2rem;
gap: 2rem;

margin-top: 2rem;
padding: 0.4rem 0.2rem;

&::-webkit-scrollbar {
width: 0.4rem;
}

&::-webkit-scrollbar-track {
background: colors.$primary600;
}

&::-webkit-scrollbar-thumb {
background-color: colors.$primary700;
border-radius: 1rem;
}
}

&__itens {
Expand Down Expand Up @@ -142,7 +159,7 @@
}

.side-menu-content {
width: 70%;
width: 80%;

&__menuitens {
transition: 0.3s;
Expand Down
5 changes: 5 additions & 0 deletions src/layouts/app/pages/NoPetRegirested/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component } from 'pet-dex-utilities';
import { Router } from 'vanilla-routing';
import Button from '../../../../components/Button';
import petUrl from './images/no-pet-regirested-page.png';
import './index.scss';
Expand Down Expand Up @@ -30,6 +31,10 @@ export default function NoPetRegirested() {
.get('button')
.classList.add('no-pet-regirested-page__button');
this.button.mount($container);

this.button.listen('click', () => {
Router.go('/add/addpets');
});
}

NoPetRegirested.prototype = Object.assign(
Expand Down
29 changes: 29 additions & 0 deletions src/services/userService.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const UserService = {
return `An error occurred: ${error}`;
}
},

login: async (email, password) => {
try {
const response = await fetch(`${url}/api/user/login`, {
Expand All @@ -38,4 +39,32 @@ export const UserService = {
};
}
},

registerUser: async (userData) => {
try {
const response = await fetch(`${url}/naoSeiARota`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(userData),
});

if (!response.ok) {
throw new Error('Failed to register user');
}

const result = await response.json();
return {
success: true,
data: result,
};
} catch (error) {
console.error(`An error occurred: ${error}`);
return {
success: false,
message: error.message,
};
}
},
};

0 comments on commit a5dd765

Please sign in to comment.