|  |  | 
 |  |  |     useStore, | 
 |  |  | } from 'react-admin'; | 
 |  |  | import { Box, Typography, Card, CardContent } from '@mui/material'; | 
 |  |  | import { styled } from '@mui/material/styles'; | 
 |  |  | import { DEFAULT_THEME_NAME } from '@/config/setting'; | 
 |  |  | import * as Common from '@/utils/common'; | 
 |  |  | import WcIcon from '@mui/icons-material/Wc'; | 
 |  |  | import BookmarkIcon from '@mui/icons-material/BookmarkBorder'; | 
 |  |  | import CategoryIcon from '@mui/icons-material/LocalOffer'; | 
 |  |  | import StyleIcon from '@mui/icons-material/Style'; | 
 |  |  | import AccessTimeIcon from '@mui/icons-material/AccessTime'; | 
 |  |  | import { | 
 |  |  |     endOfYesterday, | 
 |  |  | 
 |  |  |     startOfMonth, | 
 |  |  |     subMonths, | 
 |  |  | } from 'date-fns'; | 
 |  |  | import request from '@/utils/request' | 
 |  |  |  | 
 |  |  | const UserListAside = (props) => { | 
 |  |  |     const theme = useTheme(); | 
 |  |  |     console.log(endOfYesterday().toISOString()) | 
 |  |  |     const [roles, setRoles] = React.useState([]); | 
 |  |  |  | 
 |  |  |     React.useEffect(() => { | 
 |  |  |         request.post('/role/list', {}).then(res => { | 
 |  |  |             if (res?.data?.code === 200) { | 
 |  |  |                 setRoles(res.data.data); | 
 |  |  |             } | 
 |  |  |         }) | 
 |  |  |     }, []) | 
 |  |  |  | 
 |  |  |     const isSelected = (value, filters) => { | 
 |  |  |         const categories = filters.categories || []; | 
 |  |  |         return categories.includes(value.category); | 
 |  |  |         const roleIds = filters.roleIds || []; | 
 |  |  |         return roleIds.includes(value.roleId); | 
 |  |  |     }; | 
 |  |  |  | 
 |  |  |     const toggleFilter = (value, filters) => { | 
 |  |  |         const categories = filters.categories || []; | 
 |  |  |         const roleIds = filters.roleIds || []; | 
 |  |  |         return { | 
 |  |  |             ...filters, | 
 |  |  |             categories: categories.includes(value.category) | 
 |  |  |                 // Remove the category if it was already present | 
 |  |  |                 ? categories.filter(v => v !== value.category) | 
 |  |  |                 // Add the category if it wasn't already present | 
 |  |  |                 : [...categories, value.category], | 
 |  |  |             roleIds: roleIds.includes(value.roleId) | 
 |  |  |                 ? roleIds.filter(v => v !== value.roleId) | 
 |  |  |                 // : [...roleIds, value.roleId], | 
 |  |  |                 : [value.roleId], | 
 |  |  |         }; | 
 |  |  |     }; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     return ( | 
 |  |  |         <> | 
 |  |  |             <Card | 
 |  |  |                 sx={{ | 
 |  |  |                     display: { xs: 'none', md: 'block', }, | 
 |  |  |                     order: -1, | 
 |  |  |                     mr: 2, | 
 |  |  |                     mt: 8, | 
 |  |  |                     alignSelf: 'flex-start', | 
 |  |  |                     border: theme[0] === 'light' && '1px solid #e0e0e3', | 
 |  |  |                     // borderRadius: 0, | 
 |  |  |                     // width: 200 | 
 |  |  |                 }} | 
 |  |  |             > | 
 |  |  |                 <CardContent> | 
 |  |  |                     <SavedQueriesList icon={<BookmarkIcon />} /> | 
 |  |  |                     <FilterLiveSearch source='condition' hiddenLabel /> | 
 |  |  |         <Card | 
 |  |  |             sx={{ | 
 |  |  |                 display: { xs: 'none', md: 'block', }, | 
 |  |  |                 order: -1, | 
 |  |  |                 mr: 2, | 
 |  |  |                 mt: 8, | 
 |  |  |                 alignSelf: 'flex-start', | 
 |  |  |                 border: theme[0] === 'light' && '1px solid #e0e0e3', | 
 |  |  |                 // width: 200 | 
 |  |  |             }} | 
 |  |  |         > | 
 |  |  |             <CardContent> | 
 |  |  |                 <SavedQueriesList icon={<BookmarkIcon />} /> | 
 |  |  |                 <FilterLiveSearch source='condition' hiddenLabel /> | 
 |  |  |  | 
 |  |  |                     <FilterList | 
 |  |  |                         label="filters.lastCreated" | 
 |  |  |                         icon={<AccessTimeIcon />} | 
 |  |  |                     > | 
 |  |  |                         <FilterListItem | 
 |  |  |                             label="filters.today" | 
 |  |  |                             value={{ | 
 |  |  |                                 timeStart: endOfYesterday().toISOString(), | 
 |  |  |                                 timeEnd: undefined, | 
 |  |  |                             }} | 
 |  |  |                         /> | 
 |  |  |                         <FilterListItem | 
 |  |  |                             label="filters.thisWeek" | 
 |  |  |                             value={{ | 
 |  |  |                                 timeStart: startOfWeek(new Date()).toISOString(), | 
 |  |  |                                 timeEnd: undefined, | 
 |  |  |                             }} | 
 |  |  |                         /> | 
 |  |  |                         <FilterListItem | 
 |  |  |                             label="filters.lastWeek" | 
 |  |  |                             value={{ | 
 |  |  |                                 timeStart: subWeeks(startOfWeek(new Date()), 1).toISOString(), | 
 |  |  |                                 timeEnd: startOfWeek(new Date()).toISOString(), | 
 |  |  |                             }} | 
 |  |  |                         /> | 
 |  |  |                         <FilterListItem | 
 |  |  |                             label="filters.thisMonth" | 
 |  |  |                             value={{ | 
 |  |  |                                 timeStart: startOfMonth(new Date()).toISOString(), | 
 |  |  |                                 timeEnd: undefined, | 
 |  |  |                             }} | 
 |  |  |                         /> | 
 |  |  |                         <FilterListItem | 
 |  |  |                             label="filters.lastMonth" | 
 |  |  |                             value={{ | 
 |  |  |                                 timeStart: subMonths(startOfMonth(new Date()), 1).toISOString(), | 
 |  |  |                                 timeEnd: startOfMonth(new Date()).toISOString(), | 
 |  |  |                             }} | 
 |  |  |                         /> | 
 |  |  |                         <FilterListItem | 
 |  |  |                             label="filters.earlier" | 
 |  |  |                             value={{ | 
 |  |  |                                 timeStart: undefined, | 
 |  |  |                                 timeEnd: subMonths(startOfMonth(new Date()), 1).toISOString(), | 
 |  |  |                             }} | 
 |  |  |                         /> | 
 |  |  |                     </FilterList> | 
 |  |  |                 <FilterList | 
 |  |  |                     label="filters.lastCreated" | 
 |  |  |                     icon={<AccessTimeIcon />} | 
 |  |  |                 > | 
 |  |  |                     <FilterListItem | 
 |  |  |                         label="filters.today" | 
 |  |  |                         value={{ | 
 |  |  |                             timeStart: endOfYesterday().toISOString(), | 
 |  |  |                             timeEnd: undefined, | 
 |  |  |                         }} | 
 |  |  |                     /> | 
 |  |  |                     <FilterListItem | 
 |  |  |                         label="filters.thisWeek" | 
 |  |  |                         value={{ | 
 |  |  |                             timeStart: startOfWeek(new Date()).toISOString(), | 
 |  |  |                             timeEnd: undefined, | 
 |  |  |                         }} | 
 |  |  |                     /> | 
 |  |  |                     <FilterListItem | 
 |  |  |                         label="filters.lastWeek" | 
 |  |  |                         value={{ | 
 |  |  |                             timeStart: subWeeks(startOfWeek(new Date()), 1).toISOString(), | 
 |  |  |                             timeEnd: startOfWeek(new Date()).toISOString(), | 
 |  |  |                         }} | 
 |  |  |                     /> | 
 |  |  |                     <FilterListItem | 
 |  |  |                         label="filters.thisMonth" | 
 |  |  |                         value={{ | 
 |  |  |                             timeStart: startOfMonth(new Date()).toISOString(), | 
 |  |  |                             timeEnd: undefined, | 
 |  |  |                         }} | 
 |  |  |                     /> | 
 |  |  |                     <FilterListItem | 
 |  |  |                         label="filters.lastMonth" | 
 |  |  |                         value={{ | 
 |  |  |                             timeStart: subMonths(startOfMonth(new Date()), 1).toISOString(), | 
 |  |  |                             timeEnd: startOfMonth(new Date()).toISOString(), | 
 |  |  |                         }} | 
 |  |  |                     /> | 
 |  |  |                     <FilterListItem | 
 |  |  |                         label="filters.earlier" | 
 |  |  |                         value={{ | 
 |  |  |                             timeStart: undefined, | 
 |  |  |                             timeEnd: subMonths(startOfMonth(new Date()), 1).toISOString(), | 
 |  |  |                         }} | 
 |  |  |                     /> | 
 |  |  |                 </FilterList> | 
 |  |  |  | 
 |  |  |                     <FilterList label="table.field.user.sex" icon={<WcIcon />}> | 
 |  |  |                         <FilterListItem label="Male" value={{ sex: '1' }} /> | 
 |  |  |                         <FilterListItem label="Female" value={{ sex: '2' }} /> | 
 |  |  |                         <FilterListItem label="They" value={{ sex: '0' }} /> | 
 |  |  |                     </FilterList> | 
 |  |  |                 <FilterList label="table.field.user.sex" icon={<WcIcon />}> | 
 |  |  |                     <FilterListItem label="table.field.user.sexes.female" value={{ sex: '2' }} /> | 
 |  |  |                     <FilterListItem label="table.field.user.sexes.male" value={{ sex: '1' }} /> | 
 |  |  |                     <FilterListItem label="table.field.user.sexes.unknown" value={{ sex: '0' }} /> | 
 |  |  |                 </FilterList> | 
 |  |  |  | 
 |  |  |                     <FilterList label="Categories" icon={<CategoryIcon />}> | 
 |  |  |                         <FilterListItem | 
 |  |  |                             label="Tests" | 
 |  |  |                             value={{ category: 'tests' }} | 
 |  |  |                             isSelected={isSelected} | 
 |  |  |                             toggleFilter={toggleFilter} | 
 |  |  |                         /> | 
 |  |  |                         <FilterListItem | 
 |  |  |                             label="News" | 
 |  |  |                             value={{ category: 'news' }} | 
 |  |  |                             isSelected={isSelected} | 
 |  |  |                             toggleFilter={toggleFilter} | 
 |  |  |                         /> | 
 |  |  |                         <FilterListItem | 
 |  |  |                             label="Deals" | 
 |  |  |                             value={{ category: 'deals' }} | 
 |  |  |                             isSelected={isSelected} | 
 |  |  |                             toggleFilter={toggleFilter} | 
 |  |  |                         /> | 
 |  |  |                     </FilterList> | 
 |  |  |                 </CardContent> | 
 |  |  |             </Card> | 
 |  |  |         </> | 
 |  |  |                 <FilterList label="table.field.user.role" icon={<StyleIcon />}> | 
 |  |  |                     {roles.map(role => { | 
 |  |  |                         return ( | 
 |  |  |                             <FilterListItem | 
 |  |  |                                 key={role.id} | 
 |  |  |                                 label={`${role.name}`} | 
 |  |  |                                 value={{ roleId: role.id }} | 
 |  |  |                                 isSelected={isSelected} | 
 |  |  |                                 toggleFilter={toggleFilter} | 
 |  |  |                             /> | 
 |  |  |                         ) | 
 |  |  |                     })} | 
 |  |  |                 </FilterList> | 
 |  |  |  | 
 |  |  |             </CardContent> | 
 |  |  |         </Card> | 
 |  |  |     ) | 
 |  |  | } | 
 |  |  |  |