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