feat: create order stubs (#65)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user