1 | // @mui
|
---|
2 | import Box from '@mui/material/Box';
|
---|
3 | import Chip from '@mui/material/Chip';
|
---|
4 | import Paper from '@mui/material/Paper';
|
---|
5 | import Button from '@mui/material/Button';
|
---|
6 | import Stack, { StackProps } from '@mui/material/Stack';
|
---|
7 | // types
|
---|
8 |
|
---|
9 | // components
|
---|
10 | import Iconify from 'src/components/iconify';
|
---|
11 | import { CustomerTableFilterValue, CustomerTableFilters } from 'src/schemas';
|
---|
12 |
|
---|
13 | // ----------------------------------------------------------------------
|
---|
14 |
|
---|
15 | type Props = StackProps & {
|
---|
16 | filters: CustomerTableFilters;
|
---|
17 | onFilters: (name: string, value: CustomerTableFilterValue) => void;
|
---|
18 | //
|
---|
19 | onResetFilters: VoidFunction;
|
---|
20 | //
|
---|
21 | results: number;
|
---|
22 | };
|
---|
23 |
|
---|
24 | export default function CustomerTableFiltersResult({
|
---|
25 | filters,
|
---|
26 | onFilters,
|
---|
27 | //
|
---|
28 | onResetFilters,
|
---|
29 | //
|
---|
30 | results,
|
---|
31 | ...other
|
---|
32 | }: Props) {
|
---|
33 | const handleRemoveStatus = () => {
|
---|
34 | onFilters('status', 'all');
|
---|
35 | };
|
---|
36 |
|
---|
37 | const handleRemoveRole = (inputValue: string) => {
|
---|
38 | const newValue = filters.role.filter((item) => item !== inputValue);
|
---|
39 | onFilters('role', newValue);
|
---|
40 | };
|
---|
41 |
|
---|
42 | return (
|
---|
43 | <Stack spacing={1.5} {...other}>
|
---|
44 | <Box sx={{ typography: 'body2' }}>
|
---|
45 | <strong>{results}</strong>
|
---|
46 | <Box component="span" sx={{ color: 'text.secondary', ml: 0.25 }}>
|
---|
47 | results found
|
---|
48 | </Box>
|
---|
49 | </Box>
|
---|
50 |
|
---|
51 | <Stack flexGrow={1} spacing={1} direction="row" flexWrap="wrap" alignItems="center">
|
---|
52 | {filters.status !== 'all' && (
|
---|
53 | <Block label="Status:">
|
---|
54 | <Chip size="small" label={filters.status} onDelete={handleRemoveStatus} />
|
---|
55 | </Block>
|
---|
56 | )}
|
---|
57 |
|
---|
58 | {!!filters.role.length && (
|
---|
59 | <Block label="Role:">
|
---|
60 | {filters.role.map((item) => (
|
---|
61 | <Chip key={item} label={item} size="small" onDelete={() => handleRemoveRole(item)} />
|
---|
62 | ))}
|
---|
63 | </Block>
|
---|
64 | )}
|
---|
65 |
|
---|
66 | <Button
|
---|
67 | color="error"
|
---|
68 | onClick={onResetFilters}
|
---|
69 | startIcon={<Iconify icon="solar:trash-bin-trash-bold" />}
|
---|
70 | >
|
---|
71 | Clear
|
---|
72 | </Button>
|
---|
73 | </Stack>
|
---|
74 | </Stack>
|
---|
75 | );
|
---|
76 | }
|
---|
77 |
|
---|
78 | // ----------------------------------------------------------------------
|
---|
79 |
|
---|
80 | type BlockProps = StackProps & {
|
---|
81 | label: string;
|
---|
82 | };
|
---|
83 |
|
---|
84 | function Block({ label, children, sx, ...other }: BlockProps) {
|
---|
85 | return (
|
---|
86 | <Stack
|
---|
87 | component={Paper}
|
---|
88 | variant="outlined"
|
---|
89 | spacing={1}
|
---|
90 | direction="row"
|
---|
91 | sx={{
|
---|
92 | p: 1,
|
---|
93 | borderRadius: 1,
|
---|
94 | overflow: 'hidden',
|
---|
95 | borderStyle: 'dashed',
|
---|
96 | ...sx,
|
---|
97 | }}
|
---|
98 | {...other}
|
---|
99 | >
|
---|
100 | <Box component="span" sx={{ typography: 'subtitle2' }}>
|
---|
101 | {label}
|
---|
102 | </Box>
|
---|
103 |
|
---|
104 | <Stack spacing={1} direction="row" flexWrap="wrap">
|
---|
105 | {children}
|
---|
106 | </Stack>
|
---|
107 | </Stack>
|
---|
108 | );
|
---|
109 | }
|
---|