11import { useOrganizationList } from '@clerk/shared/react' ;
22import type { CreateOrganizationParams } from '@clerk/shared/types' ;
3+ import React from 'react' ;
34
45import { useEnvironment } from '@/ui/contexts' ;
56import { useSessionTasksContext , useTaskChooseOrganizationContext } from '@/ui/contexts/components/SessionTasks' ;
6- import { localizationKeys } from '@/ui/customizables' ;
7+ import { Icon , localizationKeys } from '@/ui/customizables' ;
78import { useCardState } from '@/ui/elements/contexts' ;
89import { Form } from '@/ui/elements/Form' ;
910import { FormButtonContainer } from '@/ui/elements/FormButtons' ;
1011import { FormContainer } from '@/ui/elements/FormContainer' ;
1112import { Header } from '@/ui/elements/Header' ;
13+ import { IconButton } from '@/ui/elements/IconButton' ;
14+ import { Upload } from '@/ui/icons' ;
1215import { createSlug } from '@/ui/utils/createSlug' ;
1316import { handleError } from '@/ui/utils/errorHandler' ;
1417import { useFormControl } from '@/ui/utils/useFormControl' ;
1518
19+ import { OrganizationProfileAvatarUploader } from '../../../OrganizationProfile/OrganizationProfileAvatarUploader' ;
1620import { organizationListParams } from '../../../OrganizationSwitcher/utils' ;
1721import { OrganizationCreationDefaultsAlert } from './OrganizationCreationDefaultsAlert' ;
1822
1923// TODO: Replace with actual API call to OrganizationCreationDefaults.retrieve()
24+ // TODO - Only replace if .organization_settings.organization_creation_defaults.enabled
2025const organizationCreationDefaults = {
2126 advisory : {
2227 type : 'existing_org_with_domain' as const ,
2328 severity : 'warning' as const ,
2429 } ,
30+ form : {
31+ name : '' ,
32+ slug : '' ,
33+ logo : null ,
34+ } ,
2535 pathRoot : '' ,
2636 reload : ( ) => Promise . resolve ( { } as any ) ,
2737} ;
@@ -38,6 +48,7 @@ export const CreateOrganizationScreen = (props: CreateOrganizationScreenProps) =
3848 userMemberships : organizationListParams . userMemberships ,
3949 } ) ;
4050 const { organizationSettings } = useEnvironment ( ) ;
51+ const [ file , setFile ] = React . useState < File | null > ( ) ;
4152
4253 const nameField = useFormControl ( 'name' , '' , {
4354 type : 'text' ,
@@ -68,6 +79,10 @@ export const CreateOrganizationScreen = (props: CreateOrganizationScreenProps) =
6879
6980 const organization = await createOrganization ( createOrgParams ) ;
7081
82+ if ( file ) {
83+ await organization . setLogo ( { file } ) ;
84+ }
85+
7186 await setActive ( {
7287 organization,
7388 navigate : async ( { session } ) => {
@@ -88,6 +103,11 @@ export const CreateOrganizationScreen = (props: CreateOrganizationScreenProps) =
88103 slugField . setValue ( val ) ;
89104 } ;
90105
106+ const onAvatarRemove = ( ) => {
107+ card . setIdle ( ) ;
108+ return setFile ( null ) ;
109+ } ;
110+
91111 const isSubmitButtonDisabled = ! nameField . value || ! isLoaded ;
92112
93113 return (
@@ -101,8 +121,44 @@ export const CreateOrganizationScreen = (props: CreateOrganizationScreenProps) =
101121 </ Header . Root >
102122
103123 < FormContainer sx = { t => ( { padding : `${ t . space . $none } ${ t . space . $10 } ${ t . space . $8 } ` } ) } >
104- < OrganizationCreationDefaultsAlert organizationCreationDefaults = { organizationCreationDefaults } />
105124 < Form . Root onSubmit = { onSubmit } >
125+ < OrganizationCreationDefaultsAlert organizationCreationDefaults = { organizationCreationDefaults } />
126+ < OrganizationProfileAvatarUploader
127+ organization = { { name : nameField . value } }
128+ onAvatarChange = { async file => await setFile ( file ) }
129+ onAvatarRemove = { file ? onAvatarRemove : null }
130+ avatarPreviewPlaceholder = {
131+ < IconButton
132+ variant = 'ghost'
133+ aria-label = 'Upload organization logo'
134+ icon = {
135+ < Icon
136+ size = 'md'
137+ icon = { Upload }
138+ sx = { t => ( {
139+ color : t . colors . $colorMutedForeground ,
140+ transitionDuration : t . transitionDuration . $controls ,
141+ } ) }
142+ />
143+ }
144+ sx = { t => ( {
145+ width : t . sizes . $16 ,
146+ height : t . sizes . $16 ,
147+ borderRadius : t . radii . $md ,
148+ borderWidth : t . borderWidths . $normal ,
149+ borderStyle : t . borderStyles . $dashed ,
150+ borderColor : t . colors . $borderAlpha200 ,
151+ backgroundColor : t . colors . $neutralAlpha50 ,
152+ ':hover' : {
153+ backgroundColor : t . colors . $neutralAlpha50 ,
154+ svg : {
155+ transform : 'scale(1.2)' ,
156+ } ,
157+ } ,
158+ } ) }
159+ />
160+ }
161+ />
106162 < Form . ControlRow elementId = { nameField . id } >
107163 < Form . PlainInput
108164 { ...nameField . props }
0 commit comments