Skip to content

Commit 52c0361

Browse files
authored
feat(OrgProfileTab): add Leave Org button in Org settings page (#6437)
* chore: remove Leave Account btn from AccountPage * feat: add Leave Org btn to OrgProfileTab * fix: display delete org and leave org btns in row * chore: removed comments * chore: update name of leaveOrg component * chore: add Leave org button back in Account page * feat: create a component for Leave Org * chore: update self removal condition * fix: spelling fix * fix: replace idpe selectors with identity selectors * fix: prettier * chore: update removeUser function name * chore: update removeUser context name
1 parent a412627 commit 52c0361

File tree

8 files changed

+107
-57
lines changed

8 files changed

+107
-57
lines changed

src/accounts/AccountPage.tsx

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
// Libraries
22
import React, {ChangeEvent, FC, useContext, useEffect, useState} from 'react'
3-
import {useSelector} from 'react-redux'
43

54
import {
65
Button,
7-
ButtonShape,
8-
ComponentColor,
96
ComponentSize,
10-
ConfirmationButton,
117
FlexBox,
128
FlexDirection,
139
Input,
1410
InputType,
1511
Overlay,
1612
Page,
1713
} from '@influxdata/clockface'
14+
import {LeaveOrgButton} from 'src/organizations/components/OrgProfileTab/LeaveOrg'
1815

19-
import {getMe} from 'src/me/selectors'
16+
// Context
2017
import {UsersContext, UsersProvider} from 'src/users/context/users'
2118

2219
// Utils
@@ -31,19 +28,12 @@ import CancelServiceProvider from 'src/billing/components/PayAsYouGo/CancelServi
3128

3229
// Styles
3330
import './AccountPageStyles.scss'
34-
import {CLOUD_URL} from 'src/shared/constants'
35-
36-
const leaveBtnStyle = {
37-
width: 'auto',
38-
marginTop: 32,
39-
paddingLeft: '8px',
40-
paddingRight: '8px',
41-
}
4231

4332
const AccountAboutPage: FC = () => {
4433
const {userAccounts, handleRenameActiveAccount} =
4534
useContext(UserAccountContext)
46-
const {users, handleRemoveUser} = useContext(UsersContext)
35+
36+
const {users} = useContext(UsersContext)
4737

4838
const [isDeactivateAccountVisible, setDeactivateAccountVisible] =
4939
useState(false)
@@ -61,32 +51,8 @@ const AccountAboutPage: FC = () => {
6151
setActiveAcctName(evt.target.value)
6252
}
6353

64-
const currentUserId = useSelector(getMe)?.id
65-
66-
const handleRemove = () => {
67-
handleRemoveUser(currentUserId)
68-
window.location.href = CLOUD_URL
69-
}
70-
71-
const allowSelfRemoval = users.length > 1
72-
73-
const leaveAcctBtn = (
74-
<ConfirmationButton
75-
confirmationLabel="This action will remove yourself from accessing this organization"
76-
confirmationButtonText="Leave Account"
77-
titleText="Leave Account"
78-
text="Leave Account"
79-
confirmationButtonColor={ComponentColor.Danger}
80-
color={ComponentColor.Default}
81-
shape={ButtonShape.Square}
82-
onConfirm={handleRemove}
83-
testID="delete-user"
84-
style={leaveBtnStyle}
85-
/>
86-
)
87-
8854
const inputStyle = {width: 250}
89-
const labelStyle = {marginBottom: 8, maxWidth: '500px'}
55+
const labelStyle = {marginBottom: '10px', maxWidth: '500px'}
9056
const dividerStyle = {marginTop: '32px', maxWidth: '500px'}
9157
const actionButtonStyle = {marginTop: '24px'}
9258

@@ -103,7 +69,8 @@ const AccountAboutPage: FC = () => {
10369
}
10470

10571
const showDeactivateAccountSection = isFlagEnabled('freeAccountCancellation')
106-
const showLeaveAcctBtn = !isFlagEnabled('createDeleteOrgs')
72+
const showLeaveOrgButton = !isFlagEnabled('createDeleteOrgs')
73+
const allowSelfRemoval = users.length > 1
10774

10875
return (
10976
<AccountTabContainer activeTab="settings">
@@ -131,7 +98,12 @@ const AccountAboutPage: FC = () => {
13198
text="Save"
13299
/>
133100
</FlexBox>
134-
{allowSelfRemoval && showLeaveAcctBtn && leaveAcctBtn}
101+
{allowSelfRemoval && showLeaveOrgButton && (
102+
<>
103+
<hr style={dividerStyle} />
104+
<LeaveOrgButton />
105+
</>
106+
)}
135107
{showDeactivateAccountSection && (
136108
<>
137109
<hr style={dividerStyle} />
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.account-settings--header {
2-
margin-bottom: 16px;
2+
margin-bottom: 25px;
33
}

src/organizations/components/OrgProfileTab/DeletePanel.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ const DeleteOrgButton: FC = () => {
187187
Delete the <b>{org.name}</b> organization and remove any data that you
188188
have loaded.
189189
</p>
190-
</FlexBox.Child>
191-
<FlexBox.Child>
192190
<>
193191
{!orgCanBeSuspended && (
194192
<Popover
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Libraries
2+
import React, {FC, useContext} from 'react'
3+
import {useSelector} from 'react-redux'
4+
5+
// Components
6+
import {
7+
ButtonShape,
8+
ComponentColor,
9+
ConfirmationButton,
10+
FlexBox,
11+
IconFont,
12+
} from '@influxdata/clockface'
13+
14+
// Selector
15+
import {selectCurrentOrg, selectUser} from 'src/identity/selectors'
16+
17+
// Providers
18+
import {UsersContext} from 'src/users/context/users'
19+
20+
// Constants
21+
import {CLOUD_URL} from 'src/shared/constants'
22+
23+
// Styles
24+
import 'src/organizations/components/OrgProfileTab/style.scss'
25+
26+
export const LeaveOrgButton: FC = () => {
27+
const org = useSelector(selectCurrentOrg)
28+
const currentUserId = useSelector(selectUser)?.id
29+
const {removeUser} = useContext(UsersContext)
30+
31+
const handleRemoveUser = () => {
32+
removeUser(currentUserId)
33+
window.location.href = CLOUD_URL
34+
}
35+
36+
return (
37+
<>
38+
<FlexBox.Child>
39+
<h4>Leave Organization</h4>
40+
<p className="org-profile-tab--heading org-profile-tab--deleteHeading">
41+
Leave the <b>{org.name}</b> organization.
42+
</p>
43+
<ConfirmationButton
44+
className="org-profile-tab--leaveOrgButton"
45+
color={ComponentColor.Default}
46+
confirmationButtonColor={ComponentColor.Danger}
47+
confirmationButtonText="Leave Organization"
48+
confirmationLabel="This action will remove yourself from accessing this organization"
49+
icon={IconFont.Logout}
50+
onConfirm={handleRemoveUser}
51+
shape={ButtonShape.Square}
52+
testID="delete-user"
53+
text="Leave Organization"
54+
titleText="Leave Organization"
55+
/>
56+
</FlexBox.Child>
57+
</>
58+
)
59+
}

src/organizations/components/OrgProfileTab/index.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Libraries
2-
import React, {FC, useEffect, useState} from 'react'
2+
import React, {FC, useContext, useEffect, useState} from 'react'
33
import {useDispatch, useSelector} from 'react-redux'
44

55
// Components
@@ -13,13 +13,14 @@ import {
1313
import LabeledData from 'src/organizations/components/OrgProfileTab/LabeledData'
1414
import CopyableLabeledData from 'src/organizations/components/OrgProfileTab/CopyableLabeledData'
1515
import {DeletePanel} from 'src/organizations/components/OrgProfileTab/DeletePanel'
16+
import {LeaveOrgButton} from 'src/organizations/components/OrgProfileTab/LeaveOrg'
1617

1718
// Notifications
1819
import {orgDetailsFetchError} from 'src/shared/copy/notifications'
1920
import {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
2526
import {getMe} from 'src/me/selectors'
@@ -35,6 +36,9 @@ import {RemoteDataState} from 'src/types'
3536
// Constants
3637
import {CLOUD} from 'src/shared/constants'
3738

39+
// Utils
40+
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
41+
3842
// Styles
3943
import '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
)

src/organizations/components/OrgProfileTab/style.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@
1919
margin-bottom: $cf-space-l;
2020
margin-right: $cf-space-3xl;
2121
flex-shrink: 0;
22+
flex-wrap: wrap;
2223
}
2324

2425
.org-profile-tab--copyableText {
2526
min-width: 500px;
2627
}
28+
29+
.org-profile-tab--leaveOrgButton {
30+
width: auto !important;
31+
padding-left: 8px;
32+
padding-right: 8px;
33+
}

src/users/components/UserListItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const formatName = (firstName: string | null, lastName: string | null) => {
4141

4242
const UserListItem: FC<Props> = ({user, isDeletable}) => {
4343
const {email, firstName, lastName, role} = user
44-
const {handleRemoveUser, removeUserStatus} = useContext(UsersContext)
44+
const {removeUser, removeUserStatus} = useContext(UsersContext)
4545

4646
const [revealOnHover, toggleRevealOnHover] = useState(true)
4747

@@ -54,7 +54,7 @@ const UserListItem: FC<Props> = ({user, isDeletable}) => {
5454
}
5555

5656
const handleRemove = () => {
57-
handleRemoveUser(user.id)
57+
removeUser(user.id)
5858
}
5959

6060
let status = ComponentStatus.Default

src/users/context/users.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface UsersContextType {
4343
draftInvite: DraftInvite
4444
handleEditDraftInvite: (_: DraftInvite) => void
4545
handleInviteUser: () => void
46-
handleRemoveUser: (userId: string) => void
46+
removeUser: (userId: string) => void
4747
handleResendInvite: (inviteId: number) => void
4848
handleWithdrawInvite: (inviteId: number) => void
4949
invites: Invite[]
@@ -62,7 +62,7 @@ export const DEFAULT_CONTEXT: UsersContextType = {
6262
draftInvite: draft,
6363
handleEditDraftInvite: (_draftInvite: DraftInvite) => {},
6464
handleInviteUser: () => {},
65-
handleRemoveUser: (_userId: string) => {},
65+
removeUser: (_userId: string) => {},
6666
handleResendInvite: (_inviteId: number) => {},
6767
handleWithdrawInvite: (_inviteId: number) => {},
6868
invites: [],
@@ -207,7 +207,7 @@ export const UsersProvider: FC<Props> = React.memo(({children}) => {
207207
[dispatch, invites, orgId]
208208
)
209209

210-
const handleRemoveUser = useCallback(
210+
const removeUser = useCallback(
211211
async (userId: string) => {
212212
try {
213213
setRemoveUserStatus({
@@ -250,7 +250,7 @@ export const UsersProvider: FC<Props> = React.memo(({children}) => {
250250
draftInvite,
251251
handleEditDraftInvite,
252252
handleInviteUser,
253-
handleRemoveUser,
253+
removeUser,
254254
handleResendInvite,
255255
handleWithdrawInvite,
256256
invites,

0 commit comments

Comments
 (0)