diff --git a/hotel-management/src/constants/path.ts b/hotel-management/src/constants/path.ts index 7775173..03014d3 100644 --- a/hotel-management/src/constants/path.ts +++ b/hotel-management/src/constants/path.ts @@ -2,6 +2,6 @@ export const DASHBOARD = '/dashboard'; export const USER = '/user'; export const ROOM = '/room'; export const OTHER_PATH = '*'; -export const BASE_URL = 'http://localhost:3000/'; +export const BASE_URL = 'https://hotel-management-api.loiphan.com/'; export const USER_PATH = 'users'; export const ROOM_PATH = 'rooms'; diff --git a/hotel-management/src/constants/variables.ts b/hotel-management/src/constants/variables.ts index fb5b26a..a2180fb 100644 --- a/hotel-management/src/constants/variables.ts +++ b/hotel-management/src/constants/variables.ts @@ -22,16 +22,6 @@ const USER_PAGE = { label: 'Sort by room', }, ], - ORDERBY_OPTIONS: [ - { - value: 'asc', - label: 'Ascending', - }, - { - value: 'desc', - label: 'Descending', - }, - ], }; const ORDERBY_OPTIONS = [ @@ -60,25 +50,9 @@ const ROOM_PAGE = { value: 'price', label: 'Sort by price', }, - { - value: 'discount', - label: 'Sort by discount', - }, - { - value: 'status', - label: 'Sort by status', - }, ], } -const INITIAL_STATE_SCHEMA = { - id: '', - name: '', - identifiedCode: '', - phone: '', - roomId: 'undefined', - address: '', -}; const VALUE = 'value'; const ERROR = 'error'; @@ -87,7 +61,6 @@ const INIT_VALUE_USER_FORM = { name: '', id: 0, identifiedCode: '', - address: '', phone: '', }; @@ -96,7 +69,6 @@ export { ROOM_PAGE, VALUE, ERROR, - INITIAL_STATE_SCHEMA, ORDERBY_OPTIONS, INIT_VALUE_USER_FORM }; diff --git a/hotel-management/src/globals/types.ts b/hotel-management/src/globals/types.ts index c36615c..67f2ea6 100644 --- a/hotel-management/src/globals/types.ts +++ b/hotel-management/src/globals/types.ts @@ -2,7 +2,6 @@ type TUser = { id: number; name: string; identifiedCode: string; - address: string; phone: string; roomId: number; }; diff --git a/hotel-management/src/helpers/utils.ts b/hotel-management/src/helpers/utils.ts index 26e721a..2f2dce8 100644 --- a/hotel-management/src/helpers/utils.ts +++ b/hotel-management/src/helpers/utils.ts @@ -87,17 +87,11 @@ const searchQuery = ( sort: string, order: string ) => { - const phoneParams = keySearch - ? `${columnSearch}_like=` + keySearch - : ''; + const phoneParams = keySearch ? `${columnSearch}_like=` + keySearch : ''; - const sortParams = sort - ? '_sort=' + sort - : ''; + const sortParams = sort ? '_sort=' + sort : ''; - const orderParams = order - ? '_order=' + order - : ''; + const orderParams = order ? '_order=' + order : ''; const finalParam = [phoneParams, sortParams, orderParams]; let query = ''; let isFirstParam = true; @@ -116,12 +110,18 @@ const searchQuery = ( return query; }; - +const formatCurrency = (value: number): string => { + return Intl.NumberFormat('en-US', { + style: 'currency', + currency: 'USD', + }).format(value); +}; export { isRequired, getPropValues, getValueFromObj, searchQuery, - REQUIRED_FIELD_ERROR + formatCurrency, + REQUIRED_FIELD_ERROR, }; diff --git a/hotel-management/src/helpers/validators.ts b/hotel-management/src/helpers/validators.ts index cd57c15..523cb48 100644 --- a/hotel-management/src/helpers/validators.ts +++ b/hotel-management/src/helpers/validators.ts @@ -12,8 +12,8 @@ const isValidNumber = (value: unknown): boolean => { * @param value Value need to be checked * @returns A boolean indicating whether or not the argument has valid */ -const isValidDiscount = (value: string): boolean => { - return +value >= 0 && +value <= 100; +const isValidDiscount = (value: number): boolean => { + return value >= 0 && value <= 100; }; /** diff --git a/hotel-management/src/pages/Room/Form.tsx b/hotel-management/src/pages/Room/Form.tsx index d69e8ab..7744a7b 100644 --- a/hotel-management/src/pages/Room/Form.tsx +++ b/hotel-management/src/pages/Room/Form.tsx @@ -12,7 +12,7 @@ import { sendRequest } from '../../helpers/sendRequest.ts'; import Input from '../../commons/styles/Input.ts'; import FormRow from '../../components/LabelControl/index.tsx'; import { INVALID_DISCOUNT, INVALID_FIELD, REQUIRED_FIELD_ERROR } from '../../constants/formValidateMessage.ts'; -import { isValidNumber, isValidString } from '../../helpers/validators.ts'; +import { isValidDiscount, isValidNumber, isValidString } from '../../helpers/validators.ts'; import Form from '../../components/Form/index.tsx'; import { useEffect } from 'react'; @@ -140,7 +140,7 @@ const RoomForm = ({ {...register('discount', { required: REQUIRED_FIELD_ERROR, validate: { - checkPhoneNum: (v) => isValidNumber(v) || INVALID_DISCOUNT, + checkPhoneNum: (v) => isValidDiscount(v) || INVALID_DISCOUNT, }, onChange: () => trigger('discount'), })} diff --git a/hotel-management/src/pages/Room/Table.tsx b/hotel-management/src/pages/Room/Table.tsx index 28de2e7..f0b0a05 100644 --- a/hotel-management/src/pages/Room/Table.tsx +++ b/hotel-management/src/pages/Room/Table.tsx @@ -3,7 +3,7 @@ import { useEffect, useState } from 'react'; import toast from 'react-hot-toast'; // Components -import { HiSquare2Stack } from 'react-icons/hi2'; +import { RiEditBoxFill } from 'react-icons/ri'; import { HiTrash } from 'react-icons/hi'; import { StyledOperationTable } from './styled'; import Menus from '../../components/Menus'; @@ -29,6 +29,7 @@ import Spinner from '../../commons/styles/Spinner'; // Utils import { sendRequest } from '../../helpers/sendRequest'; +import { formatCurrency } from '../../helpers/utils'; interface IRoomRow { room: TRoom; @@ -52,10 +53,7 @@ const RoomRow = ({ const handleOnDelete = async (room: TRoom) => { if (confirm(CONFIRM_DELETE)) { - const response = await sendRequest( - ROOM_PATH + `/${room.id}`, - 'DELETE' - ); + const response = await sendRequest(ROOM_PATH + `/${room.id}`, 'DELETE'); if (response.statusCode === STATUS_CODE.OK) { toast.success(DELETE_SUCCESS); @@ -66,7 +64,10 @@ const RoomRow = ({ } }; - const { id, name, price, status } = room; + const { id, name, price, discount, status } = room; + + // Calculate final price + const finalPrice = price - (price * discount / 100); // prettier-ignore const statusText = status @@ -77,7 +78,7 @@ const RoomRow = ({
{id}
{name}
-
{price}
+
{formatCurrency(finalPrice)}
{statusText}
@@ -85,7 +86,7 @@ const RoomRow = ({ } + icon={} onClick={() => handleOnEdit(room)} > Edit @@ -128,7 +129,7 @@ const RoomTable = ({ nameSearch, sortByValue, orderByValue, - reload, + reload ); useEffect(() => { diff --git a/hotel-management/src/pages/User/Form.tsx b/hotel-management/src/pages/User/Form.tsx index f96b8c1..a89a672 100644 --- a/hotel-management/src/pages/User/Form.tsx +++ b/hotel-management/src/pages/User/Form.tsx @@ -4,7 +4,6 @@ import { FormProvider, useForm } from 'react-hook-form'; // Styled import Input from '../../commons/styles/Input'; -import TextArea from '../../commons/styles/TextArea'; // Components import Form from '../../components/Form'; @@ -216,20 +215,6 @@ const UserForm = ({ /> - -