@codee-sh/medusa-plugin-automations 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.medusa/server/src/admin/_chunks/{__admin-extensions__-CQZdTnuf → __admin-extensions__-DIB2k6nJ} +665 -304
- package/.medusa/server/src/admin/_chunks/{__admin-extensions__-DIUFmida → __admin-extensions__-rqdPN7M1} +665 -304
- package/.medusa/server/src/admin/_chunks/{base-config-0lbnQWYz → base-config-DbRWuXsL} +25 -9
- package/.medusa/server/src/admin/_chunks/{base-config-DsBoNoxD → base-config-ro-vFPBg} +25 -9
- package/.medusa/server/src/admin/index.js +1 -1
- package/.medusa/server/src/admin/index.mjs +1 -1
- package/.medusa/server/src/api/admin/mpn/automations/actions/route.js +4 -4
- package/.medusa/server/src/api/admin/mpn/automations/available-actions/route.js +1 -1
- package/.medusa/server/src/api/admin/mpn/automations/available-events/route.js +1 -1
- package/.medusa/server/src/api/admin/mpn/automations/available-triggers/route.js +1 -1
- package/.medusa/server/src/api/admin/mpn/automations/route.js +6 -6
- package/.medusa/server/src/api/admin/mpn/automations/rules/route.js +12 -7
- package/.medusa/server/src/api/middlewares.js +4 -3
- package/.medusa/server/src/hooks/api/automations/automations.js +3 -3
- package/.medusa/server/src/hooks/api/automations-actions/automations-actions.js +3 -3
- package/.medusa/server/src/hooks/api/automations-rules/automations-rules.js +3 -3
- package/.medusa/server/src/hooks/api/available-actions/actions.js +3 -3
- package/.medusa/server/src/hooks/api/available-events/events.js +3 -3
- package/.medusa/server/src/hooks/api/available-triggers/triggers.js +3 -3
- package/.medusa/server/src/modules/mpn-automation/actions-handlers/base-action-handler.js +3 -3
- package/.medusa/server/src/modules/mpn-automation/actions-handlers/email-action-handler.js +1 -1
- package/.medusa/server/src/modules/mpn-automation/actions-handlers/slack-action-handler.js +1 -1
- package/.medusa/server/src/modules/mpn-automation/migrations/Migration20251127115228.js +1 -1
- package/.medusa/server/src/modules/mpn-automation/migrations/Migration20251127193345.js +1 -1
- package/.medusa/server/src/modules/mpn-automation/migrations/Migration20251127195615.js +1 -1
- package/.medusa/server/src/modules/mpn-automation/migrations/Migration20251130144047.js +1 -1
- package/.medusa/server/src/modules/mpn-automation/migrations/Migration20251207172856.js +1 -1
- package/.medusa/server/src/modules/mpn-automation/migrations/Migration20251208090654.js +14 -0
- package/.medusa/server/src/modules/mpn-automation/models/mpn_automation_rule.js +3 -2
- package/.medusa/server/src/modules/mpn-automation/models/mpn_automation_rule_value.js +3 -4
- package/.medusa/server/src/modules/mpn-automation/models/mpn_automation_state.js +2 -3
- package/.medusa/server/src/modules/mpn-automation/models/mpn_automation_trigger.js +9 -6
- package/.medusa/server/src/modules/mpn-automation/models/npm_automation_action.js +1 -1
- package/.medusa/server/src/modules/mpn-automation/services/service.js +9 -4
- package/.medusa/server/src/modules/mpn-automation/types/types.js +42 -48
- package/.medusa/server/src/providers/slack/service.js +14 -14
- package/.medusa/server/src/subscribers/inventory-item-updated.js +1 -1
- package/.medusa/server/src/subscribers/inventory-level-updated.js +6 -5
- package/.medusa/server/src/subscribers/inventory-reservation-item-updated.js +1 -1
- package/.medusa/server/src/subscribers/mpn.automation.action.email.executed.js +4 -4
- package/.medusa/server/src/subscribers/mpn.automation.action.slack.executed.js +2 -15
- package/.medusa/server/src/subscribers/order-completed.js +2 -2
- package/.medusa/server/src/subscribers/order-placed.js +2 -2
- package/.medusa/server/src/subscribers/payment-captured.js +2 -2
- package/.medusa/server/src/utils/index.js +1 -1
- package/.medusa/server/src/utils/plugins.js +4 -2
- package/.medusa/server/src/utils/validate-rules.js +1 -1
- package/.medusa/server/src/workflows/inventory/get-inventory-level-by-id.js +1 -1
- package/.medusa/server/src/workflows/inventory/steps/get-inventory-level-by-id.js +1 -1
- package/.medusa/server/src/workflows/mpn-automation/create-automation.js +1 -1
- package/.medusa/server/src/workflows/mpn-automation/delete-automation.js +1 -1
- package/.medusa/server/src/workflows/mpn-automation/edit-automation-actions.js +2 -2
- package/.medusa/server/src/workflows/mpn-automation/edit-automation-rules.js +2 -2
- package/.medusa/server/src/workflows/mpn-automation/edit-automation.js +1 -1
- package/.medusa/server/src/workflows/mpn-automation/index.js +2 -1
- package/.medusa/server/src/workflows/mpn-automation/run-automation.js +32 -25
- package/.medusa/server/src/workflows/mpn-automation/save-automation-state.js +16 -0
- package/.medusa/server/src/workflows/mpn-automation/send-email-action.js +1 -1
- package/.medusa/server/src/workflows/mpn-automation/send-slack-action.js +1 -1
- package/.medusa/server/src/workflows/mpn-automation/steps/create-automation.js +2 -2
- package/.medusa/server/src/workflows/mpn-automation/steps/delete-automation.js +4 -2
- package/.medusa/server/src/workflows/mpn-automation/steps/edit-automation-actions.js +4 -2
- package/.medusa/server/src/workflows/mpn-automation/steps/edit-automation-rules.js +11 -7
- package/.medusa/server/src/workflows/mpn-automation/steps/edit-automation.js +2 -2
- package/.medusa/server/src/workflows/mpn-automation/steps/index.js +2 -1
- package/.medusa/server/src/workflows/mpn-automation/steps/retrieve-automation-triggers-by-event.js +2 -4
- package/.medusa/server/src/workflows/mpn-automation/steps/run-automation-actions.js +23 -27
- package/.medusa/server/src/workflows/mpn-automation/steps/save-automation-state.js +40 -0
- package/.medusa/server/src/workflows/mpn-automation/steps/validate-automation-triggers.js +8 -6
- package/.medusa/server/src/workflows/mpn-automation/validate-automation-triggers-by-event.js +6 -6
- package/.medusa/server/src/workflows/notifications/send-email.js +1 -1
- package/.medusa/server/src/workflows/notifications/send-slack.js +1 -1
- package/.medusa/server/src/workflows/notifications/steps/send-email.js +6 -3
- package/.medusa/server/src/workflows/notifications/steps/send-slack.js +1 -1
- package/.medusa/server/src/workflows/steps/log-step.js +1 -1
- package/README.md +18 -7
- package/package.json +4 -2
|
@@ -2958,7 +2958,9 @@ function useTranslation(ns) {
|
|
|
2958
2958
|
}
|
|
2959
2959
|
});
|
|
2960
2960
|
}
|
|
2961
|
-
const JsonViewSection = ({
|
|
2961
|
+
const JsonViewSection = ({
|
|
2962
|
+
data
|
|
2963
|
+
}) => {
|
|
2962
2964
|
const { t: t2 } = useTranslation();
|
|
2963
2965
|
const numberOfKeys = Object.keys(data).length;
|
|
2964
2966
|
return /* @__PURE__ */ jsxs(Container$1, { className: "flex items-center justify-between px-6 py-4", children: [
|
|
@@ -2987,7 +2989,13 @@ const JsonViewSection = ({ data }) => {
|
|
|
2987
2989
|
i18nKey: "json.drawer.header",
|
|
2988
2990
|
count: numberOfKeys,
|
|
2989
2991
|
components: [
|
|
2990
|
-
/* @__PURE__ */ jsx(
|
|
2992
|
+
/* @__PURE__ */ jsx(
|
|
2993
|
+
"span",
|
|
2994
|
+
{
|
|
2995
|
+
className: "text-ui-fg-subtle"
|
|
2996
|
+
},
|
|
2997
|
+
"count-span"
|
|
2998
|
+
)
|
|
2991
2999
|
]
|
|
2992
3000
|
}
|
|
2993
3001
|
) }) }),
|
|
@@ -3037,7 +3045,12 @@ const JsonViewSection = ({ data }) => {
|
|
|
3037
3045
|
},
|
|
3038
3046
|
collapsed: 1,
|
|
3039
3047
|
children: [
|
|
3040
|
-
/* @__PURE__ */ jsx(
|
|
3048
|
+
/* @__PURE__ */ jsx(
|
|
3049
|
+
JsonView.Quote,
|
|
3050
|
+
{
|
|
3051
|
+
render: () => /* @__PURE__ */ jsx("span", {})
|
|
3052
|
+
}
|
|
3053
|
+
),
|
|
3041
3054
|
/* @__PURE__ */ jsx(
|
|
3042
3055
|
JsonView.Null,
|
|
3043
3056
|
{
|
|
@@ -3055,7 +3068,9 @@ const JsonViewSection = ({ data }) => {
|
|
|
3055
3068
|
{
|
|
3056
3069
|
render: (_props, { value }) => {
|
|
3057
3070
|
return /* @__PURE__ */ jsx("span", { className: "text-ui-contrast-fg-secondary ml-2", children: t2("general.items", {
|
|
3058
|
-
count: Object.keys(
|
|
3071
|
+
count: Object.keys(
|
|
3072
|
+
value
|
|
3073
|
+
).length
|
|
3059
3074
|
}) });
|
|
3060
3075
|
}
|
|
3061
3076
|
}
|
|
@@ -3066,7 +3081,13 @@ const JsonViewSection = ({ data }) => {
|
|
|
3066
3081
|
JsonView.Copied,
|
|
3067
3082
|
{
|
|
3068
3083
|
render: ({ style }, { value }) => {
|
|
3069
|
-
return /* @__PURE__ */ jsx(
|
|
3084
|
+
return /* @__PURE__ */ jsx(
|
|
3085
|
+
Copied,
|
|
3086
|
+
{
|
|
3087
|
+
style,
|
|
3088
|
+
value
|
|
3089
|
+
}
|
|
3090
|
+
);
|
|
3070
3091
|
}
|
|
3071
3092
|
}
|
|
3072
3093
|
)
|
|
@@ -3190,24 +3211,28 @@ const sdk = new Medusa({
|
|
|
3190
3211
|
}
|
|
3191
3212
|
});
|
|
3192
3213
|
const useCreateAutomation = (options) => {
|
|
3193
|
-
return useMutation(
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3214
|
+
return useMutation(
|
|
3215
|
+
{
|
|
3216
|
+
mutationFn: async (data) => {
|
|
3217
|
+
await sdk.client.fetch("/admin/mpn/automations", {
|
|
3218
|
+
method: "POST",
|
|
3219
|
+
body: data
|
|
3220
|
+
});
|
|
3221
|
+
}
|
|
3199
3222
|
}
|
|
3200
|
-
|
|
3223
|
+
);
|
|
3201
3224
|
};
|
|
3202
3225
|
const useEditAutomation = (options) => {
|
|
3203
|
-
return useMutation(
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3226
|
+
return useMutation(
|
|
3227
|
+
{
|
|
3228
|
+
mutationFn: async (data) => {
|
|
3229
|
+
await sdk.client.fetch("/admin/mpn/automations", {
|
|
3230
|
+
method: "POST",
|
|
3231
|
+
body: data
|
|
3232
|
+
});
|
|
3233
|
+
}
|
|
3209
3234
|
}
|
|
3210
|
-
|
|
3235
|
+
);
|
|
3211
3236
|
};
|
|
3212
3237
|
const useDeleteAutomation = (options) => {
|
|
3213
3238
|
return useMutation({
|
|
@@ -3223,7 +3248,15 @@ const useDeleteAutomation = (options) => {
|
|
|
3223
3248
|
});
|
|
3224
3249
|
};
|
|
3225
3250
|
const useListAutomations = (params, options) => {
|
|
3226
|
-
const {
|
|
3251
|
+
const {
|
|
3252
|
+
limit = 100,
|
|
3253
|
+
offset = 0,
|
|
3254
|
+
extraKey = [],
|
|
3255
|
+
enabled,
|
|
3256
|
+
fields,
|
|
3257
|
+
order = "created_at",
|
|
3258
|
+
id
|
|
3259
|
+
} = params;
|
|
3227
3260
|
const queryKey = [
|
|
3228
3261
|
"automations",
|
|
3229
3262
|
id,
|
|
@@ -3243,10 +3276,13 @@ const useListAutomations = (params, options) => {
|
|
|
3243
3276
|
const { data, ...rest } = useQuery({
|
|
3244
3277
|
queryKey,
|
|
3245
3278
|
queryFn: async () => {
|
|
3246
|
-
return await sdk.client.fetch(
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3279
|
+
return await sdk.client.fetch(
|
|
3280
|
+
"/admin/mpn/automations",
|
|
3281
|
+
{
|
|
3282
|
+
method: "GET",
|
|
3283
|
+
query
|
|
3284
|
+
}
|
|
3285
|
+
);
|
|
3250
3286
|
},
|
|
3251
3287
|
enabled,
|
|
3252
3288
|
...options
|
|
@@ -5135,7 +5171,15 @@ var n = function(e2, o2) {
|
|
|
5135
5171
|
};
|
|
5136
5172
|
};
|
|
5137
5173
|
const useAvailableActions = (params, options) => {
|
|
5138
|
-
const {
|
|
5174
|
+
const {
|
|
5175
|
+
limit = 100,
|
|
5176
|
+
offset = 0,
|
|
5177
|
+
extraKey = [],
|
|
5178
|
+
enabled,
|
|
5179
|
+
fields,
|
|
5180
|
+
order = "created_at",
|
|
5181
|
+
id
|
|
5182
|
+
} = params;
|
|
5139
5183
|
const queryKey = [
|
|
5140
5184
|
"available-actions",
|
|
5141
5185
|
limit,
|
|
@@ -5151,10 +5195,13 @@ const useAvailableActions = (params, options) => {
|
|
|
5151
5195
|
const { data, ...rest } = useQuery({
|
|
5152
5196
|
queryKey,
|
|
5153
5197
|
queryFn: async () => {
|
|
5154
|
-
return await sdk.client.fetch(
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5198
|
+
return await sdk.client.fetch(
|
|
5199
|
+
"/admin/mpn/automations/available-actions",
|
|
5200
|
+
{
|
|
5201
|
+
method: "GET",
|
|
5202
|
+
query
|
|
5203
|
+
}
|
|
5204
|
+
);
|
|
5158
5205
|
},
|
|
5159
5206
|
enabled,
|
|
5160
5207
|
...options
|
|
@@ -5162,7 +5209,15 @@ const useAvailableActions = (params, options) => {
|
|
|
5162
5209
|
return { data, ...rest };
|
|
5163
5210
|
};
|
|
5164
5211
|
const useAvailableEvents = (params, options) => {
|
|
5165
|
-
const {
|
|
5212
|
+
const {
|
|
5213
|
+
limit = 100,
|
|
5214
|
+
offset = 0,
|
|
5215
|
+
extraKey = [],
|
|
5216
|
+
enabled,
|
|
5217
|
+
fields,
|
|
5218
|
+
order = "created_at",
|
|
5219
|
+
id
|
|
5220
|
+
} = params;
|
|
5166
5221
|
const queryKey = [
|
|
5167
5222
|
"available-events",
|
|
5168
5223
|
limit,
|
|
@@ -5178,10 +5233,13 @@ const useAvailableEvents = (params, options) => {
|
|
|
5178
5233
|
const { data, ...rest } = useQuery({
|
|
5179
5234
|
queryKey,
|
|
5180
5235
|
queryFn: async () => {
|
|
5181
|
-
return await sdk.client.fetch(
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5236
|
+
return await sdk.client.fetch(
|
|
5237
|
+
"/admin/mpn/automations/available-events",
|
|
5238
|
+
{
|
|
5239
|
+
method: "GET",
|
|
5240
|
+
query
|
|
5241
|
+
}
|
|
5242
|
+
);
|
|
5185
5243
|
},
|
|
5186
5244
|
enabled,
|
|
5187
5245
|
...options
|
|
@@ -5189,7 +5247,14 @@ const useAvailableEvents = (params, options) => {
|
|
|
5189
5247
|
return { data, ...rest };
|
|
5190
5248
|
};
|
|
5191
5249
|
const useAvailableTriggers = (params, options) => {
|
|
5192
|
-
const {
|
|
5250
|
+
const {
|
|
5251
|
+
limit = 100,
|
|
5252
|
+
offset = 0,
|
|
5253
|
+
extraKey = [],
|
|
5254
|
+
enabled,
|
|
5255
|
+
fields,
|
|
5256
|
+
order = "created_at"
|
|
5257
|
+
} = params;
|
|
5193
5258
|
const queryKey = [
|
|
5194
5259
|
"available-triggers",
|
|
5195
5260
|
limit,
|
|
@@ -5205,24 +5270,36 @@ const useAvailableTriggers = (params, options) => {
|
|
|
5205
5270
|
const { data, ...rest } = useQuery({
|
|
5206
5271
|
queryKey,
|
|
5207
5272
|
queryFn: async () => {
|
|
5208
|
-
return await sdk.client.fetch(
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5273
|
+
return await sdk.client.fetch(
|
|
5274
|
+
"/admin/mpn/automations/available-triggers",
|
|
5275
|
+
{
|
|
5276
|
+
method: "GET",
|
|
5277
|
+
query
|
|
5278
|
+
}
|
|
5279
|
+
);
|
|
5212
5280
|
},
|
|
5213
5281
|
enabled,
|
|
5214
5282
|
...options
|
|
5215
5283
|
});
|
|
5216
5284
|
return { data, ...rest };
|
|
5217
5285
|
};
|
|
5218
|
-
function AutomationsGeneralForm({
|
|
5219
|
-
|
|
5286
|
+
function AutomationsGeneralForm({
|
|
5287
|
+
form,
|
|
5288
|
+
isOpen
|
|
5289
|
+
}) {
|
|
5290
|
+
const {
|
|
5291
|
+
data: availableEventsData
|
|
5292
|
+
} = useAvailableEvents({
|
|
5220
5293
|
enabled: isOpen !== false
|
|
5221
5294
|
});
|
|
5222
|
-
const {
|
|
5295
|
+
const {
|
|
5296
|
+
data: availableTriggersData
|
|
5297
|
+
} = useAvailableTriggers({
|
|
5223
5298
|
enabled: isOpen !== false
|
|
5224
5299
|
});
|
|
5225
|
-
const {
|
|
5300
|
+
const {
|
|
5301
|
+
data: availableActionsData
|
|
5302
|
+
} = useAvailableActions({
|
|
5226
5303
|
enabled: isOpen !== false
|
|
5227
5304
|
});
|
|
5228
5305
|
const availableEvents = useMemo(() => {
|
|
@@ -5243,7 +5320,13 @@ function AutomationsGeneralForm({ form, isOpen }) {
|
|
|
5243
5320
|
name: "general.name",
|
|
5244
5321
|
control: form.control,
|
|
5245
5322
|
render: ({ field, fieldState }) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
5246
|
-
/* @__PURE__ */ jsx(
|
|
5323
|
+
/* @__PURE__ */ jsx(
|
|
5324
|
+
Input,
|
|
5325
|
+
{
|
|
5326
|
+
...field,
|
|
5327
|
+
placeholder: "Enter the name of the automation"
|
|
5328
|
+
}
|
|
5329
|
+
),
|
|
5247
5330
|
fieldState.error && /* @__PURE__ */ jsx("span", { className: "text-red-500 text-sm", children: fieldState.error.message })
|
|
5248
5331
|
] })
|
|
5249
5332
|
}
|
|
@@ -5257,7 +5340,13 @@ function AutomationsGeneralForm({ form, isOpen }) {
|
|
|
5257
5340
|
name: "general.description",
|
|
5258
5341
|
control: form.control,
|
|
5259
5342
|
render: ({ field, fieldState }) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
5260
|
-
/* @__PURE__ */ jsx(
|
|
5343
|
+
/* @__PURE__ */ jsx(
|
|
5344
|
+
Input,
|
|
5345
|
+
{
|
|
5346
|
+
...field,
|
|
5347
|
+
placeholder: "Enter the description of the automation"
|
|
5348
|
+
}
|
|
5349
|
+
),
|
|
5261
5350
|
fieldState.error && /* @__PURE__ */ jsx("span", { className: "text-red-500 text-sm", children: fieldState.error.message })
|
|
5262
5351
|
] })
|
|
5263
5352
|
}
|
|
@@ -5280,7 +5369,14 @@ function AutomationsGeneralForm({ form, isOpen }) {
|
|
|
5280
5369
|
},
|
|
5281
5370
|
children: [
|
|
5282
5371
|
/* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Select the trigger type" }) }),
|
|
5283
|
-
/* @__PURE__ */ jsx(Select.Content, { children: availableTriggers.map((type) => /* @__PURE__ */ jsx(
|
|
5372
|
+
/* @__PURE__ */ jsx(Select.Content, { children: availableTriggers.map((type) => /* @__PURE__ */ jsx(
|
|
5373
|
+
Select.Item,
|
|
5374
|
+
{
|
|
5375
|
+
value: type.value,
|
|
5376
|
+
children: type.label
|
|
5377
|
+
},
|
|
5378
|
+
type.value
|
|
5379
|
+
)) })
|
|
5284
5380
|
]
|
|
5285
5381
|
},
|
|
5286
5382
|
`trigger-type-${availableTriggers.length}-${field.value}`
|
|
@@ -5338,7 +5434,14 @@ function AutomationsGeneralForm({ form, isOpen }) {
|
|
|
5338
5434
|
/* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Select the event name" }) }),
|
|
5339
5435
|
/* @__PURE__ */ jsx(Select.Content, { children: availableEvents == null ? void 0 : availableEvents.map((event) => /* @__PURE__ */ jsxs(Select.Group, { children: [
|
|
5340
5436
|
/* @__PURE__ */ jsx(Select.Label, { children: event.name }),
|
|
5341
|
-
event.events.map((eventItem) => /* @__PURE__ */ jsx(
|
|
5437
|
+
event.events.map((eventItem) => /* @__PURE__ */ jsx(
|
|
5438
|
+
Select.Item,
|
|
5439
|
+
{
|
|
5440
|
+
value: eventItem.value,
|
|
5441
|
+
children: eventItem.label
|
|
5442
|
+
},
|
|
5443
|
+
eventItem.value
|
|
5444
|
+
))
|
|
5342
5445
|
] }, event.name)) })
|
|
5343
5446
|
]
|
|
5344
5447
|
},
|
|
@@ -9022,37 +9125,47 @@ const baseAutomationFormSchema = objectType({
|
|
|
9022
9125
|
}).optional()
|
|
9023
9126
|
});
|
|
9024
9127
|
function createAutomationFormSchema(availableActions) {
|
|
9025
|
-
return baseAutomationFormSchema.superRefine(
|
|
9026
|
-
|
|
9027
|
-
|
|
9028
|
-
data.actions.items
|
|
9029
|
-
|
|
9030
|
-
|
|
9031
|
-
|
|
9032
|
-
const actionDef = availableActions.find(
|
|
9033
|
-
(a2) => a2.value === action.action_type
|
|
9034
|
-
);
|
|
9035
|
-
if (!actionDef || !actionDef.fields) {
|
|
9036
|
-
return;
|
|
9037
|
-
}
|
|
9038
|
-
actionDef.fields.forEach((field) => {
|
|
9039
|
-
var _a2;
|
|
9040
|
-
if (field.required) {
|
|
9041
|
-
const fieldValue = (_a2 = action.config) == null ? void 0 : _a2[field.name || field.key];
|
|
9042
|
-
if (!fieldValue || !String(fieldValue).trim()) {
|
|
9043
|
-
ctx.addIssue({
|
|
9044
|
-
code: ZodIssueCode.custom,
|
|
9045
|
-
message: `${field.label} is required`,
|
|
9046
|
-
path: ["actions", "items", index, "config", field.name || field.key]
|
|
9047
|
-
});
|
|
9048
|
-
}
|
|
9128
|
+
return baseAutomationFormSchema.superRefine(
|
|
9129
|
+
(data, ctx) => {
|
|
9130
|
+
var _a;
|
|
9131
|
+
if (((_a = data.actions) == null ? void 0 : _a.items) && availableActions) {
|
|
9132
|
+
data.actions.items.forEach((action, index) => {
|
|
9133
|
+
if (!action.action_type) {
|
|
9134
|
+
return;
|
|
9049
9135
|
}
|
|
9136
|
+
const actionDef = availableActions.find(
|
|
9137
|
+
(a2) => a2.value === action.action_type
|
|
9138
|
+
);
|
|
9139
|
+
if (!actionDef || !actionDef.fields) {
|
|
9140
|
+
return;
|
|
9141
|
+
}
|
|
9142
|
+
actionDef.fields.forEach((field) => {
|
|
9143
|
+
var _a2;
|
|
9144
|
+
if (field.required) {
|
|
9145
|
+
const fieldValue = (_a2 = action.config) == null ? void 0 : _a2[field.name || field.key];
|
|
9146
|
+
if (!fieldValue || !String(fieldValue).trim()) {
|
|
9147
|
+
ctx.addIssue({
|
|
9148
|
+
code: ZodIssueCode.custom,
|
|
9149
|
+
message: `${field.label} is required`,
|
|
9150
|
+
path: [
|
|
9151
|
+
"actions",
|
|
9152
|
+
"items",
|
|
9153
|
+
index,
|
|
9154
|
+
"config",
|
|
9155
|
+
field.name || field.key
|
|
9156
|
+
]
|
|
9157
|
+
});
|
|
9158
|
+
}
|
|
9159
|
+
}
|
|
9160
|
+
});
|
|
9050
9161
|
});
|
|
9051
|
-
}
|
|
9162
|
+
}
|
|
9052
9163
|
}
|
|
9053
|
-
|
|
9164
|
+
);
|
|
9054
9165
|
}
|
|
9055
|
-
function AutomationsCreateForm({
|
|
9166
|
+
function AutomationsCreateForm({
|
|
9167
|
+
id
|
|
9168
|
+
}) {
|
|
9056
9169
|
const [open, setOpen] = useState(false);
|
|
9057
9170
|
const [tab, setTab] = useState(Tab.GENERAL);
|
|
9058
9171
|
const [tabState, setTabState] = useState({
|
|
@@ -9071,7 +9184,10 @@ function AutomationsCreateForm({ id }) {
|
|
|
9071
9184
|
}
|
|
9072
9185
|
}, [tab]);
|
|
9073
9186
|
const queryClient = useQueryClient();
|
|
9074
|
-
const {
|
|
9187
|
+
const {
|
|
9188
|
+
data: automationsTriggerData,
|
|
9189
|
+
isLoading: isAutomationsTriggerLoading
|
|
9190
|
+
} = useListAutomations({
|
|
9075
9191
|
id,
|
|
9076
9192
|
extraKey: [],
|
|
9077
9193
|
enabled: open && !!id
|
|
@@ -9079,9 +9195,14 @@ function AutomationsCreateForm({ id }) {
|
|
|
9079
9195
|
const { data: availableActionsData } = useAvailableActions({
|
|
9080
9196
|
enabled: open
|
|
9081
9197
|
});
|
|
9082
|
-
const {
|
|
9198
|
+
const {
|
|
9199
|
+
mutateAsync: createAutomation,
|
|
9200
|
+
isPending: isCreateAutomationPending
|
|
9201
|
+
} = useCreateAutomation();
|
|
9083
9202
|
const automationFormSchema = useMemo(() => {
|
|
9084
|
-
return createAutomationFormSchema(
|
|
9203
|
+
return createAutomationFormSchema(
|
|
9204
|
+
availableActionsData == null ? void 0 : availableActionsData.actions
|
|
9205
|
+
);
|
|
9085
9206
|
}, [availableActionsData == null ? void 0 : availableActionsData.actions]);
|
|
9086
9207
|
const form = useForm({
|
|
9087
9208
|
resolver: t(automationFormSchema),
|
|
@@ -9157,7 +9278,9 @@ function AutomationsCreateForm({ id }) {
|
|
|
9157
9278
|
await createAutomation({
|
|
9158
9279
|
items: [items]
|
|
9159
9280
|
}).then(() => {
|
|
9160
|
-
queryClient.invalidateQueries({
|
|
9281
|
+
queryClient.invalidateQueries({
|
|
9282
|
+
queryKey: ["automations"]
|
|
9283
|
+
});
|
|
9161
9284
|
toast.success("Automation created successfully", {
|
|
9162
9285
|
position: "top-right",
|
|
9163
9286
|
duration: 3e3
|
|
@@ -9179,11 +9302,30 @@ function AutomationsCreateForm({ id }) {
|
|
|
9179
9302
|
dir: "ltr",
|
|
9180
9303
|
value: tab,
|
|
9181
9304
|
className: "flex h-full flex-col overflow-hidden",
|
|
9182
|
-
children: /* @__PURE__ */ jsx(ProgressTabs.List, { className: "justify-start-start flex w-full items-center", children: /* @__PURE__ */ jsx(
|
|
9305
|
+
children: /* @__PURE__ */ jsx(ProgressTabs.List, { className: "justify-start-start flex w-full items-center", children: /* @__PURE__ */ jsx(
|
|
9306
|
+
ProgressTabs.Trigger,
|
|
9307
|
+
{
|
|
9308
|
+
value: Tab.GENERAL,
|
|
9309
|
+
status: tabState[Tab.GENERAL],
|
|
9310
|
+
children: "General"
|
|
9311
|
+
}
|
|
9312
|
+
) })
|
|
9183
9313
|
}
|
|
9184
9314
|
) })
|
|
9185
9315
|
] }),
|
|
9186
|
-
/* @__PURE__ */ jsx(FocusModal.Body, { className: "w-full overflow-y-auto", children: isAutomationsTriggerLoading ? /* @__PURE__ */ jsx("div", { className: "p-6", children: "Loading..." }) : /* @__PURE__ */ jsx(
|
|
9316
|
+
/* @__PURE__ */ jsx(FocusModal.Body, { className: "w-full overflow-y-auto", children: isAutomationsTriggerLoading ? /* @__PURE__ */ jsx("div", { className: "p-6", children: "Loading..." }) : /* @__PURE__ */ jsx(
|
|
9317
|
+
"form",
|
|
9318
|
+
{
|
|
9319
|
+
onSubmit: form.handleSubmit(handleSubmit),
|
|
9320
|
+
children: tab === Tab.GENERAL && /* @__PURE__ */ jsx(
|
|
9321
|
+
AutomationsGeneralForm,
|
|
9322
|
+
{
|
|
9323
|
+
form,
|
|
9324
|
+
isOpen: open
|
|
9325
|
+
}
|
|
9326
|
+
)
|
|
9327
|
+
}
|
|
9328
|
+
) }),
|
|
9187
9329
|
/* @__PURE__ */ jsxs(FocusModal.Footer, { children: [
|
|
9188
9330
|
/* @__PURE__ */ jsx(FocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9189
9331
|
/* @__PURE__ */ jsx(
|
|
@@ -9201,17 +9343,31 @@ function AutomationsCreateForm({ id }) {
|
|
|
9201
9343
|
] });
|
|
9202
9344
|
}
|
|
9203
9345
|
const useEditAutomationRule = () => {
|
|
9204
|
-
return useMutation(
|
|
9205
|
-
|
|
9206
|
-
|
|
9207
|
-
|
|
9208
|
-
|
|
9209
|
-
|
|
9346
|
+
return useMutation(
|
|
9347
|
+
{
|
|
9348
|
+
mutationFn: async (data) => {
|
|
9349
|
+
await sdk.client.fetch(
|
|
9350
|
+
"/admin/mpn/automations/rules",
|
|
9351
|
+
{
|
|
9352
|
+
method: "POST",
|
|
9353
|
+
body: data
|
|
9354
|
+
}
|
|
9355
|
+
);
|
|
9356
|
+
}
|
|
9210
9357
|
}
|
|
9211
|
-
|
|
9358
|
+
);
|
|
9212
9359
|
};
|
|
9213
9360
|
const useListAutomationsRules = (params, options) => {
|
|
9214
|
-
const {
|
|
9361
|
+
const {
|
|
9362
|
+
limit = 100,
|
|
9363
|
+
offset = 0,
|
|
9364
|
+
extraKey = [],
|
|
9365
|
+
enabled,
|
|
9366
|
+
fields,
|
|
9367
|
+
order = "created_at",
|
|
9368
|
+
id,
|
|
9369
|
+
trigger_id
|
|
9370
|
+
} = params;
|
|
9215
9371
|
const queryKey = [
|
|
9216
9372
|
"automations-rules",
|
|
9217
9373
|
limit,
|
|
@@ -9233,10 +9389,13 @@ const useListAutomationsRules = (params, options) => {
|
|
|
9233
9389
|
const { data, ...rest } = useQuery({
|
|
9234
9390
|
queryKey,
|
|
9235
9391
|
queryFn: async () => {
|
|
9236
|
-
return await sdk.client.fetch(
|
|
9237
|
-
|
|
9238
|
-
|
|
9239
|
-
|
|
9392
|
+
return await sdk.client.fetch(
|
|
9393
|
+
"/admin/mpn/automations/rules",
|
|
9394
|
+
{
|
|
9395
|
+
method: "GET",
|
|
9396
|
+
query
|
|
9397
|
+
}
|
|
9398
|
+
);
|
|
9240
9399
|
},
|
|
9241
9400
|
enabled,
|
|
9242
9401
|
...options
|
|
@@ -9244,17 +9403,31 @@ const useListAutomationsRules = (params, options) => {
|
|
|
9244
9403
|
return { data, ...rest };
|
|
9245
9404
|
};
|
|
9246
9405
|
const useEditAutomationAction = () => {
|
|
9247
|
-
return useMutation(
|
|
9248
|
-
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9406
|
+
return useMutation(
|
|
9407
|
+
{
|
|
9408
|
+
mutationFn: async (data) => {
|
|
9409
|
+
await sdk.client.fetch(
|
|
9410
|
+
"/admin/mpn/automations/actions",
|
|
9411
|
+
{
|
|
9412
|
+
method: "POST",
|
|
9413
|
+
body: data
|
|
9414
|
+
}
|
|
9415
|
+
);
|
|
9416
|
+
}
|
|
9253
9417
|
}
|
|
9254
|
-
|
|
9418
|
+
);
|
|
9255
9419
|
};
|
|
9256
9420
|
const useListAutomationsActions = (params, options) => {
|
|
9257
|
-
const {
|
|
9421
|
+
const {
|
|
9422
|
+
limit = 100,
|
|
9423
|
+
offset = 0,
|
|
9424
|
+
extraKey = [],
|
|
9425
|
+
enabled,
|
|
9426
|
+
fields,
|
|
9427
|
+
order = "created_at",
|
|
9428
|
+
id,
|
|
9429
|
+
trigger_id
|
|
9430
|
+
} = params;
|
|
9258
9431
|
const queryKey = [
|
|
9259
9432
|
"automations-actions",
|
|
9260
9433
|
limit,
|
|
@@ -9276,10 +9449,13 @@ const useListAutomationsActions = (params, options) => {
|
|
|
9276
9449
|
const { data, ...rest } = useQuery({
|
|
9277
9450
|
queryKey,
|
|
9278
9451
|
queryFn: async () => {
|
|
9279
|
-
return await sdk.client.fetch(
|
|
9280
|
-
|
|
9281
|
-
|
|
9282
|
-
|
|
9452
|
+
return await sdk.client.fetch(
|
|
9453
|
+
"/admin/mpn/automations/actions",
|
|
9454
|
+
{
|
|
9455
|
+
method: "GET",
|
|
9456
|
+
query
|
|
9457
|
+
}
|
|
9458
|
+
);
|
|
9283
9459
|
},
|
|
9284
9460
|
enabled,
|
|
9285
9461
|
...options
|
|
@@ -9312,8 +9488,13 @@ const OPERATOR_TYPES = [
|
|
|
9312
9488
|
label: "Less Than or Equal"
|
|
9313
9489
|
}
|
|
9314
9490
|
];
|
|
9315
|
-
function AutomationsRulesForm({
|
|
9316
|
-
|
|
9491
|
+
function AutomationsRulesForm({
|
|
9492
|
+
form,
|
|
9493
|
+
isOpen
|
|
9494
|
+
}) {
|
|
9495
|
+
const {
|
|
9496
|
+
data: availableEventsData
|
|
9497
|
+
} = useAvailableEvents({
|
|
9317
9498
|
enabled: isOpen !== false
|
|
9318
9499
|
});
|
|
9319
9500
|
const eventName = form.watch("general.event_name");
|
|
@@ -9332,7 +9513,11 @@ function AutomationsRulesForm({ form, isOpen }) {
|
|
|
9332
9513
|
}
|
|
9333
9514
|
return [];
|
|
9334
9515
|
}, [availableEventsData, eventName]);
|
|
9335
|
-
const {
|
|
9516
|
+
const {
|
|
9517
|
+
fields = [],
|
|
9518
|
+
append,
|
|
9519
|
+
remove
|
|
9520
|
+
} = useFieldArray({
|
|
9336
9521
|
control: form.control,
|
|
9337
9522
|
name: "rules.items"
|
|
9338
9523
|
});
|
|
@@ -9352,93 +9537,118 @@ function AutomationsRulesForm({ form, isOpen }) {
|
|
|
9352
9537
|
};
|
|
9353
9538
|
return /* @__PURE__ */ jsx("div", { className: "w-full", children: /* @__PURE__ */ jsx("div", { className: "p-6 max-w-2xl mx-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
9354
9539
|
fields.length === 0 && /* @__PURE__ */ jsx("div", { className: "text-sm text-gray-500 text-center py-4", children: 'No rules added yet. Click "Add Item" to create a new rule.' }),
|
|
9355
|
-
fields.map((field, index) => /* @__PURE__ */ jsx(
|
|
9356
|
-
|
|
9357
|
-
|
|
9358
|
-
|
|
9359
|
-
|
|
9360
|
-
|
|
9361
|
-
|
|
9362
|
-
|
|
9363
|
-
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
{
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
|
|
9372
|
-
|
|
9373
|
-
|
|
9374
|
-
|
|
9375
|
-
|
|
9376
|
-
|
|
9377
|
-
|
|
9378
|
-
|
|
9379
|
-
|
|
9380
|
-
|
|
9381
|
-
|
|
9382
|
-
|
|
9383
|
-
|
|
9384
|
-
|
|
9385
|
-
|
|
9386
|
-
|
|
9387
|
-
|
|
9388
|
-
|
|
9389
|
-
|
|
9390
|
-
|
|
9391
|
-
|
|
9392
|
-
|
|
9393
|
-
|
|
9394
|
-
|
|
9395
|
-
|
|
9396
|
-
|
|
9397
|
-
|
|
9398
|
-
|
|
9399
|
-
|
|
9400
|
-
},
|
|
9401
|
-
|
|
9402
|
-
|
|
9403
|
-
|
|
9404
|
-
|
|
9405
|
-
|
|
9406
|
-
|
|
9407
|
-
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
|
|
9412
|
-
|
|
9413
|
-
|
|
9414
|
-
|
|
9415
|
-
|
|
9416
|
-
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
|
|
9427
|
-
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
|
|
9431
|
-
|
|
9432
|
-
|
|
9433
|
-
|
|
9434
|
-
|
|
9435
|
-
|
|
9436
|
-
|
|
9437
|
-
|
|
9438
|
-
|
|
9439
|
-
|
|
9440
|
-
|
|
9441
|
-
|
|
9540
|
+
fields.map((field, index) => /* @__PURE__ */ jsx(
|
|
9541
|
+
"div",
|
|
9542
|
+
{
|
|
9543
|
+
className: "flex flex-col gap-2 p-4 border rounded-lg",
|
|
9544
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-4", children: [
|
|
9545
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 flex flex-col gap-2", children: [
|
|
9546
|
+
/* @__PURE__ */ jsx(
|
|
9547
|
+
Controller,
|
|
9548
|
+
{
|
|
9549
|
+
name: `rules.items.${index}.attribute`,
|
|
9550
|
+
control: form.control,
|
|
9551
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
9552
|
+
/* @__PURE__ */ jsx(Label, { children: "Attribute" }),
|
|
9553
|
+
/* @__PURE__ */ jsxs(
|
|
9554
|
+
Select,
|
|
9555
|
+
{
|
|
9556
|
+
value: field2.value ?? "",
|
|
9557
|
+
onValueChange: (value) => {
|
|
9558
|
+
field2.onChange(value);
|
|
9559
|
+
},
|
|
9560
|
+
children: [
|
|
9561
|
+
/* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Select the attribute" }) }),
|
|
9562
|
+
/* @__PURE__ */ jsx(Select.Content, { children: eventAttributes.map(
|
|
9563
|
+
(attribute, attrIndex) => /* @__PURE__ */ jsx(
|
|
9564
|
+
Select.Item,
|
|
9565
|
+
{
|
|
9566
|
+
value: attribute.value || "ss",
|
|
9567
|
+
children: attribute.label
|
|
9568
|
+
},
|
|
9569
|
+
attribute.value || `attr-${index}-${attrIndex}`
|
|
9570
|
+
)
|
|
9571
|
+
) })
|
|
9572
|
+
]
|
|
9573
|
+
},
|
|
9574
|
+
`attribute-${index}-${eventAttributes.length}`
|
|
9575
|
+
),
|
|
9576
|
+
fieldState.error && /* @__PURE__ */ jsx("span", { className: "text-red-500 text-sm", children: fieldState.error.message })
|
|
9577
|
+
] })
|
|
9578
|
+
}
|
|
9579
|
+
),
|
|
9580
|
+
/* @__PURE__ */ jsx(
|
|
9581
|
+
Controller,
|
|
9582
|
+
{
|
|
9583
|
+
name: `rules.items.${index}.operator`,
|
|
9584
|
+
control: form.control,
|
|
9585
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
9586
|
+
/* @__PURE__ */ jsx(Label, { children: "Operator" }),
|
|
9587
|
+
/* @__PURE__ */ jsxs(
|
|
9588
|
+
Select,
|
|
9589
|
+
{
|
|
9590
|
+
value: field2.value ?? "",
|
|
9591
|
+
onValueChange: (value) => {
|
|
9592
|
+
field2.onChange(value);
|
|
9593
|
+
},
|
|
9594
|
+
children: [
|
|
9595
|
+
/* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Select the operator" }) }),
|
|
9596
|
+
/* @__PURE__ */ jsx(Select.Content, { children: OPERATOR_TYPES.map(
|
|
9597
|
+
(operator, opIndex) => /* @__PURE__ */ jsx(
|
|
9598
|
+
Select.Item,
|
|
9599
|
+
{
|
|
9600
|
+
value: operator.value,
|
|
9601
|
+
children: operator.label
|
|
9602
|
+
},
|
|
9603
|
+
operator.value || `op-${opIndex}`
|
|
9604
|
+
)
|
|
9605
|
+
) })
|
|
9606
|
+
]
|
|
9607
|
+
},
|
|
9608
|
+
`operator-${index}-${eventAttributes.length}-${field2.value ?? ""}`
|
|
9609
|
+
),
|
|
9610
|
+
fieldState.error && /* @__PURE__ */ jsx("span", { className: "text-red-500 text-sm", children: fieldState.error.message })
|
|
9611
|
+
] })
|
|
9612
|
+
}
|
|
9613
|
+
),
|
|
9614
|
+
/* @__PURE__ */ jsx(
|
|
9615
|
+
Controller,
|
|
9616
|
+
{
|
|
9617
|
+
name: `rules.items.${index}.rule_values.0.value`,
|
|
9618
|
+
control: form.control,
|
|
9619
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
9620
|
+
/* @__PURE__ */ jsx(Label, { children: "Value" }),
|
|
9621
|
+
/* @__PURE__ */ jsx(
|
|
9622
|
+
Input,
|
|
9623
|
+
{
|
|
9624
|
+
value: field2.value ?? "",
|
|
9625
|
+
onChange: (e2) => {
|
|
9626
|
+
field2.onChange(e2.target.value);
|
|
9627
|
+
},
|
|
9628
|
+
onBlur: field2.onBlur,
|
|
9629
|
+
ref: field2.ref
|
|
9630
|
+
}
|
|
9631
|
+
),
|
|
9632
|
+
fieldState.error && /* @__PURE__ */ jsx("span", { className: "text-red-500 text-sm", children: fieldState.error.message })
|
|
9633
|
+
] })
|
|
9634
|
+
}
|
|
9635
|
+
)
|
|
9636
|
+
] }),
|
|
9637
|
+
/* @__PURE__ */ jsx(
|
|
9638
|
+
Button,
|
|
9639
|
+
{
|
|
9640
|
+
type: "button",
|
|
9641
|
+
variant: "secondary",
|
|
9642
|
+
size: "small",
|
|
9643
|
+
onClick: () => handleRemoveRule(index),
|
|
9644
|
+
className: "mt-2",
|
|
9645
|
+
children: /* @__PURE__ */ jsx(Trash, {})
|
|
9646
|
+
}
|
|
9647
|
+
)
|
|
9648
|
+
] })
|
|
9649
|
+
},
|
|
9650
|
+
(field == null ? void 0 : field.id) ?? `rule-${index}`
|
|
9651
|
+
)),
|
|
9442
9652
|
/* @__PURE__ */ jsxs(
|
|
9443
9653
|
Button,
|
|
9444
9654
|
{
|
|
@@ -9455,7 +9665,7 @@ function AutomationsRulesForm({ form, isOpen }) {
|
|
|
9455
9665
|
] }) }) });
|
|
9456
9666
|
}
|
|
9457
9667
|
const templateLoaders = {
|
|
9458
|
-
|
|
9668
|
+
BaseConfigComponent: () => import("./base-config-DbRWuXsL")
|
|
9459
9669
|
};
|
|
9460
9670
|
async function loadTemplateComponent(key) {
|
|
9461
9671
|
const loader = templateLoaders[key];
|
|
@@ -9473,7 +9683,9 @@ function LoadActionComponent({
|
|
|
9473
9683
|
errors,
|
|
9474
9684
|
fields
|
|
9475
9685
|
}) {
|
|
9476
|
-
const [Component, setComponent] = useState(
|
|
9686
|
+
const [Component, setComponent] = useState(
|
|
9687
|
+
null
|
|
9688
|
+
);
|
|
9477
9689
|
const [loading, setLoading] = useState(false);
|
|
9478
9690
|
const [error, setError] = useState(null);
|
|
9479
9691
|
useEffect(() => {
|
|
@@ -9489,7 +9701,9 @@ function LoadActionComponent({
|
|
|
9489
9701
|
if (Component2) {
|
|
9490
9702
|
setComponent(() => Component2);
|
|
9491
9703
|
} else {
|
|
9492
|
-
setError(
|
|
9704
|
+
setError(
|
|
9705
|
+
`Component not found in ${configComponentKey}`
|
|
9706
|
+
);
|
|
9493
9707
|
}
|
|
9494
9708
|
}).catch((err) => {
|
|
9495
9709
|
console.error(
|
|
@@ -9513,16 +9727,30 @@ function LoadActionComponent({
|
|
|
9513
9727
|
if (!Component) {
|
|
9514
9728
|
return null;
|
|
9515
9729
|
}
|
|
9516
|
-
return /* @__PURE__ */ jsx(
|
|
9730
|
+
return /* @__PURE__ */ jsx(
|
|
9731
|
+
Component,
|
|
9732
|
+
{
|
|
9733
|
+
form,
|
|
9734
|
+
name,
|
|
9735
|
+
errors,
|
|
9736
|
+
fields
|
|
9737
|
+
}
|
|
9738
|
+
);
|
|
9517
9739
|
}
|
|
9518
9740
|
function AutomationsActionsForm({
|
|
9519
9741
|
form,
|
|
9520
9742
|
isOpen
|
|
9521
9743
|
}) {
|
|
9522
|
-
const {
|
|
9744
|
+
const {
|
|
9745
|
+
data: availableActionsData
|
|
9746
|
+
} = useAvailableActions({
|
|
9523
9747
|
enabled: isOpen !== false
|
|
9524
9748
|
});
|
|
9525
|
-
const {
|
|
9749
|
+
const {
|
|
9750
|
+
fields = [],
|
|
9751
|
+
append,
|
|
9752
|
+
remove
|
|
9753
|
+
} = useFieldArray({
|
|
9526
9754
|
control: form.control,
|
|
9527
9755
|
name: "actions.items"
|
|
9528
9756
|
});
|
|
@@ -9547,7 +9775,10 @@ function AutomationsActionsForm({
|
|
|
9547
9775
|
{
|
|
9548
9776
|
name: `actions.items.${index}.action_type`,
|
|
9549
9777
|
control: form.control,
|
|
9550
|
-
render: ({
|
|
9778
|
+
render: ({
|
|
9779
|
+
field: actionTypeField,
|
|
9780
|
+
fieldState
|
|
9781
|
+
}) => {
|
|
9551
9782
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
9552
9783
|
const actionType = actionTypeField.value;
|
|
9553
9784
|
const actionData = (_a = availableActionsData == null ? void 0 : availableActionsData.actions) == null ? void 0 : _a.find(
|
|
@@ -9556,69 +9787,80 @@ function AutomationsActionsForm({
|
|
|
9556
9787
|
const configComponentKey = actionData == null ? void 0 : actionData.configComponentKey;
|
|
9557
9788
|
const fields2 = actionData == null ? void 0 : actionData.fields;
|
|
9558
9789
|
const isEnabled = actionType ? actionData == null ? void 0 : actionData.enabled : true;
|
|
9559
|
-
return /* @__PURE__ */ jsxs(
|
|
9560
|
-
|
|
9561
|
-
|
|
9562
|
-
|
|
9563
|
-
|
|
9564
|
-
|
|
9790
|
+
return /* @__PURE__ */ jsxs(
|
|
9791
|
+
"div",
|
|
9792
|
+
{
|
|
9793
|
+
className: `flex flex-col gap-4 p-4 border rounded-lg ${isEnabled ? "opacity-100" : "opacity-50"}`,
|
|
9794
|
+
children: [
|
|
9795
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-4", children: [
|
|
9796
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 flex flex-col gap-2", children: [
|
|
9797
|
+
/* @__PURE__ */ jsx(Label, { children: "Action Type" }),
|
|
9798
|
+
/* @__PURE__ */ jsxs(
|
|
9799
|
+
Select,
|
|
9800
|
+
{
|
|
9801
|
+
value: actionTypeField.value ?? "",
|
|
9802
|
+
onValueChange: (value) => {
|
|
9803
|
+
actionTypeField.onChange(
|
|
9804
|
+
value
|
|
9805
|
+
);
|
|
9806
|
+
form.setValue(
|
|
9807
|
+
`actions.items.${index}.config`,
|
|
9808
|
+
{},
|
|
9809
|
+
{
|
|
9810
|
+
shouldValidate: false,
|
|
9811
|
+
shouldDirty: true
|
|
9812
|
+
}
|
|
9813
|
+
);
|
|
9814
|
+
},
|
|
9815
|
+
children: [
|
|
9816
|
+
/* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Select the action type" }) }),
|
|
9817
|
+
/* @__PURE__ */ jsx(Select.Content, { children: (_b = availableActionsData == null ? void 0 : availableActionsData.actions) == null ? void 0 : _b.map(
|
|
9818
|
+
(action, actionIndex) => /* @__PURE__ */ jsxs(
|
|
9819
|
+
Select.Item,
|
|
9820
|
+
{
|
|
9821
|
+
value: action.value || "",
|
|
9822
|
+
children: [
|
|
9823
|
+
action.label,
|
|
9824
|
+
" ",
|
|
9825
|
+
action.enabled ? "" : "(Disabled)"
|
|
9826
|
+
]
|
|
9827
|
+
},
|
|
9828
|
+
action.value || `action-${index}-${actionIndex}`
|
|
9829
|
+
)
|
|
9830
|
+
) })
|
|
9831
|
+
]
|
|
9832
|
+
},
|
|
9833
|
+
`action-type-${index}-${((_c = availableActionsData == null ? void 0 : availableActionsData.actions) == null ? void 0 : _c.length) || 0}`
|
|
9834
|
+
),
|
|
9835
|
+
fieldState.error && /* @__PURE__ */ jsx("span", { className: "text-red-500 text-sm", children: fieldState.error.message })
|
|
9836
|
+
] }),
|
|
9837
|
+
/* @__PURE__ */ jsx(
|
|
9838
|
+
Button,
|
|
9839
|
+
{
|
|
9840
|
+
type: "button",
|
|
9841
|
+
variant: "secondary",
|
|
9842
|
+
size: "small",
|
|
9843
|
+
onClick: () => handleRemoveRule(index),
|
|
9844
|
+
className: "mt-2",
|
|
9845
|
+
children: /* @__PURE__ */ jsx(Trash, {})
|
|
9846
|
+
}
|
|
9847
|
+
)
|
|
9848
|
+
] }),
|
|
9849
|
+
actionType && configComponentKey && /* @__PURE__ */ jsx("div", { className: "mt-4 pt-4 border-t", children: /* @__PURE__ */ jsx(
|
|
9850
|
+
LoadActionComponent,
|
|
9565
9851
|
{
|
|
9566
|
-
|
|
9567
|
-
|
|
9568
|
-
|
|
9569
|
-
|
|
9570
|
-
|
|
9571
|
-
|
|
9572
|
-
|
|
9573
|
-
|
|
9574
|
-
|
|
9575
|
-
|
|
9576
|
-
|
|
9577
|
-
|
|
9578
|
-
(action, actionIndex) => /* @__PURE__ */ jsxs(
|
|
9579
|
-
Select.Item,
|
|
9580
|
-
{
|
|
9581
|
-
value: action.value || "",
|
|
9582
|
-
children: [
|
|
9583
|
-
action.label,
|
|
9584
|
-
" ",
|
|
9585
|
-
action.enabled ? "" : "(Disabled)"
|
|
9586
|
-
]
|
|
9587
|
-
},
|
|
9588
|
-
action.value || `action-${index}-${actionIndex}`
|
|
9589
|
-
)
|
|
9590
|
-
) })
|
|
9591
|
-
]
|
|
9592
|
-
},
|
|
9593
|
-
`action-type-${index}-${((_c = availableActionsData == null ? void 0 : availableActionsData.actions) == null ? void 0 : _c.length) || 0}`
|
|
9594
|
-
),
|
|
9595
|
-
fieldState.error && /* @__PURE__ */ jsx("span", { className: "text-red-500 text-sm", children: fieldState.error.message })
|
|
9596
|
-
] }),
|
|
9597
|
-
/* @__PURE__ */ jsx(
|
|
9598
|
-
Button,
|
|
9599
|
-
{
|
|
9600
|
-
type: "button",
|
|
9601
|
-
variant: "secondary",
|
|
9602
|
-
size: "small",
|
|
9603
|
-
onClick: () => handleRemoveRule(index),
|
|
9604
|
-
className: "mt-2",
|
|
9605
|
-
children: /* @__PURE__ */ jsx(Trash, {})
|
|
9606
|
-
}
|
|
9607
|
-
)
|
|
9608
|
-
] }),
|
|
9609
|
-
actionType && configComponentKey && /* @__PURE__ */ jsx("div", { className: "mt-4 pt-4 border-t", children: /* @__PURE__ */ jsx(
|
|
9610
|
-
LoadActionComponent,
|
|
9611
|
-
{
|
|
9612
|
-
actionType,
|
|
9613
|
-
configComponentKey,
|
|
9614
|
-
form,
|
|
9615
|
-
name: `actions.items.${index}.config`,
|
|
9616
|
-
errors: (_g = (_f = (_e = (_d = form.formState.errors) == null ? void 0 : _d.actions) == null ? void 0 : _e.items) == null ? void 0 : _f[index]) == null ? void 0 : _g.config,
|
|
9617
|
-
fields: fields2
|
|
9618
|
-
}
|
|
9619
|
-
) }),
|
|
9620
|
-
!isEnabled && /* @__PURE__ */ jsx("p", { className: "text-sm text-red-500", children: "The action is disabled by the configuration" })
|
|
9621
|
-
] });
|
|
9852
|
+
actionType,
|
|
9853
|
+
configComponentKey,
|
|
9854
|
+
form,
|
|
9855
|
+
name: `actions.items.${index}.config`,
|
|
9856
|
+
errors: (_g = (_f = (_e = (_d = form.formState.errors) == null ? void 0 : _d.actions) == null ? void 0 : _e.items) == null ? void 0 : _f[index]) == null ? void 0 : _g.config,
|
|
9857
|
+
fields: fields2
|
|
9858
|
+
}
|
|
9859
|
+
) }),
|
|
9860
|
+
!isEnabled && /* @__PURE__ */ jsx("p", { className: "text-sm text-red-500", children: "The action is disabled by the configuration" })
|
|
9861
|
+
]
|
|
9862
|
+
}
|
|
9863
|
+
);
|
|
9622
9864
|
}
|
|
9623
9865
|
},
|
|
9624
9866
|
(field == null ? void 0 : field.id) ?? `action-${index}`
|
|
@@ -9639,7 +9881,9 @@ function AutomationsActionsForm({
|
|
|
9639
9881
|
)
|
|
9640
9882
|
] }) }) });
|
|
9641
9883
|
}
|
|
9642
|
-
function AutomationsEditForm({
|
|
9884
|
+
function AutomationsEditForm({
|
|
9885
|
+
id
|
|
9886
|
+
}) {
|
|
9643
9887
|
const [open, setOpen] = useState(false);
|
|
9644
9888
|
const [tab, setTab] = useState(Tab.GENERAL);
|
|
9645
9889
|
const [tabState, setTabState] = useState({
|
|
@@ -9658,17 +9902,26 @@ function AutomationsEditForm({ id }) {
|
|
|
9658
9902
|
}
|
|
9659
9903
|
}, [tab]);
|
|
9660
9904
|
const queryClient = useQueryClient();
|
|
9661
|
-
const {
|
|
9905
|
+
const {
|
|
9906
|
+
data: automationsTriggerData,
|
|
9907
|
+
isLoading: isAutomationsTriggerLoading
|
|
9908
|
+
} = useListAutomations({
|
|
9662
9909
|
id,
|
|
9663
9910
|
extraKey: [],
|
|
9664
9911
|
enabled: open && !!id
|
|
9665
9912
|
});
|
|
9666
|
-
const {
|
|
9913
|
+
const {
|
|
9914
|
+
data: automationsRulesData,
|
|
9915
|
+
isLoading: isAutomationsRulesLoading
|
|
9916
|
+
} = useListAutomationsRules({
|
|
9667
9917
|
trigger_id: id,
|
|
9668
9918
|
extraKey: [id],
|
|
9669
9919
|
enabled: open && !!id
|
|
9670
9920
|
});
|
|
9671
|
-
const {
|
|
9921
|
+
const {
|
|
9922
|
+
data: automationsActionsData,
|
|
9923
|
+
isLoading: isAutomationsActionsLoading
|
|
9924
|
+
} = useListAutomationsActions({
|
|
9672
9925
|
trigger_id: id,
|
|
9673
9926
|
extraKey: [id],
|
|
9674
9927
|
enabled: open && !!id
|
|
@@ -9676,11 +9929,22 @@ function AutomationsEditForm({ id }) {
|
|
|
9676
9929
|
const { data: availableActionsData } = useAvailableActions({
|
|
9677
9930
|
enabled: open
|
|
9678
9931
|
});
|
|
9679
|
-
const {
|
|
9680
|
-
|
|
9681
|
-
|
|
9932
|
+
const {
|
|
9933
|
+
mutateAsync: editAutomation,
|
|
9934
|
+
isPending: isEditAutomationPending
|
|
9935
|
+
} = useEditAutomation();
|
|
9936
|
+
const {
|
|
9937
|
+
mutateAsync: editAutomationRule,
|
|
9938
|
+
isPending: isEditAutomationRulePending
|
|
9939
|
+
} = useEditAutomationRule();
|
|
9940
|
+
const {
|
|
9941
|
+
mutateAsync: editAutomationAction,
|
|
9942
|
+
isPending: isEditAutomationActionPending
|
|
9943
|
+
} = useEditAutomationAction();
|
|
9682
9944
|
const automationFormSchema = useMemo(() => {
|
|
9683
|
-
return createAutomationFormSchema(
|
|
9945
|
+
return createAutomationFormSchema(
|
|
9946
|
+
availableActionsData == null ? void 0 : availableActionsData.actions
|
|
9947
|
+
);
|
|
9684
9948
|
}, [availableActionsData == null ? void 0 : availableActionsData.actions]);
|
|
9685
9949
|
const form = useForm({
|
|
9686
9950
|
resolver: t(automationFormSchema),
|
|
@@ -9723,11 +9987,13 @@ function AutomationsEditForm({ id }) {
|
|
|
9723
9987
|
operator: rule.operator,
|
|
9724
9988
|
description: rule.description,
|
|
9725
9989
|
metadata: rule.metadata,
|
|
9726
|
-
rule_values: rule.rule_values.map(
|
|
9727
|
-
|
|
9728
|
-
|
|
9729
|
-
|
|
9730
|
-
|
|
9990
|
+
rule_values: rule.rule_values.map(
|
|
9991
|
+
(value) => ({
|
|
9992
|
+
id: value.id,
|
|
9993
|
+
value: value.value,
|
|
9994
|
+
metadata: value.metadata
|
|
9995
|
+
})
|
|
9996
|
+
)
|
|
9731
9997
|
}))
|
|
9732
9998
|
},
|
|
9733
9999
|
actions: {
|
|
@@ -9776,7 +10042,9 @@ function AutomationsEditForm({ id }) {
|
|
|
9776
10042
|
id,
|
|
9777
10043
|
items: [items]
|
|
9778
10044
|
});
|
|
9779
|
-
queryClient.invalidateQueries({
|
|
10045
|
+
queryClient.invalidateQueries({
|
|
10046
|
+
queryKey: ["automations"]
|
|
10047
|
+
});
|
|
9780
10048
|
toast.success("Automation updated successfully", {
|
|
9781
10049
|
position: "top-right",
|
|
9782
10050
|
duration: 3e3
|
|
@@ -9788,16 +10056,23 @@ function AutomationsEditForm({ id }) {
|
|
|
9788
10056
|
rules: ((_a = data.rules) == null ? void 0 : _a.items) || []
|
|
9789
10057
|
};
|
|
9790
10058
|
const fieldsToValidate = getFieldsForTab(tab);
|
|
9791
|
-
const valid = await form.trigger(
|
|
10059
|
+
const valid = await form.trigger(
|
|
10060
|
+
fieldsToValidate
|
|
10061
|
+
);
|
|
9792
10062
|
if (!valid) {
|
|
9793
10063
|
return;
|
|
9794
10064
|
}
|
|
9795
10065
|
await editAutomationRule(items);
|
|
9796
|
-
queryClient.invalidateQueries({
|
|
9797
|
-
|
|
9798
|
-
position: "top-right",
|
|
9799
|
-
duration: 3e3
|
|
10066
|
+
queryClient.invalidateQueries({
|
|
10067
|
+
queryKey: ["automations-rules", id]
|
|
9800
10068
|
});
|
|
10069
|
+
toast.success(
|
|
10070
|
+
"Automation rules added/updated successfully",
|
|
10071
|
+
{
|
|
10072
|
+
position: "top-right",
|
|
10073
|
+
duration: 3e3
|
|
10074
|
+
}
|
|
10075
|
+
);
|
|
9801
10076
|
}
|
|
9802
10077
|
if (Tab.ACTIONS === tab) {
|
|
9803
10078
|
const items = {
|
|
@@ -9805,11 +10080,16 @@ function AutomationsEditForm({ id }) {
|
|
|
9805
10080
|
actions: ((_b = data.actions) == null ? void 0 : _b.items) || []
|
|
9806
10081
|
};
|
|
9807
10082
|
await editAutomationAction(items);
|
|
9808
|
-
queryClient.invalidateQueries({
|
|
9809
|
-
|
|
9810
|
-
position: "top-right",
|
|
9811
|
-
duration: 3e3
|
|
10083
|
+
queryClient.invalidateQueries({
|
|
10084
|
+
queryKey: ["automations-actions", id]
|
|
9812
10085
|
});
|
|
10086
|
+
toast.success(
|
|
10087
|
+
"Automation actions added/updated successfully",
|
|
10088
|
+
{
|
|
10089
|
+
position: "top-right",
|
|
10090
|
+
duration: 3e3
|
|
10091
|
+
}
|
|
10092
|
+
);
|
|
9813
10093
|
}
|
|
9814
10094
|
}
|
|
9815
10095
|
const getFieldsForTab = (tab2) => {
|
|
@@ -9830,7 +10110,9 @@ function AutomationsEditForm({ id }) {
|
|
|
9830
10110
|
};
|
|
9831
10111
|
const handleTabChange = async (newTab) => {
|
|
9832
10112
|
const fieldsToValidate = getFieldsForTab(tab);
|
|
9833
|
-
const valid = await form.trigger(
|
|
10113
|
+
const valid = await form.trigger(
|
|
10114
|
+
fieldsToValidate
|
|
10115
|
+
);
|
|
9834
10116
|
if (!valid) {
|
|
9835
10117
|
return;
|
|
9836
10118
|
}
|
|
@@ -9853,18 +10135,66 @@ function AutomationsEditForm({ id }) {
|
|
|
9853
10135
|
value: tab,
|
|
9854
10136
|
className: "flex h-full flex-col overflow-hidden",
|
|
9855
10137
|
children: /* @__PURE__ */ jsxs(ProgressTabs.List, { className: "justify-start-start flex w-full items-center", children: [
|
|
9856
|
-
/* @__PURE__ */ jsx(
|
|
9857
|
-
|
|
9858
|
-
|
|
10138
|
+
/* @__PURE__ */ jsx(
|
|
10139
|
+
ProgressTabs.Trigger,
|
|
10140
|
+
{
|
|
10141
|
+
value: Tab.GENERAL,
|
|
10142
|
+
status: tabState[Tab.GENERAL],
|
|
10143
|
+
onClick: () => handleTabChange(Tab.GENERAL),
|
|
10144
|
+
children: "General"
|
|
10145
|
+
}
|
|
10146
|
+
),
|
|
10147
|
+
/* @__PURE__ */ jsx(
|
|
10148
|
+
ProgressTabs.Trigger,
|
|
10149
|
+
{
|
|
10150
|
+
value: Tab.RULES,
|
|
10151
|
+
status: tabState[Tab.RULES],
|
|
10152
|
+
onClick: () => handleTabChange(Tab.RULES),
|
|
10153
|
+
children: "Rules"
|
|
10154
|
+
}
|
|
10155
|
+
),
|
|
10156
|
+
/* @__PURE__ */ jsx(
|
|
10157
|
+
ProgressTabs.Trigger,
|
|
10158
|
+
{
|
|
10159
|
+
value: Tab.ACTIONS,
|
|
10160
|
+
status: tabState[Tab.ACTIONS],
|
|
10161
|
+
onClick: () => handleTabChange(Tab.ACTIONS),
|
|
10162
|
+
children: "Actions"
|
|
10163
|
+
}
|
|
10164
|
+
)
|
|
9859
10165
|
] })
|
|
9860
10166
|
}
|
|
9861
10167
|
) })
|
|
9862
10168
|
] }),
|
|
9863
|
-
/* @__PURE__ */ jsx(FocusModal.Body, { className: "w-full overflow-y-auto", children: isAutomationsTriggerLoading ? /* @__PURE__ */ jsx("div", { className: "p-6", children: "Loading..." }) : /* @__PURE__ */ jsxs(
|
|
9864
|
-
|
|
9865
|
-
|
|
9866
|
-
|
|
9867
|
-
|
|
10169
|
+
/* @__PURE__ */ jsx(FocusModal.Body, { className: "w-full overflow-y-auto", children: isAutomationsTriggerLoading ? /* @__PURE__ */ jsx("div", { className: "p-6", children: "Loading..." }) : /* @__PURE__ */ jsxs(
|
|
10170
|
+
"form",
|
|
10171
|
+
{
|
|
10172
|
+
onSubmit: form.handleSubmit(handleSubmit),
|
|
10173
|
+
children: [
|
|
10174
|
+
tab === Tab.GENERAL && /* @__PURE__ */ jsx(
|
|
10175
|
+
AutomationsGeneralForm,
|
|
10176
|
+
{
|
|
10177
|
+
form,
|
|
10178
|
+
isOpen: open
|
|
10179
|
+
}
|
|
10180
|
+
),
|
|
10181
|
+
tab === Tab.RULES && /* @__PURE__ */ jsx(
|
|
10182
|
+
AutomationsRulesForm,
|
|
10183
|
+
{
|
|
10184
|
+
form,
|
|
10185
|
+
isOpen: open
|
|
10186
|
+
}
|
|
10187
|
+
),
|
|
10188
|
+
tab === Tab.ACTIONS && /* @__PURE__ */ jsx(
|
|
10189
|
+
AutomationsActionsForm,
|
|
10190
|
+
{
|
|
10191
|
+
form,
|
|
10192
|
+
isOpen: open
|
|
10193
|
+
}
|
|
10194
|
+
)
|
|
10195
|
+
]
|
|
10196
|
+
}
|
|
10197
|
+
) }),
|
|
9868
10198
|
/* @__PURE__ */ jsxs(FocusModal.Footer, { children: [
|
|
9869
10199
|
/* @__PURE__ */ jsx(FocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9870
10200
|
/* @__PURE__ */ jsx(
|
|
@@ -9881,7 +10211,9 @@ function AutomationsEditForm({ id }) {
|
|
|
9881
10211
|
] })
|
|
9882
10212
|
] });
|
|
9883
10213
|
}
|
|
9884
|
-
const AutomationDeleteButton = ({
|
|
10214
|
+
const AutomationDeleteButton = ({
|
|
10215
|
+
id
|
|
10216
|
+
}) => {
|
|
9885
10217
|
const queryClient = useQueryClient();
|
|
9886
10218
|
const prompt = usePrompt();
|
|
9887
10219
|
const { mutate: deleteAutomation } = useDeleteAutomation();
|
|
@@ -9890,7 +10222,9 @@ const AutomationDeleteButton = ({ id }) => {
|
|
|
9890
10222
|
{ id },
|
|
9891
10223
|
{
|
|
9892
10224
|
onSuccess: () => {
|
|
9893
|
-
queryClient.invalidateQueries({
|
|
10225
|
+
queryClient.invalidateQueries({
|
|
10226
|
+
queryKey: ["automations"]
|
|
10227
|
+
});
|
|
9894
10228
|
},
|
|
9895
10229
|
onError: (error) => {
|
|
9896
10230
|
toast.error(error.message);
|
|
@@ -9909,7 +10243,15 @@ const AutomationDeleteButton = ({ id }) => {
|
|
|
9909
10243
|
handleDelete();
|
|
9910
10244
|
}
|
|
9911
10245
|
};
|
|
9912
|
-
return /* @__PURE__ */ jsx(
|
|
10246
|
+
return /* @__PURE__ */ jsx(
|
|
10247
|
+
Button,
|
|
10248
|
+
{
|
|
10249
|
+
size: "small",
|
|
10250
|
+
variant: "primary",
|
|
10251
|
+
onClick: handleDeleteConfirmation,
|
|
10252
|
+
children: /* @__PURE__ */ jsx(Trash, { className: "w-4 h-4" })
|
|
10253
|
+
}
|
|
10254
|
+
);
|
|
9913
10255
|
};
|
|
9914
10256
|
const AutomationsList = () => {
|
|
9915
10257
|
const [pagination, setPagination] = useState({
|
|
@@ -9944,7 +10286,14 @@ const AutomationsList = () => {
|
|
|
9944
10286
|
/* @__PURE__ */ jsx(
|
|
9945
10287
|
Tooltip,
|
|
9946
10288
|
{
|
|
9947
|
-
content: /* @__PURE__ */ jsx(
|
|
10289
|
+
content: /* @__PURE__ */ jsx(
|
|
10290
|
+
"div",
|
|
10291
|
+
{
|
|
10292
|
+
dangerouslySetInnerHTML: {
|
|
10293
|
+
__html: tooltip
|
|
10294
|
+
}
|
|
10295
|
+
}
|
|
10296
|
+
),
|
|
9948
10297
|
maxWidth: 400,
|
|
9949
10298
|
children: /* @__PURE__ */ jsx(InformationCircleSolid, {})
|
|
9950
10299
|
}
|
|
@@ -9971,8 +10320,11 @@ const AutomationsList = () => {
|
|
|
9971
10320
|
columnHelper.accessor("last_run_at", {
|
|
9972
10321
|
header: "Last Run At",
|
|
9973
10322
|
cell: ({ row }) => {
|
|
9974
|
-
var _a;
|
|
9975
|
-
|
|
10323
|
+
var _a, _b;
|
|
10324
|
+
const lastRunAtAll = (_b = (_a = row == null ? void 0 : row.original) == null ? void 0 : _a.states) == null ? void 0 : _b.map((state) => state.last_triggered_at).sort(
|
|
10325
|
+
(a2, b) => new Date(b).getTime() - new Date(a2).getTime()
|
|
10326
|
+
);
|
|
10327
|
+
return /* @__PURE__ */ jsx("span", { children: lastRunAtAll.length > 0 ? new Date(lastRunAtAll[0]).toLocaleString() : "-" });
|
|
9976
10328
|
}
|
|
9977
10329
|
}),
|
|
9978
10330
|
columnHelper.accessor("active", {
|
|
@@ -9988,14 +10340,18 @@ const AutomationsList = () => {
|
|
|
9988
10340
|
header: "Created At",
|
|
9989
10341
|
cell: ({ row }) => {
|
|
9990
10342
|
var _a;
|
|
9991
|
-
return /* @__PURE__ */ jsx("span", { children: ((_a = row == null ? void 0 : row.original) == null ? void 0 : _a.created_at) ? new Date(
|
|
10343
|
+
return /* @__PURE__ */ jsx("span", { children: ((_a = row == null ? void 0 : row.original) == null ? void 0 : _a.created_at) ? new Date(
|
|
10344
|
+
row.original.created_at
|
|
10345
|
+
).toLocaleString() : "-" });
|
|
9992
10346
|
}
|
|
9993
10347
|
}),
|
|
9994
10348
|
columnHelper.accessor("updated_at", {
|
|
9995
10349
|
header: "Updated At",
|
|
9996
10350
|
cell: ({ row }) => {
|
|
9997
10351
|
var _a;
|
|
9998
|
-
return /* @__PURE__ */ jsx("span", { children: ((_a = row == null ? void 0 : row.original) == null ? void 0 : _a.updated_at) ? new Date(
|
|
10352
|
+
return /* @__PURE__ */ jsx("span", { children: ((_a = row == null ? void 0 : row.original) == null ? void 0 : _a.updated_at) ? new Date(
|
|
10353
|
+
row.original.updated_at
|
|
10354
|
+
).toLocaleString() : "-" });
|
|
9999
10355
|
}
|
|
10000
10356
|
}),
|
|
10001
10357
|
columnHelper.accessor("actions", {
|
|
@@ -10004,7 +10360,12 @@ const AutomationsList = () => {
|
|
|
10004
10360
|
var _a, _b;
|
|
10005
10361
|
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
10006
10362
|
/* @__PURE__ */ jsx(AutomationsEditForm, { id: (_a = row == null ? void 0 : row.original) == null ? void 0 : _a.id }),
|
|
10007
|
-
/* @__PURE__ */ jsx(
|
|
10363
|
+
/* @__PURE__ */ jsx(
|
|
10364
|
+
AutomationDeleteButton,
|
|
10365
|
+
{
|
|
10366
|
+
id: (_b = row == null ? void 0 : row.original) == null ? void 0 : _b.id
|
|
10367
|
+
}
|
|
10368
|
+
)
|
|
10008
10369
|
] });
|
|
10009
10370
|
}
|
|
10010
10371
|
})
|