Skip to content

Commit 2c0b053

Browse files
committed
fix trigger modal
1 parent 2a790d8 commit 2c0b053

1 file changed

Lines changed: 25 additions & 5 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: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,31 @@ export function TriggerModal({
4646
const [config, setConfig] = useState<Record<string, any>>(initialConfig)
4747
const [isSaving, setIsSaving] = useState(false)
4848

49-
// Track if config has changed from initial values
49+
// Snapshot initial values at open for stable dirty-checking across collaborators
50+
const initialConfigRef = useRef<Record<string, any>>(initialConfig)
51+
const initialCredentialRef = useRef<string | null>(null)
52+
53+
// Capture initial credential on first detect
54+
useEffect(() => {
55+
if (initialCredentialRef.current !== null) return
56+
const subBlockStore = useSubBlockStore.getState()
57+
const cred = (subBlockStore.getValue(blockId, 'triggerCredentials') as string | null) || null
58+
initialCredentialRef.current = cred
59+
}, [blockId])
60+
61+
// Track if config has changed from initial snapshot
5062
const hasConfigChanged = useMemo(() => {
51-
return JSON.stringify(config) !== JSON.stringify(initialConfig)
52-
}, [config, initialConfig])
63+
return JSON.stringify(config) !== JSON.stringify(initialConfigRef.current)
64+
}, [config])
65+
66+
// Track if credential has changed from initial snapshot (computed later once selectedCredentialId is declared)
67+
let hasCredentialChanged = false
5368
const [isDeleting, setIsDeleting] = useState(false)
5469
const [webhookUrl, setWebhookUrl] = useState('')
5570
const [generatedPath, setGeneratedPath] = useState('')
5671
const [hasCredentials, setHasCredentials] = useState(false)
5772
const [selectedCredentialId, setSelectedCredentialId] = useState<string | null>(null)
73+
hasCredentialChanged = selectedCredentialId !== initialCredentialRef.current
5874
const [dynamicOptions, setDynamicOptions] = useState<
5975
Record<string, Array<{ id: string; name: string }>>
6076
>({})
@@ -420,10 +436,14 @@ export function TriggerModal({
420436
</Button>
421437
<Button
422438
onClick={handleSave}
423-
disabled={isSaving || !isConfigValid() || (!hasConfigChanged && !!triggerId)}
439+
disabled={
440+
isSaving ||
441+
!isConfigValid() ||
442+
(!(hasConfigChanged || hasCredentialChanged) && !!triggerId)
443+
}
424444
className={cn(
425445
'h-10',
426-
isConfigValid() && (hasConfigChanged || !triggerId)
446+
isConfigValid() && (hasConfigChanged || hasCredentialChanged || !triggerId)
427447
? 'bg-primary hover:bg-primary/90'
428448
: '',
429449
isSaving &&

0 commit comments

Comments
 (0)