Merge branch from feat/refactor-services-views

This commit is contained in:
2023-09-12 14:26:14 +07:00
8 changed files with 31 additions and 13 deletions
@@ -1,3 +1,26 @@
export const DATABASE_URL =
'https://javascript-training-81f7a-default-rtdb.asia-southeast1.firebasedatabase.app';
export const TIME_OUT_SEC = 3;
export const URL = {
LOGIN: 'login',
REGISTER: 'register',
HOME: '',
};
export const BTN_CONTENT = {
GOT_IT: 'Got it!',
OK: 'Ok',
};
export const LOCAL_STORAGE = {
ACCESS_TOKEN: 'accessToken',
};
export const TYPE_TOAST = { success: 'success', error: 'error' };
export const MARK_ICON = { success: 'check', error: 'error' };
export const REGEX = {
PASSWORD:
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/,
};
@@ -1,7 +1,6 @@
import * as MESSAGE from '../constants/message';
import { TIME_OUT_SEC } from '../constants/config';
import { TIME_OUT_SEC, REGEX } from '../constants/config';
import FirebaseService from '../services/firebaseService';
import { REGEX_PASSWORD } from '../constants/variable';
/**
* Validate password
@@ -9,7 +8,7 @@ import { REGEX_PASSWORD } from '../constants/variable';
* @returns {boolean} Return true if validate password success, otherwise return false
*/
export const validatePassword = (password) => {
return REGEX_PASSWORD.test(password);
return REGEX.PASSWORD.test(password);
};
/**
@@ -66,13 +65,10 @@ export const convertDataObjectToModel = (data) => {
export const getSubdirectoryURL = () => {
const url = window.location.href;
const parts = url.split('/'); // Results: ['http:', '', 'example.com', '']
const subDirectory = parts[3]; // Get subdirectory url only
const index = subDirectory.indexOf('?'); // Remove query behind subDirectory
// Remove query behind subDirectory
const index = subDirectory.indexOf('?');
if (index !== -1) {
return subDirectory.substring(0, index);
}
@@ -1,4 +1,4 @@
import { LOCAL_STORAGE } from '../constants/variable';
import { LOCAL_STORAGE } from '../constants/config';
import { createToken } from '../helpers/helpers';
import CommonService from './commonService';
import LocalStorageService from './localStorageService';
@@ -1,4 +1,4 @@
import { MARK_ICON, TYPE_TOAST } from '../constants/variable';
import { MARK_ICON, TYPE_TOAST } from '../constants/config';
export default class CommonView {
constructor() {
+1 -1
View File
@@ -1,7 +1,7 @@
import RegisterView from './registerView';
import LoginView from './loginView';
import { getSubdirectoryURL } from '../helpers/helpers';
import { URL } from '../constants/variable';
import { URL } from '../constants/config';
import HomeView from './homeView';
export default class View {
@@ -1,5 +1,5 @@
import CommonLoginRegisterView from './commonLoginRegisterView';
import { TYPE_TOAST, BTN_CONTENT } from '../constants/variable';
import { TYPE_TOAST, BTN_CONTENT } from '../constants/config';
import * as MESSAGE from '../constants/message';
export default class LoginView extends CommonLoginRegisterView {
@@ -1,4 +1,4 @@
import { TYPE_TOAST, BTN_CONTENT } from '../constants/variable';
import { TYPE_TOAST, BTN_CONTENT } from '../constants/config';
import * as MESSAGE from '../constants/message';
import CommonLoginRegisterView from './commonLoginRegisterView';
import User from '../models/user';
-1
View File
@@ -412,7 +412,6 @@
</main>
<!-- End app -->
</div>
<!-- All scripts below is use for test purpose! -->
<script type="module" src="../js/main.js"></script>
</body>
</html>