@@ -66,16 +66,19 @@ enum ProviderSelectMessage {
6666// Selectors
6767import {
6868 selectCurrentAccountId ,
69+ selectOrgCreationAllowance ,
70+ selectOrgCreationAllowanceStatus ,
6971 selectQuartzOrgsContents ,
7072 selectQuartzOrgsStatus ,
7173} from 'src/identity/selectors'
7274
7375// Notifications
7476import { notify } from 'src/shared/actions/notifications'
75- import { orgCreateSuccess } from 'src/shared/copy/notifications'
77+ import { orgCreateSuccess , orgQuotaReached } from 'src/shared/copy/notifications'
7678
7779// Thunks
7880import { getQuartzOrganizationsThunk } from 'src/identity/quartzOrganizations/actions/thunks'
81+ import { getOrgCreationAllowancesThunk } from 'src/identity/allowances/actions/thunks'
7982
8083// Utils
8184import { generateProviderMap } from 'src/identity/components/GlobalHeader/GlobalHeaderDropdown/CreateOrganization/utils/generateProviderMap'
@@ -89,6 +92,10 @@ export const CreateOrganizationOverlay: FC = () => {
8992 const currentAccountId = useSelector ( selectCurrentAccountId )
9093 const organizations = useSelector ( selectQuartzOrgsContents )
9194 const orgsLoadedStatus = useSelector ( selectQuartzOrgsStatus )
95+ const orgCreationAllowed = useSelector ( selectOrgCreationAllowance )
96+ const orgCreationAllowanceStatus = useSelector (
97+ selectOrgCreationAllowanceStatus
98+ )
9299
93100 // Local State
94101 // Dropdown State
@@ -120,13 +127,31 @@ export const CreateOrganizationOverlay: FC = () => {
120127 ? RemoteDataState . Done
121128 : RemoteDataState . Loading
122129
123- // Ajax requests
130+ // Side effects
124131 useEffect ( ( ) => {
125132 if ( orgsLoadedStatus === RemoteDataState . NotStarted ) {
126133 dispatch ( getQuartzOrganizationsThunk ( currentAccountId ) )
127134 }
128135 } , [ currentAccountId , orgsLoadedStatus , dispatch ] )
129136
137+ useEffect ( ( ) => {
138+ if ( orgCreationAllowanceStatus === RemoteDataState . NotStarted ) {
139+ dispatch ( getOrgCreationAllowancesThunk ( ) )
140+ }
141+ } , [ dispatch , orgCreationAllowanceStatus ] )
142+
143+ useEffect ( ( ) => {
144+ if ( ! orgCreationAllowed ) {
145+ if ( createOrgButtonStatus === ComponentStatus . Default ) {
146+ setCreateOrgButtonStatus ( ComponentStatus . Disabled )
147+ }
148+
149+ if ( networkErrorMsg !== OrgOverlayNetworkError . OrgLimitError ) {
150+ setNetworkErrorMsg ( OrgOverlayNetworkError . OrgLimitError )
151+ }
152+ }
153+ } , [ createOrgButtonStatus , networkErrorMsg , orgCreationAllowed ] )
154+
130155 useEffect ( ( ) => {
131156 const retrieveClusters = async ( ) => {
132157 try {
@@ -162,12 +187,16 @@ export const CreateOrganizationOverlay: FC = () => {
162187 region : currentRegion ,
163188 } )
164189 setCreateOrgButtonStatus ( ComponentStatus . Default )
165- onClose ( )
166190 dispatch ( notify ( orgCreateSuccess ( ) ) )
167- // Will make another API call to the allowance endpoint in PR resolving this issue.
168- // https://github.com/influxdata/ui/issues/6267
169- // Need a parallel update to global header state to ensure list of orgs remains updated.
170191 dispatch ( getQuartzOrganizationsThunk ( currentAccountId ) )
192+ Promise . resolve ( dispatch ( getOrgCreationAllowancesThunk ( ) ) ) . then (
193+ allowed => {
194+ if ( ! allowed ) {
195+ dispatch ( notify ( orgQuotaReached ( ) ) )
196+ }
197+ onClose ( )
198+ }
199+ )
171200 } catch ( err ) {
172201 if ( err instanceof UnprocessableEntityError ) {
173202 setNetworkErrorMsg ( OrgOverlayNetworkError . NameConflictError )
0 commit comments