@@ -2,15 +2,28 @@ import { useClerk } from '@clerk/shared/react';
22import type { __internal_EnableOrganizationsPromptProps } from '@clerk/shared/types' ;
33// eslint-disable-next-line no-restricted-imports
44import { css } from '@emotion/react' ;
5- import { useState } from 'react' ;
5+ import { useMemo , useState } from 'react' ;
66
7+ import { Animated } from '@/ui/elements/Animated' ;
78import { Modal } from '@/ui/elements/Modal' ;
89import { InternalThemeProvider } from '@/ui/styledSystem' ;
910
1011import { DevTools } from '../../../../core/resources/DevTools' ;
12+ import type { Environment } from '../../../../core/resources/Environment' ;
1113import { Flex } from '../../../customizables' ;
1214import { Portal } from '../../../elements/Portal' ;
13- import { basePromptElementStyles , PromptContainer , PromptSuccessIcon } from '../shared' ;
15+ import { basePromptElementStyles , handleDashboardUrlParsing , PromptContainer , PromptSuccessIcon } from '../shared' ;
16+
17+ /**
18+ * If we cannot reconstruct the url properly, then simply fallback to Clerk Dashboard
19+ */
20+ function withLastActiveFallback ( cb : ( ) => string ) : string {
21+ try {
22+ return cb ( ) ;
23+ } catch {
24+ return 'https://dashboard.clerk.com/last-active?path=organization-settings' ;
25+ }
26+ }
1427
1528const EnableOrganizationsPromptInternal = ( {
1629 caller,
@@ -21,6 +34,28 @@ const EnableOrganizationsPromptInternal = ({
2134 const [ isLoading , setIsLoading ] = useState ( false ) ;
2235 const [ isEnabled , setIsEnabled ] = useState ( false ) ;
2336
37+ // @ts -expect-error - __unstable__environment is not typed
38+ const environment = clerk ?. __unstable__environment as Environment | undefined ;
39+
40+ const organizationSettingsUrl = useMemo ( ( ) => {
41+ return withLastActiveFallback ( ( ) => {
42+ const currentUrl = window . location . href ;
43+ try {
44+ const redirectUrlParts = handleDashboardUrlParsing ( currentUrl ) ;
45+ const url = new URL (
46+ `${ redirectUrlParts . baseDomain } /apps/${ redirectUrlParts . appId } /instances/${ redirectUrlParts . instanceId } /organization-settings` ,
47+ ) ;
48+ return url . href ;
49+ } catch {
50+ if ( ! environment ?. id ) {
51+ throw new Error ( 'Cannot construct dashboard URL' ) ;
52+ }
53+
54+ return 'https://dashboard.clerk.com/last-active?path=organization-settings' ;
55+ }
56+ } ) ;
57+ } , [ environment ?. id ] ) ;
58+
2459 const handleEnableOrganizations = ( ) => {
2560 setIsLoading ( true ) ;
2661
@@ -193,8 +228,7 @@ const EnableOrganizationsPromptInternal = ({
193228 font-size : 0.8125rem ;
194229 ` ,
195230 ] }
196- /* TODO - Generate URL to Dashboard */
197- href = 'https://clerk.com/docs/guides/organizations'
231+ href = { organizationSettingsUrl }
198232 target = '_blank'
199233 rel = 'noopener noreferrer'
200234 tabIndex = { - 1 }
@@ -264,43 +298,45 @@ const EnableOrganizationsPromptInternal = ({
264298 ` }
265299 />
266300
267- < Flex
268- direction = 'col'
269- justify = 'center'
270- sx = { t => ( {
271- padding : `${ t . sizes . $4 } ${ t . sizes . $6 } ` ,
272- gap : t . sizes . $3 ,
273- } ) }
274- >
275- { isEnabled ? (
276- < PromptButton
277- variant = 'outline'
278- onClick = { ( ) => onSuccess ?.( ) }
279- >
280- Continue
281- </ PromptButton >
282- ) : (
283- < >
284- < PromptButton
285- variant = 'solid'
286- onClick = { handleEnableOrganizations }
287- disabled = { isLoading }
288- >
289- Enable Organizations
290- </ PromptButton >
291-
301+ < Animated asChild >
302+ < Flex
303+ direction = 'col'
304+ justify = 'center'
305+ sx = { t => ( {
306+ padding : `${ t . sizes . $4 } ${ t . sizes . $6 } ` ,
307+ gap : t . sizes . $3 ,
308+ } ) }
309+ >
310+ { isEnabled ? (
292311 < PromptButton
293312 variant = 'outline'
294- onClick = { ( ) => {
295- clerk ?. __internal_closeEnableOrganizationsPrompt ?.( ) ;
296- onClose ?.( ) ;
297- } }
313+ onClick = { ( ) => onSuccess ?.( ) }
298314 >
299- I'll remove it myself
315+ Continue
300316 </ PromptButton >
301- </ >
302- ) }
303- </ Flex >
317+ ) : (
318+ < >
319+ < PromptButton
320+ variant = 'solid'
321+ onClick = { handleEnableOrganizations }
322+ disabled = { isLoading }
323+ >
324+ Enable Organizations
325+ </ PromptButton >
326+
327+ < PromptButton
328+ variant = 'outline'
329+ onClick = { ( ) => {
330+ clerk ?. __internal_closeEnableOrganizationsPrompt ?.( ) ;
331+ onClose ?.( ) ;
332+ } }
333+ >
334+ I'll remove it myself
335+ </ PromptButton >
336+ </ >
337+ ) }
338+ </ Flex >
339+ </ Animated >
304340 </ PromptContainer >
305341 </ Modal >
306342 </ Portal >
0 commit comments