feat: apply new order view api
This commit is contained in:
parent
0307f36e57
commit
431a8b27f2
@ -42,8 +42,7 @@
|
||||
"dry-wash.order-create.create-order-query.success.title": "The order is successfully created",
|
||||
"dry-wash.order-create.create-order-query.error.title": "Failed to create an order",
|
||||
"dry-wash.order-view.title": "Your order",
|
||||
"dry-wash.order-view.error.title": "Error",
|
||||
"dry-wash.order-view.fetch.error": "Failed to fetch the details of order #{{number}}",
|
||||
"dry-wash.order-view.get-order-query.error.title": "Failed to fetch the details of order #{{number}}",
|
||||
"dry-wash.order-view.details.title": "Order #{{number}}",
|
||||
"dry-wash.order-view.details.owner": "Owner",
|
||||
"dry-wash.order-view.details.car": "Car",
|
||||
|
@ -81,8 +81,7 @@
|
||||
"dry-wash.order-create.create-order-query.success.title": "Заказ успешно создан",
|
||||
"dry-wash.order-create.create-order-query.error.title": "Не удалось создать заказ",
|
||||
"dry-wash.order-view.title": "Ваш заказ",
|
||||
"dry-wash.order-view.error.title": "Ошибка",
|
||||
"dry-wash.order-view.fetch.error": "Не удалось загрузить детали заказа №{{number}}",
|
||||
"dry-wash.order-view.get-order-query.error.title": "Не удалось загрузить детали заказа №{{number}}",
|
||||
"dry-wash.order-view.details.title": "Заказ №{{number}}",
|
||||
"dry-wash.order-view.details.owner": "Владелец",
|
||||
"dry-wash.order-view.details.car": "Автомобиль",
|
||||
|
@ -17,7 +17,19 @@ import { carBodySelectOptions } from '../../order-form/form/car-body/helper';
|
||||
|
||||
import { OrderStatus } from './status';
|
||||
|
||||
type OrderDetailsProps = Order.View;
|
||||
type OrderDetailsProps = Pick<
|
||||
Order.View,
|
||||
| 'id'
|
||||
| 'status'
|
||||
| 'phone'
|
||||
| 'carNumber'
|
||||
| 'carBody'
|
||||
| 'carColor'
|
||||
| 'location'
|
||||
| 'startWashTime'
|
||||
| 'endWashTime'
|
||||
| 'created'
|
||||
>;
|
||||
|
||||
export const OrderDetails: FC<OrderDetailsProps> = ({
|
||||
id,
|
||||
@ -27,8 +39,8 @@ export const OrderDetails: FC<OrderDetailsProps> = ({
|
||||
carBody,
|
||||
carColor,
|
||||
location,
|
||||
datetimeBegin,
|
||||
datetimeEnd,
|
||||
startWashTime,
|
||||
endWashTime,
|
||||
}) => {
|
||||
const { t } = useTranslation('~', {
|
||||
keyPrefix: 'dry-wash.order-view.details',
|
||||
@ -75,8 +87,8 @@ export const OrderDetails: FC<OrderDetailsProps> = ({
|
||||
{
|
||||
label: t('datetime-range'),
|
||||
value: [
|
||||
formatDatetime(datetimeBegin),
|
||||
formatDatetime(datetimeEnd),
|
||||
formatDatetime(startWashTime),
|
||||
formatDatetime(endWashTime),
|
||||
].join(' - '),
|
||||
},
|
||||
].map(({ label, value }, i) => (
|
||||
|
@ -1,40 +0,0 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import { LandingService } from '../../api/landing';
|
||||
import { Order } from '../../models/landing';
|
||||
import { FetchOrderQueryResponse } from '../../models/api';
|
||||
|
||||
export const useFetchOrderDetails = ({
|
||||
orderId,
|
||||
}: {
|
||||
orderId: Order.View['id'];
|
||||
}) => {
|
||||
const { fetchOrder } = LandingService();
|
||||
|
||||
const [data, setData] = useState<FetchOrderQueryResponse>();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
setIsLoading(true);
|
||||
|
||||
try {
|
||||
const data = await fetchOrder(orderId);
|
||||
setData(data.body);
|
||||
} catch (error) {
|
||||
setError(error.message);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchData();
|
||||
}, []);
|
||||
|
||||
return {
|
||||
isLoading,
|
||||
data,
|
||||
error,
|
||||
};
|
||||
};
|
@ -1,36 +1,32 @@
|
||||
import React, { FC, useEffect } from 'react';
|
||||
import { HStack, Spinner, useToast } from '@chakra-ui/react';
|
||||
import React, { FC } from 'react';
|
||||
import { Alert, AlertDescription, AlertIcon, AlertTitle, HStack, Spinner } from '@chakra-ui/react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Container, Heading, VStack } from '@chakra-ui/react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
|
||||
import { LandingThemeProvider } from '../../containers';
|
||||
import {
|
||||
LandingThemeProvider,
|
||||
withLandingThemeProvider,
|
||||
} from '../../containers';
|
||||
import { OrderDetails } from '../../components/order-view';
|
||||
|
||||
import { useFetchOrderDetails } from './helper';
|
||||
import { Order } from '../../models/landing';
|
||||
import { useGetOrderQuery } from '../../api';
|
||||
|
||||
const Page: FC = () => {
|
||||
const { t } = useTranslation('~', {
|
||||
keyPrefix: 'dry-wash.order-view',
|
||||
});
|
||||
|
||||
const { orderId } = useParams();
|
||||
|
||||
const { isLoading, data, error } = useFetchOrderDetails({ orderId });
|
||||
|
||||
const toast = useToast();
|
||||
useEffect(() => {
|
||||
if (error) {
|
||||
toast({
|
||||
title: t('error.title'),
|
||||
description: t('fetch.error'),
|
||||
status: 'error',
|
||||
duration: 5000,
|
||||
isClosable: true,
|
||||
position: 'bottom-right',
|
||||
});
|
||||
}
|
||||
}, [error]);
|
||||
const { orderId } = useParams<Order.Id>();
|
||||
const {
|
||||
isLoading,
|
||||
isSuccess,
|
||||
data: { body: order } = {},
|
||||
isError,
|
||||
error,
|
||||
} = useGetOrderQuery({
|
||||
orderId,
|
||||
});
|
||||
|
||||
return (
|
||||
<LandingThemeProvider>
|
||||
@ -51,20 +47,37 @@ const Page: FC = () => {
|
||||
<Spinner size='lg' />
|
||||
</HStack>
|
||||
) : (
|
||||
data && (
|
||||
<OrderDetails
|
||||
id={data.id}
|
||||
orderDate={data.orderDate}
|
||||
status={data.status}
|
||||
phone={data.phone}
|
||||
carNumber={data.carNumber}
|
||||
carBody={data.carBody}
|
||||
carColor={data.carColor}
|
||||
location={data.location}
|
||||
datetimeBegin={data.startWashTime}
|
||||
datetimeEnd={data.endWashTime}
|
||||
/>
|
||||
)
|
||||
<>
|
||||
<>
|
||||
{isSuccess && (
|
||||
<OrderDetails
|
||||
id={order.id}
|
||||
status={order.status}
|
||||
phone={order.phone}
|
||||
carNumber={order.carNumber}
|
||||
carBody={order.carBody}
|
||||
carColor={order.carColor}
|
||||
location={order.location}
|
||||
startWashTime={order.startWashTime}
|
||||
endWashTime={order.endWashTime}
|
||||
created={order.created}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
<>
|
||||
{isError && (
|
||||
<Alert status='error'>
|
||||
<AlertIcon />
|
||||
<AlertTitle>
|
||||
{t('get-order-query.error.title', {
|
||||
number: orderId,
|
||||
})}
|
||||
</AlertTitle>
|
||||
<AlertDescription>{error.data?.error}</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
</>
|
||||
</>
|
||||
)}
|
||||
</VStack>
|
||||
</Container>
|
||||
@ -72,4 +85,4 @@ const Page: FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default Page;
|
||||
export default withLandingThemeProvider(Page);
|
||||
|
Loading…
Reference in New Issue
Block a user