Skip to content

Commit a5e83c8

Browse files
authored
feat: 'remove users first' block on deleting orgs in payg/contract accounts (#6459)
* chore: remove warning notification * feat: show user count in delete org overlay * test: update test to show user count in overlay * feat: show warning for free users only * fix: only show user count if > 0 * fix: add default value for userCount
1 parent 88cb0a7 commit a5e83c8

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

cypress/e2e/cloud/about.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ const displayRemoveUsersWarning = () => {
172172
cy.url().should('include', `/members`)
173173
}
174174

175+
const displayOtherUsersWarning = () => {
176+
cy.getByTestID('delete-org--button').should('be.visible').click()
177+
cy.get('.org-delete-overlay--warning-message').within(() => {
178+
cy.contains('a', 'users in this organization').click()
179+
cy.url().should('include', `/members`)
180+
})
181+
}
182+
175183
const upgradeAccount = () => {
176184
cy.getByTestID('delete-org--button').should('be.visible').click()
177185
cy.getByTestID('popover--dialog')
@@ -291,15 +299,15 @@ describe('PAYG Account', () => {
291299
createOrg('pay_as_you_go')
292300
})
293301

294-
it('displays the `remove other users` popup if there are other orgs in the account, but the current org has other users in it', () => {
302+
it('when deleting an org with multiple users in a multi-org payg account, delete org overlay shows how many other users the org has and clicking it takes user to /members page', () => {
295303
setupTest({
296304
accountType: 'pay_as_you_go',
297305
canCreateOrgs: false,
298306
orgHasOtherUsers: true,
299307
orgIsSuspendable: true,
300308
})
301309

302-
displayRemoveUsersWarning()
310+
displayOtherUsersWarning()
303311
})
304312

305313
it('allows the user to delete an org if there are other orgs in the account, and they are the only user in the current org', () => {
@@ -337,15 +345,15 @@ describe('Contract Account', () => {
337345
createOrg('contract')
338346
})
339347

340-
it('displays the `remove other users` popup if there are other orgs in the account, but the current org has other users in it', () => {
348+
it('when deleting an org with multiple users in a multi-org contract account, delete org overlay shows how many other users the org has and clicking it takes user to /members page ', () => {
341349
setupTest({
342350
accountType: 'contract',
343351
canCreateOrgs: false,
344352
orgHasOtherUsers: true,
345353
orgIsSuspendable: true,
346354
})
347355

348-
displayRemoveUsersWarning()
356+
displayOtherUsersWarning()
349357
})
350358

351359
it('allows the user to delete an org if there are other orgs in the account, and they are the only user in the current org', () => {

src/organizations/components/OrgProfileTab/DeletePanel.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,21 @@ import {UsersContext} from 'src/users/context/users'
2020
// Selectors
2121
import {getOrg} from 'src/organizations/selectors'
2222
import {
23+
selectCurrentAccount,
2324
selectCurrentIdentity,
2425
selectOrgCreationAllowance,
2526
selectOrgSuspendable,
2627
} from 'src/identity/selectors'
2728

28-
// Notifications
29-
import {deleteOrgWarning} from 'src/shared/copy/notifications'
30-
import {notify} from 'src/shared/actions/notifications'
31-
3229
// Constants
3330
import {CLOUD} from 'src/shared/constants'
3431
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
3532
import {dismissOverlay, showOverlay} from 'src/overlays/actions/overlays'
3633

34+
// Notifications
35+
import {deleteOrgWarning} from 'src/shared/copy/notifications'
36+
import {notify} from 'src/shared/actions/notifications'
37+
3738
// Types
3839
import {NotificationButtonElement} from 'src/types'
3940

@@ -65,6 +66,7 @@ const DeleteOrgButton: FC = () => {
6566
const orgCanBeSuspended = useSelector(selectOrgSuspendable)
6667
const canCreateOrgs = useSelector(selectOrgCreationAllowance)
6768
const {users} = useContext(UsersContext)
69+
const account = useSelector(selectCurrentAccount)
6870

6971
const popoverRef = useRef()
7072

@@ -84,18 +86,21 @@ const DeleteOrgButton: FC = () => {
8486
hidePopup()
8587
}
8688

87-
const shouldShowUsersWarning = users.length > 1
89+
// only show warning for free accounts with multiple users
90+
const freeAccountWithOtherUsers = account.type === 'free' && users.length > 1
8891

8992
const handleSuspendOrg = () => {
9093
if (orgCanBeSuspended) {
91-
if (shouldShowUsersWarning) {
94+
if (freeAccountWithOtherUsers) {
9295
const buttonElement: NotificationButtonElement = onDismiss =>
9396
OrgUsersLink(`/orgs/${org.id}/members`, onDismiss)
9497
dispatch(notify(deleteOrgWarning(buttonElement)))
9598
} else {
9699
dispatch(
97-
showOverlay('suspend-org-in-paid-account', null, () =>
98-
dispatch(dismissOverlay())
100+
showOverlay(
101+
'suspend-org-in-paid-account',
102+
{userCount: users.length || 0},
103+
() => dispatch(dismissOverlay())
99104
)
100105
)
101106
}

src/organizations/components/OrgProfileTab/SuspendPaidOrgOverlay.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Libraries
22
import React, {FC, useContext, useState} from 'react'
33
import {useDispatch, useSelector} from 'react-redux'
4+
import {Link} from 'react-router-dom'
5+
46
import {
57
Alert,
68
AlignItems,
@@ -77,7 +79,7 @@ export const SuspendPaidOrgOverlay: FC = () => {
7779
const org = useSelector(selectCurrentOrg)
7880
const user = useSelector(selectUser)
7981
const dispatch = useDispatch()
80-
const {onClose} = useContext(OverlayContext)
82+
const {onClose, params} = useContext(OverlayContext)
8183

8284
const [deleteButtonStatus, setDeleteButtonStatus] = useState(
8385
ComponentStatus.Disabled
@@ -142,7 +144,7 @@ export const SuspendPaidOrgOverlay: FC = () => {
142144
return (
143145
<Overlay.Container
144146
className="org-delete-overlay"
145-
maxWidth={600}
147+
maxWidth={750}
146148
testID="create-org-overlay--container"
147149
>
148150
<Overlay.Header
@@ -158,6 +160,16 @@ export const SuspendPaidOrgOverlay: FC = () => {
158160
>
159161
You will be able to recover this organization's data for up to 7 days
160162
by contacting support. It will be unrecoverable afterwards.
163+
{params.userCount > 1 && (
164+
<>
165+
<br />
166+
<br />
167+
<Link to={`/orgs/${org.id}/members`} onClick={onClickCancel}>
168+
{params.userCount} users in this organization
169+
</Link>{' '}
170+
will lose access to all organization data immediately.
171+
</>
172+
)}
161173
</Alert>
162174
<br />
163175
<ul>

0 commit comments

Comments
 (0)