1
1
import React , { useState } from 'react' ;
2
2
import { useTranslation } from 'react-i18next' ;
3
- import { useParams } from 'react-router-dom' ;
3
+ import { useHistory , useParams } from 'react-router-dom' ;
4
4
import moment from 'moment' ;
5
5
6
6
import { makeStyles } from '@material-ui/core/styles' ;
@@ -18,15 +18,19 @@ import {
18
18
import psono_server from '../../services/api-server' ;
19
19
import customInputStyle from '../../assets/jss/material-dashboard-react/customInputStyle' ;
20
20
import store from '../../services/store' ;
21
+ import DeleteConfirmDialog from '../../components/Dialog/DeleteConfirmDialog' ;
21
22
22
23
const useStyles = makeStyles ( customInputStyle ) ;
23
24
const UserEdit = ( ) => {
24
25
const classes = useStyles ( ) ;
25
26
const { t } = useTranslation ( ) ;
27
+ const history = useHistory ( ) ;
26
28
const { user_id } = useParams ( ) ;
27
29
const [ user , setUser ] = useState ( null ) ;
28
30
const [ errors , setErrors ] = useState ( [ ] ) ;
29
31
const [ msgs , setMsgs ] = useState ( [ ] ) ;
32
+ const [ deleteUserModalOpen , setDeleteUserModalOpen ] = useState ( false ) ;
33
+ const [ wipeUserModalOpen , setWipeUserModalOpen ] = useState ( false ) ;
30
34
31
35
React . useEffect ( ( ) => {
32
36
loadUser ( ) ;
@@ -448,6 +452,50 @@ const UserEdit = () => {
448
452
449
453
return (
450
454
< div >
455
+ { deleteUserModalOpen && (
456
+ < DeleteConfirmDialog
457
+ title = { t ( 'DELETE_USER_S' ) }
458
+ onConfirm = { ( ) => {
459
+ psono_server
460
+ . admin_delete_user (
461
+ store . getState ( ) . user . token ,
462
+ store . getState ( ) . user . session_secret_key ,
463
+ user . id
464
+ )
465
+ . then ( ( ) => {
466
+ history . push ( '/user/' ) ;
467
+ } ) ;
468
+ setDeleteUserModalOpen ( false ) ;
469
+ } }
470
+ onAbort = { ( ) => {
471
+ setDeleteUserModalOpen ( false ) ;
472
+ } }
473
+ >
474
+ { t ( 'DELETE_USER_CONFIRM_DIALOG' ) }
475
+ </ DeleteConfirmDialog >
476
+ ) }
477
+ { wipeUserModalOpen && (
478
+ < DeleteConfirmDialog
479
+ title = { t ( 'WIPE_USER_S' ) }
480
+ onConfirm = { ( ) => {
481
+ psono_server
482
+ . admin_wipe_user (
483
+ store . getState ( ) . user . token ,
484
+ store . getState ( ) . user . session_secret_key ,
485
+ user . id
486
+ )
487
+ . then ( ( ) => {
488
+ history . push ( '/user/' ) ;
489
+ } ) ;
490
+ setWipeUserModalOpen ( false ) ;
491
+ } }
492
+ onAbort = { ( ) => {
493
+ setWipeUserModalOpen ( false ) ;
494
+ } }
495
+ >
496
+ { t ( 'WIPE_USER_CONFIRM_DIALOG' ) }
497
+ </ DeleteConfirmDialog >
498
+ ) }
451
499
< Grid container >
452
500
< GridItem xs = { 12 } sm = { 12 } md = { 12 } >
453
501
< RegularCard
@@ -599,9 +647,26 @@ const UserEdit = () => {
599
647
</ div >
600
648
}
601
649
footer = {
602
- < Button color = "primary" onClick = { save } >
603
- { t ( 'SAVE' ) }
604
- </ Button >
650
+ < >
651
+ < Button color = "primary" onClick = { save } >
652
+ { t ( 'SAVE' ) }
653
+ </ Button >
654
+ < Button
655
+ onClick = { ( ) => setDeleteUserModalOpen ( true ) }
656
+ >
657
+ { t ( 'DELETE' ) }
658
+ </ Button >
659
+ { store . getState ( ) . server . type == 'EE' &&
660
+ user . authentication !== 'AUTHKEY' && (
661
+ < Button
662
+ onClick = { ( ) =>
663
+ setWipeUserModalOpen ( true )
664
+ }
665
+ >
666
+ { t ( 'WIPE' ) }
667
+ </ Button >
668
+ ) }
669
+ </ >
605
670
}
606
671
/>
607
672
</ GridItem >
0 commit comments