Hot fixed and format code

This commit is contained in:
2023-11-03 10:18:57 +07:00
parent 48af6272b3
commit ae7c25e6f3
11 changed files with 46 additions and 38 deletions
@@ -10,8 +10,8 @@ import { Main, StyledAppLayout } from './styled';
const AppLayout = () => { const AppLayout = () => {
return ( return (
<StyledAppLayout> <StyledAppLayout>
<Header accountName='Admin'/> <Header accountName="Admin" />
<Sidebar heading='Hotel Management'/> <Sidebar heading="Hotel Management" />
<Main> <Main>
<Outlet /> <Outlet />
</Main> </Main>
@@ -5,10 +5,10 @@ import HeaderMenu from '../HeaderMenu';
import { StyledHeader } from './styled'; import { StyledHeader } from './styled';
interface IHeader { interface IHeader {
accountName: string accountName: string;
} }
const Header = ({accountName}: IHeader) => { const Header = ({ accountName }: IHeader) => {
return ( return (
<StyledHeader> <StyledHeader>
<p>Hi, {accountName}!</p> <p>Hi, {accountName}!</p>
@@ -33,9 +33,7 @@ const Toggle = ({ id }: { id: string }): React.JSX.Element => {
const handleClick = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => { const handleClick = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.stopPropagation(); e.stopPropagation();
openId === '' || openId !== id openId === '' || openId !== id ? open!(id) : close!();
? open!(id)
: close!();
}; };
return ( return (
@@ -8,7 +8,7 @@ interface ISidebar {
heading: string; heading: string;
} }
const Sidebar = ({heading}: ISidebar) => { const Sidebar = ({ heading }: ISidebar) => {
return ( return (
<StyledSidebar> <StyledSidebar>
<Heading>{heading}</Heading> <Heading>{heading}</Heading>
@@ -6,7 +6,7 @@ import { StyledBody, StyledHeader, StyledRow, StyledTable } from './styled';
// Contexts // Contexts
import TableContext from '../../contexts/TableContext'; import TableContext from '../../contexts/TableContext';
interface ITable { export interface ITable {
columns?: string; columns?: string;
children: React.ReactNode; children: React.ReactNode;
} }
@@ -1,7 +1,5 @@
import styled from 'styled-components'; import styled from 'styled-components';
import { ITable } from '.';
// Interfaces
import { ITable } from '../../globals/interfaces';
const StyledTable = styled.div` const StyledTable = styled.div`
border: 1px solid var(--border-color); border: 1px solid var(--border-color);
+26 -14
View File
@@ -1,17 +1,29 @@
import { DefaultToastOptions, ToastOptions, ToastPosition, Toaster } from 'react-hot-toast'; import {
DefaultToastOptions,
ToastOptions,
ToastPosition,
Toaster,
} from 'react-hot-toast';
import { CSSProperties } from 'styled-components'; import { CSSProperties } from 'styled-components';
interface IToast { interface IToast {
position: ToastPosition; position?: ToastPosition;
gutter: number; gutter?: number;
containerStyle: CSSProperties; containerStyle?: CSSProperties;
toastOptions: DefaultToastOptions; toastOptions?: DefaultToastOptions;
success: ToastOptions; success?: ToastOptions;
error: ToastOptions; error?: ToastOptions;
style: CSSProperties | undefined; style?: CSSProperties | undefined;
} }
const Toast = ({position, gutter, containerStyle, success, error, style}: IToast) => { const Toast = ({
position,
gutter,
containerStyle,
success,
error,
style,
}: IToast) => {
return ( return (
<Toaster <Toaster
position={position} position={position}
@@ -20,27 +32,27 @@ const Toast = ({position, gutter, containerStyle, success, error, style}: IToast
toastOptions={{ toastOptions={{
success, success,
error, error,
style style,
}} }}
/> />
); );
}; };
Toast.defaultProps = { Toast.defaultProps = {
position: "top-center", position: 'top-center',
gutter: 12, gutter: 12,
containerStyle: { margin: '8px', zIndex: 1 }, containerStyle: { margin: '8px', zIndex: 1 },
success: { success: {
duration: 3000, duration: 3000,
}, },
error:{ error: {
duration: 5000, duration: 5000,
}, },
style: { style: {
fontSize: '16px', fontSize: '16px',
maxWidth: '500px', maxWidth: '500px',
padding: '16px 24px', padding: '16px 24px',
} },
} };
export default Toast; export default Toast;
+1 -1
View File
@@ -124,7 +124,7 @@ const searchQuery = (
columnSearch: string, columnSearch: string,
keySearch: string, keySearch: string,
sort: string, sort: string,
order: string order: string,
) => { ) => {
// prettier-ignore // prettier-ignore
const phoneParams = keySearch const phoneParams = keySearch
+2 -2
View File
@@ -23,7 +23,7 @@ const useFetch = (
keyWord: string = '', keyWord: string = '',
tempSortBy?: string, tempSortBy?: string,
tempOrderBy?: string, tempOrderBy?: string,
reload?: boolean reload?: boolean,
) => { ) => {
const [data, setData] = useState(null); const [data, setData] = useState(null);
const [isPending, setIsPending] = useState(false); const [isPending, setIsPending] = useState(false);
@@ -56,7 +56,7 @@ const useFetch = (
if (!response.ok) if (!response.ok)
throw new Error( throw new Error(
`Error code: ${response.status} \n Messages: ${response.statusText}` `Error code: ${response.status} \n Messages: ${response.statusText}`,
); );
setIsPending(false); setIsPending(false);
+8 -8
View File
@@ -21,7 +21,7 @@ const useForm = (
stateSchema = {}, stateSchema = {},
stateValidatorSchema = {} as TValidator, stateValidatorSchema = {} as TValidator,
submitFormCallback: (values: TKeyValue) => void, submitFormCallback: (values: TKeyValue) => void,
initialValue: string = '' initialValue: string = '',
) => { ) => {
const [values, setValues] = useState<TKeyValue>(INITIAL_STATE_SCHEMA); const [values, setValues] = useState<TKeyValue>(INITIAL_STATE_SCHEMA);
const [errors, setErrors] = useState(getPropValues(stateSchema, ERROR)); const [errors, setErrors] = useState(getPropValues(stateSchema, ERROR));
@@ -73,7 +73,7 @@ const useForm = (
return error; return error;
}, },
[stateValidatorSchema] [stateValidatorSchema],
); );
// Set Initial Error State // Set Initial Error State
@@ -86,10 +86,10 @@ const useForm = (
[name]: !initialValue // Skip error when initialValue have values [name]: !initialValue // Skip error when initialValue have values
? validateFormFields(name, values[name] as string) ? validateFormFields(name, values[name] as string)
: '', : '',
})) })),
); );
}, },
[errors, values, validateFormFields] [errors, values, validateFormFields],
); );
// Used to disable submit button if there's a value in errors // Used to disable submit button if there's a value in errors
@@ -98,7 +98,7 @@ const useForm = (
// in every re-render in component // in every re-render in component
const validateErrorState = useCallback( const validateErrorState = useCallback(
() => Object.values(errors).some((error) => error), () => Object.values(errors).some((error) => error),
[errors] [errors],
); );
// For every changed in our state this will be fired // For every changed in our state this will be fired
@@ -114,7 +114,7 @@ const useForm = (
( (
event: ChangeEvent< event: ChangeEvent<
HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement
> >,
) => { ) => {
setIsDirty(true); setIsDirty(true);
@@ -136,7 +136,7 @@ const useForm = (
setErrors((prevState) => ({ ...prevState, [name]: error })); setErrors((prevState) => ({ ...prevState, [name]: error }));
isValid((prevState) => ({ ...prevState, [name]: true })); isValid((prevState) => ({ ...prevState, [name]: true }));
}, },
[validateFormFields] [validateFormFields],
); );
const handleOnSubmit = useCallback( const handleOnSubmit = useCallback(
@@ -152,7 +152,7 @@ const useForm = (
setDisable(true); setDisable(true);
} }
}, },
[validateErrorState, submitFormCallback, values] [validateErrorState, submitFormCallback, values],
); );
return { return {
+1 -1
View File
@@ -1,7 +1,7 @@
import { forwardRef, useEffect } from 'react'; import { forwardRef, useEffect } from 'react';
// Components // Components
import Dialog, { IDialogProps } from '../../components/Dialog'; import Dialog, { IDialogProps } from '../../components/Dialog';
import RoomForm from './Form'; import RoomForm from './Form';
// Types // Types