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