Skip to content

Commit 9336ea7

Browse files
committed
fix(webflow): fix collection & site dropdown in webflow triggers
1 parent 55700b9 commit 9336ea7

File tree

4 files changed

+396
-10
lines changed

4 files changed

+396
-10
lines changed

apps/sim/triggers/webflow/collection_item_changed.ts

Lines changed: 113 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import { createLogger } from '@sim/logger'
12
import { WebflowIcon } from '@/components/icons'
3+
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
24
import type { TriggerConfig } from '../types'
35

6+
const logger = createLogger('webflow-collection-item-changed-trigger')
7+
48
export const webflowCollectionItemChangedTrigger: TriggerConfig = {
59
id: 'webflow_collection_item_changed',
610
name: 'Collection Item Changed',
@@ -38,6 +42,58 @@ export const webflowCollectionItemChangedTrigger: TriggerConfig = {
3842
field: 'selectedTriggerId',
3943
value: 'webflow_collection_item_changed',
4044
},
45+
fetchOptions: async (blockId: string) => {
46+
const credentialId = useSubBlockStore.getState().getValue(blockId, 'triggerCredentials') as
47+
| string
48+
| null
49+
if (!credentialId) {
50+
throw new Error('No Webflow credential selected')
51+
}
52+
try {
53+
const response = await fetch('/api/tools/webflow/sites', {
54+
method: 'POST',
55+
headers: { 'Content-Type': 'application/json' },
56+
body: JSON.stringify({ credential: credentialId }),
57+
})
58+
if (!response.ok) {
59+
throw new Error('Failed to fetch Webflow sites')
60+
}
61+
const data = await response.json()
62+
if (data.sites && Array.isArray(data.sites)) {
63+
return data.sites.map((site: { id: string; name: string }) => ({
64+
id: site.id,
65+
label: site.name,
66+
}))
67+
}
68+
return []
69+
} catch (error) {
70+
logger.error('Error fetching Webflow sites:', error)
71+
throw error
72+
}
73+
},
74+
fetchOptionById: async (blockId: string, _subBlockId: string, optionId: string) => {
75+
const credentialId = useSubBlockStore.getState().getValue(blockId, 'triggerCredentials') as
76+
| string
77+
| null
78+
if (!credentialId) return null
79+
try {
80+
const response = await fetch('/api/tools/webflow/sites', {
81+
method: 'POST',
82+
headers: { 'Content-Type': 'application/json' },
83+
body: JSON.stringify({ credential: credentialId, siteId: optionId }),
84+
})
85+
if (!response.ok) return null
86+
const data = await response.json()
87+
const site = data.sites?.find((s: { id: string }) => s.id === optionId)
88+
if (site) {
89+
return { id: site.id, label: site.name }
90+
}
91+
return null
92+
} catch {
93+
return null
94+
}
95+
},
96+
dependsOn: ['triggerCredentials'],
4197
},
4298
{
4399
id: 'collectionId',
@@ -52,6 +108,60 @@ export const webflowCollectionItemChangedTrigger: TriggerConfig = {
52108
field: 'selectedTriggerId',
53109
value: 'webflow_collection_item_changed',
54110
},
111+
fetchOptions: async (blockId: string) => {
112+
const credentialId = useSubBlockStore.getState().getValue(blockId, 'triggerCredentials') as
113+
| string
114+
| null
115+
const siteId = useSubBlockStore.getState().getValue(blockId, 'siteId') as string | null
116+
if (!credentialId || !siteId) {
117+
return []
118+
}
119+
try {
120+
const response = await fetch('/api/tools/webflow/collections', {
121+
method: 'POST',
122+
headers: { 'Content-Type': 'application/json' },
123+
body: JSON.stringify({ credential: credentialId, siteId }),
124+
})
125+
if (!response.ok) {
126+
throw new Error('Failed to fetch Webflow collections')
127+
}
128+
const data = await response.json()
129+
if (data.collections && Array.isArray(data.collections)) {
130+
return data.collections.map((collection: { id: string; name: string }) => ({
131+
id: collection.id,
132+
label: collection.name,
133+
}))
134+
}
135+
return []
136+
} catch (error) {
137+
logger.error('Error fetching Webflow collections:', error)
138+
throw error
139+
}
140+
},
141+
fetchOptionById: async (blockId: string, _subBlockId: string, optionId: string) => {
142+
const credentialId = useSubBlockStore.getState().getValue(blockId, 'triggerCredentials') as
143+
| string
144+
| null
145+
const siteId = useSubBlockStore.getState().getValue(blockId, 'siteId') as string | null
146+
if (!credentialId || !siteId) return null
147+
try {
148+
const response = await fetch('/api/tools/webflow/collections', {
149+
method: 'POST',
150+
headers: { 'Content-Type': 'application/json' },
151+
body: JSON.stringify({ credential: credentialId, siteId }),
152+
})
153+
if (!response.ok) return null
154+
const data = await response.json()
155+
const collection = data.collections?.find((c: { id: string }) => c.id === optionId)
156+
if (collection) {
157+
return { id: collection.id, label: collection.name }
158+
}
159+
return null
160+
} catch {
161+
return null
162+
}
163+
},
164+
dependsOn: ['triggerCredentials', 'siteId'],
55165
},
56166
{
57167
id: 'triggerSave',
@@ -72,9 +182,9 @@ export const webflowCollectionItemChangedTrigger: TriggerConfig = {
72182
type: 'text',
73183
defaultValue: [
74184
'Connect your Webflow account using the "Select Webflow credential" button above.',
75-
'Enter your Webflow Site ID (found in the site URL or site settings).',
76-
'Optionally enter a Collection ID to monitor only specific collections.',
77-
'If no Collection ID is provided, the trigger will fire for items changed in any collection on the site.',
185+
'Select your Webflow site from the dropdown.',
186+
'Optionally select a collection to monitor only specific collections.',
187+
'If no collection is selected, the trigger will fire for items changed in any collection on the site.',
78188
'The webhook will trigger whenever an existing item is updated in the specified collection(s).',
79189
'Make sure your Webflow account has appropriate permissions for the specified site.',
80190
]

apps/sim/triggers/webflow/collection_item_created.ts

Lines changed: 113 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import { createLogger } from '@sim/logger'
12
import { WebflowIcon } from '@/components/icons'
3+
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
24
import type { TriggerConfig } from '../types'
35

6+
const logger = createLogger('webflow-collection-item-created-trigger')
7+
48
export const webflowCollectionItemCreatedTrigger: TriggerConfig = {
59
id: 'webflow_collection_item_created',
610
name: 'Collection Item Created',
@@ -51,6 +55,58 @@ export const webflowCollectionItemCreatedTrigger: TriggerConfig = {
5155
field: 'selectedTriggerId',
5256
value: 'webflow_collection_item_created',
5357
},
58+
fetchOptions: async (blockId: string) => {
59+
const credentialId = useSubBlockStore.getState().getValue(blockId, 'triggerCredentials') as
60+
| string
61+
| null
62+
if (!credentialId) {
63+
throw new Error('No Webflow credential selected')
64+
}
65+
try {
66+
const response = await fetch('/api/tools/webflow/sites', {
67+
method: 'POST',
68+
headers: { 'Content-Type': 'application/json' },
69+
body: JSON.stringify({ credential: credentialId }),
70+
})
71+
if (!response.ok) {
72+
throw new Error('Failed to fetch Webflow sites')
73+
}
74+
const data = await response.json()
75+
if (data.sites && Array.isArray(data.sites)) {
76+
return data.sites.map((site: { id: string; name: string }) => ({
77+
id: site.id,
78+
label: site.name,
79+
}))
80+
}
81+
return []
82+
} catch (error) {
83+
logger.error('Error fetching Webflow sites:', error)
84+
throw error
85+
}
86+
},
87+
fetchOptionById: async (blockId: string, _subBlockId: string, optionId: string) => {
88+
const credentialId = useSubBlockStore.getState().getValue(blockId, 'triggerCredentials') as
89+
| string
90+
| null
91+
if (!credentialId) return null
92+
try {
93+
const response = await fetch('/api/tools/webflow/sites', {
94+
method: 'POST',
95+
headers: { 'Content-Type': 'application/json' },
96+
body: JSON.stringify({ credential: credentialId, siteId: optionId }),
97+
})
98+
if (!response.ok) return null
99+
const data = await response.json()
100+
const site = data.sites?.find((s: { id: string }) => s.id === optionId)
101+
if (site) {
102+
return { id: site.id, label: site.name }
103+
}
104+
return null
105+
} catch {
106+
return null
107+
}
108+
},
109+
dependsOn: ['triggerCredentials'],
54110
},
55111
{
56112
id: 'collectionId',
@@ -65,6 +121,60 @@ export const webflowCollectionItemCreatedTrigger: TriggerConfig = {
65121
field: 'selectedTriggerId',
66122
value: 'webflow_collection_item_created',
67123
},
124+
fetchOptions: async (blockId: string) => {
125+
const credentialId = useSubBlockStore.getState().getValue(blockId, 'triggerCredentials') as
126+
| string
127+
| null
128+
const siteId = useSubBlockStore.getState().getValue(blockId, 'siteId') as string | null
129+
if (!credentialId || !siteId) {
130+
return []
131+
}
132+
try {
133+
const response = await fetch('/api/tools/webflow/collections', {
134+
method: 'POST',
135+
headers: { 'Content-Type': 'application/json' },
136+
body: JSON.stringify({ credential: credentialId, siteId }),
137+
})
138+
if (!response.ok) {
139+
throw new Error('Failed to fetch Webflow collections')
140+
}
141+
const data = await response.json()
142+
if (data.collections && Array.isArray(data.collections)) {
143+
return data.collections.map((collection: { id: string; name: string }) => ({
144+
id: collection.id,
145+
label: collection.name,
146+
}))
147+
}
148+
return []
149+
} catch (error) {
150+
logger.error('Error fetching Webflow collections:', error)
151+
throw error
152+
}
153+
},
154+
fetchOptionById: async (blockId: string, _subBlockId: string, optionId: string) => {
155+
const credentialId = useSubBlockStore.getState().getValue(blockId, 'triggerCredentials') as
156+
| string
157+
| null
158+
const siteId = useSubBlockStore.getState().getValue(blockId, 'siteId') as string | null
159+
if (!credentialId || !siteId) return null
160+
try {
161+
const response = await fetch('/api/tools/webflow/collections', {
162+
method: 'POST',
163+
headers: { 'Content-Type': 'application/json' },
164+
body: JSON.stringify({ credential: credentialId, siteId }),
165+
})
166+
if (!response.ok) return null
167+
const data = await response.json()
168+
const collection = data.collections?.find((c: { id: string }) => c.id === optionId)
169+
if (collection) {
170+
return { id: collection.id, label: collection.name }
171+
}
172+
return null
173+
} catch {
174+
return null
175+
}
176+
},
177+
dependsOn: ['triggerCredentials', 'siteId'],
68178
},
69179
{
70180
id: 'triggerSave',
@@ -85,9 +195,9 @@ export const webflowCollectionItemCreatedTrigger: TriggerConfig = {
85195
type: 'text',
86196
defaultValue: [
87197
'Connect your Webflow account using the "Select Webflow credential" button above.',
88-
'Enter your Webflow Site ID (found in the site URL or site settings).',
89-
'Optionally enter a Collection ID to monitor only specific collections.',
90-
'If no Collection ID is provided, the trigger will fire for items created in any collection on the site.',
198+
'Select your Webflow site from the dropdown.',
199+
'Optionally select a collection to monitor only specific collections.',
200+
'If no collection is selected, the trigger will fire for items created in any collection on the site.',
91201
'The webhook will trigger whenever a new item is created in the specified collection(s).',
92202
'Make sure your Webflow account has appropriate permissions for the specified site.',
93203
]

0 commit comments

Comments
 (0)