-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathReviewList.tsx
88 lines (81 loc) · 2.62 KB
/
ReviewList.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
import * as React from 'react';
import { useCallback } from 'react';
import {
CreateButton,
ExportButton,
FilterButton,
List,
SelectColumnsButton,
TopToolbar,
} from 'react-admin';
import { matchPath, useLocation, useNavigate } from 'react-router-dom';
import { Box, Drawer, useMediaQuery, Theme } from '@mui/material';
import ReviewListMobile from './ReviewListMobile';
import ReviewListDesktop from './ReviewListDesktop';
import reviewFilters from './reviewFilters';
import ReviewEdit from './ReviewEdit';
const ReviewListActions = () => (
<TopToolbar>
<FilterButton />
<CreateButton />
<SelectColumnsButton />
<ExportButton />
</TopToolbar>
);
const ReviewList = () => {
const isXSmall = useMediaQuery<Theme>(theme =>
theme.breakpoints.down('sm')
);
const location = useLocation();
const navigate = useNavigate();
const handleClose = useCallback(() => {
navigate('/reviews');
}, [navigate]);
const match = matchPath('/reviews/:id', location.pathname);
return (
<Box display="flex">
<List
sx={{
flexGrow: 1,
transition: (theme: any) =>
theme.transitions.create(['all'], {
duration: theme.transitions.duration.enteringScreen,
}),
marginRight: !!match ? '400px' : 0,
}}
filters={reviewFilters}
perPage={25}
sort={{ field: 'date', order: 'DESC' }}
actions={<ReviewListActions />}
>
{isXSmall ? (
<ReviewListMobile />
) : (
<ReviewListDesktop
selectedRow={
!!match
? parseInt((match as any).params.id, 10)
: undefined
}
/>
)}
</List>
<Drawer
variant="persistent"
open={!!match}
anchor="right"
onClose={handleClose}
sx={{ zIndex: 100 }}
>
{/* To avoid any errors if the route does not match, we don't render at all the component in this case */}
{!!match && (
<ReviewEdit
id={(match as any).params.id}
onCancel={handleClose}
/>
)}
</Drawer>
</Box>
);
};
export default ReviewList;