1
- import React , { useState } from 'react' ;
1
+ import React , { useEffect , useState } from 'react' ;
2
2
import {
3
3
Button ,
4
4
Card ,
@@ -15,6 +15,7 @@ import {
15
15
import { PageAppSDK } from '@contentful/app-sdk' ;
16
16
import { useCMA , useSDK } from '@contentful/react-apps-toolkit' ;
17
17
import { styles } from './Page.styles' ;
18
+ import { C } from 'vitest/dist/chunks/reporters.d.C1ogPriE' ;
18
19
19
20
interface HubSpotEmail {
20
21
id : string ;
@@ -93,6 +94,7 @@ const Page = () => {
93
94
contentBlocks : { } ,
94
95
} ) ;
95
96
const [ updating , setUpdating ] = useState ( false ) ;
97
+ const [ hubspotAppActionId , setHubspotEmailAction ] = useState < string > ( '' ) ;
96
98
97
99
// Helper function to extract individual text nodes from HTML
98
100
const extractTextNodes = ( html : string ) : TextNode [ ] => {
@@ -166,6 +168,20 @@ const Page = () => {
166
168
} ) ;
167
169
} ;
168
170
171
+ useEffect ( ( ) => {
172
+ const getAppActions = async ( ) => {
173
+ const appActions = await cma . appAction . getManyForEnvironment ( { } ) ;
174
+ const hubspotEmailAction = appActions . items . find ( ( appAction ) => {
175
+ if ( appAction . name === 'Hubspot Email Action' ) {
176
+ return appAction ;
177
+ }
178
+ } ) ;
179
+ setHubspotEmailAction ( hubspotEmailAction ?. sys . id || '' ) ;
180
+ } ;
181
+
182
+ getAppActions ( ) ;
183
+ } , [ ] ) ;
184
+
169
185
// Test HubSpot connection and fetch emails
170
186
const fetchHubSpotEmails = async ( ) => {
171
187
try {
@@ -175,7 +191,7 @@ const Page = () => {
175
191
const res = await cma . appActionCall . createWithResponse (
176
192
{
177
193
appDefinitionId : sdk . ids . app || '' ,
178
- appActionId : '3rpmmTblbOagoCcT2QVrtb' ,
194
+ appActionId : hubspotAppActionId ,
179
195
} ,
180
196
{
181
197
parameters : {
@@ -262,7 +278,7 @@ const Page = () => {
262
278
const res = await cma . appActionCall . createWithResponse (
263
279
{
264
280
appDefinitionId : sdk . ids . app || '' ,
265
- appActionId : '3rpmmTblbOagoCcT2QVrtb' ,
281
+ appActionId : hubspotAppActionId ,
266
282
} ,
267
283
{
268
284
parameters : {
0 commit comments