mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 13:38:51 +00:00
Merge branch 'react-practice-02' into feat/unit-test-for-components
This commit is contained in:
@@ -18,7 +18,9 @@ import {
|
|||||||
initialState,
|
initialState,
|
||||||
reducer,
|
reducer,
|
||||||
} from '@context/UserRoomAvailableContext';
|
} from '@context/UserRoomAvailableContext';
|
||||||
import { useEffect, useReducer } from 'react';
|
import { useEffect, useMemo, useReducer } from 'react';
|
||||||
|
|
||||||
|
// Services
|
||||||
import { getUserNotBooked } from '@service/userServices';
|
import { getUserNotBooked } from '@service/userServices';
|
||||||
import { getRoomsAvailable } from '@service/roomServices';
|
import { getRoomsAvailable } from '@service/roomServices';
|
||||||
|
|
||||||
@@ -55,16 +57,21 @@ function App() {
|
|||||||
load();
|
load();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const store = useMemo(() => {
|
||||||
|
return { roomsAvailable, usersAvailable, dispatch };
|
||||||
|
}, [roomsAvailable, usersAvailable]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<StyleSheetManager shouldForwardProp={shouldForwardProp}>
|
<StyleSheetManager shouldForwardProp={shouldForwardProp}>
|
||||||
<UserRoomAvailableContext.Provider
|
<UserRoomAvailableContext.Provider value={store}>
|
||||||
value={{ roomsAvailable, usersAvailable, dispatch }}
|
|
||||||
>
|
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route element={<AppLayout />}>
|
<Route element={<AppLayout />}>
|
||||||
<Route index element={<Navigate replace to={PATH.DASHBOARD} />} />
|
<Route
|
||||||
|
index
|
||||||
|
element={<Navigate replace to={PATH.DASHBOARD} />}
|
||||||
|
/>
|
||||||
<Route path={PATH.DASHBOARD} element={<Dashboard />} />
|
<Route path={PATH.DASHBOARD} element={<Dashboard />} />
|
||||||
<Route path={PATH.USER} element={<User />} />
|
<Route path={PATH.USER} element={<User />} />
|
||||||
<Route path={PATH.ROOM} element={<Room />} />
|
<Route path={PATH.ROOM} element={<Room />} />
|
||||||
|
|||||||
@@ -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 IVariations;
|
variations?: keyof typeof variations;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Button = styled.button<IButtonStyle>`
|
const Button = styled.button<IButtonStyle>`
|
||||||
|
|||||||
@@ -1,92 +1,5 @@
|
|||||||
import { COLOR, SIZE } from '@constant/styles';
|
|
||||||
import { ReactNode } from 'react';
|
import { ReactNode } from 'react';
|
||||||
import styled, { css } from 'styled-components';
|
import { StyledButtonIcon } from './styled';
|
||||||
|
|
||||||
interface IStyledButtonIcon {
|
|
||||||
isHaveChildren: boolean;
|
|
||||||
style?: {
|
|
||||||
fontSize?: string;
|
|
||||||
backgroundColor?: string;
|
|
||||||
color?: string;
|
|
||||||
};
|
|
||||||
iconStyle?: {
|
|
||||||
color?: string;
|
|
||||||
size?: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const StyledButtonIcon = styled.button<IStyledButtonIcon>`
|
|
||||||
background: none;
|
|
||||||
|
|
||||||
padding: 10px;
|
|
||||||
transition: all 0.2s;
|
|
||||||
|
|
||||||
border: none;
|
|
||||||
|
|
||||||
${(props) =>
|
|
||||||
props.style?.fontSize &&
|
|
||||||
css`
|
|
||||||
font-size: ${props.style.fontSize};
|
|
||||||
`}
|
|
||||||
|
|
||||||
${(props) =>
|
|
||||||
props.style?.fontSize &&
|
|
||||||
css`
|
|
||||||
font-size: ${props.style.fontSize};
|
|
||||||
`}
|
|
||||||
|
|
||||||
${(props) =>
|
|
||||||
props.color &&
|
|
||||||
css`
|
|
||||||
font-size: ${props.color};
|
|
||||||
`}
|
|
||||||
|
|
||||||
${(props) =>
|
|
||||||
props.isHaveChildren
|
|
||||||
? css`
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 10px;
|
|
||||||
|
|
||||||
text-align: left;
|
|
||||||
width: 100%;
|
|
||||||
`
|
|
||||||
: css`
|
|
||||||
border-radius: var(--radius-md);
|
|
||||||
`}
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: var(--hover-background-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
& svg {
|
|
||||||
${(props) =>
|
|
||||||
props.iconStyle?.size &&
|
|
||||||
css`
|
|
||||||
width: ${props.iconStyle.size};
|
|
||||||
height: ${props.iconStyle.size};
|
|
||||||
`}
|
|
||||||
|
|
||||||
${(props) =>
|
|
||||||
props.iconStyle?.color &&
|
|
||||||
css`
|
|
||||||
color: ${props.iconStyle.color};
|
|
||||||
`}
|
|
||||||
transition: all 0.3s;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
StyledButtonIcon.defaultProps = {
|
|
||||||
style: {
|
|
||||||
fontSize: SIZE.DEFAULT,
|
|
||||||
backgroundColor: COLOR.DEFAULT,
|
|
||||||
color: COLOR.BLACK,
|
|
||||||
},
|
|
||||||
iconStyle: {
|
|
||||||
color: COLOR.BLACK,
|
|
||||||
size: SIZE.DEFAULT,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
interface IButtonIcon {
|
interface IButtonIcon {
|
||||||
icon: ReactNode;
|
icon: ReactNode;
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
import styled, { css } from 'styled-components';
|
||||||
|
import { COLOR, SIZE } from '@constant/styles';
|
||||||
|
|
||||||
|
interface IStyledButtonIcon {
|
||||||
|
isHaveChildren: boolean;
|
||||||
|
style?: {
|
||||||
|
fontSize?: string;
|
||||||
|
backgroundColor?: string;
|
||||||
|
color?: string;
|
||||||
|
};
|
||||||
|
iconStyle?: {
|
||||||
|
color?: string;
|
||||||
|
size?: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const StyledButtonIcon = styled.button<IStyledButtonIcon>`
|
||||||
|
background: none;
|
||||||
|
|
||||||
|
padding: 10px;
|
||||||
|
transition: all 0.2s;
|
||||||
|
|
||||||
|
border: none;
|
||||||
|
|
||||||
|
${(props) =>
|
||||||
|
props.style?.fontSize &&
|
||||||
|
css`
|
||||||
|
font-size: ${props.style.fontSize};
|
||||||
|
`}
|
||||||
|
|
||||||
|
${(props) =>
|
||||||
|
props.style?.fontSize &&
|
||||||
|
css`
|
||||||
|
font-size: ${props.style.fontSize};
|
||||||
|
`}
|
||||||
|
|
||||||
|
${(props) =>
|
||||||
|
props.color &&
|
||||||
|
css`
|
||||||
|
font-size: ${props.color};
|
||||||
|
`}
|
||||||
|
|
||||||
|
${(props) =>
|
||||||
|
props.isHaveChildren
|
||||||
|
? css`
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
|
||||||
|
text-align: left;
|
||||||
|
width: 100%;
|
||||||
|
`
|
||||||
|
: css`
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
`}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: var(--hover-background-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
& svg {
|
||||||
|
${(props) =>
|
||||||
|
props.iconStyle?.size &&
|
||||||
|
css`
|
||||||
|
width: ${props.iconStyle.size};
|
||||||
|
height: ${props.iconStyle.size};
|
||||||
|
`}
|
||||||
|
|
||||||
|
${(props) =>
|
||||||
|
props.iconStyle?.color &&
|
||||||
|
css`
|
||||||
|
color: ${props.iconStyle.color};
|
||||||
|
`}
|
||||||
|
transition: all 0.3s;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
StyledButtonIcon.defaultProps = {
|
||||||
|
style: {
|
||||||
|
fontSize: SIZE.DEFAULT,
|
||||||
|
backgroundColor: COLOR.DEFAULT,
|
||||||
|
color: COLOR.BLACK,
|
||||||
|
},
|
||||||
|
iconStyle: {
|
||||||
|
color: COLOR.BLACK,
|
||||||
|
size: SIZE.DEFAULT,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export { StyledButtonIcon };
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ interface IConfirmMessage {
|
|||||||
|
|
||||||
const ConfirmMessage = memo(
|
const ConfirmMessage = memo(
|
||||||
({ message, disabled, onConfirm, onCloseModal }: IConfirmMessage) => {
|
({ message, disabled, onConfirm, onCloseModal }: IConfirmMessage) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledConfirmDelete>
|
<StyledConfirmDelete>
|
||||||
<p>{message}</p>
|
<p>{message}</p>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import styled from "styled-components";
|
import styled from 'styled-components';
|
||||||
|
|
||||||
const StyledConfirmDelete = styled.div`
|
const StyledConfirmDelete = styled.div`
|
||||||
width: 450px;
|
width: 450px;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { HiEllipsisVertical } from 'react-icons/hi2';
|
|||||||
|
|
||||||
// Hooks
|
// Hooks
|
||||||
import { useOutsideClick } from '@hook/useOutsideClick';
|
import { useOutsideClick } from '@hook/useOutsideClick';
|
||||||
|
import ButtonIcon from '@component/ButtonIcon';
|
||||||
|
|
||||||
// Styled
|
// Styled
|
||||||
import { StyledMenu, StyledList, StyledToggle } from './styled';
|
import { StyledMenu, StyledList, StyledToggle } from './styled';
|
||||||
@@ -14,7 +15,8 @@ import MenusContext from '@context/MenuContext';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { Nullable } from '@type/common';
|
import { Nullable } from '@type/common';
|
||||||
import ButtonIcon from '@component/ButtonIcon';
|
|
||||||
|
// Constants
|
||||||
import { COLOR } from '@constant/styles';
|
import { COLOR } from '@constant/styles';
|
||||||
|
|
||||||
interface IButton {
|
interface IButton {
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useSearchParams } from 'react-router-dom';
|
||||||
|
|
||||||
// Styled
|
// Styled
|
||||||
import { StyledSearch } from './styled';
|
import { StyledSearch } from './styled';
|
||||||
|
|
||||||
// Hooks
|
// Hooks
|
||||||
import { useDebounce } from '@hook/useDebounce';
|
import { useDebounce } from '@hook/useDebounce';
|
||||||
import { useSearchParams } from 'react-router-dom';
|
|
||||||
|
// Types
|
||||||
import { Nullable } from '@type/common';
|
import { Nullable } from '@type/common';
|
||||||
|
|
||||||
interface ISearch {
|
interface ISearch {
|
||||||
|
|||||||
@@ -43,20 +43,6 @@ const ROOM_PAGE = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const INIT_VALUE_USER_FORM = {
|
|
||||||
name: '',
|
|
||||||
id: 0,
|
|
||||||
identifiedCode: '',
|
|
||||||
phone: '',
|
|
||||||
};
|
|
||||||
|
|
||||||
const INIT_VALUE_ROOM_FORM = {
|
|
||||||
name: '',
|
|
||||||
id: 0,
|
|
||||||
price: 0,
|
|
||||||
discount: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
const FORM = {
|
const FORM = {
|
||||||
EDIT: 'edit',
|
EDIT: 'edit',
|
||||||
DELETE: 'delete',
|
DELETE: 'delete',
|
||||||
@@ -76,6 +62,4 @@ export {
|
|||||||
FORM,
|
FORM,
|
||||||
REGEX,
|
REGEX,
|
||||||
ORDERBY_OPTIONS,
|
ORDERBY_OPTIONS,
|
||||||
INIT_VALUE_USER_FORM,
|
|
||||||
INIT_VALUE_ROOM_FORM,
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,5 +2,3 @@ export const DASHBOARD = '/dashboard';
|
|||||||
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';
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { IDataState } from '@type/common';
|
|
||||||
import { Dispatch, createContext } from 'react';
|
import { Dispatch, createContext } from 'react';
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import { IDataState } from '@type/common';
|
||||||
|
|
||||||
interface IUserRoomState {
|
interface IUserRoomState {
|
||||||
usersAvailable: IDataState[];
|
usersAvailable: IDataState[];
|
||||||
roomsAvailable: IDataState[];
|
roomsAvailable: IDataState[];
|
||||||
@@ -36,16 +38,19 @@ 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(
|
||||||
@@ -61,6 +66,7 @@ const reducer = (state: IUserRoomState, action: IAction) => {
|
|||||||
usersAvailable: tempArr,
|
usersAvailable: tempArr,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'updateUserName': {
|
case 'updateUserName': {
|
||||||
const tempArr = state.usersAvailable;
|
const tempArr = state.usersAvailable;
|
||||||
|
|
||||||
@@ -77,6 +83,7 @@ const reducer = (state: IUserRoomState, action: IAction) => {
|
|||||||
usersAvailable: tempArr,
|
usersAvailable: tempArr,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'removeUser':
|
case 'removeUser':
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
@@ -84,6 +91,7 @@ const reducer = (state: IUserRoomState, action: IAction) => {
|
|||||||
(item) => item.id !== action.payload[0].id
|
(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(
|
||||||
@@ -99,6 +107,7 @@ const reducer = (state: IUserRoomState, action: IAction) => {
|
|||||||
roomsAvailable: tempArr,
|
roomsAvailable: tempArr,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'updateRoomName': {
|
case 'updateRoomName': {
|
||||||
const tempArr = state.roomsAvailable;
|
const tempArr = state.roomsAvailable;
|
||||||
|
|
||||||
@@ -115,6 +124,7 @@ const reducer = (state: IUserRoomState, action: IAction) => {
|
|||||||
roomsAvailable: tempArr,
|
roomsAvailable: tempArr,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'removeRoom':
|
case 'removeRoom':
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
@@ -122,6 +132,7 @@ const reducer = (state: IUserRoomState, action: IAction) => {
|
|||||||
(item) => item.id !== action.payload[0].id
|
(item) => item.id !== action.payload[0].id
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error('Action unknown');
|
throw new Error('Action unknown');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { createRoom as createRoomFn } from '@service/roomServices';
|
|||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
import { ADD_SUCCESS } from '@constant/messages';
|
import { ADD_SUCCESS } from '@constant/messages';
|
||||||
|
|
||||||
|
// Hooks
|
||||||
import { useUserRoomAvailable } from '@hook/useUserRoomAvailable';
|
import { useUserRoomAvailable } from '@hook/useUserRoomAvailable';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import toast from "react-hot-toast";
|
import toast from 'react-hot-toast';
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { useSearchParams } from "react-router-dom";
|
import { useSearchParams } from 'react-router-dom';
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
import { getAllRooms } from "@service/roomServices";
|
import { getAllRooms } from '@service/roomServices';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch room from database
|
* Fetch room from database
|
||||||
@@ -13,7 +13,7 @@ const useRooms = () => {
|
|||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const sortByValue = searchParams.get('sortBy') || 'id';
|
const sortByValue = searchParams.get('sortBy') || 'id';
|
||||||
const orderByValue = searchParams.get('orderBy') || 'asc';
|
const orderByValue = searchParams.get('orderBy') || 'asc';
|
||||||
const phoneSearch = searchParams.get('search') || ''
|
const phoneSearch = searchParams.get('search') || '';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isLoading,
|
isLoading,
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { updateRoom as updateRoomFn } from '@service/roomServices';
|
|||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
import { UPDATE_SUCCESS } from '@constant/messages';
|
import { UPDATE_SUCCESS } from '@constant/messages';
|
||||||
|
|
||||||
|
// Hooks
|
||||||
import { useUserRoomAvailable } from '@hook/useUserRoomAvailable';
|
import { useUserRoomAvailable } from '@hook/useUserRoomAvailable';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { UserRoomAvailableContext } from '@context/UserRoomAvailableContext';
|
|
||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
|
|
||||||
|
// Contexts
|
||||||
|
import { UserRoomAvailableContext } from '@context/UserRoomAvailableContext';
|
||||||
|
|
||||||
const useUserRoomAvailable = () => {
|
const useUserRoomAvailable = () => {
|
||||||
const context = useContext(UserRoomAvailableContext);
|
const context = useContext(UserRoomAvailableContext);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { createUser as createUserFn } from '@service/userServices';
|
|||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
import { ADD_SUCCESS } from '@constant/messages';
|
import { ADD_SUCCESS } from '@constant/messages';
|
||||||
|
|
||||||
|
// Hooks
|
||||||
import { useUserRoomAvailable } from '@hook/useUserRoomAvailable';
|
import { useUserRoomAvailable } from '@hook/useUserRoomAvailable';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { updateUser as updateUserFn } from '@service/userServices';
|
|||||||
|
|
||||||
// Messages
|
// Messages
|
||||||
import { UPDATE_SUCCESS } from '@constant/messages';
|
import { UPDATE_SUCCESS } from '@constant/messages';
|
||||||
|
|
||||||
|
// Hooks
|
||||||
import { useUserRoomAvailable } from '@hook/useUserRoomAvailable';
|
import { useUserRoomAvailable } from '@hook/useUserRoomAvailable';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import toast from "react-hot-toast";
|
import toast from 'react-hot-toast';
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { useSearchParams } from "react-router-dom";
|
import { useSearchParams } from 'react-router-dom';
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
import { getAllUsers } from "@service/userServices";
|
import { getAllUsers } from '@service/userServices';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch data of users from database
|
* Fetch data of users from database
|
||||||
@@ -13,7 +13,7 @@ const useUsers = () => {
|
|||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const sortByValue = searchParams.get('sortBy') || 'id';
|
const sortByValue = searchParams.get('sortBy') || 'id';
|
||||||
const orderByValue = searchParams.get('orderBy') || 'asc';
|
const orderByValue = searchParams.get('orderBy') || 'asc';
|
||||||
const phoneSearch = searchParams.get('search') || ''
|
const phoneSearch = searchParams.get('search') || '';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isLoading,
|
isLoading,
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { useUserRoomAvailable } from '@hook/useUserRoomAvailable';
|
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
// Hooks
|
||||||
|
import { useUserRoomAvailable } from '@hook/useUserRoomAvailable';
|
||||||
|
|
||||||
const StyledDashboard = styled.main`
|
const StyledDashboard = styled.main`
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// Types
|
// Types
|
||||||
import { IRoom } from '@type/rooms';
|
import { IRoom } from '@type/rooms';
|
||||||
|
import { IDataState } from '@type/common';
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
import supabase from './supabaseService';
|
import supabase from './supabaseService';
|
||||||
import { IDataState } from '@type/common';
|
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const ROOMS_TABLE = 'rooms';
|
const ROOMS_TABLE = 'rooms';
|
||||||
@@ -25,7 +25,7 @@ const getAllRooms = async (
|
|||||||
.from(ROOMS_TABLE)
|
.from(ROOMS_TABLE)
|
||||||
.select('*')
|
.select('*')
|
||||||
.order(sortBy, { ascending: orderBy === 'asc' })
|
.order(sortBy, { ascending: orderBy === 'asc' })
|
||||||
.like('name', `%${roomName}%`);
|
.ilike('name', `%${roomName}%`);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(error.message);
|
console.error(error.message);
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { createClient } from "@supabase/supabase-js";
|
import { createClient } from '@supabase/supabase-js';
|
||||||
import { Database } from "@type/supabase";
|
|
||||||
|
// Types
|
||||||
|
import { Database } from '@type/supabase';
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
import { supabaseKey, supabaseUrl } from "@constant/config";
|
import { supabaseKey, supabaseUrl } from '@constant/config';
|
||||||
|
|
||||||
const supabase = createClient<Database>(supabaseUrl, supabaseKey!);
|
const supabase = createClient<Database>(supabaseUrl, supabaseKey!);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// Types
|
// Types
|
||||||
import { IUser } from '@type/users';
|
import { IUser } from '@type/users';
|
||||||
|
import { IDataState } from '@type/common';
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
import supabase from './supabaseService';
|
import supabase from './supabaseService';
|
||||||
import { IDataState } from '@type/common';
|
|
||||||
|
|
||||||
const USERS_TABLE = 'users';
|
const USERS_TABLE = 'users';
|
||||||
const ERROR_FETCHING = "Users can't be loaded!";
|
const ERROR_FETCHING = "Users can't be loaded!";
|
||||||
@@ -65,7 +65,7 @@ const getAllUsers = async (
|
|||||||
.from(USERS_TABLE)
|
.from(USERS_TABLE)
|
||||||
.select('*')
|
.select('*')
|
||||||
.order(sortBy, { ascending: orderBy === 'asc' })
|
.order(sortBy, { ascending: orderBy === 'asc' })
|
||||||
.like('phone', `%${phoneSearch}%`);
|
.ilike('phone', `%${phoneSearch}%`);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(error.message);
|
console.error(error.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user