File tree Expand file tree Collapse file tree 1 file changed +23
-16
lines changed
Expand file tree Collapse file tree 1 file changed +23
-16
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ export const ActionButtons: React.FunctionComponent = () => {
1010 const props = useGridSlotComponentProps ( ) ;
1111 const { enqueueSnackbar } = useSnackbar ( ) ;
1212 const userDispatch = useUserDispatch ( ) ;
13- const { userList } = useUserState ( ) ;
13+ const { userList, user } = useUserState ( ) ;
1414
1515 const ids : GridRowId [ ] = React . useMemo (
1616 ( ) => Object . values ( props . state . selection ) ,
@@ -23,22 +23,29 @@ export const ActionButtons: React.FunctionComponent = () => {
2323 < IconButton
2424 disabled = { ! ids . length }
2525 onClick = { ( ) => {
26- usersService
27- . remove ( ids )
28- . then ( ( ) => {
29- enqueueSnackbar ( `Removed` , {
30- variant : "success" ,
31- } ) ;
32- userDispatch ( {
33- type : "getAll" ,
34- payload : userList . filter ( ( user ) => ! ids . includes ( user . id ) ) ,
35- } ) ;
36- } )
37- . catch ( ( err ) =>
38- enqueueSnackbar ( err , {
39- variant : "error" ,
26+ const currentUserId = user ?. id ;
27+ if ( currentUserId && ids . includes ( currentUserId ) ) {
28+ enqueueSnackbar ( `You cannot delete yourself.` , {
29+ variant : "error" ,
30+ } ) ;
31+ } else {
32+ usersService
33+ . remove ( ids )
34+ . then ( ( ) => {
35+ enqueueSnackbar ( `Removed` , {
36+ variant : "success" ,
37+ } ) ;
38+ userDispatch ( {
39+ type : "getAll" ,
40+ payload : userList . filter ( ( user ) => ! ids . includes ( user . id ) ) ,
41+ } ) ;
4042 } )
41- ) ;
43+ . catch ( ( err ) =>
44+ enqueueSnackbar ( err , {
45+ variant : "error" ,
46+ } )
47+ ) ;
48+ }
4249 } }
4350 >
4451 < Delete />
You can’t perform that action at this time.
0 commit comments