mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-23 04:19:48 +00:00
Refactor code
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
import { forwardRef, useEffect } from 'react';
|
||||
|
||||
// Components
|
||||
import Dialog from '../../components/Dialog';
|
||||
import Dialog, { IDialogProps } from '../../components/Dialog';
|
||||
import RoomForm from './Form';
|
||||
|
||||
// Interfaces
|
||||
import { IDialogProps } from '../../globals/interfaces';
|
||||
|
||||
// Types
|
||||
import { TRoom } from '../../globals/types';
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import TextArea from '../../commons/styles/TextArea.ts';
|
||||
|
||||
// Components
|
||||
import Form from '../../components/Form/index.tsx';
|
||||
import FormRow from '../../components/FormRow/index.tsx';
|
||||
import FormRow from '../../components/LabelControl/index.tsx';
|
||||
import Button from '../../commons/styles/Button.ts';
|
||||
|
||||
// Types
|
||||
@@ -170,7 +170,7 @@ const RoomForm = ({
|
||||
const response = await sendRequest(
|
||||
ROOM_PATH,
|
||||
JSON.stringify(data),
|
||||
'POST',
|
||||
'POST'
|
||||
);
|
||||
|
||||
if (response.statusCode === STATUS_CODE.CREATE) {
|
||||
@@ -185,7 +185,7 @@ const RoomForm = ({
|
||||
const response = await sendRequest(
|
||||
ROOM_PATH + `/${room!.id}`,
|
||||
JSON.stringify(data),
|
||||
'PUT',
|
||||
'PUT'
|
||||
);
|
||||
|
||||
if (response.statusCode == STATUS_CODE.OK) {
|
||||
@@ -215,7 +215,7 @@ const RoomForm = ({
|
||||
const {
|
||||
values,
|
||||
errors,
|
||||
dirty,
|
||||
valid,
|
||||
handleOnChange,
|
||||
handleOnSubmit,
|
||||
disable } =
|
||||
@@ -257,7 +257,7 @@ const RoomForm = ({
|
||||
label="Name"
|
||||
error={
|
||||
// prettier-ignore
|
||||
errors.name && dirty.name
|
||||
errors.name && valid.name
|
||||
? (errors.name as string)
|
||||
: ''
|
||||
}
|
||||
@@ -274,7 +274,7 @@ const RoomForm = ({
|
||||
label="Amount"
|
||||
// prettier-ignore
|
||||
error={
|
||||
errors.amount && dirty.amount
|
||||
errors.amount && valid.amount
|
||||
? (errors.amount as string)
|
||||
: ''
|
||||
}
|
||||
@@ -291,7 +291,7 @@ const RoomForm = ({
|
||||
label="Price"
|
||||
error={
|
||||
// prettier-ignore
|
||||
errors.price && dirty.price
|
||||
errors.price && valid.price
|
||||
? (errors.price as string)
|
||||
: ''
|
||||
}
|
||||
@@ -308,7 +308,7 @@ const RoomForm = ({
|
||||
label="Discount"
|
||||
error={
|
||||
// prettier-ignore
|
||||
errors.discount && dirty.discount
|
||||
errors.discount && valid.discount
|
||||
? (errors.discount as string)
|
||||
: ''
|
||||
}
|
||||
@@ -334,7 +334,7 @@ const RoomForm = ({
|
||||
label="Description"
|
||||
error={
|
||||
// prettier-ignore
|
||||
errors.description && dirty.description
|
||||
errors.description && valid.description
|
||||
? (errors.description as string)
|
||||
: ''
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import toast from 'react-hot-toast';
|
||||
import { HiSquare2Stack } from 'react-icons/hi2';
|
||||
import { HiTrash } from 'react-icons/hi';
|
||||
import { StyledOperationTable } from './styled';
|
||||
import Menus from '../../components/Menus/Menus';
|
||||
import Menus from '../../components/Menus';
|
||||
import Table from '../../components/Table';
|
||||
import Direction from '../../commons/styles/Direction';
|
||||
import Message from '../../components/Message';
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { forwardRef, useEffect } from 'react';
|
||||
|
||||
// Components
|
||||
import Dialog from '../../components/Dialog';
|
||||
import Dialog, { IDialogProps } from '../../components/Dialog';
|
||||
import UserForm from './Form';
|
||||
|
||||
// Interfaces
|
||||
import { IDialogProps } from '../../globals/interfaces';
|
||||
|
||||
// Types
|
||||
import { TUser } from '../../globals/types';
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import TextArea from '../../commons/styles/TextArea';
|
||||
|
||||
// Components
|
||||
import Form from '../../components/Form';
|
||||
import FormRow from '../../components/FormRow';
|
||||
import FormRow from '../../components/LabelControl/index.tsx';
|
||||
import Button from '../../commons/styles/Button.ts';
|
||||
|
||||
// Types
|
||||
@@ -39,12 +39,9 @@ import {
|
||||
errorMsg,
|
||||
} from '../../constants/messages.ts';
|
||||
import { USER_PATH } from '../../constants/path.ts';
|
||||
import Select from '../../components/Select/index.tsx';
|
||||
import Select, { ISelectOptions } from '../../components/Select/index.tsx';
|
||||
import { useFetch } from '../../hooks/useFetch.ts';
|
||||
|
||||
// Interfaces
|
||||
import { ISelectOptions } from '../../globals/interfaces.ts';
|
||||
|
||||
const FormBtn = styled(Button)`
|
||||
width: 100%;
|
||||
|
||||
@@ -130,7 +127,7 @@ const UserForm = ({
|
||||
error: '',
|
||||
},
|
||||
roomId: {
|
||||
value: roomIdValue || '',
|
||||
value: roomIdValue || '' + (options && options[0].value),
|
||||
error: '' ,
|
||||
},
|
||||
address: {
|
||||
@@ -181,7 +178,7 @@ const UserForm = ({
|
||||
const response = await sendRequest(
|
||||
USER_PATH,
|
||||
JSON.stringify(data),
|
||||
'POST',
|
||||
'POST'
|
||||
);
|
||||
|
||||
if (response.statusCode === STATUS_CODE.CREATE) {
|
||||
@@ -196,7 +193,7 @@ const UserForm = ({
|
||||
const response = await sendRequest(
|
||||
USER_PATH + `/${user!.id}`,
|
||||
JSON.stringify(data),
|
||||
'PUT',
|
||||
'PUT'
|
||||
);
|
||||
|
||||
if (response.statusCode == STATUS_CODE.OK) {
|
||||
@@ -226,7 +223,7 @@ const UserForm = ({
|
||||
const {
|
||||
values,
|
||||
errors,
|
||||
dirty,
|
||||
valid,
|
||||
handleOnChange,
|
||||
handleOnSubmit,
|
||||
disable } =
|
||||
@@ -266,7 +263,7 @@ const UserForm = ({
|
||||
label="Full Name"
|
||||
error={
|
||||
// prettier-ignore
|
||||
errors.name && dirty.name
|
||||
errors.name && valid.name
|
||||
? (errors.name as string)
|
||||
: ''
|
||||
}
|
||||
@@ -282,7 +279,7 @@ const UserForm = ({
|
||||
<FormRow
|
||||
label="Identified Code"
|
||||
error={
|
||||
errors.identifiedCode && dirty.identifiedCode
|
||||
errors.identifiedCode && valid.identifiedCode
|
||||
? (errors.identifiedCode as string)
|
||||
: ''
|
||||
}
|
||||
@@ -299,7 +296,7 @@ const UserForm = ({
|
||||
label="Phone"
|
||||
error={
|
||||
// prettier-ignore
|
||||
errors.phone && dirty.phone
|
||||
errors.phone && valid.phone
|
||||
? (errors.phone as string)
|
||||
: ''
|
||||
}
|
||||
@@ -316,17 +313,11 @@ const UserForm = ({
|
||||
label="Room"
|
||||
error={
|
||||
// prettier-ignore
|
||||
errors.roomId && dirty.roomId
|
||||
errors.roomId && valid.roomId
|
||||
? (errors.roomId as string)
|
||||
: ''
|
||||
}
|
||||
>
|
||||
{/* <Input
|
||||
type="text"
|
||||
name="roomId"
|
||||
value={roomId as string}
|
||||
onChange={handleOnChange}
|
||||
/> */}
|
||||
<Select
|
||||
name="roomId"
|
||||
value={roomId as string}
|
||||
@@ -339,7 +330,7 @@ const UserForm = ({
|
||||
label="Address"
|
||||
error={
|
||||
// prettier-ignore
|
||||
errors.address && dirty.address
|
||||
errors.address && valid.address
|
||||
? (errors.address as string)
|
||||
: ''
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import toast from 'react-hot-toast';
|
||||
import { HiSquare2Stack } from 'react-icons/hi2';
|
||||
import { HiTrash } from 'react-icons/hi';
|
||||
import { StyledOperationTable } from './styled';
|
||||
import Menus from '../../components/Menus/Menus';
|
||||
import Menus from '../../components/Menus';
|
||||
import Table from '../../components/Table';
|
||||
import Direction from '../../commons/styles/Direction';
|
||||
import Message from '../../components/Message';
|
||||
|
||||
Reference in New Issue
Block a user