mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 13:38:51 +00:00
Update common files
This commit is contained in:
@@ -16,8 +16,6 @@ coverage
|
|||||||
coverage
|
coverage
|
||||||
.jest
|
.jest
|
||||||
|
|
||||||
src/db.json
|
|
||||||
|
|
||||||
# Editor directories and files
|
# Editor directories and files
|
||||||
.vscode/*
|
.vscode/*
|
||||||
!.vscode/extensions.json
|
!.vscode/extensions.json
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ const variations: IVariations = {
|
|||||||
background-color: var(--danger-btn-color);
|
background-color: var(--danger-btn-color);
|
||||||
color: var(--light-text);
|
color: var(--light-text);
|
||||||
`,
|
`,
|
||||||
} as const;
|
};
|
||||||
|
|
||||||
interface IButtonStyle {
|
interface IButtonStyle {
|
||||||
variations?: keyof typeof variations;
|
variations?: keyof IVariations;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Button = styled.button<IButtonStyle>`
|
const Button = styled.button<IButtonStyle>`
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import styled, { css } from 'styled-components';
|
|||||||
// Styled
|
// Styled
|
||||||
import CommonInput from './CommonInput';
|
import CommonInput from './CommonInput';
|
||||||
|
|
||||||
type TInput = 'text' | 'checkbox' | 'hidden';
|
type TInput = 'text' | 'checkbox' | 'hidden' | 'date';
|
||||||
|
|
||||||
interface IInputTyped {
|
interface IInputTyped {
|
||||||
type?: TInput;
|
type?: TInput;
|
||||||
@@ -11,6 +11,7 @@ interface IInputTyped {
|
|||||||
|
|
||||||
const Input = styled.input<IInputTyped>`
|
const Input = styled.input<IInputTyped>`
|
||||||
${CommonInput}
|
${CommonInput}
|
||||||
|
width: 160px;
|
||||||
|
|
||||||
${(props) =>
|
${(props) =>
|
||||||
props.type === 'checkbox' &&
|
props.type === 'checkbox' &&
|
||||||
|
|||||||
@@ -1,9 +1,31 @@
|
|||||||
const ADD_SUCCESS = 'Add success';
|
const ADD_SUCCESS = 'Add success!';
|
||||||
const UPDATE_SUCCESS = 'Update success';
|
const UPDATE_SUCCESS = 'Update success!';
|
||||||
const CONFIRM_MESSAGE = 'Do you want to checkout this user?';
|
const CONFIRM_MESSAGE = 'Do you want to checkout this user?';
|
||||||
const CONFIRM_DELETE = 'Are you sure to delete it?'
|
const CONFIRM_DELETE = 'Are you sure to delete it?';
|
||||||
const DELETE_SUCCESS = 'Delete success';
|
const DELETE_SUCCESS = 'Delete success!';
|
||||||
const CHECKOUT_SUCCESS = 'Check out 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 {
|
export {
|
||||||
ADD_SUCCESS,
|
ADD_SUCCESS,
|
||||||
@@ -12,4 +34,20 @@ export {
|
|||||||
CONFIRM_DELETE,
|
CONFIRM_DELETE,
|
||||||
DELETE_SUCCESS,
|
DELETE_SUCCESS,
|
||||||
CHECKOUT_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,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
export const DASHBOARD = '/dashboard';
|
export const BOOKING = '/booking';
|
||||||
export const USER = '/user';
|
export const USER = '/user';
|
||||||
export const ROOM = '/room';
|
export const ROOM = '/room';
|
||||||
export const OTHER_PATH = '*';
|
export const OTHER_PATH = '*';
|
||||||
|
export const USER_PATH = 'users';
|
||||||
|
export const ROOM_PATH = 'rooms';
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ type TAction =
|
|||||||
| 'initRoom'
|
| 'initRoom'
|
||||||
| 'initUser'
|
| 'initUser'
|
||||||
| 'addRoom'
|
| 'addRoom'
|
||||||
| 'removeRoom'
|
| 'updateStatusRoom'
|
||||||
| 'addUser'
|
| 'addUser'
|
||||||
| 'removeUser'
|
| 'updateStatusUser'
|
||||||
| 'updateUserName'
|
| 'updateUserName'
|
||||||
| 'updateRoomName';
|
| 'updateRoomName';
|
||||||
|
|
||||||
@@ -38,19 +38,16 @@ const initialState: IUserRoomState = {
|
|||||||
|
|
||||||
const reducer = (state: IUserRoomState, action: IAction) => {
|
const reducer = (state: IUserRoomState, action: IAction) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
|
||||||
case 'initRoom':
|
case 'initRoom':
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
roomsAvailable: action.payload,
|
roomsAvailable: action.payload,
|
||||||
};
|
};
|
||||||
|
|
||||||
case 'initUser':
|
case 'initUser':
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
usersAvailable: action.payload,
|
usersAvailable: action.payload,
|
||||||
};
|
};
|
||||||
|
|
||||||
case 'addUser': {
|
case 'addUser': {
|
||||||
const tempArr = state.usersAvailable;
|
const tempArr = state.usersAvailable;
|
||||||
const itemExist = state.usersAvailable.find(
|
const itemExist = state.usersAvailable.find(
|
||||||
@@ -66,7 +63,6 @@ const reducer = (state: IUserRoomState, action: IAction) => {
|
|||||||
usersAvailable: tempArr,
|
usersAvailable: tempArr,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'updateUserName': {
|
case 'updateUserName': {
|
||||||
const tempArr = state.usersAvailable;
|
const tempArr = state.usersAvailable;
|
||||||
|
|
||||||
@@ -83,15 +79,18 @@ const reducer = (state: IUserRoomState, action: IAction) => {
|
|||||||
usersAvailable: tempArr,
|
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 {
|
return {
|
||||||
...state,
|
...state,
|
||||||
usersAvailable: state.usersAvailable.filter(
|
usersAvailable: tempArr,
|
||||||
(item) => item.id !== action.payload[0].id
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
case 'addRoom': {
|
case 'addRoom': {
|
||||||
const tempArr = state.roomsAvailable;
|
const tempArr = state.roomsAvailable;
|
||||||
const itemExist = state.roomsAvailable.find(
|
const itemExist = state.roomsAvailable.find(
|
||||||
@@ -107,7 +106,6 @@ const reducer = (state: IUserRoomState, action: IAction) => {
|
|||||||
roomsAvailable: tempArr,
|
roomsAvailable: tempArr,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'updateRoomName': {
|
case 'updateRoomName': {
|
||||||
const tempArr = state.roomsAvailable;
|
const tempArr = state.roomsAvailable;
|
||||||
|
|
||||||
@@ -124,15 +122,18 @@ const reducer = (state: IUserRoomState, action: IAction) => {
|
|||||||
roomsAvailable: tempArr,
|
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 {
|
return {
|
||||||
...state,
|
...state,
|
||||||
roomsAvailable: state.roomsAvailable.filter(
|
roomsAvailable: tempArr,
|
||||||
(item) => item.id !== action.payload[0].id
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw new Error('Action unknown');
|
throw new Error('Action unknown');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 };
|
||||||
@@ -2,7 +2,9 @@ type Nullable<T> = T | null;
|
|||||||
|
|
||||||
interface IDataState {
|
interface IDataState {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name?: string;
|
||||||
|
status?: boolean;
|
||||||
|
isBooked?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type { Nullable, IDataState };
|
export type { Nullable, IDataState };
|
||||||
|
|||||||
Reference in New Issue
Block a user