11// Libraries
2- import React , { FC , useContext } from 'react'
3- import { useSelector , useDispatch } from 'react-redux'
4- import { useHistory } from 'react-router-dom'
2+ import React , { FC , useContext , useRef } from 'react'
53import { track } from 'rudder-sdk-js'
4+ import { useDispatch , useSelector } from 'react-redux'
5+ import { useHistory } from 'react-router-dom'
66
77// Components
8- import { Button , IconFont , FlexBox } from '@influxdata/clockface'
8+ import {
9+ Button ,
10+ IconFont ,
11+ FlexBox ,
12+ Popover ,
13+ PopoverInteraction ,
14+ PopoverPosition ,
15+ } from '@influxdata/clockface'
16+ import { getDeleteAccountWarningButton } from 'src/shared/components/notifications/NotificationButtons'
917import PageSpinner from 'src/perf/components/PageSpinner'
18+
19+ // Contexts
1020import { UsersContext } from 'src/users/context/users'
11- import { getDeleteAccountWarningButton } from 'src/shared/components/notifications/NotificationButtons'
1221
13- // Utils
22+ // Selectors
1423import { getOrg } from 'src/organizations/selectors'
15- import { notify } from 'src/shared/actions/notifications'
24+ import {
25+ selectCurrentAccount ,
26+ selectCurrentIdentity ,
27+ selectOrgCreationAllowance ,
28+ selectOrgSuspendable ,
29+ selectUser ,
30+ } from 'src/identity/selectors'
31+
32+ // Notifications
1633import { deleteAccountWarning } from 'src/shared/copy/notifications'
34+ import { notify } from 'src/shared/actions/notifications'
35+
36+ // Utils
37+ import { event } from 'src/cloud/utils/reporting'
38+
39+ // Constants
1740import { CLOUD } from 'src/shared/constants'
1841import { isFlagEnabled } from 'src/shared/utils/featureFlag'
19- import { event } from 'src/cloud/utils/reporting '
42+ import { dismissOverlay , showOverlay } from 'src/overlays/actions/overlays '
2043
2144// Types
22- import { selectCurrentIdentity } from 'src/identity/selectors'
2345import { NotificationButtonElement } from 'src/types'
2446
47+ // Styles
2548import 'src/organizations/components/OrgProfileTab/style.scss'
26- import { dismissOverlay , showOverlay } from 'src/overlays/actions/overlays'
2749
28- const DeletePanel : FC = ( ) => {
50+ const linkStyle = { textDecoration : 'underline' }
51+
52+ export const DeletePanel : FC = ( ) => {
2953 const { user, account} = useSelector ( selectCurrentIdentity )
30- const org = useSelector ( getOrg )
54+ const { status} = useContext ( UsersContext )
55+
56+ const shouldShowDeleteFreeAccountButton =
57+ CLOUD && account . type === 'free' && user . orgCount === 1
58+
59+ const shouldShowDeleteOrgButton =
60+ CLOUD &&
61+ isFlagEnabled ( 'createDeleteOrgs' ) &&
62+ ! shouldShowDeleteFreeAccountButton
63+
64+ return (
65+ < PageSpinner loading = { status } >
66+ < >
67+ { shouldShowDeleteFreeAccountButton && < DeleteFreeAccountButton /> }
68+ { shouldShowDeleteOrgButton && < DeleteOrgButton /> }
69+ </ >
70+ </ PageSpinner >
71+ )
72+ }
73+
74+ const DeleteFreeAccountButton : FC = ( ) => {
75+ const account = useSelector ( selectCurrentAccount )
3176 const history = useHistory ( )
32- const { status, users} = useContext ( UsersContext )
33- const dispatch = useDispatch ( )
77+ const org = useSelector ( getOrg )
78+ const user = useSelector ( selectUser )
79+ const { users} = useContext ( UsersContext )
3480
35- const handleDeletePaidAccount = ( ) => {
36- dispatch (
37- showOverlay ( 'delete-org-in-paid-account' , null , ( ) =>
38- dispatch ( dismissOverlay ( ) )
39- )
40- )
41- }
81+ const dispatch = useDispatch ( )
4282
4383 const handleShowDeleteOverlay = ( ) => {
4484 const payload = {
@@ -61,64 +101,122 @@ const DeletePanel: FC = () => {
61101 dispatch ( notify ( deleteAccountWarning ( buttonElement ) ) )
62102 }
63103
64- let handleDeleteFreeAccount = handleShowDeleteOverlay
104+ let handleDeleteAccountFree = handleShowDeleteOverlay
65105
66106 if ( users . length > 1 ) {
67- handleDeleteFreeAccount = handleShowWarning
107+ handleDeleteAccountFree = handleShowWarning
68108 }
69109
70- const shouldShowDeleteFreeAccountButton =
71- CLOUD && account . type === 'free' && user . orgCount === 1
110+ return (
111+ < >
112+ < FlexBox . Child >
113+ < h4 > Delete Organization</ h4 >
114+ < p className = "org-profile-tab--heading org-profile-tab--deleteHeading" >
115+ Delete your Free InfluxDB Cloud account and remove any data that you
116+ have loaded.
117+ </ p >
118+ </ FlexBox . Child >
119+ < FlexBox . Child >
120+ < Button
121+ testID = "delete-org--button"
122+ text = "Delete"
123+ icon = { IconFont . Trash_New }
124+ onClick = { handleDeleteAccountFree }
125+ />
126+ </ FlexBox . Child >
127+ </ >
128+ )
129+ }
72130
73- const shouldShowDeleteOrgButton =
74- CLOUD &&
75- isFlagEnabled ( 'createDeleteOrgs' ) &&
76- ! shouldShowDeleteFreeAccountButton
131+ const popoverStyle = { padding : '10px' }
132+
133+ const DeleteOrgButton : FC = ( ) => {
134+ const dispatch = useDispatch ( )
135+ const org = useSelector ( getOrg )
136+ const orgCanBeSuspended = useSelector ( selectOrgSuspendable )
137+ const canCreateOrgs = useSelector ( selectOrgCreationAllowance )
138+
139+ const popoverRef = useRef ( )
140+
141+ const handleClickCreateOrg = ( hidePopup : Function ) => {
142+ dispatch (
143+ showOverlay ( 'create-organization' , null , ( ) => dispatch ( dismissOverlay ( ) ) )
144+ )
145+ hidePopup ( )
146+ }
147+
148+ const handleClickUpgradeAccount = ( hidePopup : Function ) => {
149+ dispatch (
150+ showOverlay ( 'marketo-upgrade-account-overlay' , null , ( ) =>
151+ dispatch ( dismissOverlay ( ) )
152+ )
153+ )
154+ hidePopup ( )
155+ }
156+
157+ const handleSuspendOrg = ( ) => {
158+ if ( orgCanBeSuspended ) {
159+ dispatch (
160+ showOverlay ( 'suspend-org-in-paid-account' , null , ( ) =>
161+ dispatch ( dismissOverlay ( ) )
162+ )
163+ )
164+ }
165+ }
77166
78167 return (
79- < PageSpinner loading = { status } >
80- < >
81- { shouldShowDeleteFreeAccountButton && (
82- < >
83- < FlexBox . Child >
84- < h4 > Delete Organization</ h4 >
85- < p className = "org-profile-tab--heading org-profile-tab--deleteHeading" >
86- Delete your Free InfluxDB Cloud account and remove any data that
87- you have loaded.
88- </ p >
89- </ FlexBox . Child >
90- < FlexBox . Child >
91- < Button
92- testID = "delete-org--button"
93- text = "Delete"
94- icon = { IconFont . Trash_New }
95- onClick = { handleDeleteFreeAccount }
96- />
97- </ FlexBox . Child >
98- </ >
99- ) }
100- { shouldShowDeleteOrgButton && (
101- < >
102- < FlexBox . Child >
103- < h4 > Delete Organization</ h4 >
104- < p className = "org-profile-tab--heading org-profile-tab--deleteHeading" >
105- Delete the < b > { org . name } </ b > organization and remove any data
106- that you have loaded.
107- </ p >
108- </ FlexBox . Child >
109- < FlexBox . Child >
110- < Button
111- icon = { IconFont . Trash_New }
112- onClick = { handleDeletePaidAccount }
113- testID = "delete-org--button"
114- text = "Delete"
115- />
116- </ FlexBox . Child >
117- </ >
118- ) }
119- </ >
120- </ PageSpinner >
168+ < >
169+ < FlexBox . Child >
170+ < h4 > Delete Organization</ h4 >
171+ < p className = "org-profile-tab--heading org-profile-tab--deleteHeading" >
172+ Delete the < b > { org . name } </ b > organization and remove any data that you
173+ have loaded.
174+ </ p >
175+ </ FlexBox . Child >
176+ < FlexBox . Child >
177+ < >
178+ { ! orgCanBeSuspended && (
179+ < Popover
180+ contents = { onHide => (
181+ < div >
182+ < >
183+ < Popover . DismissButton onClick = { onHide } />
184+ < b > "{ org . name } "</ b > cannot be deleted because it is your
185+ last accessible organization in this account. < br />
186+ To continue, please{ ' ' }
187+ < a
188+ className = "delete-org-panel--create-org-link"
189+ onClick = {
190+ canCreateOrgs
191+ ? ( ) => handleClickCreateOrg ( onHide )
192+ : ( ) => handleClickUpgradeAccount ( onHide )
193+ }
194+ style = { linkStyle }
195+ >
196+ { canCreateOrgs
197+ ? 'create another organization'
198+ : 'upgrade this account' }
199+ </ a > { ' ' }
200+ first.
201+ </ >
202+ </ div >
203+ ) }
204+ hideEvent = { PopoverInteraction . Click }
205+ position = { PopoverPosition . ToTheRightTop }
206+ showEvent = { PopoverInteraction . Click }
207+ style = { popoverStyle }
208+ triggerRef = { popoverRef }
209+ />
210+ ) }
211+ < Button
212+ icon = { IconFont . Trash_New }
213+ onClick = { handleSuspendOrg }
214+ ref = { popoverRef }
215+ testID = "delete-org--button"
216+ text = "Delete"
217+ />
218+ </ >
219+ </ FlexBox . Child >
220+ </ >
121221 )
122222}
123-
124- export default DeletePanel
0 commit comments