Update common files

This commit is contained in:
2023-11-29 17:11:53 +07:00
parent 2658b78557
commit b8281c2dc5
8 changed files with 98 additions and 29 deletions
-2
View File
@@ -16,8 +16,6 @@ coverage
coverage
.jest
src/db.json
# Editor directories and files
.vscode/*
!.vscode/extensions.json
@@ -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<IButtonStyle>`
+2 -1
View File
@@ -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<IInputTyped>`
${CommonInput}
width: 160px;
${(props) =>
props.type === 'checkbox' &&
+43 -5
View File
@@ -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,
};
+3 -1
View File
@@ -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';
@@ -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');
}
+27
View File
@@ -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 };
+3 -1
View File
@@ -2,7 +2,9 @@ type Nullable<T> = T | null;
interface IDataState {
id: number;
name: string;
name?: string;
status?: boolean;
isBooked?: boolean;
}
export type { Nullable, IDataState };