@@ -14,14 +14,8 @@ import MenuItem from "@mui/material/MenuItem";
14
14
import { Field , Form , Formik , FormikProps } from "formik" ;
15
15
import Grid from "@mui/material/Grid" ;
16
16
import TextField from "~/components/Form/TextField" ;
17
- import Table from "@mui/material/Table" ;
18
- import TableHead from "@mui/material/TableHead" ;
19
- import TableRow from "@mui/material/TableRow" ;
20
- import TableCell from "@mui/material/TableCell" ;
21
- import TableBody from "@mui/material/TableBody" ;
22
- import TableContainer from "@mui/material/TableContainer" ;
23
17
import Box from "@mui/material/Box" ;
24
- import { useQueries } from "react-query" ;
18
+ import { useQuery } from "react-query" ;
25
19
import { useInvalidateOrder , useUpdateOrderStatus } from "~/queries/orders" ;
26
20
27
21
type FormValues = {
@@ -31,63 +25,37 @@ type FormValues = {
31
25
32
26
export default function PageOrder ( ) {
33
27
const { id } = useParams < { id : string } > ( ) ;
34
- const results = useQueries ( [
35
- {
36
- queryKey : [ "order" , { id } ] ,
37
- queryFn : async ( ) => {
38
- const res = await axios . get < Order > ( `${ API_PATHS . order } /order/${ id } ` ) ;
39
- return res . data ;
40
- } ,
28
+ const {
29
+ data : order ,
30
+ isLoading,
31
+ } = useQuery ( {
32
+ queryKey : [ "order" , { id } ] ,
33
+ queryFn : async ( ) => {
34
+ const res = await axios . get < Order > ( `${ API_PATHS . order } /order/${ id } ` ) ;
35
+ return res . data ;
41
36
} ,
42
- {
43
- queryKey : "products" ,
44
- queryFn : async ( ) => {
45
- const res = await axios . get < AvailableProduct [ ] > (
46
- `${ API_PATHS . bff } /product/available`
47
- ) ;
48
- return res . data ;
49
- } ,
50
- } ,
51
- ] ) ;
52
- const [
53
- { data : order , isLoading : isOrderLoading } ,
54
- { data : products , isLoading : isProductsLoading } ,
55
- ] = results ;
37
+ } ) ;
56
38
const { mutateAsync : updateOrderStatus } = useUpdateOrderStatus ( ) ;
57
39
const invalidateOrder = useInvalidateOrder ( ) ;
58
- const cartItems : CartItem [ ] = React . useMemo ( ( ) => {
59
- if ( order && products ) {
60
- return order . items . map ( ( item : OrderItem ) => {
61
- const product = products . find ( ( p ) => p . id === item . productId ) ;
62
- if ( ! product ) {
63
- throw new Error ( "Product not found" ) ;
64
- }
65
- return { product, count : item . count } ;
66
- } ) ;
67
- }
68
- return [ ] ;
69
- } , [ order , products ] ) ;
70
-
71
- if ( isOrderLoading || isProductsLoading ) return < p > loading...</ p > ;
72
40
73
- const statusHistory = order ?. statusHistory || [ ] ;
41
+ if ( isLoading ) return < p > loading... </ p > ;
74
42
75
- const lastStatusItem = statusHistory [ statusHistory . length - 1 ] ;
43
+ const orderStatus = order . status ;
76
44
77
45
return order ? (
78
46
< PaperLayout >
79
47
< Typography component = "h1" variant = "h4" align = "center" >
80
48
Manage order
81
49
</ Typography >
82
- < ReviewOrder address = { order . address } items = { cartItems } />
50
+ < ReviewOrder address = { order . delivery . address } items = { order . cart . items } />
83
51
< Typography variant = "h6" > Status:</ Typography >
84
52
< Typography variant = "h6" color = "primary" >
85
- { lastStatusItem ?. status . toUpperCase ( ) }
53
+ { orderStatus . toUpperCase ( ) }
86
54
</ Typography >
87
55
< Typography variant = "h6" > Change status:</ Typography >
88
56
< Box py = { 2 } >
89
57
< Formik
90
- initialValues = { { status : lastStatusItem . status , comment : "" } }
58
+ initialValues = { { status : orderStatus , comment : "" } }
91
59
enableReinitialize
92
60
onSubmit = { ( values ) =>
93
61
updateOrderStatus (
@@ -145,30 +113,6 @@ export default function PageOrder() {
145
113
</ Formik >
146
114
</ Box >
147
115
< Typography variant = "h6" > Status history:</ Typography >
148
- < TableContainer >
149
- < Table aria-label = "simple table" >
150
- < TableHead >
151
- < TableRow >
152
- < TableCell > Status</ TableCell >
153
- < TableCell align = "right" > Date and Time</ TableCell >
154
- < TableCell align = "right" > Comment</ TableCell >
155
- </ TableRow >
156
- </ TableHead >
157
- < TableBody >
158
- { statusHistory . map ( ( statusHistoryItem ) => (
159
- < TableRow key = { order . id } >
160
- < TableCell component = "th" scope = "row" >
161
- { statusHistoryItem . status . toUpperCase ( ) }
162
- </ TableCell >
163
- < TableCell align = "right" >
164
- { new Date ( statusHistoryItem . timestamp ) . toString ( ) }
165
- </ TableCell >
166
- < TableCell align = "right" > { statusHistoryItem . comment } </ TableCell >
167
- </ TableRow >
168
- ) ) }
169
- </ TableBody >
170
- </ Table >
171
- </ TableContainer >
172
116
</ PaperLayout >
173
117
) : null ;
174
118
}
0 commit comments