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 CONFIRM_DELETE = 'Are you sure to delete it?';
const DELETE_SUCCESS = 'Delete success';
const REQUIRED_FIELD_ERROR = 'This is required field';
export {
invalidFormatMsg,
@@ -18,4 +19,5 @@ export {
EDIT_SUCCESS,
CONFIRM_DELETE,
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 = {
[key: string]: string | undefined | boolean | number;
[key: string]: boolean | undefined | string;
};
export type Test = {
type TKeyString = {
[key: string]: string;
};
@@ -54,6 +54,7 @@ export type {
TRoom,
TStateSchema,
TKeyValue,
TKeyString,
TPropValues,
TValidator,
TResponse,
+10 -13
View File
@@ -1,12 +1,13 @@
// Constants
import { invalidFormatMsg } from '../constants/messages';
import { REQUIRED_FIELD_ERROR, invalidFormatMsg } from '../constants/messages';
// Types
import { TKeyValue, TPropValues, TStateSchema, Test } from '../globals/types';
const VALUE = 'value';
const ERROR = 'error';
const REQUIRED_FIELD_ERROR = 'This is required field';
import {
TKeyString,
TKeyValue,
TPropValues,
TStateSchema,
} from '../globals/types';
const isBool = (value: unknown) => {
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 = {};
if (obj) {
for (const key of Object.keys(obj)) {
const tempValue = obj[key as keyof typeof obj];
const value: string | boolean | number =
typeof tempValue === 'boolean' ||
typeof tempValue === 'string' ||
typeof tempValue === 'number'
typeof tempValue === 'boolean' || typeof tempValue === 'string'
? tempValue
: '';
result = { ...result, [`${key}Value`]: value };
result = { ...result, [`${key}Value`]: value as string };
}
}
@@ -112,7 +111,5 @@ export {
getValueFromObj,
addValidator,
searchQuery,
VALUE,
ERROR,
REQUIRED_FIELD_ERROR,
};