Skip to content

Commit e9a8e4d

Browse files
committed
fix triggers
1 parent bd5bd7c commit e9a8e4d

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/trigger-config/components

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/trigger-config/components/trigger-modal.tsx

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,35 +79,44 @@ export function TriggerModal({
7979
}
8080
}, [triggerDef.configFields, initialConfig])
8181

82-
// Monitor credential selection
82+
// Monitor credential selection across collaborators; clear options on change/clear
8383
useEffect(() => {
8484
if (triggerDef.requiresCredentials && triggerDef.credentialProvider) {
85-
// Check if credentials are selected by monitoring the sub-block store
8685
const checkCredentials = () => {
8786
const subBlockStore = useSubBlockStore.getState()
88-
const credentialValue = subBlockStore.getValue(blockId, 'triggerCredentials')
87+
const credentialValue = subBlockStore.getValue(blockId, 'triggerCredentials') as
88+
| string
89+
| null
8990
const hasCredential = Boolean(credentialValue)
9091
setHasCredentials(hasCredential)
9192

92-
// If credential changed and it's a Gmail trigger, load labels
93-
if (hasCredential && credentialValue !== selectedCredentialId) {
93+
// If credential was cleared by another user, reset local state and dynamic options
94+
if (!hasCredential) {
95+
if (selectedCredentialId !== null) {
96+
setSelectedCredentialId(null)
97+
}
98+
// Clear provider-specific dynamic options
99+
setDynamicOptions({})
100+
return
101+
}
102+
103+
// If credential changed, clear options immediately and load for new cred
104+
if (credentialValue && credentialValue !== selectedCredentialId) {
94105
setSelectedCredentialId(credentialValue)
106+
// Clear stale options before loading new ones
107+
setDynamicOptions({})
95108
if (triggerDef.provider === 'gmail') {
96-
loadGmailLabels(credentialValue)
109+
void loadGmailLabels(credentialValue)
97110
} else if (triggerDef.provider === 'outlook') {
98-
loadOutlookFolders(credentialValue)
111+
void loadOutlookFolders(credentialValue)
99112
}
100113
}
101114
}
102115

103116
checkCredentials()
104-
105-
// Set up a subscription to monitor changes
106117
const unsubscribe = useSubBlockStore.subscribe(checkCredentials)
107-
108118
return unsubscribe
109119
}
110-
// If credentials aren't required, set to true
111120
setHasCredentials(true)
112121
}, [
113122
blockId,

0 commit comments

Comments
 (0)