11import { useOrganizationList } from '@clerk/shared/react' ;
2- import type { CreateOrganizationParams } from '@clerk/shared/types' ;
2+ import type { CreateOrganizationParams , OrganizationCreationDefaultsResource } from '@clerk/shared/types' ;
33import { useState } from 'react' ;
44
55import { useEnvironment } from '@/ui/contexts' ;
@@ -20,24 +20,9 @@ import { OrganizationProfileAvatarUploader } from '../../../OrganizationProfile/
2020import { organizationListParams } from '../../../OrganizationSwitcher/utils' ;
2121import { OrganizationCreationDefaultsAlert } from './OrganizationCreationDefaultsAlert' ;
2222
23- // TODO: Replace with actual API call to OrganizationCreationDefaults.retrieve()
24- // TODO - Only replace if .organization_settings.organization_creation_defaults.enabled
25- const organizationCreationDefaults = {
26- advisory : {
27- type : 'existing_org_with_domain' as const ,
28- severity : 'warning' as const ,
29- } ,
30- form : {
31- name : '' ,
32- slug : '' ,
33- logo : null ,
34- } ,
35- pathRoot : '' ,
36- reload : ( ) => Promise . resolve ( { } as any ) ,
37- } ;
38-
3923type CreateOrganizationScreenProps = {
4024 onCancel ?: ( ) => void ;
25+ organizationCreationDefaults ?: OrganizationCreationDefaultsResource ;
4126} ;
4227
4328export const CreateOrganizationScreen = ( props : CreateOrganizationScreenProps ) => {
@@ -50,12 +35,15 @@ export const CreateOrganizationScreen = (props: CreateOrganizationScreenProps) =
5035 const { organizationSettings } = useEnvironment ( ) ;
5136 const [ file , setFile ] = useState < File | null > ( ) ;
5237
53- const nameField = useFormControl ( 'name' , '' , {
38+ // Show default logo only when no file action has been taken (file is undefined)
39+ const defaultLogoUrl = file === undefined ? props . organizationCreationDefaults ?. form . logo : undefined ;
40+
41+ const nameField = useFormControl ( 'name' , props . organizationCreationDefaults ?. form . name ?? '' , {
5442 type : 'text' ,
5543 label : localizationKeys ( 'taskChooseOrganization.createOrganization.formFieldLabel__name' ) ,
5644 placeholder : localizationKeys ( 'taskChooseOrganization.createOrganization.formFieldInputPlaceholder__name' ) ,
5745 } ) ;
58- const slugField = useFormControl ( 'slug' , '' , {
46+ const slugField = useFormControl ( 'slug' , props . organizationCreationDefaults ?. form . slug ?? '' , {
5947 type : 'text' ,
6048 label : localizationKeys ( 'taskChooseOrganization.createOrganization.formFieldLabel__slug' ) ,
6149 placeholder : localizationKeys ( 'taskChooseOrganization.createOrganization.formFieldInputPlaceholder__slug' ) ,
@@ -81,6 +69,11 @@ export const CreateOrganizationScreen = (props: CreateOrganizationScreenProps) =
8169
8270 if ( file ) {
8371 await organization . setLogo ( { file } ) ;
72+ } else if ( defaultLogoUrl ) {
73+ const response = await fetch ( defaultLogoUrl ) ;
74+ const blob = await response . blob ( ) ;
75+ const logoFile = new File ( [ blob ] , 'logo' , { type : blob . type } ) ;
76+ await organization . setLogo ( { file : logoFile } ) ;
8477 }
8578
8679 await setActive ( {
@@ -122,11 +115,11 @@ export const CreateOrganizationScreen = (props: CreateOrganizationScreenProps) =
122115
123116 < FormContainer sx = { t => ( { padding : `${ t . space . $none } ${ t . space . $10 } ${ t . space . $8 } ` } ) } >
124117 < Form . Root onSubmit = { onSubmit } >
125- < OrganizationCreationDefaultsAlert organizationCreationDefaults = { organizationCreationDefaults } />
118+ < OrganizationCreationDefaultsAlert organizationCreationDefaults = { props . organizationCreationDefaults } />
126119 < OrganizationProfileAvatarUploader
127- organization = { { name : nameField . value } }
120+ organization = { { name : nameField . value , imageUrl : defaultLogoUrl ?? undefined } }
128121 onAvatarChange = { async file => await setFile ( file ) }
129- onAvatarRemove = { file ? onAvatarRemove : null }
122+ onAvatarRemove = { file || defaultLogoUrl ? onAvatarRemove : null }
130123 avatarPreviewPlaceholder = {
131124 < IconButton
132125 variant = 'ghost'
0 commit comments