@codee-sh/medusa-plugin-automations 1.0.3 → 1.0.4
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__-rqdPN7M1 → __admin-extensions__-BD2AvjDH} +76 -66
- package/.medusa/server/src/admin/_chunks/{__admin-extensions__-DIB2k6nJ → __admin-extensions__-BxUQA9oD} +76 -66
- package/.medusa/server/src/admin/_chunks/{base-config-DbRWuXsL → base-config-ON0ZG0Je} +2 -3
- package/.medusa/server/src/admin/_chunks/{base-config-ro-vFPBg → base-config-XI6iR6Jp} +2 -3
- 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/available-actions/route.js +4 -2
- package/.medusa/server/src/api/admin/mpn/automations/rules/route.js +1 -1
- package/.medusa/server/src/hooks/api/automations-actions/automations-actions.js +1 -3
- package/.medusa/server/src/hooks/api/automations-rules/automations-rules.js +1 -3
- package/.medusa/server/src/hooks/api/available-actions/actions.js +5 -2
- package/.medusa/server/src/hooks/api/available-events/events.js +1 -1
- package/.medusa/server/src/modules/mpn-automation/actions-handlers/base-action-handler.js +43 -2
- package/.medusa/server/src/modules/mpn-automation/actions-handlers/email-action-handler.js +3 -15
- package/.medusa/server/src/modules/mpn-automation/actions-handlers/slack-action-handler.js +3 -29
- package/.medusa/server/src/modules/mpn-automation/services/service.js +221 -30
- package/.medusa/server/src/modules/mpn-automation/types/modules/index.js +76 -0
- package/.medusa/server/src/modules/mpn-automation/types/modules/inventory/index.js +18 -0
- package/.medusa/server/src/modules/mpn-automation/types/modules/inventory/inventory.js +56 -0
- package/.medusa/server/src/modules/mpn-automation/types/types.js +2 -136
- package/.medusa/server/src/providers/slack/service.js +6 -58
- package/.medusa/server/src/subscribers/inventory-level-updated.js +2 -1
- package/.medusa/server/src/subscribers/inventory-reservation-item-updated.js +3 -3
- package/.medusa/server/src/subscribers/mpn.automation.action.email.executed.js +6 -5
- package/.medusa/server/src/subscribers/mpn.automation.action.slack.executed.js +12 -8
- package/.medusa/server/src/subscribers/order-placed.js +9 -106
- package/.medusa/server/src/templates/slack/index.js +40 -0
- package/.medusa/server/src/templates/slack/inventory-level/index.js +18 -0
- package/.medusa/server/src/templates/slack/inventory-level/inventory-level.js +95 -0
- package/.medusa/server/src/templates/slack/inventory-level/translations/en.json +18 -0
- package/.medusa/server/src/templates/slack/inventory-level/translations/index.js +15 -0
- package/.medusa/server/src/templates/slack/inventory-level/translations/pl.json +18 -0
- package/.medusa/server/src/templates/slack/types.js +7 -0
- package/.medusa/server/src/utils/i18n/i18n.js +127 -0
- package/.medusa/server/src/utils/i18n/index.js +18 -0
- package/.medusa/server/src/utils/index.js +2 -1
- package/.medusa/server/src/utils/validate-rules.js +1 -1
- package/.medusa/server/src/workflows/inventory/steps/get-inventory-level-by-id.js +23 -6
- package/.medusa/server/src/workflows/mpn-automation/index.js +3 -2
- package/.medusa/server/src/workflows/mpn-automation/run-automation.js +2 -1
- package/.medusa/server/src/workflows/mpn-automation/{send-email-action.js → run-email-action.js} +8 -7
- package/.medusa/server/src/workflows/mpn-automation/run-slack-action.js +67 -0
- package/.medusa/server/src/workflows/mpn-automation/steps/edit-automation-actions.js +16 -5
- package/.medusa/server/src/workflows/mpn-automation/steps/retrieve-automation-triggers-by-event.js +1 -1
- package/.medusa/server/src/workflows/mpn-automation/steps/run-automation-actions.js +3 -2
- package/.medusa/server/src/workflows/notifications/send-email.js +2 -1
- package/.medusa/server/src/workflows/notifications/send-slack.js +2 -1
- package/.medusa/server/src/workflows/notifications/steps/send-email.js +3 -2
- package/.medusa/server/src/workflows/notifications/steps/send-slack.js +19 -5
- package/package.json +2 -3
- package/.medusa/server/src/workflows/mpn-automation/send-slack-action.js +0 -69
|
@@ -5178,19 +5178,25 @@ const useAvailableActions = (params, options) => {
|
|
|
5178
5178
|
enabled,
|
|
5179
5179
|
fields,
|
|
5180
5180
|
order = "created_at",
|
|
5181
|
-
id
|
|
5181
|
+
id,
|
|
5182
|
+
eventName
|
|
5183
|
+
// Add eventName parameter
|
|
5182
5184
|
} = params;
|
|
5183
5185
|
const queryKey = [
|
|
5184
5186
|
"available-actions",
|
|
5185
5187
|
limit,
|
|
5186
5188
|
offset,
|
|
5189
|
+
eventName,
|
|
5190
|
+
// Include eventName in query key for proper caching
|
|
5187
5191
|
...extraKey
|
|
5188
5192
|
];
|
|
5189
5193
|
const query = {
|
|
5190
5194
|
limit,
|
|
5191
5195
|
offset,
|
|
5192
5196
|
fields,
|
|
5193
|
-
order
|
|
5197
|
+
order,
|
|
5198
|
+
...eventName && { eventName }
|
|
5199
|
+
// Add eventName to query params if provided
|
|
5194
5200
|
};
|
|
5195
5201
|
const { data, ...rest } = useQuery({
|
|
5196
5202
|
queryKey,
|
|
@@ -5285,7 +5291,8 @@ const useAvailableTriggers = (params, options) => {
|
|
|
5285
5291
|
};
|
|
5286
5292
|
function AutomationsGeneralForm({
|
|
5287
5293
|
form,
|
|
5288
|
-
isOpen
|
|
5294
|
+
isOpen,
|
|
5295
|
+
isEditMode = false
|
|
5289
5296
|
}) {
|
|
5290
5297
|
const {
|
|
5291
5298
|
data: availableEventsData
|
|
@@ -5428,8 +5435,12 @@ function AutomationsGeneralForm({
|
|
|
5428
5435
|
{
|
|
5429
5436
|
value: field.value ?? "",
|
|
5430
5437
|
onValueChange: (value) => {
|
|
5438
|
+
if (isEditMode) {
|
|
5439
|
+
return;
|
|
5440
|
+
}
|
|
5431
5441
|
field.onChange(value);
|
|
5432
5442
|
},
|
|
5443
|
+
disabled: isEditMode,
|
|
5433
5444
|
children: [
|
|
5434
5445
|
/* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Select the event name" }) }),
|
|
5435
5446
|
/* @__PURE__ */ jsx(Select.Content, { children: availableEvents == null ? void 0 : availableEvents.map((event) => /* @__PURE__ */ jsxs(Select.Group, { children: [
|
|
@@ -9163,9 +9174,7 @@ function createAutomationFormSchema(availableActions) {
|
|
|
9163
9174
|
}
|
|
9164
9175
|
);
|
|
9165
9176
|
}
|
|
9166
|
-
function AutomationsCreateForm({
|
|
9167
|
-
id
|
|
9168
|
-
}) {
|
|
9177
|
+
function AutomationsCreateForm() {
|
|
9169
9178
|
const [open, setOpen] = useState(false);
|
|
9170
9179
|
const [tab, setTab] = useState(Tab.GENERAL);
|
|
9171
9180
|
const [tabState, setTabState] = useState({
|
|
@@ -9185,12 +9194,10 @@ function AutomationsCreateForm({
|
|
|
9185
9194
|
}, [tab]);
|
|
9186
9195
|
const queryClient = useQueryClient();
|
|
9187
9196
|
const {
|
|
9188
|
-
data: automationsTriggerData,
|
|
9189
9197
|
isLoading: isAutomationsTriggerLoading
|
|
9190
9198
|
} = useListAutomations({
|
|
9191
|
-
id,
|
|
9192
9199
|
extraKey: [],
|
|
9193
|
-
enabled: open
|
|
9200
|
+
enabled: open
|
|
9194
9201
|
});
|
|
9195
9202
|
const { data: availableActionsData } = useAvailableActions({
|
|
9196
9203
|
enabled: open
|
|
@@ -9223,28 +9230,6 @@ function AutomationsCreateForm({
|
|
|
9223
9230
|
}
|
|
9224
9231
|
}
|
|
9225
9232
|
});
|
|
9226
|
-
useEffect(() => {
|
|
9227
|
-
var _a;
|
|
9228
|
-
if (automationsTriggerData && ((_a = automationsTriggerData.triggers) == null ? void 0 : _a[0])) {
|
|
9229
|
-
const trigger = automationsTriggerData.triggers[0];
|
|
9230
|
-
form.reset({
|
|
9231
|
-
general: {
|
|
9232
|
-
name: trigger.name || "",
|
|
9233
|
-
description: trigger.description || "",
|
|
9234
|
-
trigger_type: trigger.trigger_type || "event",
|
|
9235
|
-
event_name: trigger.event_name || "",
|
|
9236
|
-
interval_minutes: trigger.interval_minutes || null,
|
|
9237
|
-
active: trigger.active || false
|
|
9238
|
-
},
|
|
9239
|
-
rules: {
|
|
9240
|
-
items: []
|
|
9241
|
-
},
|
|
9242
|
-
actions: {
|
|
9243
|
-
items: []
|
|
9244
|
-
}
|
|
9245
|
-
});
|
|
9246
|
-
}
|
|
9247
|
-
}, [open, automationsTriggerData]);
|
|
9248
9233
|
useEffect(() => {
|
|
9249
9234
|
if (open === false) {
|
|
9250
9235
|
form.reset({
|
|
@@ -9295,7 +9280,7 @@ function AutomationsCreateForm({
|
|
|
9295
9280
|
/* @__PURE__ */ jsx(FocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "primary", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
|
|
9296
9281
|
/* @__PURE__ */ jsxs(FocusModal.Content, { children: [
|
|
9297
9282
|
/* @__PURE__ */ jsxs(FocusModal.Header, { children: [
|
|
9298
|
-
/* @__PURE__ */ jsx(
|
|
9283
|
+
/* @__PURE__ */ jsx(Heading, { level: "h3", className: "shrink-0", children: "Create Automation" }),
|
|
9299
9284
|
/* @__PURE__ */ jsx("div", { className: "-my-2 w-full border-l", children: /* @__PURE__ */ jsx(
|
|
9300
9285
|
ProgressTabs,
|
|
9301
9286
|
{
|
|
@@ -9370,8 +9355,6 @@ const useListAutomationsRules = (params, options) => {
|
|
|
9370
9355
|
} = params;
|
|
9371
9356
|
const queryKey = [
|
|
9372
9357
|
"automations-rules",
|
|
9373
|
-
limit,
|
|
9374
|
-
offset,
|
|
9375
9358
|
...extraKey
|
|
9376
9359
|
];
|
|
9377
9360
|
const query = {
|
|
@@ -9430,8 +9413,6 @@ const useListAutomationsActions = (params, options) => {
|
|
|
9430
9413
|
} = params;
|
|
9431
9414
|
const queryKey = [
|
|
9432
9415
|
"automations-actions",
|
|
9433
|
-
limit,
|
|
9434
|
-
offset,
|
|
9435
9416
|
...extraKey
|
|
9436
9417
|
];
|
|
9437
9418
|
const query = {
|
|
@@ -9560,11 +9541,19 @@ function AutomationsRulesForm({
|
|
|
9560
9541
|
children: [
|
|
9561
9542
|
/* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Select the attribute" }) }),
|
|
9562
9543
|
/* @__PURE__ */ jsx(Select.Content, { children: eventAttributes.map(
|
|
9563
|
-
(attribute, attrIndex) => /* @__PURE__ */
|
|
9544
|
+
(attribute, attrIndex) => /* @__PURE__ */ jsxs(
|
|
9564
9545
|
Select.Item,
|
|
9565
9546
|
{
|
|
9566
9547
|
value: attribute.value || "ss",
|
|
9567
|
-
children:
|
|
9548
|
+
children: [
|
|
9549
|
+
attribute.label,
|
|
9550
|
+
" ",
|
|
9551
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs text-gray-500", children: [
|
|
9552
|
+
"(",
|
|
9553
|
+
attribute.value,
|
|
9554
|
+
")"
|
|
9555
|
+
] })
|
|
9556
|
+
]
|
|
9568
9557
|
},
|
|
9569
9558
|
attribute.value || `attr-${index}-${attrIndex}`
|
|
9570
9559
|
)
|
|
@@ -9665,7 +9654,7 @@ function AutomationsRulesForm({
|
|
|
9665
9654
|
] }) }) });
|
|
9666
9655
|
}
|
|
9667
9656
|
const templateLoaders = {
|
|
9668
|
-
BaseConfigComponent: () => import("./base-config-
|
|
9657
|
+
BaseConfigComponent: () => import("./base-config-ON0ZG0Je")
|
|
9669
9658
|
};
|
|
9670
9659
|
async function loadTemplateComponent(key) {
|
|
9671
9660
|
const loader = templateLoaders[key];
|
|
@@ -9697,7 +9686,6 @@ function LoadActionComponent({
|
|
|
9697
9686
|
setError(null);
|
|
9698
9687
|
loadTemplateComponent(configComponentKey).then((module) => {
|
|
9699
9688
|
const Component2 = module;
|
|
9700
|
-
console.log("Component", Component2);
|
|
9701
9689
|
if (Component2) {
|
|
9702
9690
|
setComponent(() => Component2);
|
|
9703
9691
|
} else {
|
|
@@ -9739,13 +9727,9 @@ function LoadActionComponent({
|
|
|
9739
9727
|
}
|
|
9740
9728
|
function AutomationsActionsForm({
|
|
9741
9729
|
form,
|
|
9742
|
-
isOpen
|
|
9730
|
+
isOpen,
|
|
9731
|
+
availableActionsData
|
|
9743
9732
|
}) {
|
|
9744
|
-
const {
|
|
9745
|
-
data: availableActionsData
|
|
9746
|
-
} = useAvailableActions({
|
|
9747
|
-
enabled: isOpen !== false
|
|
9748
|
-
});
|
|
9749
9733
|
const {
|
|
9750
9734
|
fields = [],
|
|
9751
9735
|
append,
|
|
@@ -9754,7 +9738,7 @@ function AutomationsActionsForm({
|
|
|
9754
9738
|
control: form.control,
|
|
9755
9739
|
name: "actions.items"
|
|
9756
9740
|
});
|
|
9757
|
-
useWatch({
|
|
9741
|
+
const watchedActions = useWatch({
|
|
9758
9742
|
control: form.control,
|
|
9759
9743
|
name: "actions.items"
|
|
9760
9744
|
});
|
|
@@ -9767,6 +9751,32 @@ function AutomationsActionsForm({
|
|
|
9767
9751
|
const handleRemoveRule = (index) => {
|
|
9768
9752
|
remove(index);
|
|
9769
9753
|
};
|
|
9754
|
+
const actionTypeValueChange = (index, value, isExistingAction) => {
|
|
9755
|
+
var _a;
|
|
9756
|
+
if (isExistingAction) {
|
|
9757
|
+
return;
|
|
9758
|
+
}
|
|
9759
|
+
form.setValue(`actions.items.${index}.action_type`, value, {
|
|
9760
|
+
shouldValidate: false,
|
|
9761
|
+
shouldDirty: true
|
|
9762
|
+
});
|
|
9763
|
+
form.clearErrors(`actions.items.${index}`);
|
|
9764
|
+
const actionData = (_a = availableActionsData == null ? void 0 : availableActionsData.actions) == null ? void 0 : _a.find(
|
|
9765
|
+
(a2) => a2.value === value
|
|
9766
|
+
);
|
|
9767
|
+
const fields2 = actionData == null ? void 0 : actionData.fields;
|
|
9768
|
+
form.setValue(
|
|
9769
|
+
`actions.items.${index}.config`,
|
|
9770
|
+
fields2 == null ? void 0 : fields2.reduce((acc, field) => {
|
|
9771
|
+
acc[field.name || field.key] = "";
|
|
9772
|
+
return acc;
|
|
9773
|
+
}, {}),
|
|
9774
|
+
{
|
|
9775
|
+
shouldValidate: false,
|
|
9776
|
+
shouldDirty: true
|
|
9777
|
+
}
|
|
9778
|
+
);
|
|
9779
|
+
};
|
|
9770
9780
|
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: [
|
|
9771
9781
|
fields.length === 0 && /* @__PURE__ */ jsx("div", { className: "text-sm text-gray-500 text-center py-4", children: 'No actions added yet. Click "Add Item" to create a new action.' }),
|
|
9772
9782
|
fields.map((field, index) => {
|
|
@@ -9787,6 +9797,8 @@ function AutomationsActionsForm({
|
|
|
9787
9797
|
const configComponentKey = actionData == null ? void 0 : actionData.configComponentKey;
|
|
9788
9798
|
const fields2 = actionData == null ? void 0 : actionData.fields;
|
|
9789
9799
|
const isEnabled = actionType ? actionData == null ? void 0 : actionData.enabled : true;
|
|
9800
|
+
const currentAction = watchedActions == null ? void 0 : watchedActions[index];
|
|
9801
|
+
const isExistingAction = !!(currentAction == null ? void 0 : currentAction.id);
|
|
9790
9802
|
return /* @__PURE__ */ jsxs(
|
|
9791
9803
|
"div",
|
|
9792
9804
|
{
|
|
@@ -9800,18 +9812,9 @@ function AutomationsActionsForm({
|
|
|
9800
9812
|
{
|
|
9801
9813
|
value: actionTypeField.value ?? "",
|
|
9802
9814
|
onValueChange: (value) => {
|
|
9803
|
-
|
|
9804
|
-
value
|
|
9805
|
-
);
|
|
9806
|
-
form.setValue(
|
|
9807
|
-
`actions.items.${index}.config`,
|
|
9808
|
-
{},
|
|
9809
|
-
{
|
|
9810
|
-
shouldValidate: false,
|
|
9811
|
-
shouldDirty: true
|
|
9812
|
-
}
|
|
9813
|
-
);
|
|
9815
|
+
actionTypeValueChange(index, value, isExistingAction);
|
|
9814
9816
|
},
|
|
9817
|
+
disabled: isExistingAction,
|
|
9815
9818
|
children: [
|
|
9816
9819
|
/* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Select the action type" }) }),
|
|
9817
9820
|
/* @__PURE__ */ jsx(Select.Content, { children: (_b = availableActionsData == null ? void 0 : availableActionsData.actions) == null ? void 0 : _b.map(
|
|
@@ -9849,8 +9852,8 @@ function AutomationsActionsForm({
|
|
|
9849
9852
|
actionType && configComponentKey && /* @__PURE__ */ jsx("div", { className: "mt-4 pt-4 border-t", children: /* @__PURE__ */ jsx(
|
|
9850
9853
|
LoadActionComponent,
|
|
9851
9854
|
{
|
|
9852
|
-
actionType,
|
|
9853
9855
|
configComponentKey,
|
|
9856
|
+
actionType,
|
|
9854
9857
|
form,
|
|
9855
9858
|
name: `actions.items.${index}.config`,
|
|
9856
9859
|
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,
|
|
@@ -9892,6 +9895,7 @@ function AutomationsEditForm({
|
|
|
9892
9895
|
[Tab.ACTIONS]: "not-started"
|
|
9893
9896
|
});
|
|
9894
9897
|
const [buttonText, setButtonText] = useState("");
|
|
9898
|
+
const [eventName, setEventName] = useState(void 0);
|
|
9895
9899
|
useEffect(() => {
|
|
9896
9900
|
if (Tab.GENERAL === tab) {
|
|
9897
9901
|
setButtonText("Save automation");
|
|
@@ -9927,7 +9931,8 @@ function AutomationsEditForm({
|
|
|
9927
9931
|
enabled: open && !!id
|
|
9928
9932
|
});
|
|
9929
9933
|
const { data: availableActionsData } = useAvailableActions({
|
|
9930
|
-
enabled: open
|
|
9934
|
+
enabled: open,
|
|
9935
|
+
eventName
|
|
9931
9936
|
});
|
|
9932
9937
|
const {
|
|
9933
9938
|
mutateAsync: editAutomation,
|
|
@@ -9971,6 +9976,7 @@ function AutomationsEditForm({
|
|
|
9971
9976
|
const trigger = automationsTriggerData.triggers[0];
|
|
9972
9977
|
const rules = (automationsRulesData == null ? void 0 : automationsRulesData.rules) || [];
|
|
9973
9978
|
const actions = (automationsActionsData == null ? void 0 : automationsActionsData.actions) || [];
|
|
9979
|
+
setEventName(trigger.event_name || void 0);
|
|
9974
9980
|
form.reset({
|
|
9975
9981
|
general: {
|
|
9976
9982
|
name: trigger.name || "",
|
|
@@ -10005,9 +10011,11 @@ function AutomationsEditForm({
|
|
|
10005
10011
|
}
|
|
10006
10012
|
});
|
|
10007
10013
|
}
|
|
10008
|
-
}, [open, automationsTriggerData, automationsRulesData]);
|
|
10014
|
+
}, [open, automationsTriggerData, automationsRulesData, automationsActionsData]);
|
|
10009
10015
|
useEffect(() => {
|
|
10010
10016
|
if (open === false) {
|
|
10017
|
+
setEventName(void 0);
|
|
10018
|
+
setTab(Tab.GENERAL);
|
|
10011
10019
|
form.reset({
|
|
10012
10020
|
general: {
|
|
10013
10021
|
name: "",
|
|
@@ -10127,7 +10135,7 @@ function AutomationsEditForm({
|
|
|
10127
10135
|
/* @__PURE__ */ jsx(FocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "primary", children: /* @__PURE__ */ jsx(Pencil, {}) }) }),
|
|
10128
10136
|
/* @__PURE__ */ jsxs(FocusModal.Content, { children: [
|
|
10129
10137
|
/* @__PURE__ */ jsxs(FocusModal.Header, { children: [
|
|
10130
|
-
/* @__PURE__ */ jsx(
|
|
10138
|
+
/* @__PURE__ */ jsx(Heading, { level: "h3", className: "shrink-0", children: "Edit Automation" }),
|
|
10131
10139
|
/* @__PURE__ */ jsx("div", { className: "-my-2 w-full border-l", children: /* @__PURE__ */ jsx(
|
|
10132
10140
|
ProgressTabs,
|
|
10133
10141
|
{
|
|
@@ -10175,7 +10183,8 @@ function AutomationsEditForm({
|
|
|
10175
10183
|
AutomationsGeneralForm,
|
|
10176
10184
|
{
|
|
10177
10185
|
form,
|
|
10178
|
-
isOpen: open
|
|
10186
|
+
isOpen: open,
|
|
10187
|
+
isEditMode: !!id
|
|
10179
10188
|
}
|
|
10180
10189
|
),
|
|
10181
10190
|
tab === Tab.RULES && /* @__PURE__ */ jsx(
|
|
@@ -10189,7 +10198,8 @@ function AutomationsEditForm({
|
|
|
10189
10198
|
AutomationsActionsForm,
|
|
10190
10199
|
{
|
|
10191
10200
|
form,
|
|
10192
|
-
isOpen: open
|
|
10201
|
+
isOpen: open,
|
|
10202
|
+
availableActionsData
|
|
10193
10203
|
}
|
|
10194
10204
|
)
|
|
10195
10205
|
]
|
|
@@ -10273,7 +10283,7 @@ const AutomationsList = () => {
|
|
|
10273
10283
|
order: "-created_at"
|
|
10274
10284
|
});
|
|
10275
10285
|
const columnHelper = createDataTableColumnHelper();
|
|
10276
|
-
const columns = [
|
|
10286
|
+
const columns = useMemo(() => [
|
|
10277
10287
|
columnHelper.accessor("to", {
|
|
10278
10288
|
header: "Name and description",
|
|
10279
10289
|
cell: ({ row }) => {
|
|
@@ -10369,7 +10379,7 @@ const AutomationsList = () => {
|
|
|
10369
10379
|
] });
|
|
10370
10380
|
}
|
|
10371
10381
|
})
|
|
10372
|
-
];
|
|
10382
|
+
], []);
|
|
10373
10383
|
const table = useDataTable({
|
|
10374
10384
|
columns,
|
|
10375
10385
|
data: (automationsTriggersData == null ? void 0 : automationsTriggersData.triggers) ?? [],
|
|
@@ -5182,19 +5182,25 @@ const useAvailableActions = (params, options) => {
|
|
|
5182
5182
|
enabled,
|
|
5183
5183
|
fields,
|
|
5184
5184
|
order = "created_at",
|
|
5185
|
-
id
|
|
5185
|
+
id,
|
|
5186
|
+
eventName
|
|
5187
|
+
// Add eventName parameter
|
|
5186
5188
|
} = params;
|
|
5187
5189
|
const queryKey = [
|
|
5188
5190
|
"available-actions",
|
|
5189
5191
|
limit,
|
|
5190
5192
|
offset,
|
|
5193
|
+
eventName,
|
|
5194
|
+
// Include eventName in query key for proper caching
|
|
5191
5195
|
...extraKey
|
|
5192
5196
|
];
|
|
5193
5197
|
const query = {
|
|
5194
5198
|
limit,
|
|
5195
5199
|
offset,
|
|
5196
5200
|
fields,
|
|
5197
|
-
order
|
|
5201
|
+
order,
|
|
5202
|
+
...eventName && { eventName }
|
|
5203
|
+
// Add eventName to query params if provided
|
|
5198
5204
|
};
|
|
5199
5205
|
const { data, ...rest } = reactQuery.useQuery({
|
|
5200
5206
|
queryKey,
|
|
@@ -5289,7 +5295,8 @@ const useAvailableTriggers = (params, options) => {
|
|
|
5289
5295
|
};
|
|
5290
5296
|
function AutomationsGeneralForm({
|
|
5291
5297
|
form,
|
|
5292
|
-
isOpen
|
|
5298
|
+
isOpen,
|
|
5299
|
+
isEditMode = false
|
|
5293
5300
|
}) {
|
|
5294
5301
|
const {
|
|
5295
5302
|
data: availableEventsData
|
|
@@ -5432,8 +5439,12 @@ function AutomationsGeneralForm({
|
|
|
5432
5439
|
{
|
|
5433
5440
|
value: field.value ?? "",
|
|
5434
5441
|
onValueChange: (value) => {
|
|
5442
|
+
if (isEditMode) {
|
|
5443
|
+
return;
|
|
5444
|
+
}
|
|
5435
5445
|
field.onChange(value);
|
|
5436
5446
|
},
|
|
5447
|
+
disabled: isEditMode,
|
|
5437
5448
|
children: [
|
|
5438
5449
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, { placeholder: "Select the event name" }) }),
|
|
5439
5450
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: availableEvents == null ? void 0 : availableEvents.map((event) => /* @__PURE__ */ jsxRuntime.jsxs(ui.Select.Group, { children: [
|
|
@@ -9167,9 +9178,7 @@ function createAutomationFormSchema(availableActions) {
|
|
|
9167
9178
|
}
|
|
9168
9179
|
);
|
|
9169
9180
|
}
|
|
9170
|
-
function AutomationsCreateForm({
|
|
9171
|
-
id
|
|
9172
|
-
}) {
|
|
9181
|
+
function AutomationsCreateForm() {
|
|
9173
9182
|
const [open, setOpen] = React.useState(false);
|
|
9174
9183
|
const [tab, setTab] = React.useState(Tab.GENERAL);
|
|
9175
9184
|
const [tabState, setTabState] = React.useState({
|
|
@@ -9189,12 +9198,10 @@ function AutomationsCreateForm({
|
|
|
9189
9198
|
}, [tab]);
|
|
9190
9199
|
const queryClient = reactQuery.useQueryClient();
|
|
9191
9200
|
const {
|
|
9192
|
-
data: automationsTriggerData,
|
|
9193
9201
|
isLoading: isAutomationsTriggerLoading
|
|
9194
9202
|
} = useListAutomations({
|
|
9195
|
-
id,
|
|
9196
9203
|
extraKey: [],
|
|
9197
|
-
enabled: open
|
|
9204
|
+
enabled: open
|
|
9198
9205
|
});
|
|
9199
9206
|
const { data: availableActionsData } = useAvailableActions({
|
|
9200
9207
|
enabled: open
|
|
@@ -9227,28 +9234,6 @@ function AutomationsCreateForm({
|
|
|
9227
9234
|
}
|
|
9228
9235
|
}
|
|
9229
9236
|
});
|
|
9230
|
-
React.useEffect(() => {
|
|
9231
|
-
var _a;
|
|
9232
|
-
if (automationsTriggerData && ((_a = automationsTriggerData.triggers) == null ? void 0 : _a[0])) {
|
|
9233
|
-
const trigger = automationsTriggerData.triggers[0];
|
|
9234
|
-
form.reset({
|
|
9235
|
-
general: {
|
|
9236
|
-
name: trigger.name || "",
|
|
9237
|
-
description: trigger.description || "",
|
|
9238
|
-
trigger_type: trigger.trigger_type || "event",
|
|
9239
|
-
event_name: trigger.event_name || "",
|
|
9240
|
-
interval_minutes: trigger.interval_minutes || null,
|
|
9241
|
-
active: trigger.active || false
|
|
9242
|
-
},
|
|
9243
|
-
rules: {
|
|
9244
|
-
items: []
|
|
9245
|
-
},
|
|
9246
|
-
actions: {
|
|
9247
|
-
items: []
|
|
9248
|
-
}
|
|
9249
|
-
});
|
|
9250
|
-
}
|
|
9251
|
-
}, [open, automationsTriggerData]);
|
|
9252
9237
|
React.useEffect(() => {
|
|
9253
9238
|
if (open === false) {
|
|
9254
9239
|
form.reset({
|
|
@@ -9299,7 +9284,7 @@ function AutomationsCreateForm({
|
|
|
9299
9284
|
/* @__PURE__ */ jsxRuntime.jsx(ui.FocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "primary", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
|
|
9300
9285
|
/* @__PURE__ */ jsxRuntime.jsxs(ui.FocusModal.Content, { children: [
|
|
9301
9286
|
/* @__PURE__ */ jsxRuntime.jsxs(ui.FocusModal.Header, { children: [
|
|
9302
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.
|
|
9287
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "shrink-0", children: "Create Automation" }),
|
|
9303
9288
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "-my-2 w-full border-l", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9304
9289
|
ui.ProgressTabs,
|
|
9305
9290
|
{
|
|
@@ -9374,8 +9359,6 @@ const useListAutomationsRules = (params, options) => {
|
|
|
9374
9359
|
} = params;
|
|
9375
9360
|
const queryKey = [
|
|
9376
9361
|
"automations-rules",
|
|
9377
|
-
limit,
|
|
9378
|
-
offset,
|
|
9379
9362
|
...extraKey
|
|
9380
9363
|
];
|
|
9381
9364
|
const query = {
|
|
@@ -9434,8 +9417,6 @@ const useListAutomationsActions = (params, options) => {
|
|
|
9434
9417
|
} = params;
|
|
9435
9418
|
const queryKey = [
|
|
9436
9419
|
"automations-actions",
|
|
9437
|
-
limit,
|
|
9438
|
-
offset,
|
|
9439
9420
|
...extraKey
|
|
9440
9421
|
];
|
|
9441
9422
|
const query = {
|
|
@@ -9564,11 +9545,19 @@ function AutomationsRulesForm({
|
|
|
9564
9545
|
children: [
|
|
9565
9546
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, { placeholder: "Select the attribute" }) }),
|
|
9566
9547
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: eventAttributes.map(
|
|
9567
|
-
(attribute, attrIndex) => /* @__PURE__ */ jsxRuntime.
|
|
9548
|
+
(attribute, attrIndex) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9568
9549
|
ui.Select.Item,
|
|
9569
9550
|
{
|
|
9570
9551
|
value: attribute.value || "ss",
|
|
9571
|
-
children:
|
|
9552
|
+
children: [
|
|
9553
|
+
attribute.label,
|
|
9554
|
+
" ",
|
|
9555
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-xs text-gray-500", children: [
|
|
9556
|
+
"(",
|
|
9557
|
+
attribute.value,
|
|
9558
|
+
")"
|
|
9559
|
+
] })
|
|
9560
|
+
]
|
|
9572
9561
|
},
|
|
9573
9562
|
attribute.value || `attr-${index}-${attrIndex}`
|
|
9574
9563
|
)
|
|
@@ -9669,7 +9658,7 @@ function AutomationsRulesForm({
|
|
|
9669
9658
|
] }) }) });
|
|
9670
9659
|
}
|
|
9671
9660
|
const templateLoaders = {
|
|
9672
|
-
BaseConfigComponent: () => Promise.resolve().then(() => require("./base-config-
|
|
9661
|
+
BaseConfigComponent: () => Promise.resolve().then(() => require("./base-config-XI6iR6Jp"))
|
|
9673
9662
|
};
|
|
9674
9663
|
async function loadTemplateComponent(key) {
|
|
9675
9664
|
const loader = templateLoaders[key];
|
|
@@ -9701,7 +9690,6 @@ function LoadActionComponent({
|
|
|
9701
9690
|
setError(null);
|
|
9702
9691
|
loadTemplateComponent(configComponentKey).then((module2) => {
|
|
9703
9692
|
const Component2 = module2;
|
|
9704
|
-
console.log("Component", Component2);
|
|
9705
9693
|
if (Component2) {
|
|
9706
9694
|
setComponent(() => Component2);
|
|
9707
9695
|
} else {
|
|
@@ -9743,13 +9731,9 @@ function LoadActionComponent({
|
|
|
9743
9731
|
}
|
|
9744
9732
|
function AutomationsActionsForm({
|
|
9745
9733
|
form,
|
|
9746
|
-
isOpen
|
|
9734
|
+
isOpen,
|
|
9735
|
+
availableActionsData
|
|
9747
9736
|
}) {
|
|
9748
|
-
const {
|
|
9749
|
-
data: availableActionsData
|
|
9750
|
-
} = useAvailableActions({
|
|
9751
|
-
enabled: isOpen !== false
|
|
9752
|
-
});
|
|
9753
9737
|
const {
|
|
9754
9738
|
fields = [],
|
|
9755
9739
|
append,
|
|
@@ -9758,7 +9742,7 @@ function AutomationsActionsForm({
|
|
|
9758
9742
|
control: form.control,
|
|
9759
9743
|
name: "actions.items"
|
|
9760
9744
|
});
|
|
9761
|
-
useWatch({
|
|
9745
|
+
const watchedActions = useWatch({
|
|
9762
9746
|
control: form.control,
|
|
9763
9747
|
name: "actions.items"
|
|
9764
9748
|
});
|
|
@@ -9771,6 +9755,32 @@ function AutomationsActionsForm({
|
|
|
9771
9755
|
const handleRemoveRule = (index) => {
|
|
9772
9756
|
remove(index);
|
|
9773
9757
|
};
|
|
9758
|
+
const actionTypeValueChange = (index, value, isExistingAction) => {
|
|
9759
|
+
var _a;
|
|
9760
|
+
if (isExistingAction) {
|
|
9761
|
+
return;
|
|
9762
|
+
}
|
|
9763
|
+
form.setValue(`actions.items.${index}.action_type`, value, {
|
|
9764
|
+
shouldValidate: false,
|
|
9765
|
+
shouldDirty: true
|
|
9766
|
+
});
|
|
9767
|
+
form.clearErrors(`actions.items.${index}`);
|
|
9768
|
+
const actionData = (_a = availableActionsData == null ? void 0 : availableActionsData.actions) == null ? void 0 : _a.find(
|
|
9769
|
+
(a2) => a2.value === value
|
|
9770
|
+
);
|
|
9771
|
+
const fields2 = actionData == null ? void 0 : actionData.fields;
|
|
9772
|
+
form.setValue(
|
|
9773
|
+
`actions.items.${index}.config`,
|
|
9774
|
+
fields2 == null ? void 0 : fields2.reduce((acc, field) => {
|
|
9775
|
+
acc[field.name || field.key] = "";
|
|
9776
|
+
return acc;
|
|
9777
|
+
}, {}),
|
|
9778
|
+
{
|
|
9779
|
+
shouldValidate: false,
|
|
9780
|
+
shouldDirty: true
|
|
9781
|
+
}
|
|
9782
|
+
);
|
|
9783
|
+
};
|
|
9774
9784
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6 max-w-2xl mx-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
9775
9785
|
fields.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm text-gray-500 text-center py-4", children: 'No actions added yet. Click "Add Item" to create a new action.' }),
|
|
9776
9786
|
fields.map((field, index) => {
|
|
@@ -9791,6 +9801,8 @@ function AutomationsActionsForm({
|
|
|
9791
9801
|
const configComponentKey = actionData == null ? void 0 : actionData.configComponentKey;
|
|
9792
9802
|
const fields2 = actionData == null ? void 0 : actionData.fields;
|
|
9793
9803
|
const isEnabled = actionType ? actionData == null ? void 0 : actionData.enabled : true;
|
|
9804
|
+
const currentAction = watchedActions == null ? void 0 : watchedActions[index];
|
|
9805
|
+
const isExistingAction = !!(currentAction == null ? void 0 : currentAction.id);
|
|
9794
9806
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9795
9807
|
"div",
|
|
9796
9808
|
{
|
|
@@ -9804,18 +9816,9 @@ function AutomationsActionsForm({
|
|
|
9804
9816
|
{
|
|
9805
9817
|
value: actionTypeField.value ?? "",
|
|
9806
9818
|
onValueChange: (value) => {
|
|
9807
|
-
|
|
9808
|
-
value
|
|
9809
|
-
);
|
|
9810
|
-
form.setValue(
|
|
9811
|
-
`actions.items.${index}.config`,
|
|
9812
|
-
{},
|
|
9813
|
-
{
|
|
9814
|
-
shouldValidate: false,
|
|
9815
|
-
shouldDirty: true
|
|
9816
|
-
}
|
|
9817
|
-
);
|
|
9819
|
+
actionTypeValueChange(index, value, isExistingAction);
|
|
9818
9820
|
},
|
|
9821
|
+
disabled: isExistingAction,
|
|
9819
9822
|
children: [
|
|
9820
9823
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, { placeholder: "Select the action type" }) }),
|
|
9821
9824
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: (_b = availableActionsData == null ? void 0 : availableActionsData.actions) == null ? void 0 : _b.map(
|
|
@@ -9853,8 +9856,8 @@ function AutomationsActionsForm({
|
|
|
9853
9856
|
actionType && configComponentKey && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 pt-4 border-t", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9854
9857
|
LoadActionComponent,
|
|
9855
9858
|
{
|
|
9856
|
-
actionType,
|
|
9857
9859
|
configComponentKey,
|
|
9860
|
+
actionType,
|
|
9858
9861
|
form,
|
|
9859
9862
|
name: `actions.items.${index}.config`,
|
|
9860
9863
|
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,
|
|
@@ -9896,6 +9899,7 @@ function AutomationsEditForm({
|
|
|
9896
9899
|
[Tab.ACTIONS]: "not-started"
|
|
9897
9900
|
});
|
|
9898
9901
|
const [buttonText, setButtonText] = React.useState("");
|
|
9902
|
+
const [eventName, setEventName] = React.useState(void 0);
|
|
9899
9903
|
React.useEffect(() => {
|
|
9900
9904
|
if (Tab.GENERAL === tab) {
|
|
9901
9905
|
setButtonText("Save automation");
|
|
@@ -9931,7 +9935,8 @@ function AutomationsEditForm({
|
|
|
9931
9935
|
enabled: open && !!id
|
|
9932
9936
|
});
|
|
9933
9937
|
const { data: availableActionsData } = useAvailableActions({
|
|
9934
|
-
enabled: open
|
|
9938
|
+
enabled: open,
|
|
9939
|
+
eventName
|
|
9935
9940
|
});
|
|
9936
9941
|
const {
|
|
9937
9942
|
mutateAsync: editAutomation,
|
|
@@ -9975,6 +9980,7 @@ function AutomationsEditForm({
|
|
|
9975
9980
|
const trigger = automationsTriggerData.triggers[0];
|
|
9976
9981
|
const rules = (automationsRulesData == null ? void 0 : automationsRulesData.rules) || [];
|
|
9977
9982
|
const actions = (automationsActionsData == null ? void 0 : automationsActionsData.actions) || [];
|
|
9983
|
+
setEventName(trigger.event_name || void 0);
|
|
9978
9984
|
form.reset({
|
|
9979
9985
|
general: {
|
|
9980
9986
|
name: trigger.name || "",
|
|
@@ -10009,9 +10015,11 @@ function AutomationsEditForm({
|
|
|
10009
10015
|
}
|
|
10010
10016
|
});
|
|
10011
10017
|
}
|
|
10012
|
-
}, [open, automationsTriggerData, automationsRulesData]);
|
|
10018
|
+
}, [open, automationsTriggerData, automationsRulesData, automationsActionsData]);
|
|
10013
10019
|
React.useEffect(() => {
|
|
10014
10020
|
if (open === false) {
|
|
10021
|
+
setEventName(void 0);
|
|
10022
|
+
setTab(Tab.GENERAL);
|
|
10015
10023
|
form.reset({
|
|
10016
10024
|
general: {
|
|
10017
10025
|
name: "",
|
|
@@ -10131,7 +10139,7 @@ function AutomationsEditForm({
|
|
|
10131
10139
|
/* @__PURE__ */ jsxRuntime.jsx(ui.FocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "primary", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Pencil, {}) }) }),
|
|
10132
10140
|
/* @__PURE__ */ jsxRuntime.jsxs(ui.FocusModal.Content, { children: [
|
|
10133
10141
|
/* @__PURE__ */ jsxRuntime.jsxs(ui.FocusModal.Header, { children: [
|
|
10134
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.
|
|
10142
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "shrink-0", children: "Edit Automation" }),
|
|
10135
10143
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "-my-2 w-full border-l", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
10136
10144
|
ui.ProgressTabs,
|
|
10137
10145
|
{
|
|
@@ -10179,7 +10187,8 @@ function AutomationsEditForm({
|
|
|
10179
10187
|
AutomationsGeneralForm,
|
|
10180
10188
|
{
|
|
10181
10189
|
form,
|
|
10182
|
-
isOpen: open
|
|
10190
|
+
isOpen: open,
|
|
10191
|
+
isEditMode: !!id
|
|
10183
10192
|
}
|
|
10184
10193
|
),
|
|
10185
10194
|
tab === Tab.RULES && /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -10193,7 +10202,8 @@ function AutomationsEditForm({
|
|
|
10193
10202
|
AutomationsActionsForm,
|
|
10194
10203
|
{
|
|
10195
10204
|
form,
|
|
10196
|
-
isOpen: open
|
|
10205
|
+
isOpen: open,
|
|
10206
|
+
availableActionsData
|
|
10197
10207
|
}
|
|
10198
10208
|
)
|
|
10199
10209
|
]
|
|
@@ -10277,7 +10287,7 @@ const AutomationsList = () => {
|
|
|
10277
10287
|
order: "-created_at"
|
|
10278
10288
|
});
|
|
10279
10289
|
const columnHelper = ui.createDataTableColumnHelper();
|
|
10280
|
-
const columns = [
|
|
10290
|
+
const columns = React.useMemo(() => [
|
|
10281
10291
|
columnHelper.accessor("to", {
|
|
10282
10292
|
header: "Name and description",
|
|
10283
10293
|
cell: ({ row }) => {
|
|
@@ -10373,7 +10383,7 @@ const AutomationsList = () => {
|
|
|
10373
10383
|
] });
|
|
10374
10384
|
}
|
|
10375
10385
|
})
|
|
10376
|
-
];
|
|
10386
|
+
], []);
|
|
10377
10387
|
const table = ui.useDataTable({
|
|
10378
10388
|
columns,
|
|
10379
10389
|
data: (automationsTriggersData == null ? void 0 : automationsTriggersData.triggers) ?? [],
|