1+ import { useClerk } from '@clerk/shared/react' ;
12import type { __internal_EnableOrganizationsPromptProps } from '@clerk/shared/types' ;
23// eslint-disable-next-line no-restricted-imports
34import { css } from '@emotion/react' ;
5+ import { useState } from 'react' ;
46
57import { Modal } from '@/ui/elements/Modal' ;
68import { InternalThemeProvider } from '@/ui/styledSystem' ;
79
10+ import { DevTools } from '../../../../core/resources/DevTools' ;
811import { Flex } from '../../../customizables' ;
912import { Portal } from '../../../elements/Portal' ;
1013import { basePromptElementStyles , PromptContainer } from '../shared' ;
1114
1215const EnableOrganizationsPromptInternal = ( props : __internal_EnableOrganizationsPromptProps ) => {
1316 const ctaText = 'componentName' in props ? `<${ props . componentName } />` : props . utilityName ;
17+ const clerk = useClerk ( ) ;
18+ const [ isLoading , setIsLoading ] = useState ( false ) ;
19+
20+ const handleEnableOrganizations = ( ) => {
21+ setIsLoading ( true ) ;
22+
23+ void new DevTools ( )
24+ . __internal_enableEnvironmentSetting ( {
25+ enable_organizations : true ,
26+ } )
27+ . then ( ( ) => {
28+ // Re-fetch environment to get updated settings
29+ // @ts -expect-error - __unstable__environment is not typed
30+ const environment = clerk ?. __unstable__environment ;
31+ environment . fetch ?.( ) ;
32+ clerk ?. __internal_closeEnableOrganizationsPrompt ?.( ) ;
33+ } )
34+ . finally ( ( ) => {
35+ setIsLoading ( false ) ;
36+ } ) ;
37+ } ;
1438
1539 return (
1640 < Portal >
@@ -152,7 +176,6 @@ const EnableOrganizationsPromptInternal = (props: __internal_EnableOrganizations
152176 ` }
153177 />
154178
155- { /* TODO -> Introduce FAPI mutation to enable organizations */ }
156179 < Flex
157180 direction = 'col'
158181 justify = 'center'
@@ -163,6 +186,8 @@ const EnableOrganizationsPromptInternal = (props: __internal_EnableOrganizations
163186 >
164187 < button
165188 type = 'button'
189+ onClick = { handleEnableOrganizations }
190+ disabled = { isLoading }
166191 css = { css `
167192 ${ mainCTAStyles } ;
168193 min- width: 100%;
@@ -175,14 +200,19 @@ const EnableOrganizationsPromptInternal = (props: __internal_EnableOrganizations
175200 0px 1.5px 2px 0px rgba(0, 0, 0, 0.48),
176201 0px 0px 4px 0px rgba(243, 107, 22, 0) inset;
177202
178- & : hover {
203+ & : hover : not ( : disabled ) {
179204 box-shadow :
180205 0px 0px 6px 0px rgba (255 , 255 , 255 , 0.04 ) inset,
181206 0px 0px 0px 1px rgba (255 , 255 , 255 , 0.04 ) inset,
182207 0px 1px 0px 0px rgba (255 , 255 , 255 , 0.04 ) inset,
183208 0px 0px 0px 1px rgba (0 , 0 , 0 , 0.1 ),
184209 0px 1.5px 2px 0px rgba (0 , 0 , 0 , 0.48 );
185210 }
211+
212+ & : disabled {
213+ opacity : 0.6 ;
214+ cursor : not-allowed;
215+ }
186216 ` }
187217 >
188218 Enable Organizations
0 commit comments