@@ -14,6 +14,25 @@ import type { TriggerConfig } from '@/triggers/types'
1414
1515const logger = createLogger ( 'HubSpotPollingTrigger' )
1616
17+ /**
18+ * Resolves the effective object type from the subblock store. `getValue` returns `null`
19+ * for fields the user hasn't interacted with yet, so we fall back to the dropdown's
20+ * default ('contact') — otherwise the cascading property selectors render empty on
21+ * first render even when the dropdown visibly shows "contact".
22+ */
23+ function resolveSelectedObjectType ( blockId : string ) : string | null {
24+ const objectType = useSubBlockStore . getState ( ) . getValue ( blockId , 'objectType' ) as string | null
25+ const customId = useSubBlockStore . getState ( ) . getValue ( blockId , 'customObjectTypeId' ) as
26+ | string
27+ | null
28+ const selected = objectType ?? 'contact'
29+ if ( selected === 'custom' ) {
30+ const trimmed = customId ?. trim ( )
31+ return trimmed ? trimmed : null
32+ }
33+ return selected
34+ }
35+
1736async function fetchHubSpotProperties ( blockId : string , objectType : string ) {
1837 const credentialId = useSubBlockStore . getState ( ) . getValue ( blockId , 'triggerCredentials' ) as
1938 | string
@@ -128,13 +147,7 @@ export const hubspotPollingTrigger: TriggerConfig = {
128147 placeholder : 'Select a property' ,
129148 options : [ ] ,
130149 fetchOptions : async ( blockId : string ) => {
131- const objectType = useSubBlockStore . getState ( ) . getValue ( blockId , 'objectType' ) as
132- | string
133- | null
134- const customId = useSubBlockStore . getState ( ) . getValue ( blockId , 'customObjectTypeId' ) as
135- | string
136- | null
137- const resolved = objectType === 'custom' ? customId : objectType
150+ const resolved = resolveSelectedObjectType ( blockId )
138151 if ( ! resolved ) throw new Error ( 'Select an object type first' )
139152 try {
140153 return await fetchHubSpotProperties ( blockId , resolved )
@@ -162,13 +175,7 @@ export const hubspotPollingTrigger: TriggerConfig = {
162175 placeholder : 'Select properties (optional)' ,
163176 options : [ ] ,
164177 fetchOptions : async ( blockId : string ) => {
165- const objectType = useSubBlockStore . getState ( ) . getValue ( blockId , 'objectType' ) as
166- | string
167- | null
168- const customId = useSubBlockStore . getState ( ) . getValue ( blockId , 'customObjectTypeId' ) as
169- | string
170- | null
171- const resolved = objectType === 'custom' ? customId : objectType
178+ const resolved = resolveSelectedObjectType ( blockId )
172179 if ( ! resolved ) return [ ]
173180 try {
174181 return await fetchHubSpotProperties ( blockId , resolved )
@@ -193,10 +200,10 @@ export const hubspotPollingTrigger: TriggerConfig = {
193200 const credentialId = useSubBlockStore . getState ( ) . getValue ( blockId , 'triggerCredentials' ) as
194201 | string
195202 | null
196- const objectType = useSubBlockStore . getState ( ) . getValue ( blockId , 'objectType' ) as
197- | string
198- | null
199- if ( ! credentialId || ! objectType ) return [ ]
203+ const objectType =
204+ ( useSubBlockStore . getState ( ) . getValue ( blockId , 'objectType' ) as string | null ) ??
205+ 'contact'
206+ if ( ! credentialId ) throw new Error ( 'No HubSpot credential selected' )
200207 if ( isCredentialSetValue ( credentialId ) ) return [ ]
201208 try {
202209 const data = await requestJson ( hubspotPipelinesSelectorContract , {
@@ -224,14 +231,15 @@ export const hubspotPollingTrigger: TriggerConfig = {
224231 const credentialId = useSubBlockStore . getState ( ) . getValue ( blockId , 'triggerCredentials' ) as
225232 | string
226233 | null
227- const objectType = useSubBlockStore . getState ( ) . getValue ( blockId , 'objectType' ) as
228- | string
229- | null
234+ const objectType =
235+ ( useSubBlockStore . getState ( ) . getValue ( blockId , 'objectType' ) as string | null ) ??
236+ 'contact'
230237 const pipelineId = useSubBlockStore . getState ( ) . getValue ( blockId , 'pipelineId' ) as
231238 | string
232239 | null
233- if ( ! credentialId || ! objectType || ! pipelineId ) return [ ]
240+ if ( ! credentialId ) throw new Error ( 'No HubSpot credential selected' )
234241 if ( isCredentialSetValue ( credentialId ) ) return [ ]
242+ if ( ! pipelineId ) return [ ]
235243 try {
236244 const data = await requestJson ( hubspotPipelinesSelectorContract , {
237245 query : { credentialId, objectType } ,
@@ -259,7 +267,7 @@ export const hubspotPollingTrigger: TriggerConfig = {
259267 const credentialId = useSubBlockStore . getState ( ) . getValue ( blockId , 'triggerCredentials' ) as
260268 | string
261269 | null
262- if ( ! credentialId ) return [ ]
270+ if ( ! credentialId ) throw new Error ( 'No HubSpot credential selected' )
263271 if ( isCredentialSetValue ( credentialId ) ) return [ ]
264272 try {
265273 const data = await requestJson ( hubspotOwnersSelectorContract , {
0 commit comments