1
1
import React , { useEffect , useState } from "react" ;
2
- import { capitalize , formatOS , timeAgo } from "../utils/common" ;
2
+ import { capitalize , formatOS , isLocalDev , isNetBirdHosted , timeAgo } from "../utils/common" ;
3
3
import { useDispatch , useSelector } from "react-redux" ;
4
4
import { RootState } from "typesafe-actions" ;
5
5
import { actions as peerActions } from "../store/peer" ;
@@ -79,6 +79,7 @@ export const Peers = () => {
79
79
( state : RootState ) => state . peer . updateGroupsVisible
80
80
) ;
81
81
const users = useSelector ( ( state : RootState ) => state . user . data ) ;
82
+ const account = useSelector ( ( state : RootState ) => state . account . data ) ;
82
83
const [ addPeerModalOpen , setAddPeerModalOpen ] = useState ( false ) ;
83
84
const { oidcUser } = useOidcUser ( ) ;
84
85
const [ isAdmin , setIsAdmin ] = useState ( false ) ;
@@ -100,6 +101,7 @@ export const Peers = () => {
100
101
const optionsOnOff = [
101
102
{ label : "Online" , value : "on" } ,
102
103
{ label : "All" , value : "all" } ,
104
+ // ...((isNetBirdHosted() || isLocalDev()) && account[0].settings.extra.peer_approval_enabled ? [{ label: "Needs approval", value: "approval" }] : []),
103
105
] ;
104
106
105
107
const transformDataTable = ( d : Peer [ ] ) : PeerDataTable [ ] => {
@@ -291,6 +293,16 @@ export const Peers = () => {
291
293
) ;
292
294
} ) as Peer [ ] ;
293
295
296
+ // switch (optionOnOff) {
297
+ // case "on":
298
+ // f = filter(f, (f: Peer) => f.connected);
299
+ // break;
300
+ // case "approval":
301
+ // f = filter(f, (f: Peer) => f.approval_required);
302
+ // break;
303
+ // default:
304
+ // break;
305
+ // }
294
306
if ( optionOnOff === "on" ) {
295
307
f = filter ( f , ( f : Peer ) => f . connected ) ;
296
308
}
@@ -410,6 +422,36 @@ export const Peers = () => {
410
422
} ) ;
411
423
} ;
412
424
425
+ const showConfirmApprove = ( record : PeerDataTable ) => {
426
+ setPeerToAction ( record ) ;
427
+
428
+ let content = (
429
+ < Paragraph >
430
+ Are you sure you want to approve this peer?
431
+ </ Paragraph >
432
+ ) ;
433
+
434
+ let name = record ? record . name : "" ;
435
+ confirmModal . confirm ( {
436
+ icon : < ExclamationCircleOutlined /> ,
437
+ title : < span className = "font-500" > Approve peer { name } </ span > ,
438
+ width : 600 ,
439
+ content : content ,
440
+ onOk ( ) {
441
+ record . approval_required = false
442
+ dispatch (
443
+ peerActions . updatePeer . request ( {
444
+ getAccessTokenSilently : getTokenSilently ,
445
+ payload : record ,
446
+ } )
447
+ ) ;
448
+ } ,
449
+ onCancel ( ) {
450
+ setPeerToAction ( null ) ;
451
+ } ,
452
+ } ) ;
453
+ } ;
454
+
413
455
const showConfirmEnableSSH = ( record : PeerDataTable ) => {
414
456
confirmModal . confirm ( {
415
457
icon : < ExclamationCircleOutlined /> ,
@@ -601,6 +643,19 @@ export const Peers = () => {
601
643
""
602
644
) ;
603
645
646
+ let approval = peer . approval_required ? (
647
+ < Tooltip title = "The peer needs to be approved by an administrator before it can connect to other peers" >
648
+ < Tag color = "gold" >
649
+ < Text
650
+ style = { { fontSize : "10px" , color : "rgba(212, 136, 6, 1)" } }
651
+ type = { "secondary" }
652
+ > needs approval</ Text >
653
+ </ Tag >
654
+ </ Tooltip >
655
+ ) : (
656
+ ""
657
+ ) ;
658
+
604
659
const userEmail = users ?. find ( ( u ) => u . id === peer . user_id ) ?. email ;
605
660
let expiry = ! peer . login_expiration_enabled ? (
606
661
< Tag >
@@ -622,9 +677,9 @@ export const Peers = () => {
622
677
< Row >
623
678
< Text className = "font-500" > { status } </ Text >
624
679
</ Row >
625
- < Row > { loginExpire } </ Row >
626
680
</ span >
627
681
</ Button >
682
+ < Row > { loginExpire } </ Row >
628
683
</ >
629
684
) ;
630
685
}
@@ -643,11 +698,18 @@ export const Peers = () => {
643
698
< Row >
644
699
< Text type = "secondary" > { userEmail } </ Text >
645
700
</ Row >
646
- < Row style = { { minWidth : "195px" } } >
647
- { expiry } { loginExpire }
648
- </ Row >
649
701
</ span >
650
702
</ Button >
703
+ < Row style = { { minWidth : "195px" , paddingLeft : "15px" } } >
704
+ { expiry } { loginExpire } < Button
705
+ type = "text"
706
+ style = { { height : "auto" , whiteSpace : "normal" , textAlign : "center" , padding : "0px" , margin : "0px" } }
707
+ onClick = { ( ) => showConfirmApprove ( peer ) }
708
+ className = { ! isAdmin ? "nohover" : "" }
709
+ >
710
+ { approval }
711
+ </ Button >
712
+ </ Row >
651
713
</ div >
652
714
) ;
653
715
} ;
0 commit comments