1- import { forwardRef , useEffect , useState } from 'react'
2- import { useDispatch , useSelector } from 'react-redux'
31import moment from 'moment/moment'
42import PropTypes from 'prop-types'
3+ import { forwardRef , useEffect , useState } from 'react'
4+ import { useSelector } from 'react-redux'
55
66// material-ui
77import {
88 Box ,
9+ Checkbox ,
10+ FormControl ,
11+ IconButton ,
12+ InputLabel ,
13+ ListItemButton ,
14+ ListItemText ,
15+ MenuItem ,
16+ OutlinedInput ,
17+ Paper ,
18+ Select ,
919 Skeleton ,
1020 Stack ,
1121 Table ,
1222 TableBody ,
1323 TableContainer ,
1424 TableHead ,
1525 TableRow ,
16- Paper ,
17- IconButton ,
18- useTheme ,
19- Checkbox ,
20- Button ,
21- OutlinedInput ,
22- MenuItem ,
23- Select ,
24- InputLabel ,
25- FormControl ,
26- ListItemText ,
27- ListItemButton
26+ useTheme
2827} from '@mui/material'
2928
3029// project imports
31- import MainCard from '@/ui-component/cards/MainCard'
32- import ConfirmDialog from '@/ui-component/dialog/ConfirmDialog'
33- import ViewHeader from '@/layout/MainLayout/ViewHeader'
3430import ErrorBoundary from '@/ErrorBoundary'
31+ import ViewHeader from '@/layout/MainLayout/ViewHeader'
32+ import MainCard from '@/ui-component/cards/MainCard'
3533import { StyledTableCell , StyledTableRow } from '@/ui-component/table/TableStyles'
3634import DatePicker from 'react-datepicker'
3735import 'react-datepicker/dist/react-datepicker.css'
@@ -41,18 +39,15 @@ import auditApi from '@/api/audit'
4139
4240// Hooks
4341import useApi from '@/hooks/useApi'
44- import useConfirm from '@/hooks/useConfirm'
4542
4643// utils
4744import useNotifier from '@/utils/useNotifier'
4845
4946// Icons
50- import { IconCircleX , IconChevronLeft , IconChevronRight , IconTrash , IconX , IconLogin , IconLogout } from '@tabler/icons-react'
47+ import { IconChevronLeft , IconChevronRight , IconCircleX , IconLogin , IconLogout } from '@tabler/icons-react'
5148
5249// store
5350import { useError } from '@/store/context/ErrorContext'
54- import { enqueueSnackbar as enqueueSnackbarAction , closeSnackbar as closeSnackbarAction } from '@/store/actions'
55- import { PermissionButton } from '@/ui-component/button/RBACButtons'
5651
5752const activityTypes = [
5853 'Login Success' ,
@@ -93,17 +88,11 @@ DatePickerCustomInput.propTypes = {
9388const LoginActivity = ( ) => {
9489 const theme = useTheme ( )
9590 const customization = useSelector ( ( state ) => state . customization )
96- const dispatch = useDispatch ( )
9791 useNotifier ( )
9892 const { error, setError } = useError ( )
9993
100- const enqueueSnackbar = ( ...args ) => dispatch ( enqueueSnackbarAction ( ...args ) )
101- const closeSnackbar = ( ...args ) => dispatch ( closeSnackbarAction ( ...args ) )
102-
10394 const [ isLoading , setLoading ] = useState ( true )
10495
105- const { confirm } = useConfirm ( )
106-
10796 const getLoginActivityApi = useApi ( auditApi . fetchLoginActivity )
10897 const [ activity , setActivity ] = useState ( [ ] )
10998 const [ typeFilter , setTypeFilter ] = useState ( [ ] )
@@ -114,8 +103,6 @@ const LoginActivity = () => {
114103 const [ startDate , setStartDate ] = useState ( new Date ( new Date ( ) . setMonth ( new Date ( ) . getMonth ( ) - 1 ) ) )
115104 const [ endDate , setEndDate ] = useState ( new Date ( ) )
116105
117- const [ selected , setSelected ] = useState ( [ ] )
118-
119106 const onStartDateSelected = ( date ) => {
120107 setStartDate ( date )
121108 refreshData ( currentPage , date , endDate , typeFilter )
@@ -126,31 +113,6 @@ const LoginActivity = () => {
126113 refreshData ( currentPage , startDate , date , typeFilter )
127114 }
128115
129- const onSelectAllClick = ( event ) => {
130- if ( event . target . checked ) {
131- const newSelected = activity . map ( ( n ) => n . id )
132- setSelected ( newSelected )
133- return
134- }
135- setSelected ( [ ] )
136- }
137-
138- const handleSelect = ( event , id ) => {
139- const selectedIndex = selected . indexOf ( id )
140- let newSelected = [ ]
141-
142- if ( selectedIndex === - 1 ) {
143- newSelected = newSelected . concat ( selected , id )
144- } else if ( selectedIndex === 0 ) {
145- newSelected = newSelected . concat ( selected . slice ( 1 ) )
146- } else if ( selectedIndex === selected . length - 1 ) {
147- newSelected = newSelected . concat ( selected . slice ( 0 , - 1 ) )
148- } else if ( selectedIndex > 0 ) {
149- newSelected = newSelected . concat ( selected . slice ( 0 , selectedIndex ) , selected . slice ( selectedIndex + 1 ) )
150- }
151- setSelected ( newSelected )
152- }
153-
154116 const refreshData = ( _page , _start , _end , _filter ) => {
155117 const activityCodes = [ ]
156118 if ( _filter . length > 0 ) {
@@ -219,59 +181,6 @@ const LoginActivity = () => {
219181 }
220182 }
221183
222- const deleteLoginActivity = async ( ) => {
223- const confirmPayload = {
224- title : `Delete` ,
225- description : `Delete ${ selected . length } ${ selected . length > 1 ? 'records' : 'record' } ? ` ,
226- confirmButtonName : 'Delete' ,
227- cancelButtonName : 'Cancel'
228- }
229- const isConfirmed = await confirm ( confirmPayload )
230- //
231- if ( isConfirmed ) {
232- try {
233- const deleteResp = await auditApi . deleteLoginActivity ( {
234- selected : selected
235- } )
236- if ( deleteResp . data ) {
237- enqueueSnackbar ( {
238- message : selected . length + ' Login Activity Records Deleted Successfully' ,
239- options : {
240- key : new Date ( ) . getTime ( ) + Math . random ( ) ,
241- variant : 'success' ,
242- action : ( key ) => (
243- < Button style = { { color : 'white' } } onClick = { ( ) => closeSnackbar ( key ) } >
244- < IconX />
245- </ Button >
246- )
247- }
248- } )
249- onConfirm ( )
250- }
251- } catch ( error ) {
252- enqueueSnackbar ( {
253- message : `Failed to delete records: ${
254- typeof error . response . data === 'object' ? error . response . data . message : error . response . data
255- } `,
256- options : {
257- key : new Date ( ) . getTime ( ) + Math . random ( ) ,
258- variant : 'error' ,
259- persist : true ,
260- action : ( key ) => (
261- < Button style = { { color : 'white' } } onClick = { ( ) => closeSnackbar ( key ) } >
262- < IconX />
263- </ Button >
264- )
265- }
266- } )
267- }
268- }
269- }
270-
271- const onConfirm = ( ) => {
272- getLoginActivityApi . request ( )
273- }
274-
275184 useEffect ( ( ) => {
276185 getLoginActivityApi . request ( {
277186 pageNo : 1
@@ -298,7 +207,6 @@ const LoginActivity = () => {
298207 setStart ( data . currentPage * data . pageSize - ( data . pageSize - 1 ) )
299208 setEnd ( data . currentPage * data . pageSize > data . count ? data . count : data . currentPage * data . pageSize )
300209 setActivity ( data . data )
301- setSelected ( [ ] )
302210 }
303211 } , [ getLoginActivityApi . data ] )
304212
@@ -447,17 +355,6 @@ const LoginActivity = () => {
447355 />
448356 </ IconButton >
449357 </ div >
450- < PermissionButton
451- permissionId = { 'loginActivity:delete' }
452- sx = { { mt : 1 , mb : 2 } }
453- variant = 'outlined'
454- disabled = { selected . length === 0 }
455- onClick = { deleteLoginActivity }
456- color = 'error'
457- startIcon = { < IconTrash /> }
458- >
459- { 'Delete Selected' }
460- </ PermissionButton >
461358 </ div >
462359 </ div >
463360 < TableContainer
@@ -475,13 +372,6 @@ const LoginActivity = () => {
475372 } }
476373 >
477374 < TableRow >
478- < StyledTableCell style = { { width : '5%' } } >
479- < Checkbox
480- color = 'primary'
481- checked = { selected . length === ( activity || [ ] ) . length }
482- onChange = { onSelectAllClick }
483- />
484- </ StyledTableCell >
485375 < StyledTableCell > Activity</ StyledTableCell >
486376 < StyledTableCell > User</ StyledTableCell >
487377 < StyledTableCell > Date</ StyledTableCell >
@@ -508,15 +398,6 @@ const LoginActivity = () => {
508398 < StyledTableCell >
509399 < Skeleton variant = 'text' />
510400 </ StyledTableCell >
511- < StyledTableCell >
512- < Skeleton variant = 'text' />
513- </ StyledTableCell >
514- < StyledTableCell >
515- < Skeleton variant = 'text' />
516- </ StyledTableCell >
517- < StyledTableCell >
518- < Skeleton variant = 'text' />
519- </ StyledTableCell >
520401 </ StyledTableRow >
521402 < StyledTableRow >
522403 < StyledTableCell >
@@ -534,12 +415,6 @@ const LoginActivity = () => {
534415 < StyledTableCell >
535416 < Skeleton variant = 'text' />
536417 </ StyledTableCell >
537- < StyledTableCell >
538- < Skeleton variant = 'text' />
539- </ StyledTableCell >
540- < StyledTableCell >
541- < Skeleton variant = 'text' />
542- </ StyledTableCell >
543418 </ StyledTableRow >
544419 </ >
545420 ) : (
@@ -550,13 +425,6 @@ const LoginActivity = () => {
550425 key = { index }
551426 sx = { { '&:last-child td, &:last-child th' : { border : 0 } } }
552427 >
553- < StyledTableCell component = 'th' scope = 'row' style = { { width : '5%' } } >
554- < Checkbox
555- color = 'primary'
556- checked = { selected . indexOf ( item . id ) !== - 1 }
557- onChange = { ( event ) => handleSelect ( event , item . id ) }
558- />
559- </ StyledTableCell >
560428 < StyledTableCell component = 'th' scope = 'row' >
561429 < div
562430 style = { {
@@ -630,7 +498,6 @@ const LoginActivity = () => {
630498 </ Stack >
631499 ) }
632500 </ MainCard >
633- < ConfirmDialog />
634501 </ >
635502 )
636503}
0 commit comments