diff --git a/javascript-practice/src/js/controllers/homeController.js b/javascript-practice/src/js/controllers/homeController.js index a77adfb..2b5a7ce 100644 --- a/javascript-practice/src/js/controllers/homeController.js +++ b/javascript-practice/src/js/controllers/homeController.js @@ -8,8 +8,8 @@ export default class HomeController { return this.service.userService.getInfoUserLogin(); } - handlerCheckWalletExist(idUser) { - return this.service.walletService.checkWalletExist(idUser); + handlerCheckWalletValid(idUser) { + return this.service.walletService.isValidWallet(idUser); } handlerGetWalletUser(idUser) { @@ -30,7 +30,7 @@ export default class HomeController { this.homeView.loadPage( this.handlerGetInfoUserLogin.bind(this), - this.handlerCheckWalletExist.bind(this), + this.handlerCheckWalletValid.bind(this), this.handlerGetWalletUser.bind(this), ); diff --git a/javascript-practice/src/js/controllers/registerController.js b/javascript-practice/src/js/controllers/registerController.js index 0722299..367688f 100644 --- a/javascript-practice/src/js/controllers/registerController.js +++ b/javascript-practice/src/js/controllers/registerController.js @@ -4,8 +4,8 @@ export default class RegisterController { this.service = service; } - handlerCheckUserExist(email) { - return this.service.userService.checkUserExist(email); + handlerCheckUserValid(email) { + return this.service.userService.isValidUser(email); } handlerSaveUser(user) { @@ -15,7 +15,7 @@ export default class RegisterController { init() { if (this.registerView) { this.registerView.addHandlerForm( - this.handlerCheckUserExist.bind(this), + this.handlerCheckUserValid.bind(this), this.handlerSaveUser.bind(this), ); this.registerView.addHandlerInputFormChange(); diff --git a/javascript-practice/src/js/helpers/helpers.js b/javascript-practice/src/js/helpers/helpers.js index 21ea8a3..3592996 100644 --- a/javascript-practice/src/js/helpers/helpers.js +++ b/javascript-practice/src/js/helpers/helpers.js @@ -7,7 +7,7 @@ import FirebaseService from '../services/firebaseService'; * @param {string} password Password input * @returns {boolean} Return true if validate password success, otherwise return false */ -export const validatePassword = (password) => { +export const isValidatePassword = (password) => { return REGEX.PASSWORD.test(password); }; diff --git a/javascript-practice/src/js/services/commonService.js b/javascript-practice/src/js/services/commonService.js index cce9cb5..ce4a698 100644 --- a/javascript-practice/src/js/services/commonService.js +++ b/javascript-practice/src/js/services/commonService.js @@ -20,12 +20,8 @@ export default class CommonService { async getDataFromProp(property, value, path = this.defaultPath) { this.connectToDb(); - const dataExists = this.firebaseService.getDataFromProp( - path, - property, - value, - ); - const result = await timeOutConnect(dataExists); + const data = this.firebaseService.getDataFromProp(path, property, value); + const result = await timeOutConnect(data); if (result.id && result.data) { return convertDataObjectToModel(result); diff --git a/javascript-practice/src/js/services/firebaseService.js b/javascript-practice/src/js/services/firebaseService.js index 80d2036..3f31092 100644 --- a/javascript-practice/src/js/services/firebaseService.js +++ b/javascript-practice/src/js/services/firebaseService.js @@ -22,7 +22,7 @@ class FirebaseService { * Save data in database * @param {Object} data The object need to save into database * @param {string} path The path of database need to be save - * @returns {Promise} Return the relsoves when write to database completed + * @returns {Promise} Return the resolves when write to database completed */ save(data, path) { return set(ref(this.db, path), data); diff --git a/javascript-practice/src/js/services/userService.js b/javascript-practice/src/js/services/userService.js index 6f53cda..5ea89e5 100644 --- a/javascript-practice/src/js/services/userService.js +++ b/javascript-practice/src/js/services/userService.js @@ -23,7 +23,7 @@ export default class UserService extends CommonService { * @param {string} email Email to find user * @returns {boolean} Return true if find, otherwise return false */ - async checkUserExist(email) { + async isValidUser(email) { const userExist = await this.getUserByEmail(email); if (userExist) { diff --git a/javascript-practice/src/js/services/walletService.js b/javascript-practice/src/js/services/walletService.js index e33a3f1..11af7d6 100644 --- a/javascript-practice/src/js/services/walletService.js +++ b/javascript-practice/src/js/services/walletService.js @@ -21,10 +21,10 @@ export default class WalletService extends CommonService { * @param {string} idUser The id user to find user's wallet * @returns {boolean} Return true if find, otherwise return false */ - async checkWalletExist(idUser) { - const walletExist = await this.getWalletByIdUser(idUser); + async isValidWallet(idUser) { + const wallet = await this.getWalletByIdUser(idUser); - if (walletExist) { + if (wallet) { return true; } diff --git a/javascript-practice/src/js/views/commonLoginRegisterView.js b/javascript-practice/src/js/views/commonLoginRegisterView.js index 5003978..5a598a6 100644 --- a/javascript-practice/src/js/views/commonLoginRegisterView.js +++ b/javascript-practice/src/js/views/commonLoginRegisterView.js @@ -1,6 +1,6 @@ import CommonView from './commonView'; import * as MESSAGE from '../constants/message'; -import { validatePassword } from '../helpers/helpers'; +import { isValidatePassword } from '../helpers/helpers'; export default class CommonLoginRegisterView extends CommonView { constructor() { @@ -19,9 +19,9 @@ export default class CommonLoginRegisterView extends CommonView { * @param {Object} account The account object with email, password, passwordConfirm field * @returns {boolean} Return true if validate success and return false if validate not success */ - validateForm(account) { + isValidateAccount(account) { if (account.password === account.passwordConfirm) { - if (validatePassword(account.passwordConfirm)) { + if (isValidatePassword(account.passwordConfirm)) { return true; } this.showError(MESSAGE.PASSWORD_NOT_STRONG); diff --git a/javascript-practice/src/js/views/commonView.js b/javascript-practice/src/js/views/commonView.js index f329ae3..02bd595 100644 --- a/javascript-practice/src/js/views/commonView.js +++ b/javascript-practice/src/js/views/commonView.js @@ -56,13 +56,13 @@ export default class CommonView { */ initToastContent(typeToast, title, content, btnContent) { // Remove old typeToast class if haved - Object.keys(TYPE_TOAST).forEach((value) => { - CommonView.removeClassElement(value, this.toast); + Object.keys(TYPE_TOAST).forEach((key) => { + CommonView.removeClassElement(TYPE_TOAST[key], this.toast); }); // Remove old icon toast if haved - Object.keys(MARK_ICON).forEach((value) => { - CommonView.removeClassElement(value, this.toastIcon); + Object.keys(MARK_ICON).forEach((key) => { + CommonView.removeClassElement(MARK_ICON[key], this.toastIcon); }); // Init content toast diff --git a/javascript-practice/src/js/views/homeView.js b/javascript-practice/src/js/views/homeView.js index d99a94c..ac1df21 100644 --- a/javascript-practice/src/js/views/homeView.js +++ b/javascript-practice/src/js/views/homeView.js @@ -13,6 +13,7 @@ export default class HomeView extends CommonView { this.addTransactionBtn = document.getElementById('addTransaction'); this.addBudgetBtn = document.getElementById('addBudget'); this.cancelBtns = document.querySelectorAll('.form__cancel-btn'); + this.saveBtns = document.querySelectorAll('.form__save-btn'); this.dialogs = document.querySelectorAll('.dialog'); this.categoryField = document.getElementById('selectCategory'); this.closeIcon = document.querySelector('.close-icon'); @@ -23,7 +24,7 @@ export default class HomeView extends CommonView { this.walletDialog = document.getElementById('walletDialog'); } - async loadPage(getInfoUserLogin, checkWalletExist, getWalletByIdUser) { + async loadPage(getInfoUserLogin, isValidWallet, getWalletByIdUser) { this.getWalletByIdUser = getWalletByIdUser; // Init function this.toggleLoaderSpinner(); const user = await getInfoUserLogin(); @@ -32,10 +33,10 @@ export default class HomeView extends CommonView { window.location.replace('/login'); } else { this.user = user; - const walletExist = await checkWalletExist(user.id); + const wallet = await isValidWallet(user.id); // Check user's wallet if have or not - if (!walletExist) { + if (!wallet) { // Show add wallet dialog this.walletDialog.showModal(); } else { @@ -126,12 +127,12 @@ export default class HomeView extends CommonView { validateWalletForm(bodyDialog) { this.walletName = bodyDialog.querySelector('.form__input-text').value; this.amount = bodyDialog.querySelector('.form__input-balance').value; - const saveBtn = bodyDialog.querySelector('.form__save-btn'); + const saveBtns = bodyDialog.querySelector('.form__save-btn'); if (this.walletName.length >= 3 && this.amount.length >= 1) { - saveBtn.classList.add('active'); + saveBtns.classList.add('active'); } else { - saveBtn.classList.remove('active'); + saveBtns.classList.remove('active'); } } diff --git a/javascript-practice/src/js/views/registerView.js b/javascript-practice/src/js/views/registerView.js index 327433d..9d920f6 100644 --- a/javascript-practice/src/js/views/registerView.js +++ b/javascript-practice/src/js/views/registerView.js @@ -23,7 +23,7 @@ export default class RegisterView extends CommonLoginRegisterView { const account = { email, password, passwordConfirm }; - if (this.validateForm(account)) { + if (this.isValidateAccount(account)) { const user = new User(account); return user;