Add comments and optimized code

This commit is contained in:
2023-10-30 09:34:14 +07:00
parent 367b24f4fa
commit 04469af993
6 changed files with 22 additions and 12 deletions
+1 -1
View File
@@ -150,7 +150,7 @@ const UserForm = ({
onClose();
};
// Close form
// Close and reset form
const closeAndReset = () => {
onClose();
onResetForm();
+6 -4
View File
@@ -1,4 +1,5 @@
import { useEffect, useState } from 'react';
import toast from 'react-hot-toast';
// Components
import { HiSquare2Stack } from 'react-icons/hi2';
@@ -14,14 +15,15 @@ import { TUser } from '../../globals/types';
// Constants
import { useFetch } from '../../hooks/useFetch';
import { USER_PATH } from '../../constants/path';
import { STATUS_CODE } from '../../constants/statusCode';
import { CONFIRM_DELETE, DELETE_SUCCESS } from '../../constants/messages';
// Styled
import Spinner from '../../commons/styles/Spinner';
// Utils
import { sendRequest } from '../../helpers/sendRequest';
import { USER_PATH } from '../../constants/path';
import toast from 'react-hot-toast';
import { STATUS_CODE } from '../../constants/statusCode';
import { CONFIRM_DELETE, DELETE_SUCCESS } from '../../constants/messages';
interface IUserRow {
user: TUser;
+8 -6
View File
@@ -8,6 +8,8 @@ import UserTable from './Table';
// Styled
import { StyledUser, Title } from './styled';
import UserDialog from './Dialog';
// Types
import { TUser } from '../../globals/types';
const User = () => {
@@ -16,12 +18,12 @@ const User = () => {
const [user, setUser] = useState<TUser | null>(null);
const [isAdd, setIsAdd] = useState(false);
const openDialog = (isAdd: boolean) => {
setIsAdd(isAdd);
const openFormDialog = (isAddForm: boolean = false) => {
setIsAdd(isAddForm);
dialogRef.current?.showModal();
};
const closeDialog = () => {
const closeFormDialog = () => {
dialogRef.current?.close();
};
@@ -30,19 +32,19 @@ const User = () => {
<StyledUser>
<Direction type="horizontal">
<Title>List User</Title>
<Button onClick={() => openDialog(true)}>Add user</Button>
<Button onClick={() => openFormDialog(true)}>Add user</Button>
</Direction>
<UserTable
reload={reload}
setReload={setReload}
openFormDialog={() => openDialog(false)}
openFormDialog={() => openFormDialog()}
setUser={setUser}
/>
</StyledUser>
<UserDialog
onClose={closeDialog}
onClose={closeFormDialog}
ref={dialogRef}
setReload={setReload}
reload={reload}