Skip to content

Commit 1ac6177

Browse files
committed
fix autoselect logic
1 parent 00edd91 commit 1ac6177

File tree

2 files changed

+16
-22
lines changed
  • apps/sim/app/workspace/[workspaceId]/w
    • [workflowId]/components/control-bar/components/deploy-modal/components/template-deploy
    • components/sidebar/components-new/settings-modal/components/components/creator-profile

2 files changed

+16
-22
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/control-bar/components/deploy-modal/components/template-deploy/template-deploy.tsx

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,22 @@ export function TemplateDeploy({ workflowId, onDeploymentComplete }: TemplateDep
107107
fetchCreatorOptions()
108108
}, [session?.user?.id])
109109

110-
// Listen for creator profile saved event
110+
// Auto-select creator profile when there's only one option and no selection yet
111111
useEffect(() => {
112-
const handleCreatorProfileSaved = async (event: Event) => {
113-
const customEvent = event as CustomEvent<{ profileId: string }>
114-
logger.info('Creator profile saved, refreshing profiles...', customEvent.detail)
112+
const currentCreatorId = form.getValues('creatorId')
113+
if (creatorOptions.length === 1 && !currentCreatorId) {
114+
form.setValue('creatorId', creatorOptions[0].id)
115+
logger.info('Auto-selected single creator profile:', creatorOptions[0].name)
116+
}
117+
}, [creatorOptions, form])
115118

116-
// Refetch creator profiles
117-
const profiles = await fetchCreatorOptions()
119+
// Listen for creator profile saved event
120+
useEffect(() => {
121+
const handleCreatorProfileSaved = async () => {
122+
logger.info('Creator profile saved, refreshing profiles...')
118123

119-
// Auto-select the newly created profile
120-
if (customEvent.detail.profileId && profiles.length > 0) {
121-
const newProfile = profiles.find(
122-
(p: CreatorOption) => p.id === customEvent.detail.profileId
123-
)
124-
if (newProfile) {
125-
form.setValue('creatorId', newProfile.id)
126-
logger.info('Auto-selected newly created creator profile:', newProfile.name)
127-
}
128-
}
124+
// Refetch creator profiles (autoselection will happen via the effect above)
125+
await fetchCreatorOptions()
129126

130127
// Close settings modal and reopen deploy modal to template tab
131128
window.dispatchEvent(new CustomEvent('close-settings'))
@@ -139,7 +136,7 @@ export function TemplateDeploy({ workflowId, onDeploymentComplete }: TemplateDep
139136
return () => {
140137
window.removeEventListener('creator-profile-saved', handleCreatorProfileSaved)
141138
}
142-
}, [session?.user?.id, form])
139+
}, [])
143140

144141
// Check for existing template
145142
useEffect(() => {

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/settings-modal/components/components/creator-profile/creator-profile.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,8 @@ export function CreatorProfile() {
196196
logger.info('Creator profile saved successfully')
197197
setSaveStatus('saved')
198198

199-
window.dispatchEvent(
200-
new CustomEvent('creator-profile-saved', {
201-
detail: { profileId: result.data?.id },
202-
})
203-
)
199+
// Dispatch event to notify that a creator profile was saved
200+
window.dispatchEvent(new CustomEvent('creator-profile-saved'))
204201

205202
setTimeout(() => {
206203
setSaveStatus('idle')

0 commit comments

Comments
 (0)