mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 20:01:59 +00:00
Update status message and remove amount property
This commit is contained in:
@@ -55,10 +55,6 @@ const ROOM_PAGE = {
|
|||||||
value: 'name',
|
value: 'name',
|
||||||
label: 'Sort by name',
|
label: 'Sort by name',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
value: 'amount',
|
|
||||||
label: 'Sort by amount',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
value: 'price',
|
value: 'price',
|
||||||
label: 'Sort by price',
|
label: 'Sort by price',
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ type TUser = {
|
|||||||
type TRoom = {
|
type TRoom = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
amount: number;
|
|
||||||
price: number;
|
price: number;
|
||||||
discount: number;
|
discount: number;
|
||||||
description: string;
|
description: string;
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ const RoomForm = ({
|
|||||||
const {
|
const {
|
||||||
idValue,
|
idValue,
|
||||||
nameValue,
|
nameValue,
|
||||||
amountValue,
|
|
||||||
priceValue,
|
priceValue,
|
||||||
discountValue,
|
discountValue,
|
||||||
statusValue,
|
statusValue,
|
||||||
@@ -100,10 +99,6 @@ const RoomForm = ({
|
|||||||
value: nameValue || '',
|
value: nameValue || '',
|
||||||
error: ''
|
error: ''
|
||||||
},
|
},
|
||||||
amount: {
|
|
||||||
value: amountValue || '',
|
|
||||||
error: ''
|
|
||||||
},
|
|
||||||
price: {
|
price: {
|
||||||
value: priceValue || '',
|
value: priceValue || '',
|
||||||
error: ''
|
error: ''
|
||||||
@@ -128,10 +123,6 @@ const RoomForm = ({
|
|||||||
validatorFunc: isValidString,
|
validatorFunc: isValidString,
|
||||||
prop: 'name'
|
prop: 'name'
|
||||||
}),
|
}),
|
||||||
amount: addValidator({
|
|
||||||
validatorFunc: isValidNumber,
|
|
||||||
prop: 'amount',
|
|
||||||
}),
|
|
||||||
price: addValidator({
|
price: addValidator({
|
||||||
validatorFunc: isValidNumber,
|
validatorFunc: isValidNumber,
|
||||||
prop: 'price',
|
prop: 'price',
|
||||||
@@ -157,7 +148,6 @@ const RoomForm = ({
|
|||||||
const data: TRoom = {
|
const data: TRoom = {
|
||||||
id: +state.id!,
|
id: +state.id!,
|
||||||
name: '' + state.name,
|
name: '' + state.name,
|
||||||
amount: +state.amount!,
|
|
||||||
discount: +state.discount!,
|
discount: +state.discount!,
|
||||||
price: +state.price!,
|
price: +state.price!,
|
||||||
status: !!state.status,
|
status: !!state.status,
|
||||||
@@ -170,7 +160,7 @@ const RoomForm = ({
|
|||||||
const response = await sendRequest(
|
const response = await sendRequest(
|
||||||
ROOM_PATH,
|
ROOM_PATH,
|
||||||
JSON.stringify(data),
|
JSON.stringify(data),
|
||||||
'POST'
|
'POST',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode === STATUS_CODE.CREATE) {
|
if (response.statusCode === STATUS_CODE.CREATE) {
|
||||||
@@ -185,7 +175,7 @@ const RoomForm = ({
|
|||||||
const response = await sendRequest(
|
const response = await sendRequest(
|
||||||
ROOM_PATH + `/${room!.id}`,
|
ROOM_PATH + `/${room!.id}`,
|
||||||
JSON.stringify(data),
|
JSON.stringify(data),
|
||||||
'PUT'
|
'PUT',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode == STATUS_CODE.OK) {
|
if (response.statusCode == STATUS_CODE.OK) {
|
||||||
@@ -229,8 +219,7 @@ const RoomForm = ({
|
|||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
const {
|
const {
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
amount,
|
|
||||||
price,
|
price,
|
||||||
discount,
|
discount,
|
||||||
status,
|
status,
|
||||||
@@ -269,24 +258,6 @@ const RoomForm = ({
|
|||||||
onChange={handleOnChange}
|
onChange={handleOnChange}
|
||||||
/>
|
/>
|
||||||
</FormRow>
|
</FormRow>
|
||||||
|
|
||||||
<FormRow
|
|
||||||
label="Amount"
|
|
||||||
// prettier-ignore
|
|
||||||
error={
|
|
||||||
errors.amount && valid.amount
|
|
||||||
? (errors.amount as string)
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Input
|
|
||||||
type="text"
|
|
||||||
name="amount"
|
|
||||||
value={amount as string}
|
|
||||||
onChange={handleOnChange}
|
|
||||||
/>
|
|
||||||
</FormRow>
|
|
||||||
|
|
||||||
<FormRow
|
<FormRow
|
||||||
label="Price"
|
label="Price"
|
||||||
error={
|
error={
|
||||||
|
|||||||
@@ -67,18 +67,17 @@ const RoomRow = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const { id, name, amount, price, discount, status } = room;
|
const { id, name, price, discount, status } = room;
|
||||||
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
const statusText = status
|
const statusText = status
|
||||||
? 'Invalid'
|
? 'Unavailable'
|
||||||
: 'Valid';
|
: 'Available';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table.Row>
|
<Table.Row>
|
||||||
<div>{id}</div>
|
<div>{id}</div>
|
||||||
<div>{name}</div>
|
<div>{name}</div>
|
||||||
<div>{amount}</div>
|
|
||||||
<div>{price}</div>
|
<div>{price}</div>
|
||||||
<div>{discount}</div>
|
<div>{discount}</div>
|
||||||
<div>{statusText}</div>
|
<div>{statusText}</div>
|
||||||
@@ -163,11 +162,10 @@ const RoomTable = ({
|
|||||||
|
|
||||||
{rooms.length ? (
|
{rooms.length ? (
|
||||||
<Menus>
|
<Menus>
|
||||||
<Table columns="10% 20% 20% 20% 10% 10% 5%">
|
<Table columns="10% 30% 20% 10% 20% 5%">
|
||||||
<Table.Header>
|
<Table.Header>
|
||||||
<div>Id</div>
|
<div>Id</div>
|
||||||
<div>Name</div>
|
<div>Name</div>
|
||||||
<div>Amount</div>
|
|
||||||
<div>Price</div>
|
<div>Price</div>
|
||||||
<div>Discount</div>
|
<div>Discount</div>
|
||||||
<div>Status</div>
|
<div>Status</div>
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ import {
|
|||||||
errorMsg,
|
errorMsg,
|
||||||
} from '../../constants/messages.ts';
|
} from '../../constants/messages.ts';
|
||||||
import { USER_PATH } from '../../constants/path.ts';
|
import { USER_PATH } from '../../constants/path.ts';
|
||||||
import Select, { ISelectOptions } from '../../components/Select/index.tsx';
|
import Select, { ISelectOptions } from '../../components/Select';
|
||||||
import { useFetch } from '../../hooks/useFetch.ts';
|
import { useFetch } from '../../hooks/useFetch.ts';
|
||||||
|
|
||||||
const FormBtn = styled(Button)`
|
const FormBtn = styled(Button)`
|
||||||
@@ -163,7 +163,7 @@ const UserForm = ({
|
|||||||
// Submit form
|
// Submit form
|
||||||
const onSubmitForm = async (state: TKeyValue) => {
|
const onSubmitForm = async (state: TKeyValue) => {
|
||||||
// Convert to user type
|
// Convert to user type
|
||||||
const data: TUser = {
|
const user: TUser = {
|
||||||
id: +state.id!,
|
id: +state.id!,
|
||||||
name: '' + state.name,
|
name: '' + state.name,
|
||||||
identifiedCode: '' + state.identifiedCode,
|
identifiedCode: '' + state.identifiedCode,
|
||||||
@@ -177,8 +177,8 @@ const UserForm = ({
|
|||||||
// Add request
|
// Add request
|
||||||
const response = await sendRequest(
|
const response = await sendRequest(
|
||||||
USER_PATH,
|
USER_PATH,
|
||||||
JSON.stringify(data),
|
JSON.stringify(user),
|
||||||
'POST'
|
'POST',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode === STATUS_CODE.CREATE) {
|
if (response.statusCode === STATUS_CODE.CREATE) {
|
||||||
@@ -187,13 +187,15 @@ const UserForm = ({
|
|||||||
throw new Error(errorMsg(response.statusCode, response.msg));
|
throw new Error(errorMsg(response.statusCode, response.msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Update status when user create
|
||||||
|
|
||||||
onResetForm();
|
onResetForm();
|
||||||
} else {
|
} else {
|
||||||
// Edit request
|
// Edit request
|
||||||
const response = await sendRequest(
|
const response = await sendRequest(
|
||||||
USER_PATH + `/${user!.id}`,
|
USER_PATH + `/${user!.id}`,
|
||||||
JSON.stringify(data),
|
JSON.stringify(data),
|
||||||
'PUT'
|
'PUT',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode == STATUS_CODE.OK) {
|
if (response.statusCode == STATUS_CODE.OK) {
|
||||||
|
|||||||
Reference in New Issue
Block a user