Skip to content

Commit

Permalink
Удалил компонент кнопки-ссылки, добавил валидацию для формы регистрации
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikMix committed Feb 29, 2024
1 parent f4580dd commit ae052c7
Show file tree
Hide file tree
Showing 29 changed files with 130 additions and 99 deletions.
1 change: 0 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ handlebars -m public/src/components/input/input.hbs -f public/build/input.js
handlebars -m public/src/components/wrapper/wrapper.hbs -f public/build/wrapper.js
handlebars -m public/src/components/footer/footer.hbs -f public/build/footer.js
handlebars -m public/src/components/button/button.hbs -f public/build/button.js
handlebars -m public/src/components/link-button/link-button.hbs -f public/build/link-button.js
1 change: 1 addition & 0 deletions public/build/button.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/build/footer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/build/header.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/build/home.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/build/image.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/build/input.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/build/link.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/build/login.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/build/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/build/not-found.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/build/note-editor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/build/note.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/build/notes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/build/profile.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/build/register.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/build/wrapper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions public/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ const mainPage = {
home: {
id: "home",
linkToLogin: {
href: "/login",
text: "Попробовать",
type: "submit"
text: "Попробовать"
}
}
}
Expand Down
1 change: 0 additions & 1 deletion public/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
@import "src/components/button/button.css";
@import "src/components/wrapper/wrapper.css";
@import "src/components/footer/footer.css";
@import "src/components/link-button/link-button.css";

*, *::before, *::after {
box-sizing: border-box;
Expand Down
8 changes: 5 additions & 3 deletions public/src/components/button/button.css
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
.submit-btn{
width: 100%;
min-width: 80px;
display: flex;
align-items: center;
justify-content: center;
background-color: #56A6F0;
border-radius: 20px;
padding: 8px 16px;
border: none;
outline: none;
color: #ffffff;
text-align: center;
padding: 8px;
box-shadow: 0 4px 4px rgba(0, 0, 0, 0.25);
cursor: pointer;
transition: 0.3s;
Expand All @@ -22,4 +20,8 @@

.submit-btn:active{
transform: scale(0.98)
}

.submit-btn.hidden {
display: none;
}
15 changes: 9 additions & 6 deletions public/src/components/button/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@ export class Button {
}

#addEventListeners(){
this.self.addEventListener('click', (e) => {
console.log(e)
e.preventDefault()
this.#onSubmit()
});
if (this.#onSubmit !== undefined) {
this.self.addEventListener('click', (e) => {
e.preventDefault()
this.#onSubmit()
});
}
}

#removeEventListeners(){
this.self.removeEventListener('click', this.#onSubmit);
}

remove(){
this.#removeEventListeners();
if (this.#onSubmit !== undefined) {
this.#removeEventListeners();
}
}

render(){
Expand Down
13 changes: 7 additions & 6 deletions public/src/components/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import '../../../build/header.js';
import {AppEventMaker} from "../../modules/eventMaker.js";
import {UserStoreEvents} from "../../stores/user/events.js";
import {AppUserStore} from "../../stores/user/userStore.js";
import {LinkButton} from "../link-button/link-button.js";
import {router} from "../../modules/router.js";
import {Button} from "../button/button.js";

export class Header {
#parent;
Expand Down Expand Up @@ -37,8 +38,6 @@ export class Header {


AppEventMaker.subscribe(UserStoreEvents.SUCCSSESFUL_LOGIN, () => {
console.log("log hueg")

if (this.#avatarLink === undefined) {
this.#avatarLink = new Link(document.querySelector(".right-container"), this.#config.avatarLink)
this.#avatarLink.render()
Expand All @@ -57,14 +56,16 @@ export class Header {
})

AppEventMaker.subscribe(UserStoreEvents.LOGOUT, () => {
console.log(this.#avatar.self)

this.#avatarLink.self.hidden = true;

this.#authPageLink.self.classList.remove("hidden");
});
}

handleButtonClick = () => {
router.redirect("/login")
}

render() {
console.log("header render")

Expand All @@ -84,7 +85,7 @@ export class Header {
rightContainer.appendChild(this.#menu)

if (this.#authPageLink === undefined) {
this.#authPageLink = new LinkButton(this.#menu, this.#config.menu.auth)
this.#authPageLink = new Button(this.#menu, this.#config.menu.auth, this.handleButtonClick)
this.#authPageLink.render()
}

Expand Down
9 changes: 7 additions & 2 deletions public/src/components/home/home.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "../../../build/home.js"
import {LinkButton} from "../link-button/link-button.js";
import {router} from "../../modules/router.js";
import {Button} from "../button/button.js";

export class Home {
#parent;
Expand All @@ -14,13 +15,17 @@ export class Home {
return document.getElementById('home');
}

handleButtonClick = () => {
router.redirect("/login")
}

render() {
this.#parent.insertAdjacentHTML(
'afterbegin',
window.Handlebars.templates['home.hbs'](this.#config)
);

const link = new LinkButton(document.querySelector(".first"), this.#config.linkToLogin)
const link = new Button(document.querySelector(".first"), this.#config.linkToLogin, this.handleButtonClick)
link.render()

}
Expand Down
27 changes: 0 additions & 27 deletions public/src/components/link-button/link-button.css

This file was deleted.

3 changes: 0 additions & 3 deletions public/src/components/link-button/link-button.hbs

This file was deleted.

43 changes: 0 additions & 43 deletions public/src/components/link-button/link-button.js

This file was deleted.

10 changes: 7 additions & 3 deletions public/src/pages/notFound/not-found.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "../../../build/not-found.js"
import {LinkButton} from "../../components/link-button/link-button.js";
import {router} from "../../modules/router.js";
import {Button} from "../../components/button/button.js";

export default class NotFoundPage {
#parent;
Expand All @@ -19,9 +20,12 @@ export default class NotFoundPage {
}

remove() {

this.#parent.innerHTML = '';
}

handleButtonClick = () => {
router.redirect("/")
}

render() {
console.log("404 page render")
Expand All @@ -31,7 +35,7 @@ export default class NotFoundPage {
window.Handlebars.templates['not-found.hbs'](this.#config)
);

const link = new LinkButton(this.self, this.#config.link)
const link = new Button(this.self, this.#config.link, this.handleButtonClick)
link.render()
}
}
25 changes: 24 additions & 1 deletion public/src/pages/register/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {Button} from "../../components/button/button.js";
import {ValidateLogin, ValidatePassword} from "../../shared/validation.js";
import {AppEventMaker} from "../../modules/eventMaker.js";
import {inputEvents} from "../../components/input/events.js";
import {AppDispatcher} from "../../modules/dispathcer.js";
import {UserActions} from "../../stores/user/userStore.js";
import {router} from "../../modules/router.js";

export default class RegisterPage {
#parent;
Expand All @@ -29,6 +32,20 @@ export default class RegisterPage {
return document.getElementById(this.#config.form.id)
}

validateData = () => {
const validateLogin = this.#validateLogin()
const validatePassword = this.#validatePassword()
if (validateLogin && validatePassword) {

AppDispatcher.dispatch({
type: UserActions.LOGIN,
payload: this.#loginInput.value
})

router.redirect("/")
}
}

#validateLogin(){
delete this.#loginInput.self.dataset.error;

Expand All @@ -52,6 +69,12 @@ export default class RegisterPage {

if (!validationResult.result){
this.#passwordInput.throwError(validationResult.message);
this.#repeatPasswordInput.throwError(validationResult.message);
}

if (this.#passwordInput.value !== this.#repeatPasswordInput.value) {
this.#passwordInput.throwError("Пароли не совпадают");
this.#repeatPasswordInput.throwError("Пароли не совпадают");
}

return validationResult.result;
Expand Down Expand Up @@ -115,7 +138,7 @@ export default class RegisterPage {
this.#link = new Link(this.form, this.#config.form.links.loginPage);
this.#link.render();

this.#submitBtn = new Button(this.form, this.#config.form.buttons.submitBtn);
this.#submitBtn = new Button(this.form, this.#config.form.buttons.submitBtn, this.validateData);
this.#submitBtn.render();

this.#subscribeToEvents();
Expand Down
Loading

0 comments on commit ae052c7

Please sign in to comment.