From 644d62ffff454841786589ffec643f4b66a117e4 Mon Sep 17 00:00:00 2001 From: Loi Phan Date: Mon, 20 Nov 2023 09:21:21 +0700 Subject: [PATCH] Update components and constants folder --- hotel-management/src/commons/styles/Button.ts | 40 ++++++++++++------- .../src/components/ConfirmMessage/index.tsx | 39 ++++++++++++++++++ .../src/components/ConfirmMessage/styled.ts | 20 ++++++++++ .../src/components/Search/index.tsx | 19 ++++++--- .../src/components/Toast/index.tsx | 2 +- hotel-management/src/constants/commons.ts | 27 +------------ hotel-management/src/constants/config.ts | 5 ++- hotel-management/src/constants/messages.ts | 6 +-- hotel-management/src/constants/path.ts | 3 -- .../src/constants/responseStatus.ts | 11 ----- 10 files changed, 105 insertions(+), 67 deletions(-) create mode 100644 hotel-management/src/components/ConfirmMessage/index.tsx create mode 100644 hotel-management/src/components/ConfirmMessage/styled.ts delete mode 100644 hotel-management/src/constants/responseStatus.ts diff --git a/hotel-management/src/commons/styles/Button.ts b/hotel-management/src/commons/styles/Button.ts index 30d6165..2324d3a 100644 --- a/hotel-management/src/commons/styles/Button.ts +++ b/hotel-management/src/commons/styles/Button.ts @@ -1,9 +1,25 @@ -import styled, { css } from 'styled-components'; +import styled, { RuleSet, css } from 'styled-components'; -type TButtonStyle = 'primary' | 'secondary'; +interface IVariations { + [key: string]: RuleSet; +} + +const variations: IVariations = { + primary: css` + background-color: var(--primary-color); + color: var(--light-text); + `, + secondary: css` + background-color: var(--secondary-btn-color); + `, + danger: css` + background-color: var(--danger-btn-color); + color: var(--light-text); + `, +} as const; interface IButtonStyle { - styled?: TButtonStyle; + variations?: keyof typeof variations; } const Button = styled.button` @@ -16,22 +32,16 @@ const Button = styled.button` border-radius: var(--radius-md); - ${(props) => - props.styled === 'primary' && - css` - background-color: var(--primary-color); - color: var(--light-text); - `} + ${(props) => variations[props.variations!]} - ${(props) => - props.styled === 'secondary' && - css` - background-color: var(--secondary-btn-color); - `} + &:disabled, + &[disabled] { + cursor: no-drop; + } `; Button.defaultProps = { - styled: 'primary', + variations: 'primary', }; export default Button; diff --git a/hotel-management/src/components/ConfirmMessage/index.tsx b/hotel-management/src/components/ConfirmMessage/index.tsx new file mode 100644 index 0000000..ce9b911 --- /dev/null +++ b/hotel-management/src/components/ConfirmMessage/index.tsx @@ -0,0 +1,39 @@ +import { memo } from 'react'; + +// Styled +import { StyledConfirmDelete } from './styled'; + +// Component +import Button from '@commonStyle/Button'; + +interface IConfirmMessage { + message: string; + disabled: boolean; + onConfirm: () => void; + onCloseModal?: () => void; +} + +const ConfirmMessage = memo( + ({ message, disabled, onConfirm, onCloseModal }: IConfirmMessage) => { + return ( + +

{message}

+ +
+ + +
+
+ ); + } +); + +export default ConfirmMessage; diff --git a/hotel-management/src/components/ConfirmMessage/styled.ts b/hotel-management/src/components/ConfirmMessage/styled.ts new file mode 100644 index 0000000..47590e1 --- /dev/null +++ b/hotel-management/src/components/ConfirmMessage/styled.ts @@ -0,0 +1,20 @@ +import styled from 'styled-components'; + +const StyledConfirmDelete = styled.div` + width: 450px; + + & p { + font-size: var(--fs-sm); + text-align: center; + margin-bottom: 30px; + } + + & div { + display: flex; + justify-content: space-around; + + padding-inline: 50px; + } +`; + +export { StyledConfirmDelete }; diff --git a/hotel-management/src/components/Search/index.tsx b/hotel-management/src/components/Search/index.tsx index b60db2c..887ce30 100644 --- a/hotel-management/src/components/Search/index.tsx +++ b/hotel-management/src/components/Search/index.tsx @@ -5,19 +5,26 @@ import { StyledSearch } from './styled'; // Hooks import { useDebounce } from '@hook/useDebounce'; +import { useSearchParams } from 'react-router-dom'; +import { Nullable } from '@type/common'; interface ISearch { setPlaceHolder: string; - setValueSearch: (phone: string) => void; } -const Search = ({ setValueSearch, setPlaceHolder }: ISearch) => { - const [query, setQuery] = useState(''); - const debounceValue = useDebounce(query, 700); +const Search = ({ setPlaceHolder }: ISearch) => { + const field = 'search'; + const [searchParams, setSearchParams] = useSearchParams(); + const [query, setQuery] = useState>(null); + const debounceValue = useDebounce>(query, 700); useEffect(() => { - setValueSearch(debounceValue); - }, [debounceValue, setValueSearch]); + if (debounceValue !== null) { + searchParams.set(field, debounceValue); + + setSearchParams(searchParams); + } + }, [debounceValue, searchParams, setSearchParams]); return (