-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
/
OrderTable.tsx
550 lines (543 loc) · 15.5 KB
/
OrderTable.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
/* eslint-disable jsx-a11y/anchor-is-valid */
import * as React from 'react';
import { ColorPaletteProp } from '@mui/joy/styles';
import Avatar from '@mui/joy/Avatar';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import Chip from '@mui/joy/Chip';
import Divider from '@mui/joy/Divider';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Link from '@mui/joy/Link';
import Input from '@mui/joy/Input';
import Modal from '@mui/joy/Modal';
import ModalDialog from '@mui/joy/ModalDialog';
import ModalClose from '@mui/joy/ModalClose';
import Select from '@mui/joy/Select';
import Option from '@mui/joy/Option';
import Table from '@mui/joy/Table';
import Sheet from '@mui/joy/Sheet';
import Checkbox from '@mui/joy/Checkbox';
import IconButton, { iconButtonClasses } from '@mui/joy/IconButton';
import Typography from '@mui/joy/Typography';
import Menu from '@mui/joy/Menu';
import MenuButton from '@mui/joy/MenuButton';
import MenuItem from '@mui/joy/MenuItem';
import Dropdown from '@mui/joy/Dropdown';
import FilterAltIcon from '@mui/icons-material/FilterAlt';
import SearchIcon from '@mui/icons-material/Search';
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
import CheckRoundedIcon from '@mui/icons-material/CheckRounded';
import BlockIcon from '@mui/icons-material/Block';
import AutorenewRoundedIcon from '@mui/icons-material/AutorenewRounded';
import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';
import KeyboardArrowLeftIcon from '@mui/icons-material/KeyboardArrowLeft';
import MoreHorizRoundedIcon from '@mui/icons-material/MoreHorizRounded';
const rows = [
{
id: 'INV-1234',
date: 'Feb 3, 2023',
status: 'Refunded',
customer: {
initial: 'O',
name: 'Olivia Ryhe',
email: '[email protected]',
},
},
{
id: 'INV-1233',
date: 'Feb 3, 2023',
status: 'Paid',
customer: {
initial: 'S',
name: 'Steve Hampton',
email: '[email protected]',
},
},
{
id: 'INV-1232',
date: 'Feb 3, 2023',
status: 'Refunded',
customer: {
initial: 'C',
name: 'Ciaran Murray',
email: '[email protected]',
},
},
{
id: 'INV-1231',
date: 'Feb 3, 2023',
status: 'Refunded',
customer: {
initial: 'M',
name: 'Maria Macdonald',
email: '[email protected]',
},
},
{
id: 'INV-1230',
date: 'Feb 3, 2023',
status: 'Cancelled',
customer: {
initial: 'C',
name: 'Charles Fulton',
email: '[email protected]',
},
},
{
id: 'INV-1229',
date: 'Feb 3, 2023',
status: 'Cancelled',
customer: {
initial: 'J',
name: 'Jay Hooper',
email: '[email protected]',
},
},
{
id: 'INV-1228',
date: 'Feb 3, 2023',
status: 'Refunded',
customer: {
initial: 'K',
name: 'Krystal Stevens',
email: '[email protected]',
},
},
{
id: 'INV-1227',
date: 'Feb 3, 2023',
status: 'Paid',
customer: {
initial: 'S',
name: 'Sachin Flynn',
email: '[email protected]',
},
},
{
id: 'INV-1226',
date: 'Feb 3, 2023',
status: 'Cancelled',
customer: {
initial: 'B',
name: 'Bradley Rosales',
email: '[email protected]',
},
},
{
id: 'INV-1225',
date: 'Feb 3, 2023',
status: 'Paid',
customer: {
initial: 'O',
name: 'Olivia Ryhe',
email: '[email protected]',
},
},
{
id: 'INV-1224',
date: 'Feb 3, 2023',
status: 'Cancelled',
customer: {
initial: 'S',
name: 'Steve Hampton',
email: '[email protected]',
},
},
{
id: 'INV-1223',
date: 'Feb 3, 2023',
status: 'Paid',
customer: {
initial: 'C',
name: 'Ciaran Murray',
email: '[email protected]',
},
},
{
id: 'INV-1221',
date: 'Feb 3, 2023',
status: 'Refunded',
customer: {
initial: 'M',
name: 'Maria Macdonald',
email: '[email protected]',
},
},
{
id: 'INV-1220',
date: 'Feb 3, 2023',
status: 'Paid',
customer: {
initial: 'C',
name: 'Charles Fulton',
email: '[email protected]',
},
},
{
id: 'INV-1219',
date: 'Feb 3, 2023',
status: 'Cancelled',
customer: {
initial: 'J',
name: 'Jay Hooper',
email: '[email protected]',
},
},
{
id: 'INV-1218',
date: 'Feb 3, 2023',
status: 'Cancelled',
customer: {
initial: 'K',
name: 'Krystal Stevens',
email: '[email protected]',
},
},
{
id: 'INV-1217',
date: 'Feb 3, 2023',
status: 'Paid',
customer: {
initial: 'S',
name: 'Sachin Flynn',
email: '[email protected]',
},
},
{
id: 'INV-1216',
date: 'Feb 3, 2023',
status: 'Cancelled',
customer: {
initial: 'B',
name: 'Bradley Rosales',
email: '[email protected]',
},
},
];
function descendingComparator<T>(a: T, b: T, orderBy: keyof T) {
if (b[orderBy] < a[orderBy]) {
return -1;
}
if (b[orderBy] > a[orderBy]) {
return 1;
}
return 0;
}
type Order = 'asc' | 'desc';
function getComparator<Key extends keyof any>(
order: Order,
orderBy: Key,
): (
a: { [key in Key]: number | string },
b: { [key in Key]: number | string },
) => number {
return order === 'desc'
? (a, b) => descendingComparator(a, b, orderBy)
: (a, b) => -descendingComparator(a, b, orderBy);
}
function RowMenu() {
return (
<Dropdown>
<MenuButton
slots={{ root: IconButton }}
slotProps={{ root: { variant: 'plain', color: 'neutral', size: 'sm' } }}
>
<MoreHorizRoundedIcon />
</MenuButton>
<Menu size="sm" sx={{ minWidth: 140 }}>
<MenuItem>Edit</MenuItem>
<MenuItem>Rename</MenuItem>
<MenuItem>Move</MenuItem>
<Divider />
<MenuItem color="danger">Delete</MenuItem>
</Menu>
</Dropdown>
);
}
export default function OrderTable() {
const [order, setOrder] = React.useState<Order>('desc');
const [selected, setSelected] = React.useState<readonly string[]>([]);
const [open, setOpen] = React.useState(false);
const renderFilters = () => (
<React.Fragment>
<FormControl size="sm">
<FormLabel>Status</FormLabel>
<Select
size="sm"
placeholder="Filter by status"
slotProps={{ button: { sx: { whiteSpace: 'nowrap' } } }}
>
<Option value="paid">Paid</Option>
<Option value="pending">Pending</Option>
<Option value="refunded">Refunded</Option>
<Option value="cancelled">Cancelled</Option>
</Select>
</FormControl>
<FormControl size="sm">
<FormLabel>Category</FormLabel>
<Select size="sm" placeholder="All">
<Option value="all">All</Option>
<Option value="refund">Refund</Option>
<Option value="purchase">Purchase</Option>
<Option value="debit">Debit</Option>
</Select>
</FormControl>
<FormControl size="sm">
<FormLabel>Customer</FormLabel>
<Select size="sm" placeholder="All">
<Option value="all">All</Option>
<Option value="olivia">Olivia Rhye</Option>
<Option value="steve">Steve Hampton</Option>
<Option value="ciaran">Ciaran Murray</Option>
<Option value="marina">Marina Macdonald</Option>
<Option value="charles">Charles Fulton</Option>
<Option value="jay">Jay Hoper</Option>
</Select>
</FormControl>
</React.Fragment>
);
return (
<React.Fragment>
<Sheet
className="SearchAndFilters-mobile"
sx={{ display: { xs: 'flex', sm: 'none' }, my: 1, gap: 1 }}
>
<Input
size="sm"
placeholder="Search"
startDecorator={<SearchIcon />}
sx={{ flexGrow: 1 }}
/>
<IconButton
size="sm"
variant="outlined"
color="neutral"
onClick={() => setOpen(true)}
>
<FilterAltIcon />
</IconButton>
<Modal open={open} onClose={() => setOpen(false)}>
<ModalDialog aria-labelledby="filter-modal" layout="fullscreen">
<ModalClose />
<Typography id="filter-modal" level="h2">
Filters
</Typography>
<Divider sx={{ my: 2 }} />
<Sheet sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
{renderFilters()}
<Button color="primary" onClick={() => setOpen(false)}>
Submit
</Button>
</Sheet>
</ModalDialog>
</Modal>
</Sheet>
<Box
className="SearchAndFilters-tabletUp"
sx={{
borderRadius: 'sm',
py: 2,
display: { xs: 'none', sm: 'flex' },
flexWrap: 'wrap',
gap: 1.5,
'& > *': {
minWidth: { xs: '120px', md: '160px' },
},
}}
>
<FormControl sx={{ flex: 1 }} size="sm">
<FormLabel>Search for order</FormLabel>
<Input size="sm" placeholder="Search" startDecorator={<SearchIcon />} />
</FormControl>
{renderFilters()}
</Box>
<Sheet
className="OrderTableContainer"
variant="outlined"
sx={{
display: { xs: 'none', sm: 'initial' },
width: '100%',
borderRadius: 'sm',
flexShrink: 1,
overflow: 'auto',
minHeight: 0,
}}
>
<Table
aria-labelledby="tableTitle"
stickyHeader
hoverRow
sx={{
'--TableCell-headBackground': 'var(--joy-palette-background-level1)',
'--Table-headerUnderlineThickness': '1px',
'--TableRow-hoverBackground': 'var(--joy-palette-background-level1)',
'--TableCell-paddingY': '4px',
'--TableCell-paddingX': '8px',
}}
>
<thead>
<tr>
<th style={{ width: 48, textAlign: 'center', padding: '12px 6px' }}>
<Checkbox
size="sm"
indeterminate={
selected.length > 0 && selected.length !== rows.length
}
checked={selected.length === rows.length}
onChange={(event) => {
setSelected(
event.target.checked ? rows.map((row) => row.id) : [],
);
}}
color={
selected.length > 0 || selected.length === rows.length
? 'primary'
: undefined
}
sx={{ verticalAlign: 'text-bottom' }}
/>
</th>
<th style={{ width: 120, padding: '12px 6px' }}>
<Link
underline="none"
color="primary"
component="button"
onClick={() => setOrder(order === 'asc' ? 'desc' : 'asc')}
endDecorator={<ArrowDropDownIcon />}
sx={[
{
fontWeight: 'lg',
'& svg': {
transition: '0.2s',
transform:
order === 'desc' ? 'rotate(0deg)' : 'rotate(180deg)',
},
},
order === 'desc'
? { '& svg': { transform: 'rotate(0deg)' } }
: { '& svg': { transform: 'rotate(180deg)' } },
]}
>
Invoice
</Link>
</th>
<th style={{ width: 140, padding: '12px 6px' }}>Date</th>
<th style={{ width: 140, padding: '12px 6px' }}>Status</th>
<th style={{ width: 240, padding: '12px 6px' }}>Customer</th>
<th style={{ width: 140, padding: '12px 6px' }}> </th>
</tr>
</thead>
<tbody>
{[...rows].sort(getComparator(order, 'id')).map((row) => (
<tr key={row.id}>
<td style={{ textAlign: 'center', width: 120 }}>
<Checkbox
size="sm"
checked={selected.includes(row.id)}
color={selected.includes(row.id) ? 'primary' : undefined}
onChange={(event) => {
setSelected((ids) =>
event.target.checked
? ids.concat(row.id)
: ids.filter((itemId) => itemId !== row.id),
);
}}
slotProps={{ checkbox: { sx: { textAlign: 'left' } } }}
sx={{ verticalAlign: 'text-bottom' }}
/>
</td>
<td>
<Typography level="body-xs">{row.id}</Typography>
</td>
<td>
<Typography level="body-xs">{row.date}</Typography>
</td>
<td>
<Chip
variant="soft"
size="sm"
startDecorator={
{
Paid: <CheckRoundedIcon />,
Refunded: <AutorenewRoundedIcon />,
Cancelled: <BlockIcon />,
}[row.status]
}
color={
{
Paid: 'success',
Refunded: 'neutral',
Cancelled: 'danger',
}[row.status] as ColorPaletteProp
}
>
{row.status}
</Chip>
</td>
<td>
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center' }}>
<Avatar size="sm">{row.customer.initial}</Avatar>
<div>
<Typography level="body-xs">{row.customer.name}</Typography>
<Typography level="body-xs">{row.customer.email}</Typography>
</div>
</Box>
</td>
<td>
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center' }}>
<Link level="body-xs" component="button">
Download
</Link>
<RowMenu />
</Box>
</td>
</tr>
))}
</tbody>
</Table>
</Sheet>
<Box
className="Pagination-laptopUp"
sx={{
pt: 2,
gap: 1,
[`& .${iconButtonClasses.root}`]: { borderRadius: '50%' },
display: {
xs: 'none',
md: 'flex',
},
}}
>
<Button
size="sm"
variant="outlined"
color="neutral"
startDecorator={<KeyboardArrowLeftIcon />}
>
Previous
</Button>
<Box sx={{ flex: 1 }} />
{['1', '2', '3', '…', '8', '9', '10'].map((page) => (
<IconButton
key={page}
size="sm"
variant={Number(page) ? 'outlined' : 'plain'}
color="neutral"
>
{page}
</IconButton>
))}
<Box sx={{ flex: 1 }} />
<Button
size="sm"
variant="outlined"
color="neutral"
endDecorator={<KeyboardArrowRightIcon />}
>
Next
</Button>
</Box>
</React.Fragment>
);
}