Skip to content

Commit 6f0bb35

Browse files
committed
feat: support multiple actions on wizard hook
1 parent bde7dc9 commit 6f0bb35

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

components/wizards/notifications/NotificationStep.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export function NotificationStep({ notificationTrigger, readonly }: Props) {
9292
throw new Error(`Email is required`)
9393
}
9494
return {
95+
integrationKey: key,
9596
key: 'sendEmailToYourself',
9697
inputs: {
9798
email: inputs.email,
@@ -101,6 +102,7 @@ export function NotificationStep({ notificationTrigger, readonly }: Props) {
101102
}
102103
case 'discord':
103104
return {
105+
integrationKey: key,
104106
key: 'sendMessage',
105107
inputs: {
106108
channelId: inputs.channelId,
@@ -110,6 +112,7 @@ export function NotificationStep({ notificationTrigger, readonly }: Props) {
110112
}
111113
case 'telegram':
112114
return {
115+
integrationKey: key,
113116
key: 'sendMessage',
114117
inputs: {
115118
text: actionData.message,
@@ -118,6 +121,7 @@ export function NotificationStep({ notificationTrigger, readonly }: Props) {
118121
}
119122
case 'xmtp':
120123
return {
124+
integrationKey: key,
121125
key: 'sendMessageWallet',
122126
inputs: {
123127
address,

pages/create/bulkaction/setup.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ function SetupBulkActionPage() {
212212
},
213213
actions: [
214214
{
215+
integrationKey: actionIntegration.key,
215216
key: action.operationKey,
216217
inputs: {
217218
...inputs, // TODO filter only action?
@@ -280,10 +281,10 @@ function SetupBulkActionPage() {
280281
</Head>
281282
<PageWrapper title="Create a Bulk Action" extra={<OperationsUsed />}>
282283
<div className="container px-0 mx-auto lg:px-24">
283-
<Card className="w-full flex justify-center">
284-
<div className="w-full md:w-fit gap-4 my-8 mx-0 lg:mx-48">
285-
<div className="text-center text-2xl font-bold mb-8">Select Data Source and Action</div>
286-
<div className="text-center text-lg mb-12">
284+
<Card className="flex justify-center w-full">
285+
<div className="w-full gap-4 mx-0 my-8 md:w-fit lg:mx-48">
286+
<div className="mb-8 text-2xl font-bold text-center">Select Data Source and Action</div>
287+
<div className="mb-12 text-lg text-center">
287288
To create a Bulk Action, select a data source and an action. The action will be executed for all items
288289
in the data source.
289290
</div>

src/services/WizardHooks.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type OperationData = {
1818

1919
type TriggerData = OperationData & { schedule?: Record<string, any> }
2020

21+
type ActionData = OperationData & { integrationKey: string }
22+
2123
interface 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

3234
const 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

5359
export 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

Comments
 (0)