Fix comments

This commit is contained in:
2023-10-03 20:50:53 +07:00
parent 6ab489049b
commit e6dc029405
14 changed files with 76 additions and 97 deletions
@@ -1,31 +1,23 @@
export const PASSWORD_NOT_MATCH = 'Password not match!';
export const PASSWORD_NOT_STRONG =
'Password must at least one uppercase, one lowercase letter, one number and one special character!';
export const ERROR_CREDENTIAL = {
title: 'Error Credential',
message: 'Email or password not match! Please try again!',
export const VALIDATE_FORM = {
INVALID_EMAIL_FORMAT: `The email is not correct!`,
PASSWORD_NOT_MATCH: 'Password not match!',
PASSWORD_NOT_STRONG:
'Password must at least one uppercase, one lowercase letter, one number and one special character!',
ERROR_CREDENTIAL: {
title: 'Error Credential',
message: 'Email or password not match! Please try again!',
},
REQUIRED_MESSAGE: (field: string) => `The ${field} is required!`,
};
export const INVALID_EMAIL_FORMAT = `The email is not correct!`;
export const REQUIRED_MESSAGE = (field: string) => `The ${field} is required!`;
export const ERROR_MESSAGE_DEFAULT = ['Something went wrong!'];
export const TIME_OUT_ERROR = 'Connection time out! Please try again!';
export const DEFAULT_TITLE_ERROR_TOAST = 'Error';
export const USER_EXIST_ERROR = 'User is exists! Please try another email!';
export const ADD_WALLET_SUCCESS = 'Add wallet success!';
export const DEFAULT_MESSAGE = 'Press OK to continue!';
export const ADD_TRANSACTION_SUCCESS = 'Add success!';
export const UPDATE_TRANSACTION_SUCCESS = 'Update success!';
export const REGISTER_SUCCESS = 'Register Success';
export const TOAST = {
ERROR_MESSAGE_DEFAULT: ['Something went wrong!'],
TIME_OUT_ERROR: 'Connection time out! Please try again!',
DEFAULT_TITLE_ERROR_TOAST: 'Error',
USER_EXIST_ERROR: 'User is exists! Please try another email!',
ADD_WALLET_SUCCESS: 'Add wallet success!',
DEFAULT_MESSAGE: 'Press OK to continue!',
ADD_TRANSACTION_SUCCESS: 'Add success!',
UPDATE_TRANSACTION_SUCCESS: 'Update success!',
REGISTER_SUCCESS: 'Register Success',
};
@@ -1,20 +1,17 @@
import HomeView from 'views/home/homeView';
import Service from 'services';
import View from 'views';
import Wallet from 'models/wallet';
import Transaction from 'models/transaction';
import Category from 'models/category';
import { IHomeFunc } from 'global/types';
import { IHomeFunc, Nullable } from 'global/types';
export default class HomeController {
public homeView: HomeView | null = null;
constructor(
public service: Service,
public view: View,
public homeView: Nullable<HomeView>,
) {
this.service = service;
this.homeView = view.homeView;
this.homeView = homeView;
}
handlerGetInfoUserLogin() {
@@ -15,8 +15,11 @@ export default class Controller {
public service: Service,
public view: View,
) {
this.registerController = new RegisterController(service, view);
this.loginController = new LoginController(service, view);
this.homeController = new HomeController(service, view);
this.registerController = new RegisterController(
service,
view.registerView,
);
this.loginController = new LoginController(service, view.loginView);
this.homeController = new HomeController(service, view.homeView);
}
}
@@ -1,17 +1,15 @@
import { Nullable } from 'global/types';
import User from 'models/user';
import Service from 'services';
import View from 'views';
import LoginView from 'views/loginView';
export default class LoginController {
public loginView: LoginView | null = null;
constructor(
public service: Service,
public view: View,
public loginView: Nullable<LoginView>,
) {
this.service = service;
this.loginView = view.loginView;
this.loginView = loginView;
}
handlerLoginUser(email: string, password: string): Promise<boolean> {
@@ -1,17 +1,15 @@
import { Nullable } from 'global/types';
import User from 'models/user';
import Service from 'services';
import View from 'views';
import RegisterView from 'views/registerView';
export default class RegisterController {
public registerView: RegisterView | null = null;
constructor(
public service: Service,
public view: View,
public registerView: Nullable<RegisterView>,
) {
this.service = service;
this.registerView = view.registerView;
this.registerView = registerView;
}
handlerCheckUserValid(email: string): Promise<boolean> {
@@ -1,4 +1,4 @@
import { TIME_OUT_ERROR } from '../constants/messages';
import { TOAST } from '../constants/messages';
import { TIME_OUT_SEC } from '../constants/config';
import FirebaseService from '../services/firebaseService';
@@ -11,7 +11,7 @@ export const timeout = (s: number): Promise<string> => {
return new Promise((_, reject) => {
setTimeout(() => {
FirebaseService.disconnect();
reject(TIME_OUT_ERROR);
reject(TOAST.TIME_OUT_ERROR);
}, s * 1000);
});
};
@@ -1,5 +1,5 @@
import { REGEX } from '../constants/config';
import { REQUIRED_MESSAGE } from '../constants/messages';
import { VALIDATE_FORM } from '../constants/messages';
/**
* Validate password
@@ -23,7 +23,7 @@ export const compare2Password = (
export const renderRequiredText = (field: string, element: Element) => {
const markup: string = `
<p class="error-text">${REQUIRED_MESSAGE(field)}</p>
<p class="error-text">${VALIDATE_FORM.REQUIRED_MESSAGE(field)}</p>
`;
element.insertAdjacentHTML('afterend', markup);
@@ -1,10 +1,5 @@
import CommonView from './commonView';
import {
INVALID_EMAIL_FORMAT,
PASSWORD_NOT_MATCH,
PASSWORD_NOT_STRONG,
ERROR_MESSAGE_DEFAULT,
} from 'constants/messages';
import { TOAST, VALIDATE_FORM } from 'constants/messages';
import {
compare2Password,
isValidPassword,
@@ -31,7 +26,7 @@ export default class AuthenticationView extends CommonView {
this.formEl = document.querySelector('.form');
this.emailEl = document.querySelector("[name='email']");
this.messageDefault = ERROR_MESSAGE_DEFAULT;
this.messageDefault = TOAST.ERROR_MESSAGE_DEFAULT;
this.inputPasswordEl = document.querySelector('input[name="password"]');
this.inputPasswordConfirmEl = document.querySelector(
'input[name="password_confirm"]',
@@ -44,7 +39,7 @@ export default class AuthenticationView extends CommonView {
validateEmail(email: string): boolean {
if (email) {
if (!isValidateEmail(email)) {
this.listError.push(INVALID_EMAIL_FORMAT);
this.listError.push(VALIDATE_FORM.INVALID_EMAIL_FORMAT);
return false;
}
@@ -58,7 +53,7 @@ export default class AuthenticationView extends CommonView {
validatePassword(password: string): boolean {
if (password) {
if (!isValidPassword(password)) {
this.listError.push(PASSWORD_NOT_STRONG);
this.listError.push(VALIDATE_FORM.PASSWORD_NOT_STRONG);
return false;
}
@@ -74,7 +69,7 @@ export default class AuthenticationView extends CommonView {
validatePasswordConfirm(password: string, passwordConfirm: string): boolean {
if (passwordConfirm) {
if (!compare2Password(password, passwordConfirm)) {
this.listError.push(PASSWORD_NOT_MATCH);
this.listError.push(VALIDATE_FORM.PASSWORD_NOT_MATCH);
return false;
}
@@ -4,7 +4,7 @@ import EventDataTrigger from 'helpers/evDataTrigger';
import Wallet from 'models/wallet';
import User from 'models/user';
import { DEFAULT_CATEGORY } from 'constants/config';
import { ADD_TRANSACTION_SUCCESS, DEFAULT_MESSAGE } from 'constants/messages';
import { TOAST } from 'constants/messages';
import {
IBudgetViewFunc,
Data,
@@ -140,7 +140,10 @@ export default class BudgetView {
this.toggleLoaderSpinner!();
// Show success message
this.showSuccessToast!(ADD_TRANSACTION_SUCCESS, DEFAULT_MESSAGE);
this.showSuccessToast!(
TOAST.ADD_TRANSACTION_SUCCESS,
TOAST.DEFAULT_MESSAGE,
);
(<HTMLFormElement>document.getElementById('formAddBudget')!).reset();
}
@@ -17,7 +17,7 @@ import {
PromiseOrNull,
TError,
} from 'global/types';
import { DEFAULT_TITLE_ERROR_TOAST } from 'constants/messages';
import { TOAST } from 'constants/messages';
import { redirectToLoginPage } from 'helpers/url';
import Category from 'models/category';
import CategoryView from './categoryView';
@@ -191,13 +191,10 @@ export default class HomeView extends CommonView {
this.sendData();
await this.categoryView.loadCategory();
await this.loadWalletUser();
this.summaryTabView.load();
this.transactionTabView.loadTransactionTab();
await this.loadWalletUser();
await this.updateAmountWallet();
}
@@ -327,7 +324,7 @@ export default class HomeView extends CommonView {
const title =
typeof error === 'object' && error.title
? error.title
: DEFAULT_TITLE_ERROR_TOAST;
: TOAST.DEFAULT_TITLE_ERROR_TOAST;
const content =
typeof error === 'object' && error.message
@@ -12,11 +12,7 @@ import {
} from 'global/types';
import Wallet from 'models/wallet';
import Category from 'models/category';
import {
ADD_TRANSACTION_SUCCESS,
DEFAULT_MESSAGE,
UPDATE_TRANSACTION_SUCCESS,
} from 'constants/messages';
import { TOAST } from 'constants/messages';
import { renderRequiredText } from 'helpers/validatorForm';
export default class TransactionView {
@@ -170,7 +166,7 @@ export default class TransactionView {
await this.updateAmountWallet!();
await this.loadData!();
this.showSuccessToast!('Delete success!', DEFAULT_MESSAGE);
this.showSuccessToast!('Delete success!', TOAST.DEFAULT_MESSAGE);
} catch (error) {
this.showErrorToast!(error as TError);
}
@@ -296,10 +292,16 @@ export default class TransactionView {
if (!idEl.value) {
// Add success
this.showSuccessToast!(ADD_TRANSACTION_SUCCESS, DEFAULT_MESSAGE);
this.showSuccessToast!(
TOAST.ADD_TRANSACTION_SUCCESS,
TOAST.DEFAULT_MESSAGE,
);
} else {
// Update success
this.showSuccessToast!(UPDATE_TRANSACTION_SUCCESS, DEFAULT_MESSAGE);
this.showSuccessToast!(
TOAST.UPDATE_TRANSACTION_SUCCESS,
TOAST.DEFAULT_MESSAGE,
);
}
this.toggleLoaderSpinner!();
@@ -12,7 +12,7 @@ import {
} from 'global/types';
import User from 'models/user';
import { FIRST_ADD_WALLET_NOTE } from 'constants/defaultVariable';
import { ADD_WALLET_SUCCESS, DEFAULT_MESSAGE } from 'constants/messages';
import { TOAST } from 'constants/messages';
export default class WalletView {
walletDialog: Nullable<HTMLDialogElement> = null;
@@ -148,7 +148,7 @@ export default class WalletView {
await this.loadData!();
this.loadEvent!();
this.showSuccessToast!(ADD_WALLET_SUCCESS, DEFAULT_MESSAGE);
this.showSuccessToast!(TOAST.ADD_WALLET_SUCCESS, TOAST.DEFAULT_MESSAGE);
this.toggleLoaderSpinner!();
}
@@ -180,7 +180,6 @@ export default class WalletView {
return true;
}
// eslint-disable-next-line class-methods-use-this
changeBtnStyleWalletDialog(bodyDialog: Element) {
const walletName = (<HTMLDataElement>(
bodyDialog.querySelector('.form__input-text')
@@ -1,10 +1,7 @@
import AuthenticationView from './authenticationView';
import { TypeToast, BTN_CONTENT } from '../constants/config';
import User from 'models/user';
import {
DEFAULT_TITLE_ERROR_TOAST,
ERROR_CREDENTIAL,
} from 'constants/messages';
import { TOAST, VALIDATE_FORM } from 'constants/messages';
import { CustomError, Nullable, PromiseOrNull, TError } from 'global/types';
import { redirectToLoginPage } from 'helpers/url';
@@ -34,7 +31,7 @@ export default class LoginView extends AuthenticationView {
const title =
typeof error === 'object' && error.title
? error.title
: DEFAULT_TITLE_ERROR_TOAST;
: TOAST.DEFAULT_TITLE_ERROR_TOAST;
const content =
typeof error === 'object' && error.message
@@ -88,7 +85,10 @@ export default class LoginView extends AuthenticationView {
window.location.replace('/');
return;
}
throw new CustomError(ERROR_CREDENTIAL.title, ERROR_CREDENTIAL.message);
throw new CustomError(
VALIDATE_FORM.ERROR_CREDENTIAL.title,
VALIDATE_FORM.ERROR_CREDENTIAL.message,
);
}
} catch (error) {
// Show toast error
@@ -2,12 +2,7 @@ import { TypeToast, BTN_CONTENT } from '../constants/config';
import AuthenticationView from './authenticationView';
import User from '../models/user';
import { redirectToLoginPage } from '../helpers/url';
import {
DEFAULT_MESSAGE,
DEFAULT_TITLE_ERROR_TOAST,
REGISTER_SUCCESS,
USER_EXIST_ERROR,
} from 'constants/messages';
import { TOAST } from 'constants/messages';
import { Nullable, PromiseOrNull, TError } from 'global/types';
interface UserInput {
@@ -95,8 +90,8 @@ export default class RegisterView extends AuthenticationView {
*/
showRegisterSuccessToast() {
const typeToast = TypeToast.success;
const title = REGISTER_SUCCESS;
const content = DEFAULT_MESSAGE;
const title = TOAST.REGISTER_SUCCESS;
const content = TOAST.DEFAULT_MESSAGE;
const btnContent = BTN_CONTENT.OK;
this.initToastContent(typeToast, title, content, btnContent);
@@ -117,7 +112,7 @@ export default class RegisterView extends AuthenticationView {
const title =
typeof error === 'object' && error.title
? error.title
: DEFAULT_TITLE_ERROR_TOAST;
: TOAST.DEFAULT_TITLE_ERROR_TOAST;
const content =
typeof error === 'object' && error.message
@@ -168,7 +163,7 @@ export default class RegisterView extends AuthenticationView {
// Check user exist
const userExist = await checkExistUser(user.email);
if (userExist) {
throw Error(USER_EXIST_ERROR);
throw Error(TOAST.USER_EXIST_ERROR);
} else {
await saveUser(user);
// Show toast success