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 | import { InvoiceTableFilters, InvoiceTableFilterValue } from 'src/schemas';
|
---|
9 | // components
|
---|
10 | import Iconify from 'src/components/iconify';
|
---|
11 | import { shortDateLabel } from 'src/components/custom-date-range-picker';
|
---|
12 |
|
---|
13 | // ----------------------------------------------------------------------
|
---|
14 |
|
---|
15 | type Props = StackProps & {
|
---|
16 | filters: InvoiceTableFilters;
|
---|
17 | onFilters: (name: string, value: InvoiceTableFilterValue) => void;
|
---|
18 | //
|
---|
19 | onResetFilters: VoidFunction;
|
---|
20 | //
|
---|
21 | results: number;
|
---|
22 | };
|
---|
23 |
|
---|
24 | export default function InvoiceTableFiltersResult({
|
---|
25 | filters,
|
---|
26 | onFilters,
|
---|
27 | //
|
---|
28 | onResetFilters,
|
---|
29 | //
|
---|
30 | results,
|
---|
31 | ...other
|
---|
32 | }: Props) {
|
---|
33 | const shortLabel = shortDateLabel(filters.startDate, filters.endDate);
|
---|
34 |
|
---|
35 | const handleRemoveService = (inputValue: string) => {
|
---|
36 | const newValue = filters.service.filter((item) => item !== inputValue);
|
---|
37 | onFilters('service', newValue);
|
---|
38 | };
|
---|
39 |
|
---|
40 | const handleRemoveStatus = () => {
|
---|
41 | onFilters('status', 'all');
|
---|
42 | };
|
---|
43 |
|
---|
44 | const handleRemoveDate = () => {
|
---|
45 | onFilters('startDate', null);
|
---|
46 | onFilters('endDate', null);
|
---|
47 | };
|
---|
48 |
|
---|
49 | return (
|
---|
50 | <Stack spacing={1.5} {...other}>
|
---|
51 | <Box sx={{ typography: 'body2' }}>
|
---|
52 | <strong>{results}</strong>
|
---|
53 | <Box component="span" sx={{ color: 'text.secondary', ml: 0.25 }}>
|
---|
54 | results found
|
---|
55 | </Box>
|
---|
56 | </Box>
|
---|
57 |
|
---|
58 | <Stack flexGrow={1} spacing={1} direction="row" flexWrap="wrap" alignItems="center">
|
---|
59 | {!!filters.service.length && (
|
---|
60 | <Block label="Service:">
|
---|
61 | {filters.service.map((item) => (
|
---|
62 | <Chip
|
---|
63 | key={item}
|
---|
64 | label={item}
|
---|
65 | size="small"
|
---|
66 | onDelete={() => handleRemoveService(item)}
|
---|
67 | />
|
---|
68 | ))}
|
---|
69 | </Block>
|
---|
70 | )}
|
---|
71 |
|
---|
72 | {filters.status !== 'all' && (
|
---|
73 | <Block label="Status:">
|
---|
74 | <Chip size="small" label={filters.status} onDelete={handleRemoveStatus} />
|
---|
75 | </Block>
|
---|
76 | )}
|
---|
77 |
|
---|
78 | {filters.startDate && filters.endDate && (
|
---|
79 | <Block label="Date:">
|
---|
80 | <Chip size="small" label={shortLabel} onDelete={handleRemoveDate} />
|
---|
81 | </Block>
|
---|
82 | )}
|
---|
83 |
|
---|
84 | <Button
|
---|
85 | color="error"
|
---|
86 | onClick={onResetFilters}
|
---|
87 | startIcon={<Iconify icon="solar:trash-bin-trash-bold" />}
|
---|
88 | >
|
---|
89 | Clear
|
---|
90 | </Button>
|
---|
91 | </Stack>
|
---|
92 | </Stack>
|
---|
93 | );
|
---|
94 | }
|
---|
95 |
|
---|
96 | // ----------------------------------------------------------------------
|
---|
97 |
|
---|
98 | type BlockProps = StackProps & {
|
---|
99 | label: string;
|
---|
100 | };
|
---|
101 |
|
---|
102 | function Block({ label, children, sx, ...other }: BlockProps) {
|
---|
103 | return (
|
---|
104 | <Stack
|
---|
105 | component={Paper}
|
---|
106 | variant="outlined"
|
---|
107 | spacing={1}
|
---|
108 | direction="row"
|
---|
109 | sx={{
|
---|
110 | p: 1,
|
---|
111 | borderRadius: 1,
|
---|
112 | overflow: 'hidden',
|
---|
113 | borderStyle: 'dashed',
|
---|
114 | ...sx,
|
---|
115 | }}
|
---|
116 | {...other}
|
---|
117 | >
|
---|
118 | <Box component="span" sx={{ typography: 'subtitle2' }}>
|
---|
119 | {label}
|
---|
120 | </Box>
|
---|
121 |
|
---|
122 | <Stack spacing={1} direction="row" flexWrap="wrap">
|
---|
123 | {children}
|
---|
124 | </Stack>
|
---|
125 | </Stack>
|
---|
126 | );
|
---|
127 | }
|
---|