Fix format code style

This commit is contained in:
2023-11-01 11:11:29 +07:00
parent 117723df8c
commit e8457d8e2c
4 changed files with 19 additions and 16 deletions
@@ -10,6 +10,7 @@ const ADD_SUCCESS = 'Add success';
const EDIT_SUCCESS = 'Edit success'; const EDIT_SUCCESS = 'Edit success';
const CONFIRM_DELETE = 'Are you sure to delete it?'; const CONFIRM_DELETE = 'Are you sure to delete it?';
const DELETE_SUCCESS = 'Delete success'; const DELETE_SUCCESS = 'Delete success';
const REQUIRED_FIELD_ERROR = 'This is required field';
export { export {
invalidFormatMsg, invalidFormatMsg,
@@ -18,4 +19,5 @@ export {
EDIT_SUCCESS, EDIT_SUCCESS,
CONFIRM_DELETE, CONFIRM_DELETE,
DELETE_SUCCESS, DELETE_SUCCESS,
REQUIRED_FIELD_ERROR,
}; };
+4 -1
View File
@@ -74,4 +74,7 @@ const ROOM_PAGE = {
], ],
} }
export { USER_PAGE, ROOM_PAGE }; const VALUE = 'value';
const ERROR = 'error';
export { USER_PAGE, ROOM_PAGE, VALUE, ERROR };
+3 -2
View File
@@ -25,10 +25,10 @@ type TStateSchema = {
}; };
type TKeyValue = { type TKeyValue = {
[key: string]: string | undefined | boolean | number; [key: string]: boolean | undefined | string;
}; };
export type Test = { type TKeyString = {
[key: string]: string; [key: string]: string;
}; };
@@ -54,6 +54,7 @@ export type {
TRoom, TRoom,
TStateSchema, TStateSchema,
TKeyValue, TKeyValue,
TKeyString,
TPropValues, TPropValues,
TValidator, TValidator,
TResponse, TResponse,
+10 -13
View File
@@ -1,12 +1,13 @@
// Constants // Constants
import { invalidFormatMsg } from '../constants/messages'; import { REQUIRED_FIELD_ERROR, invalidFormatMsg } from '../constants/messages';
// Types // Types
import { TKeyValue, TPropValues, TStateSchema, Test } from '../globals/types'; import {
TKeyString,
const VALUE = 'value'; TKeyValue,
const ERROR = 'error'; TPropValues,
const REQUIRED_FIELD_ERROR = 'This is required field'; TStateSchema,
} from '../globals/types';
const isBool = (value: unknown) => { const isBool = (value: unknown) => {
return typeof value === 'boolean'; return typeof value === 'boolean';
@@ -47,20 +48,18 @@ const addValidator = ({ validatorFunc, prop, required = true }: TValidator) => {
}; };
}; };
const getValueFromObj = <T>(obj: T | null = null): Test => { const getValueFromObj = <T>(obj: T | null = null): TKeyString => {
let result = {}; let result = {};
if (obj) { if (obj) {
for (const key of Object.keys(obj)) { for (const key of Object.keys(obj)) {
const tempValue = obj[key as keyof typeof obj]; const tempValue = obj[key as keyof typeof obj];
const value: string | boolean | number = const value: string | boolean | number =
typeof tempValue === 'boolean' || typeof tempValue === 'boolean' || typeof tempValue === 'string'
typeof tempValue === 'string' ||
typeof tempValue === 'number'
? tempValue ? tempValue
: ''; : '';
result = { ...result, [`${key}Value`]: value }; result = { ...result, [`${key}Value`]: value as string };
} }
} }
@@ -112,7 +111,5 @@ export {
getValueFromObj, getValueFromObj,
addValidator, addValidator,
searchQuery, searchQuery,
VALUE,
ERROR,
REQUIRED_FIELD_ERROR, REQUIRED_FIELD_ERROR,
}; };