From b8281c2dc584651c83a6ae756829f3ef41262261 Mon Sep 17 00:00:00 2001 From: Loi Phan Date: Wed, 29 Nov 2023 17:11:53 +0700 Subject: [PATCH] Update common files --- hotel-management/.gitignore | 2 - hotel-management/src/commons/styles/Button.ts | 4 +- hotel-management/src/commons/styles/Input.ts | 3 +- hotel-management/src/constants/messages.ts | 48 +++++++++++++++++-- hotel-management/src/constants/path.ts | 4 +- .../src/contexts/UserRoomAvailableContext.ts | 35 +++++++------- hotel-management/src/types/booking.ts | 27 +++++++++++ hotel-management/src/types/common.ts | 4 +- 8 files changed, 98 insertions(+), 29 deletions(-) create mode 100644 hotel-management/src/types/booking.ts diff --git a/hotel-management/.gitignore b/hotel-management/.gitignore index 13549f4..36e326e 100644 --- a/hotel-management/.gitignore +++ b/hotel-management/.gitignore @@ -16,8 +16,6 @@ coverage coverage .jest -src/db.json - # Editor directories and files .vscode/* !.vscode/extensions.json diff --git a/hotel-management/src/commons/styles/Button.ts b/hotel-management/src/commons/styles/Button.ts index 00c8db1..ad82be0 100644 --- a/hotel-management/src/commons/styles/Button.ts +++ b/hotel-management/src/commons/styles/Button.ts @@ -16,10 +16,10 @@ const variations: IVariations = { background-color: var(--danger-btn-color); color: var(--light-text); `, -} as const; +}; interface IButtonStyle { - variations?: keyof typeof variations; + variations?: keyof IVariations; } const Button = styled.button` diff --git a/hotel-management/src/commons/styles/Input.ts b/hotel-management/src/commons/styles/Input.ts index 32e5eb2..bd746fa 100644 --- a/hotel-management/src/commons/styles/Input.ts +++ b/hotel-management/src/commons/styles/Input.ts @@ -3,7 +3,7 @@ import styled, { css } from 'styled-components'; // Styled import CommonInput from './CommonInput'; -type TInput = 'text' | 'checkbox' | 'hidden'; +type TInput = 'text' | 'checkbox' | 'hidden' | 'date'; interface IInputTyped { type?: TInput; @@ -11,6 +11,7 @@ interface IInputTyped { const Input = styled.input` ${CommonInput} + width: 160px; ${(props) => props.type === 'checkbox' && diff --git a/hotel-management/src/constants/messages.ts b/hotel-management/src/constants/messages.ts index 73342ea..b8fefdd 100644 --- a/hotel-management/src/constants/messages.ts +++ b/hotel-management/src/constants/messages.ts @@ -1,9 +1,31 @@ -const ADD_SUCCESS = 'Add success'; -const UPDATE_SUCCESS = 'Update success'; +const ADD_SUCCESS = 'Add success!'; +const UPDATE_SUCCESS = 'Update success!'; const CONFIRM_MESSAGE = 'Do you want to checkout this user?'; -const CONFIRM_DELETE = 'Are you sure to delete it?' -const DELETE_SUCCESS = 'Delete success'; -const CHECKOUT_SUCCESS = 'Check out success'; +const CONFIRM_DELETE = 'Are you sure to delete it?'; +const DELETE_SUCCESS = 'Delete success!'; + +// Booking connection messages +const BOOKINGS_TABLE = 'bookings'; +const ERROR_FETCHING_BOOKING = "Can't fetch booking data!"; +const ERROR_UPDATE_BOOKING = "Can't update booking!"; +const ERROR_CREATE_BOOKING = "Can't create booking!"; +const ERROR_DELETE_BOOKING = "Can't delete booking!"; +const CHECKOUT_SUCCESS = 'Check out success!'; +const ERROR_CHECKOUT = "Can't checkout!"; + +// Room connection messages +const ROOMS_TABLE = 'rooms'; +const ERROR_FETCHING_ROOM = "Can't fetch room data!"; +const ERROR_UPDATE_ROOM = "Can't update room!"; +const ERROR_CREATE_ROOM = "Can't create room!"; +const ERROR_DELETE_ROOM = "Can't delete room!"; + +// User connection messages +const USERS_TABLE = 'users'; +const ERROR_FETCHING_USER = "Users can't be loaded!"; +const ERROR_CREATE_USER = "Can't create user!"; +const ERROR_UPDATE_USER = "Can't update user!"; +const ERROR_DELETE_USER = "Can't delete user!"; export { ADD_SUCCESS, @@ -12,4 +34,20 @@ export { CONFIRM_DELETE, DELETE_SUCCESS, CHECKOUT_SUCCESS, + ERROR_CHECKOUT, + BOOKINGS_TABLE, + ERROR_FETCHING_BOOKING, + ERROR_UPDATE_BOOKING, + ERROR_CREATE_BOOKING, + ERROR_DELETE_BOOKING, + ROOMS_TABLE, + ERROR_FETCHING_ROOM, + ERROR_UPDATE_ROOM, + ERROR_DELETE_ROOM, + ERROR_CREATE_ROOM, + USERS_TABLE, + ERROR_FETCHING_USER, + ERROR_CREATE_USER, + ERROR_UPDATE_USER, + ERROR_DELETE_USER, }; diff --git a/hotel-management/src/constants/path.ts b/hotel-management/src/constants/path.ts index c96883d..a83803e 100644 --- a/hotel-management/src/constants/path.ts +++ b/hotel-management/src/constants/path.ts @@ -1,4 +1,6 @@ -export const DASHBOARD = '/dashboard'; +export const BOOKING = '/booking'; export const USER = '/user'; export const ROOM = '/room'; export const OTHER_PATH = '*'; +export const USER_PATH = 'users'; +export const ROOM_PATH = 'rooms'; diff --git a/hotel-management/src/contexts/UserRoomAvailableContext.ts b/hotel-management/src/contexts/UserRoomAvailableContext.ts index 17371d3..13c5e28 100644 --- a/hotel-management/src/contexts/UserRoomAvailableContext.ts +++ b/hotel-management/src/contexts/UserRoomAvailableContext.ts @@ -12,9 +12,9 @@ type TAction = | 'initRoom' | 'initUser' | 'addRoom' - | 'removeRoom' + | 'updateStatusRoom' | 'addUser' - | 'removeUser' + | 'updateStatusUser' | 'updateUserName' | 'updateRoomName'; @@ -38,19 +38,16 @@ const initialState: IUserRoomState = { const reducer = (state: IUserRoomState, action: IAction) => { switch (action.type) { - case 'initRoom': return { ...state, roomsAvailable: action.payload, }; - case 'initUser': return { ...state, usersAvailable: action.payload, }; - case 'addUser': { const tempArr = state.usersAvailable; const itemExist = state.usersAvailable.find( @@ -66,7 +63,6 @@ const reducer = (state: IUserRoomState, action: IAction) => { usersAvailable: tempArr, }; } - case 'updateUserName': { const tempArr = state.usersAvailable; @@ -83,15 +79,18 @@ const reducer = (state: IUserRoomState, action: IAction) => { usersAvailable: tempArr, }; } + case 'updateStatusUser': { + const tempArr = state.usersAvailable; + const indexItemUpdate = tempArr.findIndex( + (item) => item.id === action.payload[0].id + ); + tempArr[indexItemUpdate].isBooked = action.payload[0].isBooked; - case 'removeUser': return { ...state, - usersAvailable: state.usersAvailable.filter( - (item) => item.id !== action.payload[0].id - ), + usersAvailable: tempArr, }; - + } case 'addRoom': { const tempArr = state.roomsAvailable; const itemExist = state.roomsAvailable.find( @@ -107,7 +106,6 @@ const reducer = (state: IUserRoomState, action: IAction) => { roomsAvailable: tempArr, }; } - case 'updateRoomName': { const tempArr = state.roomsAvailable; @@ -124,15 +122,18 @@ const reducer = (state: IUserRoomState, action: IAction) => { roomsAvailable: tempArr, }; } + case 'updateStatusRoom': { + const tempArr = state.roomsAvailable; + const indexItemUpdate = tempArr.findIndex( + (item) => item.id === action.payload[0].id + ); + tempArr[indexItemUpdate].status = action.payload[0].status; - case 'removeRoom': return { ...state, - roomsAvailable: state.roomsAvailable.filter( - (item) => item.id !== action.payload[0].id - ), + roomsAvailable: tempArr, }; - + } default: throw new Error('Action unknown'); } diff --git a/hotel-management/src/types/booking.ts b/hotel-management/src/types/booking.ts new file mode 100644 index 0000000..460b999 --- /dev/null +++ b/hotel-management/src/types/booking.ts @@ -0,0 +1,27 @@ +interface IBooking { + id: number; + startDate: string; + endDate: string; + status: boolean; + amount: number; + roomId: number; + userId: number; +} + +interface TBookingResponse { + id: number; + startDate: string; + endDate: string; + status: boolean; + amount: number; + rooms: { + id: number + name: string; + } | null; + users: { + id: number; + name: string; + } | null; +} + +export type { IBooking, TBookingResponse }; diff --git a/hotel-management/src/types/common.ts b/hotel-management/src/types/common.ts index 825c8f3..7445679 100644 --- a/hotel-management/src/types/common.ts +++ b/hotel-management/src/types/common.ts @@ -2,7 +2,9 @@ type Nullable = T | null; interface IDataState { id: number; - name: string; + name?: string; + status?: boolean; + isBooked?: boolean; } export type { Nullable, IDataState };