mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 13:38:51 +00:00
Hot fixed and format code
This commit is contained in:
@@ -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,7 +5,7 @@ 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) => {
|
||||||
|
|||||||
@@ -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 (
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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,14 +32,14 @@ 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: {
|
||||||
@@ -40,7 +52,7 @@ Toast.defaultProps = {
|
|||||||
fontSize: '16px',
|
fontSize: '16px',
|
||||||
maxWidth: '500px',
|
maxWidth: '500px',
|
||||||
padding: '16px 24px',
|
padding: '16px 24px',
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
export default Toast;
|
export default Toast;
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user