11// Libraries
22import React , { FC , useContext , useEffect , useState } from 'react'
3+ import { useSelector } from 'react-redux'
4+
35import {
46 Button ,
7+ ButtonShape ,
8+ ComponentColor ,
59 ComponentSize ,
10+ ConfirmationButton ,
611 FlexBox ,
712 FlexDirection ,
813 IconFont ,
@@ -12,7 +17,11 @@ import {
1217 Page ,
1318} from '@influxdata/clockface'
1419
20+ import { getMe } from 'src/me/selectors'
21+ import { UsersContext } from 'src/users/context/users'
22+
1523// Utils
24+ import { isFlagEnabled } from 'src/shared/utils/featureFlag'
1625import { pageTitleSuffixer } from 'src/shared/utils/pageTitles'
1726import {
1827 UserAccountContext ,
@@ -24,15 +33,24 @@ import AccountHeader from 'src/accounts/AccountHeader'
2433import { SwitchAccountOverlay } from 'src/accounts/SwitchAccountOverlay'
2534import CancellationOverlay from './CancellationOverlay'
2635import CancelServiceProvider from 'src/billing/components/PayAsYouGo/CancelServiceContext'
27- import { isFlagEnabled } from 'src/shared/utils/featureFlag'
2836
2937// Styles
3038import './AccountPageStyles.scss'
39+ import { CLOUD_URL } from 'src/shared/constants'
40+
41+ const leaveBtnStyle = {
42+ width : 'auto' ,
43+ marginTop : 32 ,
44+ paddingLeft : '8px' ,
45+ paddingRight : '8px' ,
46+ }
3147
3248const AccountAboutPage : FC = ( ) => {
3349 const { userAccounts, handleRenameActiveAccount} = useContext (
3450 UserAccountContext
3551 )
52+ const { users, handleRemoveUser} = useContext ( UsersContext )
53+
3654 const [ isSwitchAccountVisible , setSwitchAccountVisible ] = useState ( false )
3755 const [ isDeactivateAccountVisible , setDeactivateAccountVisible ] = useState (
3856 false
@@ -69,6 +87,30 @@ const AccountAboutPage: FC = () => {
6987 const closeSwitchAccountDialog = ( ) => {
7088 setSwitchAccountVisible ( false )
7189 }
90+ const currentUserId = useSelector ( getMe ) ?. id
91+
92+ const handleRemove = ( ) => {
93+ handleRemoveUser ( currentUserId )
94+ window . location . href = CLOUD_URL
95+ }
96+
97+ const allowSelfRemoval =
98+ isFlagEnabled ( 'selfRemovalFromAccount' ) && users . length > 1
99+
100+ const leaveAcctBtn = (
101+ < ConfirmationButton
102+ confirmationLabel = "This action will remove yourself from accessing this organization"
103+ confirmationButtonText = "Leave Account"
104+ titleText = "Leave Account"
105+ text = "Leave Account"
106+ confirmationButtonColor = { ComponentColor . Danger }
107+ color = { ComponentColor . Default }
108+ shape = { ButtonShape . Square }
109+ onConfirm = { handleRemove }
110+ testID = "delete-user"
111+ style = { leaveBtnStyle }
112+ />
113+ )
72114
73115 const inputStyle = { width : 250 }
74116 const labelStyle = { marginBottom : 8 , maxWidth : '500px' }
@@ -127,6 +169,7 @@ const AccountAboutPage: FC = () => {
127169 text = "Save"
128170 />
129171 </ FlexBox >
172+ { allowSelfRemoval && leaveAcctBtn }
130173 { showDeactivateAccountSection && (
131174 < >
132175 < hr style = { dividerStyle } />
0 commit comments