@@ -18,6 +18,8 @@ type OperationData = {
1818
1919type TriggerData = OperationData & { schedule ?: Record < string , any > }
2020
21+ type ActionData = OperationData & { integrationKey : string }
22+
2123interface CreateWorkflowWithOperations {
2224 workflowName : string
2325 triggerIntegration : {
@@ -26,7 +28,7 @@ interface CreateWorkflowWithOperations {
2628 version ?: string
2729 }
2830 trigger : TriggerData
29- actions : Array < OperationData >
31+ actions : ActionData [ ]
3032}
3133
3234const integrationFragment = gql `
@@ -47,14 +49,18 @@ const integrationActionFragment = gql`
4749 fragment WizardHookIntegrationActionFragment on IntegrationAction {
4850 id
4951 key
52+ integration {
53+ id
54+ key
55+ }
5056 }
5157`
5258
5359export function useCreateWorkflowWithOperations ( ) {
5460 const [ loading , setLoading ] = useState ( false )
5561 const [ error , setError ] = useState < string | null > ( null )
5662 const [ trigger , setTrigger ] = useState < TriggerData > ( )
57- const [ actions , setActions ] = useState < Array < OperationData > > ( )
63+ const [ actions , setActions ] = useState < Array < ActionData > > ( )
5864 const [ runStarted , setRunStarted ] = useState ( false )
5965 const [ integrationQuery , setIntegrationQuery ] = useState < { id ?: string ; key : string ; version ?: string } > ( )
6066 const [ workflow , setWorkflow ] = useState < Workflow > ( )
@@ -164,28 +170,36 @@ export function useCreateWorkflowWithOperations() {
164170 setError ( ( e as Error ) ?. message )
165171 }
166172
167- // TODO support multiple actions
168- if ( integrationActions ?. length ) {
169- try {
173+ try {
174+ const workflowActions : WorkflowAction [ ] = [ ]
175+ for ( const action of actions ) {
176+ const integrationAction = integrationActions ?. find (
177+ ( ia ) => ia . key === action . key && ia . integration . key === action . integrationKey ,
178+ )
179+ if ( ! integrationAction ) {
180+ setError ( `Integration action not found` )
181+ return
182+ }
170183 const workflowActionRes = await createWorkflowAction ( {
171184 variables : {
172185 input : {
173186 workflowAction : {
174187 workflow : workflow . id ,
175- integrationAction : integrationActions [ 0 ] . id ,
176- inputs : actions [ 0 ] . inputs ,
177- credentials : actions [ 0 ] . credentialsId ,
178- name : actions [ 0 ] . name ,
188+ integrationAction : integrationAction . id ,
189+ inputs : action . inputs ,
190+ credentials : action . credentialsId ,
191+ name : action . name ,
179192 } ,
180193 } ,
181194 } ,
182195 } )
183196 if ( workflowActionRes . data ?. createOneWorkflowAction ) {
184- setWorkflowActions ( [ workflowActionRes . data . createOneWorkflowAction ] )
197+ workflowActions . push ( workflowActionRes . data . createOneWorkflowAction )
185198 }
186- } catch ( e ) {
187- setError ( ( e as Error ) ?. message )
188199 }
200+ setWorkflowActions ( workflowActions )
201+ } catch ( e ) {
202+ setError ( ( e as Error ) ?. message )
189203 }
190204
191205 runStartedInternal = false
0 commit comments