mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 13:38:51 +00:00
Update helpers and types folder
This commit is contained in:
@@ -1,47 +1,3 @@
|
|||||||
// Constants
|
|
||||||
import { REQUIRED_FIELD_ERROR } from '../constants/formValidateMessage';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create query url for search
|
|
||||||
* @param columnSearch Column want to search
|
|
||||||
* @param keySearch Keyword search
|
|
||||||
* @param sort Sort by
|
|
||||||
* @param order Order by
|
|
||||||
* @returns Return query url
|
|
||||||
*/
|
|
||||||
const searchQuery = (
|
|
||||||
columnSearch: string,
|
|
||||||
keySearch: string,
|
|
||||||
sort: string,
|
|
||||||
order: string
|
|
||||||
) => {
|
|
||||||
const phoneParams = keySearch
|
|
||||||
? `${columnSearch}_like=` + keySearch
|
|
||||||
: '';
|
|
||||||
const sortParams = sort
|
|
||||||
? '_sort=' + sort
|
|
||||||
: '';
|
|
||||||
const orderParams = order
|
|
||||||
? '_order=' + order
|
|
||||||
: '';
|
|
||||||
const finalParam = [phoneParams, sortParams, orderParams];
|
|
||||||
let query = '';
|
|
||||||
let isFirstParam = true;
|
|
||||||
|
|
||||||
finalParam.forEach((param) => {
|
|
||||||
if (param) {
|
|
||||||
if (isFirstParam) {
|
|
||||||
query = query.concat('', param);
|
|
||||||
isFirstParam = false;
|
|
||||||
} else {
|
|
||||||
query = query.concat('&', param);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return query;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert value to currency format with value
|
* Convert value to currency format with value
|
||||||
* @param value Value need to be converted
|
* @param value Value need to be converted
|
||||||
@@ -54,14 +10,4 @@ const formatCurrency = (value: number): string => {
|
|||||||
}).format(value);
|
}).format(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
export { formatCurrency };
|
||||||
* Create error string
|
|
||||||
* @param errorCode Error code
|
|
||||||
* @param msg Message error
|
|
||||||
* @returns Return the full error string
|
|
||||||
*/
|
|
||||||
const errorMsg = (errorCode: number, msg: string) => {
|
|
||||||
return `Error code: ${errorCode}. Message: ${msg}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
export { errorMsg, searchQuery, formatCurrency, REQUIRED_FIELD_ERROR };
|
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
// Constants
|
|
||||||
import { BASE_URL } from '@constant/path';
|
|
||||||
|
|
||||||
// Types
|
|
||||||
import { IResponse } from '@type/responses';
|
|
||||||
|
|
||||||
type TMethodRequest = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The send request method to the server
|
|
||||||
* @param path The path of URL
|
|
||||||
* @param body The content will push on
|
|
||||||
* @param method HTTP method
|
|
||||||
* @returns The status code and message from server
|
|
||||||
*/
|
|
||||||
export const sendRequest = async <T>(
|
|
||||||
path: string,
|
|
||||||
method: TMethodRequest = 'GET',
|
|
||||||
body?: BodyInit
|
|
||||||
): Promise<IResponse<T>> => {
|
|
||||||
const response = await fetch(BASE_URL + path, {
|
|
||||||
method,
|
|
||||||
body,
|
|
||||||
headers: {
|
|
||||||
'Accept': 'application/json',
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const data = (await response.json()) as T;
|
|
||||||
|
|
||||||
return {
|
|
||||||
statusCode: response.status,
|
|
||||||
msg: response.statusText,
|
|
||||||
data,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
const isValidRegex = (regex: RegExp, value: string): boolean => {
|
const isValidRegex = (regex: RegExp, value: string): boolean => {
|
||||||
return regex.test(value);
|
return regex.test(value);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check value is valid discount or not
|
* Check value is valid discount or not
|
||||||
@@ -17,7 +17,6 @@ const isValidDiscount = (value: number): boolean => {
|
|||||||
return value >= 0 && value <= 100;
|
return value >= 0 && value <= 100;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check value is valid string or not
|
* Check value is valid string or not
|
||||||
* @param value Value need to be checked
|
* @param value Value need to be checked
|
||||||
@@ -27,18 +26,4 @@ const isValidString = (value: string): boolean => {
|
|||||||
return value.trim().length >= 5;
|
return value.trim().length >= 5;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
export { isValidRegex, isValidString, isValidDiscount };
|
||||||
* Check object is empty or not
|
|
||||||
* @param obj Object need to be check
|
|
||||||
* @returns A boolean indicating whether or not the argument has valid
|
|
||||||
*/
|
|
||||||
const isEmptyObj = (obj: object) => {
|
|
||||||
return Object.keys(obj).length === 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
export {
|
|
||||||
isValidRegex,
|
|
||||||
isValidString,
|
|
||||||
isValidDiscount,
|
|
||||||
isEmptyObj,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
--secondary-btn-color: #d1d1d1;
|
--secondary-btn-color: #d1d1d1;
|
||||||
--disabled-btn-color: #7f82a6;
|
--disabled-btn-color: #7f82a6;
|
||||||
|
--danger-btn-color: #ff4f4f;
|
||||||
|
|
||||||
--hover-background-color: #f3f4f6;
|
--hover-background-color: #f3f4f6;
|
||||||
--hover-dark-background-color: #d0d0d0;
|
--hover-dark-background-color: #d0d0d0;
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
interface IResponse<T> {
|
|
||||||
statusCode: number;
|
|
||||||
msg: string;
|
|
||||||
data?: T;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type { IResponse };
|
|
||||||
@@ -2,8 +2,6 @@ interface IRoom {
|
|||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
price: number;
|
price: number;
|
||||||
discount: number;
|
|
||||||
finalPrice: number;
|
|
||||||
status: boolean;
|
status: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
export type Json =
|
||||||
|
| string
|
||||||
|
| number
|
||||||
|
| boolean
|
||||||
|
| null
|
||||||
|
| { [key: string]: Json | undefined }
|
||||||
|
| Json[]
|
||||||
|
|
||||||
|
export interface Database {
|
||||||
|
public: {
|
||||||
|
Tables: {
|
||||||
|
bookings: {
|
||||||
|
Row: {
|
||||||
|
amount: number
|
||||||
|
endDate: string
|
||||||
|
id: number
|
||||||
|
roomId: number
|
||||||
|
startDate: string
|
||||||
|
status: boolean
|
||||||
|
userId: number
|
||||||
|
}
|
||||||
|
Insert: {
|
||||||
|
amount: number
|
||||||
|
endDate: string
|
||||||
|
id?: number
|
||||||
|
roomId: number
|
||||||
|
startDate: string
|
||||||
|
status: boolean
|
||||||
|
userId: number
|
||||||
|
}
|
||||||
|
Update: {
|
||||||
|
amount?: number
|
||||||
|
endDate?: string
|
||||||
|
id?: number
|
||||||
|
roomId?: number
|
||||||
|
startDate?: string
|
||||||
|
status?: boolean
|
||||||
|
userId?: number
|
||||||
|
}
|
||||||
|
Relationships: [
|
||||||
|
{
|
||||||
|
foreignKeyName: "bookings_roomId_fkey"
|
||||||
|
columns: ["roomId"]
|
||||||
|
isOneToOne: false
|
||||||
|
referencedRelation: "rooms"
|
||||||
|
referencedColumns: ["id"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
foreignKeyName: "bookings_userId_fkey"
|
||||||
|
columns: ["userId"]
|
||||||
|
isOneToOne: false
|
||||||
|
referencedRelation: "users"
|
||||||
|
referencedColumns: ["id"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
rooms: {
|
||||||
|
Row: {
|
||||||
|
id: number
|
||||||
|
name: string
|
||||||
|
price: number
|
||||||
|
status: boolean
|
||||||
|
}
|
||||||
|
Insert: {
|
||||||
|
id?: number
|
||||||
|
name: string
|
||||||
|
price: number
|
||||||
|
status: boolean
|
||||||
|
}
|
||||||
|
Update: {
|
||||||
|
id?: number
|
||||||
|
name?: string
|
||||||
|
price?: number
|
||||||
|
status?: boolean
|
||||||
|
}
|
||||||
|
Relationships: []
|
||||||
|
}
|
||||||
|
users: {
|
||||||
|
Row: {
|
||||||
|
id: number
|
||||||
|
name: string
|
||||||
|
phone: string
|
||||||
|
}
|
||||||
|
Insert: {
|
||||||
|
id?: number
|
||||||
|
name: string
|
||||||
|
phone: string
|
||||||
|
}
|
||||||
|
Update: {
|
||||||
|
id?: number
|
||||||
|
name?: string
|
||||||
|
phone?: string
|
||||||
|
}
|
||||||
|
Relationships: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Views: {
|
||||||
|
[_ in never]: never
|
||||||
|
}
|
||||||
|
Functions: {
|
||||||
|
[_ in never]: never
|
||||||
|
}
|
||||||
|
Enums: {
|
||||||
|
[_ in never]: never
|
||||||
|
}
|
||||||
|
CompositeTypes: {
|
||||||
|
[_ in never]: never
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
interface IUser {
|
interface IUser {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
identifiedCode: string;
|
|
||||||
phone: string;
|
phone: string;
|
||||||
roomId: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type { IUser };
|
export type { IUser };
|
||||||
|
|||||||
Reference in New Issue
Block a user