-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathOnlyMineInput.tsx
34 lines (32 loc) · 1.18 KB
/
OnlyMineInput.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
import * as React from 'react';
import { useListFilterContext, useGetIdentity } from 'react-admin';
import { Box, Switch, FormControlLabel } from '@mui/material';
export const OnlyMineInput = (_: { alwaysOn: boolean; source: string }) => {
const { filterValues, displayedFilters, setFilters } =
useListFilterContext();
const { identity } = useGetIdentity();
const handleChange = () => {
const newFilterValues = { ...filterValues };
if (typeof filterValues.sales_id !== 'undefined') {
delete newFilterValues.sales_id;
} else {
newFilterValues.sales_id = identity && identity?.id;
}
setFilters(newFilterValues, displayedFilters);
};
return (
<Box sx={{ marginBottom: 1, marginLeft: 1 }}>
<FormControlLabel
control={
<Switch
checked={typeof filterValues.sales_id !== 'undefined'}
onChange={handleChange}
color="primary"
name="checkedC"
/>
}
label="Only companies I manage"
/>
</Box>
);
};