-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrders.tsx
100 lines (92 loc) · 2.82 KB
/
Orders.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React from 'react';
import { CellProps, LoaderIcon, Table } from '@tabetalt/kit';
import Layout from '../../components/layout/Layout';
import { Badge, Box, Button } from 'theme-ui';
import { useNavigate } from 'react-router-dom';
import { GetOrdersQuery, useGetOrdersQuery } from '../../generated/graphql';
import * as DineroHelper from '../../helpers';
import moment from 'moment';
export type OrderItem = GetOrdersQuery['orders']['items'][0];
const Orders: React.FC = () => {
const navigate = useNavigate();
const { data, loading, error } = useGetOrdersQuery();
const columns = React.useMemo(
() => [
{
Header: 'Ordre',
accessor: 'id',
},
{
Header: 'Dato',
accessor: 'orderTime',
Cell: ({ row: { original: order } }: CellProps<OrderItem>) =>
moment(order.orderTime).format('DD.MM.YYYY hh:mm'),
},
{
Header: 'Kunde',
accessor: 'tenantId',
},
{
Header: 'Ordrestatus',
accessor: 'status',
Cell: ({ row: { original: order } }: CellProps<OrderItem>) => {
const statusVariant =
order.status === 'CONFIRMED'
? 'success'
: order.status === 'UNCONFIRMED'
? 'warning'
: 'error';
return <Badge variant={statusVariant}>{order.status}</Badge>;
},
},
{
Header: 'Betaling',
accessor: 'paymentStatus',
Cell: ({ row: { original: order } }: CellProps<OrderItem>) => {
const statusVariant =
order.paymentStatus === 'PAID'
? 'success'
: order.paymentStatus === 'PENDING'
? 'warning'
: 'error';
return <Badge variant={statusVariant}>{order.paymentStatus}</Badge>;
},
},
{
Header: 'Totalsum',
accessor: 'totalPrice.amount',
Cell: ({ row: { original: order } }: CellProps<OrderItem>) =>
DineroHelper.formatPrice(order?.totalPrice).grossAmount,
},
{
Header: '',
accessor: 'actions',
Cell: ({ row: { original: order } }: CellProps<OrderItem>) => (
<Box sx={{ textAlign: 'right' }}>
<Button
variant="outline"
onClick={() => navigate(`/order/${order.id}`)}
>
Vis
</Button>
</Box>
),
},
],
[]
);
let content = null;
if (loading) {
content = <LoaderIcon sx={{ width: 5, display: 'block', m: '0 auto' }} />;
} else if (error) {
content = <span>Error getting order list</span>; // TODO: improve error message
} else {
content = <Table options={{ columns, data: data?.orders.items || [] }} />;
}
return (
<Layout>
<Box sx={{ p: 5 }}>{content}</Box>
</Layout>
);
};
export default Orders;