11// Libraries
2- import React , { FC , useEffect , useState } from 'react'
2+ import React , { FC , useContext , useEffect , useState } from 'react'
33import { useDispatch , useSelector } from 'react-redux'
44
55// Components
@@ -13,13 +13,14 @@ import {
1313import LabeledData from 'src/organizations/components/OrgProfileTab/LabeledData'
1414import CopyableLabeledData from 'src/organizations/components/OrgProfileTab/CopyableLabeledData'
1515import { DeletePanel } from 'src/organizations/components/OrgProfileTab/DeletePanel'
16+ import { LeaveOrgButton } from 'src/organizations/components/OrgProfileTab/LeaveOrg'
1617
1718// Notifications
1819import { orgDetailsFetchError } from 'src/shared/copy/notifications'
1920import { notify } from 'src/shared/actions/notifications'
2021
2122// Providers
22- import UsersProvider from 'src/users/context/users'
23+ import { UsersContext , UsersProvider } from 'src/users/context/users'
2324
2425// Selectors
2526import { getMe } from 'src/me/selectors'
@@ -35,6 +36,9 @@ import {RemoteDataState} from 'src/types'
3536// Constants
3637import { CLOUD } from 'src/shared/constants'
3738
39+ // Utils
40+ import { isFlagEnabled } from 'src/shared/utils/featureFlag'
41+
3842// Styles
3943import 'src/organizations/components/OrgProfileTab/style.scss'
4044
@@ -43,6 +47,7 @@ const OrgProfileTab: FC = () => {
4347 const org = useSelector ( getOrg )
4448 const quartzOrg = useSelector ( selectCurrentOrg )
4549 const dispatch = useDispatch ( )
50+ const { users} = useContext ( UsersContext )
4651
4752 // Data about the user's organization is intentionally re-fetched when this component mounts again.
4853 const [ orgDetailsStatus , setOrgDetailsStatus ] = useState (
@@ -73,6 +78,8 @@ const OrgProfileTab: FC = () => {
7378 retrieveOrgDetails ( )
7479 } , [ dispatch , orgDetailsStatus , quartzOrg . id ] )
7580
81+ const allowSelfRemoval = users . length > 1
82+ const showLeaveOrgButton = isFlagEnabled ( 'createDeleteOrgs' )
7683 const hasFetchedOrgDetails = orgDetailsStatus === RemoteDataState . Done
7784
7885 const OrgProfile = ( ) => (
@@ -134,10 +141,10 @@ const OrgProfileTab: FC = () => {
134141
135142 return (
136143 < FlexBox
137- direction = { FlexDirection . Column }
138144 alignItems = { AlignItems . FlexStart }
139- testID = "organization-profile--panel"
145+ direction = { FlexDirection . Column }
140146 margin = { ComponentSize . Large }
147+ testID = "organization-profile--panel"
141148 >
142149 < FlexBox
143150 direction = { FlexDirection . Row }
@@ -149,11 +156,18 @@ const OrgProfileTab: FC = () => {
149156 </ FlexBox >
150157
151158 { CLOUD && orgDetailsLoaded && (
152- < FlexBox . Child className = "org-profile-tab--section" >
159+ < FlexBox
160+ className = "org-profile-tab--section"
161+ direction = { FlexDirection . Row }
162+ stretchToFitWidth = { true }
163+ >
153164 < UsersProvider >
154- < DeletePanel />
165+ < >
166+ { allowSelfRemoval && showLeaveOrgButton && < LeaveOrgButton /> }
167+ < DeletePanel />
168+ </ >
155169 </ UsersProvider >
156- </ FlexBox . Child >
170+ </ FlexBox >
157171 ) }
158172 </ FlexBox >
159173 )
0 commit comments