@drawbridge/components 0.1.13 → 0.1.15

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.
Files changed (242) hide show
  1. package/components/styles.css +364 -2
  2. package/dist/advertisement.js +3 -1
  3. package/dist/advertisement.mjs +3 -1
  4. package/dist/bridge/advertisements.js +2 -0
  5. package/dist/bridge/advertisements.mjs +2 -0
  6. package/dist/bridge/countdown.js +2 -1
  7. package/dist/bridge/countdown.mjs +2 -1
  8. package/dist/bridge/form-subdomain-embed.js +18 -20
  9. package/dist/bridge/form-subdomain-embed.mjs +18 -20
  10. package/dist/bridge/form-subdomain-header.js +24 -1
  11. package/dist/bridge/form-subdomain-header.mjs +24 -1
  12. package/dist/bridge/form-subdomain-missions.js +577 -0
  13. package/dist/bridge/form-subdomain-missions.mjs +540 -0
  14. package/dist/bridge/form-subdomain.js +530 -220
  15. package/dist/bridge/form-subdomain.mjs +533 -222
  16. package/dist/bridge/lib/entry.js +59 -0
  17. package/dist/bridge/lib/entry.mjs +29 -0
  18. package/dist/bridge/lib/location.js +38 -0
  19. package/dist/bridge/lib/location.mjs +13 -0
  20. package/dist/bridge/lib/order.js +71 -0
  21. package/dist/bridge/lib/order.mjs +44 -0
  22. package/dist/bridge/lib/url.js +9 -0
  23. package/dist/bridge/lib/url.mjs +7 -0
  24. package/dist/bridge/share-button.js +5 -3
  25. package/dist/bridge/share-button.mjs +5 -3
  26. package/dist/bridge/subdomain-content.js +7 -6
  27. package/dist/bridge/subdomain-content.mjs +7 -6
  28. package/dist/bridge/template-layout.js +59 -21
  29. package/dist/bridge/template-layout.mjs +59 -21
  30. package/dist/bridge/template-modal.js +42 -76
  31. package/dist/bridge/template-modal.mjs +39 -73
  32. package/dist/bridge/template-preview.js +208 -0
  33. package/dist/bridge/template-preview.mjs +173 -0
  34. package/dist/bridge/template-subdomain-gallery.js +6 -2
  35. package/dist/bridge/template-subdomain-gallery.mjs +6 -2
  36. package/dist/bridge/template-subdomain-link.js +6 -1
  37. package/dist/bridge/template-subdomain-link.mjs +6 -1
  38. package/dist/bridge/template-subdomain.js +20 -15
  39. package/dist/bridge/template-subdomain.mjs +20 -15
  40. package/dist/dashboard/accordion.js +74 -39
  41. package/dist/dashboard/accordion.mjs +74 -39
  42. package/dist/dashboard/avatar.js +109 -3
  43. package/dist/dashboard/avatar.mjs +106 -4
  44. package/dist/dashboard/buttons-subscription.js +384 -0
  45. package/dist/dashboard/buttons-subscription.mjs +349 -0
  46. package/dist/dashboard/card-campaign-switch.js +277 -0
  47. package/dist/dashboard/card-campaign-switch.mjs +243 -0
  48. package/dist/dashboard/card-order.js +231 -29
  49. package/dist/dashboard/card-order.mjs +231 -29
  50. package/dist/dashboard/card-section.js +26 -2
  51. package/dist/dashboard/card-section.mjs +26 -2
  52. package/dist/dashboard/card-tile.js +6 -7
  53. package/dist/dashboard/card-tile.mjs +6 -7
  54. package/dist/dashboard/connection-workflows.js +205 -0
  55. package/dist/dashboard/connection-workflows.mjs +171 -0
  56. package/dist/dashboard/device.js +95 -0
  57. package/dist/dashboard/device.mjs +72 -0
  58. package/dist/dashboard/form-admin-campaign.js +19 -50
  59. package/dist/dashboard/form-admin-campaign.mjs +20 -51
  60. package/dist/dashboard/form-ai.js +9 -6
  61. package/dist/dashboard/form-ai.mjs +9 -6
  62. package/dist/dashboard/form-auth.js +35 -25
  63. package/dist/dashboard/form-auth.mjs +36 -26
  64. package/dist/dashboard/form-file.js +10 -1
  65. package/dist/dashboard/form-file.mjs +10 -1
  66. package/dist/dashboard/form-filters-analytics.js +14 -1
  67. package/dist/dashboard/form-filters-analytics.mjs +15 -2
  68. package/dist/dashboard/form-organization-campaign-advertisement.js +15 -1
  69. package/dist/dashboard/form-organization-campaign-advertisement.mjs +16 -2
  70. package/dist/dashboard/form-organization-campaign-agreement.js +215 -164
  71. package/dist/dashboard/form-organization-campaign-agreement.mjs +215 -164
  72. package/dist/dashboard/form-organization-campaign-field-email.js +0 -34
  73. package/dist/dashboard/form-organization-campaign-field-email.mjs +0 -34
  74. package/dist/dashboard/form-organization-campaign-field-list.js +466 -0
  75. package/dist/dashboard/form-organization-campaign-field-list.mjs +437 -0
  76. package/dist/dashboard/form-organization-campaign-field-phone.js +0 -34
  77. package/dist/dashboard/form-organization-campaign-field-phone.mjs +0 -34
  78. package/dist/dashboard/form-organization-campaign-field-remove.js +66 -0
  79. package/dist/dashboard/form-organization-campaign-field-remove.mjs +33 -0
  80. package/dist/dashboard/form-organization-campaign-field-select.js +51 -5
  81. package/dist/dashboard/form-organization-campaign-field-select.mjs +51 -5
  82. package/dist/dashboard/form-organization-campaign-field-textarea.js +46 -8
  83. package/dist/dashboard/form-organization-campaign-field-textarea.mjs +46 -8
  84. package/dist/dashboard/form-organization-campaign-integration-age.js +6 -12
  85. package/dist/dashboard/form-organization-campaign-integration-age.mjs +6 -12
  86. package/dist/dashboard/form-organization-campaign-integration-enable.js +52 -24
  87. package/dist/dashboard/form-organization-campaign-integration-enable.mjs +54 -26
  88. package/dist/dashboard/form-organization-campaign-integration-geocode.js +6 -12
  89. package/dist/dashboard/form-organization-campaign-integration-geocode.mjs +6 -12
  90. package/dist/dashboard/form-organization-campaign-integration-gtm.js +6 -12
  91. package/dist/dashboard/form-organization-campaign-integration-gtm.mjs +6 -12
  92. package/dist/dashboard/form-organization-campaign-link.js +7 -1
  93. package/dist/dashboard/form-organization-campaign-link.mjs +7 -1
  94. package/dist/dashboard/form-organization-campaign-mission.js +291 -0
  95. package/dist/dashboard/form-organization-campaign-mission.mjs +258 -0
  96. package/dist/dashboard/form-organization-campaign-page-embed.js +13 -2
  97. package/dist/dashboard/form-organization-campaign-page-embed.mjs +12 -1
  98. package/dist/dashboard/form-organization-campaign-page.js +20 -11
  99. package/dist/dashboard/form-organization-campaign-page.mjs +20 -11
  100. package/dist/dashboard/form-organization-campaign-prize-edit.js +12 -1
  101. package/dist/dashboard/form-organization-campaign-prize-edit.mjs +12 -1
  102. package/dist/dashboard/form-organization-campaign-section.js +243 -0
  103. package/dist/dashboard/form-organization-campaign-section.mjs +214 -0
  104. package/dist/dashboard/form-organization-campaign.js +114 -469
  105. package/dist/dashboard/form-organization-campaign.mjs +113 -467
  106. package/dist/dashboard/form-organization-export.js +4 -7
  107. package/dist/dashboard/form-organization-export.mjs +4 -7
  108. package/dist/dashboard/form-organization-identity.js +46 -51
  109. package/dist/dashboard/form-organization-identity.mjs +46 -51
  110. package/dist/dashboard/form-organization-workflow.js +708 -687
  111. package/dist/dashboard/form-organization-workflow.mjs +704 -683
  112. package/dist/dashboard/form-organization.js +82 -110
  113. package/dist/dashboard/form-organization.mjs +81 -109
  114. package/dist/dashboard/form-otc.js +4 -5
  115. package/dist/dashboard/form-otc.mjs +4 -5
  116. package/dist/dashboard/form-payment-methods.js +20 -9
  117. package/dist/dashboard/form-payment-methods.mjs +20 -9
  118. package/dist/dashboard/form-stripe.js +30 -0
  119. package/dist/dashboard/form-stripe.mjs +26 -0
  120. package/dist/dashboard/input-array.js +4 -2
  121. package/dist/dashboard/input-array.mjs +4 -2
  122. package/dist/dashboard/input-combobox.js +7 -3
  123. package/dist/dashboard/input-combobox.mjs +7 -3
  124. package/dist/dashboard/input-date.js +7 -0
  125. package/dist/dashboard/input-date.mjs +7 -0
  126. package/dist/dashboard/input-fields.js +80 -20
  127. package/dist/dashboard/input-fields.mjs +80 -20
  128. package/dist/dashboard/input-file.js +21 -1
  129. package/dist/dashboard/input-file.mjs +21 -1
  130. package/dist/dashboard/input-font.js +10 -1
  131. package/dist/dashboard/input-font.mjs +10 -1
  132. package/dist/dashboard/lib/item-list.js +57 -0
  133. package/dist/dashboard/lib/item-list.mjs +33 -0
  134. package/dist/dashboard/lib/menu.js +50 -0
  135. package/dist/dashboard/lib/menu.mjs +26 -0
  136. package/dist/dashboard/locked.js +82 -0
  137. package/dist/dashboard/locked.mjs +53 -0
  138. package/dist/dashboard/menu.js +72 -19
  139. package/dist/dashboard/menu.mjs +72 -19
  140. package/dist/dashboard/note-ai.js +69 -0
  141. package/dist/dashboard/note-ai.mjs +36 -0
  142. package/dist/dashboard/preview.js +419 -0
  143. package/dist/dashboard/preview.mjs +384 -0
  144. package/dist/dashboard/steps.js +39 -13
  145. package/dist/dashboard/steps.mjs +37 -12
  146. package/dist/dashboard/table-contacts.js +136 -0
  147. package/dist/dashboard/table-contacts.mjs +103 -0
  148. package/dist/dashboard/template-not-found.js +4 -2
  149. package/dist/dashboard/template-not-found.mjs +4 -2
  150. package/dist/dashboard/template-socket.js +20 -7
  151. package/dist/dashboard/template-socket.mjs +20 -7
  152. package/dist/icons/desktop.js +46 -0
  153. package/dist/icons/desktop.mjs +27 -0
  154. package/dist/icons/phone.js +46 -0
  155. package/dist/icons/phone.mjs +27 -0
  156. package/dist/icons/puzzle-piece.js +46 -0
  157. package/dist/icons/puzzle-piece.mjs +27 -0
  158. package/dist/icons/tablet.js +46 -0
  159. package/dist/icons/tablet.mjs +27 -0
  160. package/dist/icons/users.js +46 -0
  161. package/dist/icons/users.mjs +27 -0
  162. package/dist/input-checkbox.js +1 -0
  163. package/dist/input-checkbox.mjs +1 -0
  164. package/dist/input-code.js +83 -0
  165. package/dist/input-code.mjs +50 -0
  166. package/dist/input-text.js +2 -1
  167. package/dist/input-text.mjs +2 -1
  168. package/dist/shared/button.js +1 -1
  169. package/dist/shared/button.mjs +1 -1
  170. package/dist/shared/input-checkbox-list.js +0 -1
  171. package/dist/shared/input-checkbox-list.mjs +0 -1
  172. package/dist/shared/input-switch.js +6 -1
  173. package/dist/shared/input-switch.mjs +6 -1
  174. package/dist/shared/lib/campaign.js +123 -0
  175. package/dist/shared/lib/campaign.mjs +96 -0
  176. package/dist/shared/lib/helpers.js +14 -2
  177. package/dist/shared/lib/helpers.mjs +13 -2
  178. package/package.json +133 -13
  179. package/types/bridge/form-subdomain-header.d.ts +2 -0
  180. package/types/bridge/form-subdomain-missions.d.ts +38 -0
  181. package/types/bridge/form-subdomain.d.ts +23 -1
  182. package/types/bridge/lib/entry.d.ts +26 -0
  183. package/types/bridge/lib/location.d.ts +13 -0
  184. package/types/bridge/lib/order.d.ts +30 -0
  185. package/types/bridge/lib/url.d.ts +19 -0
  186. package/types/bridge/template-modal.d.ts +1 -1
  187. package/types/bridge/template-preview.d.ts +10 -0
  188. package/types/bridge/template-subdomain-link.d.ts +2 -0
  189. package/types/dashboard/accordion.d.ts +2 -0
  190. package/types/dashboard/avatar.d.ts +18 -2
  191. package/types/dashboard/buttons-subscription.d.ts +22 -0
  192. package/types/dashboard/card-campaign-switch.d.ts +32 -0
  193. package/types/dashboard/card-order.d.ts +25 -1
  194. package/types/dashboard/card-section.d.ts +2 -0
  195. package/types/dashboard/connection-workflows.d.ts +33 -0
  196. package/types/dashboard/device.d.ts +12 -0
  197. package/types/dashboard/form-admin-campaign.d.ts +3 -2
  198. package/types/dashboard/form-ai.d.ts +2 -2
  199. package/types/dashboard/form-organization-campaign-agreement.d.ts +18 -12
  200. package/types/dashboard/form-organization-campaign-field-email.d.ts +1 -2
  201. package/types/dashboard/form-organization-campaign-field-list.d.ts +36 -0
  202. package/types/dashboard/form-organization-campaign-field-phone.d.ts +1 -2
  203. package/types/dashboard/form-organization-campaign-field-remove.d.ts +22 -0
  204. package/types/dashboard/form-organization-campaign-field-select.d.ts +2 -1
  205. package/types/dashboard/form-organization-campaign-field-textarea.d.ts +2 -1
  206. package/types/dashboard/form-organization-campaign-integration-age.d.ts +3 -3
  207. package/types/dashboard/form-organization-campaign-integration-enable.d.ts +3 -3
  208. package/types/dashboard/form-organization-campaign-mission.d.ts +40 -0
  209. package/types/dashboard/form-organization-campaign-section.d.ts +29 -0
  210. package/types/dashboard/form-organization-campaign.d.ts +27 -17
  211. package/types/dashboard/form-organization-identity.d.ts +2 -0
  212. package/types/dashboard/form-organization-workflow.d.ts +56 -47
  213. package/types/dashboard/form-organization.d.ts +7 -2
  214. package/types/dashboard/form-stripe.d.ts +3 -0
  215. package/types/dashboard/input-combobox.d.ts +2 -0
  216. package/types/dashboard/input-date.d.ts +2 -0
  217. package/types/dashboard/input-fields.d.ts +3 -2
  218. package/types/dashboard/input-file.d.ts +4 -0
  219. package/types/dashboard/lib/item-list.d.ts +14 -0
  220. package/types/dashboard/lib/menu.d.ts +17 -0
  221. package/types/dashboard/locked.d.ts +10 -0
  222. package/types/dashboard/menu.d.ts +10 -2
  223. package/types/dashboard/note-ai.d.ts +15 -0
  224. package/types/dashboard/preview.d.ts +33 -0
  225. package/types/dashboard/steps.d.ts +19 -4
  226. package/types/dashboard/table-cell-title.d.ts +2 -2
  227. package/types/dashboard/table-contacts.d.ts +2 -0
  228. package/types/icons/desktop.d.ts +5 -0
  229. package/types/icons/phone.d.ts +5 -0
  230. package/types/icons/puzzle-piece.d.ts +5 -0
  231. package/types/icons/tablet.d.ts +5 -0
  232. package/types/icons/users.d.ts +5 -0
  233. package/types/input-code.d.ts +23 -0
  234. package/types/shared/input-switch.d.ts +2 -0
  235. package/types/shared/lib/campaign.d.ts +35 -0
  236. package/types/shared/lib/helpers.d.ts +3 -0
  237. package/dist/dashboard/card-integration.js +0 -187
  238. package/dist/dashboard/card-integration.mjs +0 -158
  239. package/dist/dashboard/iframe.js +0 -159
  240. package/dist/dashboard/iframe.mjs +0 -130
  241. package/types/dashboard/card-integration.d.ts +0 -24
  242. package/types/dashboard/iframe.d.ts +0 -18
@@ -27,14 +27,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
  var form_organization_workflow_exports = {};
29
29
  __export(form_organization_workflow_exports, {
30
- FormOrganizationWorkflow: () => FormOrganizationWorkflow,
31
30
  FormOrganizationWorkflowEdit: () => FormOrganizationWorkflowEdit,
32
- campaignFilterId: () => campaignFilterId,
33
- campaignFilterIds: () => campaignFilterIds,
34
- filterMissing: () => filterMissing,
35
- filterRows: () => filterRows,
36
- filterSeed: () => filterSeed,
31
+ SAMPLE: () => SAMPLE,
32
+ prefillRow: () => prefillRow,
33
+ stepReason: () => stepReason,
37
34
  stepRow: () => stepRow,
35
+ stepVariables: () => stepVariables,
36
+ teamSample: () => teamSample,
37
+ webhookSample: () => webhookSample,
38
38
  workflowSchema: () => workflowSchema
39
39
  });
40
40
  module.exports = __toCommonJS(form_organization_workflow_exports);
@@ -50,7 +50,6 @@ var import_form2 = __toESM(require("../shared/form"));
50
50
  var import_fieldset = __toESM(require("../shared/fieldset"));
51
51
  var import_input_group = __toESM(require("../input-group"));
52
52
  var import_error = __toESM(require("../shared/error"));
53
- var import_input_text = __toESM(require("../input-text"));
54
53
  var import_input_textarea = __toESM(require("../input-textarea"));
55
54
  var import_input_url = __toESM(require("../shared/input-url"));
56
55
  var import_input_resource = __toESM(require("./input-resource"));
@@ -58,13 +57,18 @@ var import_input_combobox = __toESM(require("./input-combobox"));
58
57
  var import_form_notification = require("./form-notification");
59
58
  var import_input_array = require("./input-array");
60
59
  var import_badge = __toESM(require("../shared/badge"));
60
+ var import_input_switch = __toESM(require("../shared/input-switch"));
61
+ var import_tooltip = __toESM(require("../shared/tooltip"));
62
+ var import_card_section = __toESM(require("./card-section"));
63
+ var import_accordion = __toESM(require("./accordion"));
64
+ var import_preview = __toESM(require("./preview"));
61
65
  var import_card_task = __toESM(require("./card-task"));
62
66
  var import_loader = require("../shared/loader");
63
67
  var import_sms = require("./lib/sms");
64
68
  var import_trash = __toESM(require("../icons/trash"));
65
69
  var import_button = __toESM(require("../shared/button"));
66
- const emailSteps = ["step.email.send", "step.email.digest"];
67
- const teamSteps = ["step.email.notify", "step.email.digest"];
70
+ const emailSteps = ["step.email.send"];
71
+ const teamSteps = ["step.email.notify"];
68
72
  const messageSteps = [...emailSteps, "step.sms.send"];
69
73
  const defaultScore = {
70
74
  rules: [
@@ -83,16 +87,8 @@ const stepPrefills = {
83
87
  subject: "Thanks for entering",
84
88
  text: "Thanks for entering. We have your entry and will be in touch."
85
89
  },
86
- // Nothing to prefill — the step writes its own copy — but the entry has to
87
- // exist: an unlisted step arrives from the deep link with no settings shape
88
- // and the drawer creates the workflow without it.
89
- "step.email.notify": {},
90
- "step.email.digest": {
91
- message: "You had {{count}} new entries.",
92
- score: defaultScore,
93
- subject: "Your entries",
94
- text: "You had {{count}} new entries."
95
- }
90
+ // Nothing to prefill: the step writes its own copy.
91
+ "step.email.notify": {}
96
92
  };
97
93
  const memberParams = {
98
94
  filters: {
@@ -130,194 +126,39 @@ const memberLabel = (member) => {
130
126
  var _a, _b, _c;
131
127
  return [(_a = member == null ? void 0 : member.user) == null ? void 0 : _a.firstName, (_b = member == null ? void 0 : member.user) == null ? void 0 : _b.lastName].filter(Boolean).join(" ") || (member == null ? void 0 : member.email) || ((_c = member == null ? void 0 : member.user) == null ? void 0 : _c.email) || "Member";
132
128
  };
133
- const useWorkflowCatalog = (organization, current) => {
134
- const catalog = (0, import_react_query.useQuery)({
135
- queryKey: ["organization-workflow-catalog", organization],
136
- queryFn: async () => {
137
- const { result } = await (0, import_fetch.request)({
138
- endpoint: "/organization/" + organization + "/workflows/catalog"
139
- });
140
- return result;
141
- },
142
- enabled: Boolean(organization),
143
- staleTime: Infinity
129
+ const stepVariables = (entry, steps = [], index = 0) => [
130
+ ...(entry == null ? void 0 : entry.variables) || [],
131
+ ...steps.slice(0, index).flatMap((step) => {
132
+ var _a;
133
+ return ((_a = ((entry == null ? void 0 : entry.steps) || []).find((option) => option.value === (step == null ? void 0 : step.type))) == null ? void 0 : _a.returns) || [];
134
+ })
135
+ ];
136
+ const prefillRow = ({ entry, step, steps = [] }) => {
137
+ if (!step || steps.some((row) => (row == null ? void 0 : row.type) === step)) return null;
138
+ const option = ((entry == null ? void 0 : entry.steps) || []).find((each) => each.value === step);
139
+ if (!option || option.ownerOnly || option.disabled) return null;
140
+ return stepRow({
141
+ connectionId: option.connectionId,
142
+ settings: stepPrefills[step] || {},
143
+ slug: option.slug,
144
+ type: step
144
145
  });
145
- const catalogList = catalog.data || [];
146
- const triggerGroups = catalogList.filter((item) => item.type !== "schedule" || item.trigger === current).reduce((groups, item) => {
147
- const model = item.type === "schedule" ? "schedule" : item.trigger.split(".")[0];
148
- if (!groups[model]) groups[model] = [];
149
- groups[model].push(item);
150
- return groups;
151
- }, {});
152
- const triggerOptions = [
153
- { key: "Select a trigger", value: "" },
154
- ...Object.entries(triggerGroups).sort(([a], [b]) => a.localeCompare(b)).flatMap(([model, items]) => [
155
- { key: model.charAt(0).toUpperCase() + model.slice(1), header: true },
156
- ...items.sort((a, b) => a.title.localeCompare(b.title)).map((item) => ({
157
- image: item.image,
158
- key: item.title,
159
- value: item.trigger
160
- }))
161
- ])
162
- ];
163
- return { catalog, catalogList, triggerOptions };
164
- };
165
- const WorkflowTriggerField = ({ control, formState, catalogList, triggerOptions, getValues, setValue }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
166
- import_form.Controller,
167
- {
168
- ...{
169
- control,
170
- name: "triggerEvent",
171
- render: ({ field: { value, onChange } }) => {
172
- var _a, _b;
173
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
174
- import_input_group.default,
175
- {
176
- ...{
177
- error: (_b = (_a = formState == null ? void 0 : formState.errors) == null ? void 0 : _a.triggerEvent) == null ? void 0 : _b.message,
178
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
179
- import_input_combobox.default,
180
- {
181
- ...{
182
- onChange: (val) => {
183
- onChange(val);
184
- const entry = catalogList.find((item) => item.trigger === val);
185
- if (entry) {
186
- const currentTitle = getValues("title");
187
- const catalogTitles = catalogList.map((item) => item.title);
188
- if (!currentTitle || catalogTitles.includes(currentTitle)) {
189
- setValue("title", entry.title);
190
- }
191
- ;
192
- }
193
- ;
194
- },
195
- options: triggerOptions,
196
- value: value || ""
197
- }
198
- }
199
- ),
200
- label: "Trigger"
201
- }
202
- }
203
- );
204
- }
205
- }
206
- }
207
- );
208
- const WorkflowTitleField = ({ control, formState }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
209
- import_form.Controller,
210
- {
211
- ...{
212
- control,
213
- name: "title",
214
- render: ({ field: { value, onChange } }) => {
215
- var _a, _b;
216
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
217
- import_input_group.default,
218
- {
219
- ...{
220
- error: (_b = (_a = formState == null ? void 0 : formState.errors) == null ? void 0 : _a.title) == null ? void 0 : _b.message,
221
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
222
- import_input_text.default,
223
- {
224
- ...{
225
- onChange,
226
- placeholder: "Workflow name",
227
- value: value || ""
228
- }
229
- }
230
- ),
231
- label: "Title"
232
- }
233
- }
234
- );
235
- }
236
- }
237
- }
238
- );
239
- const campaignFilterId = (campaign) => (campaign == null ? void 0 : campaign.id) || campaign || null;
240
- const campaignFilterIds = (filters) => (Array.isArray(filters == null ? void 0 : filters.campaigns) ? filters.campaigns : [filters == null ? void 0 : filters.campaign]).map(campaignFilterId).filter(Boolean);
241
- const filterRows = (ids, docs) => ids.map((id) => docs.find((doc) => (doc == null ? void 0 : doc.id) === id) || { id });
242
- const filterSeed = (seeds, id) => (seeds || []).find((doc) => (doc == null ? void 0 : doc.id) === id);
243
- const filterMissing = (error) => {
244
- if ((error == null ? void 0 : error.status) === 404) return { result: null };
245
- throw error;
246
146
  };
247
- const WorkflowFilterField = ({
248
- collection,
249
- control,
250
- label,
251
- message,
252
- model,
253
- multiple = false,
254
- name,
255
- organization,
256
- resource,
257
- seeds
258
- }) => {
259
- const queryClient = (0, import_react_query.useQueryClient)();
260
- const value = (0, import_form.useWatch)({
261
- control,
262
- name
263
- });
264
- const ids = multiple ? value || [] : [value].filter(Boolean);
265
- const docs = (0, import_react_query.useQueries)({
266
- queries: ids.map((id) => ({
267
- queryKey: ["workflow-filter", model, organization, id],
268
- queryFn: async () => {
269
- const { result } = await (0, import_fetch.request)({
270
- endpoint: "/organization/" + organization + "/" + resource + "/" + id
271
- }).catch(filterMissing);
272
- return result;
273
- },
274
- initialData: () => filterSeed(seeds, id),
275
- staleTime: Infinity
276
- }))
277
- }).map((query) => query.data);
278
- const seed = (doc) => (doc == null ? void 0 : doc.id) && queryClient.setQueryData(["workflow-filter", model, organization, doc.id], doc);
279
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
280
- import_form.Controller,
281
- {
282
- ...{
283
- control,
284
- name,
285
- render: ({ field: { onChange } }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
286
- import_input_group.default,
287
- {
288
- ...{
289
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
290
- import_input_resource.default,
291
- {
292
- ...{
293
- endpoint: "/organization/" + organization + "/" + collection,
294
- model,
295
- multiple,
296
- onChange: multiple ? (picked) => {
297
- picked.forEach(seed);
298
- onChange(picked.map((doc) => doc == null ? void 0 : doc.id).filter(Boolean));
299
- } : (doc) => {
300
- seed(doc);
301
- onChange((doc == null ? void 0 : doc.id) || null);
302
- },
303
- value: multiple ? filterRows(ids, docs) : docs[0] || null
304
- }
305
- }
306
- ),
307
- label,
308
- message
309
- }
310
- }
311
- )
312
- }
313
- }
314
- );
147
+ const stepReason = ({ entry, saved = [], type }) => {
148
+ var _a, _b;
149
+ return ((_a = ((entry == null ? void 0 : entry.steps) || []).find((step) => (step == null ? void 0 : step.value) === type && (step == null ? void 0 : step.reason))) == null ? void 0 : _a.reason) || ((_b = saved.find((step) => (step == null ? void 0 : step.type) === type && (step == null ? void 0 : step.reason))) == null ? void 0 : _b.reason) || null;
315
150
  };
316
151
  const stepRow = (step = {}, members = []) => {
317
152
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
318
153
  return {
154
+ // @story workflows/entry-confirmation
155
+ // The System email: no remove and no switch ( the api keeps it on ).
156
+ confirmation: Boolean(step.confirmation),
319
157
  connectionId: step.connectionId || "",
320
158
  discount: ((_a = step.settings) == null ? void 0 : _a.discount) || null,
159
+ // @story workflows/step-switch
160
+ // The step's own switch; absent reads on.
161
+ enabled: step.enabled !== false,
321
162
  // Stored as ids, picked as documents. Hydrating through the fetched list
322
163
  // also drops ids whose member no longer exists — a removed teammate
323
164
  // leaves their id on the step, and an id with nothing behind it would
@@ -346,119 +187,7 @@ const stepRow = (step = {}, members = []) => {
346
187
  url: ((_i = step.settings) == null ? void 0 : _i.url) || ""
347
188
  };
348
189
  };
349
- const FormOrganizationWorkflow = ({
350
- disabled,
351
- onClose,
352
- onError,
353
- onSuccess,
354
- values
355
- }) => {
356
- const { catalog, catalogList, triggerOptions } = useWorkflowCatalog(values == null ? void 0 : values.organization, values == null ? void 0 : values.triggerEvent);
357
- const { control, formState, getValues, handleSubmit, setValue } = (0, import_form.useForm)({
358
- defaultValues: {
359
- title: "",
360
- triggerEvent: (values == null ? void 0 : values.triggerEvent) || ""
361
- },
362
- resolver: (0, import_yup.resolver)(
363
- import_yup.default.object({
364
- title: import_yup.default.string().required().max(100).label("Title"),
365
- triggerEvent: import_yup.default.string().label("Trigger").required("A trigger is required")
366
- })
367
- )
368
- });
369
- const watchedTrigger = (0, import_form.useWatch)({
370
- control,
371
- name: "triggerEvent"
372
- });
373
- const onSubmit = async ({ title, triggerEvent }) => {
374
- const prefill = stepPrefills[values == null ? void 0 : values.step];
375
- const prefilledSteps = prefill ? [{
376
- settings: { ...prefill },
377
- type: values.step
378
- }] : [];
379
- try {
380
- const response = await (0, import_fetch.request)({
381
- body: {
382
- steps: prefilledSteps,
383
- title,
384
- trigger: {
385
- event: triggerEvent,
386
- filters: {
387
- // Both blank, meaning every campaign and every segment. The
388
- // create drawer asks for a trigger and a title only; narrowing
389
- // is done on the workflow page afterwards.
390
- campaigns: [],
391
- segment: null
392
- }
393
- }
394
- },
395
- endpoint: "/organization/" + (values == null ? void 0 : values.organization) + "/workflow",
396
- method: "POST"
397
- });
398
- onSuccess(response);
399
- onClose == null ? void 0 : onClose();
400
- } catch (error) {
401
- onError(error);
402
- }
403
- };
404
- if (catalog.isLoading) {
405
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_loader.LoaderDynamic, {});
406
- }
407
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
408
- import_form2.default,
409
- {
410
- ...{
411
- className: "relative w-full",
412
- onSubmit: handleSubmit(onSubmit)
413
- },
414
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
415
- import_fieldset.default,
416
- {
417
- ...{
418
- disabled: disabled || (formState == null ? void 0 : formState.isSubmitting)
419
- },
420
- children: [
421
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
422
- WorkflowTriggerField,
423
- {
424
- ...{
425
- control,
426
- formState,
427
- catalogList,
428
- triggerOptions,
429
- getValues,
430
- setValue
431
- }
432
- }
433
- ),
434
- watchedTrigger && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
435
- WorkflowTitleField,
436
- {
437
- ...{
438
- control,
439
- formState
440
- }
441
- }
442
- ),
443
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
444
- import_button.default,
445
- {
446
- ...{
447
- loading: formState == null ? void 0 : formState.isSubmitting,
448
- type: "submit"
449
- },
450
- children: "Create workflow"
451
- }
452
- )
453
- ]
454
- }
455
- )
456
- }
457
- );
458
- };
459
190
  const workflowSchema = import_yup.default.object({
460
- title: import_yup.default.string().required().max(100).label("Title"),
461
- triggerEvent: import_yup.default.string().label("Trigger").required("A trigger is required"),
462
191
  steps: import_yup.default.array().of(
463
192
  import_yup.default.object({
464
193
  type: import_yup.default.string().label("Step").required("A step is required"),
@@ -474,7 +203,13 @@ const workflowSchema = import_yup.default.object({
474
203
  }
475
204
  return schema;
476
205
  }),
477
- message: import_yup.default.string().when("type", ([type], schema) => {
206
+ // @story workflows/edit
207
+ // The editor writes an empty message as "<p></p>", which a plain
208
+ // required() accepts: a message needs words, not only markup.
209
+ message: import_yup.default.string().test("words", "Message is required", function(value) {
210
+ var _a;
211
+ return !messageSteps.includes((_a = this.parent) == null ? void 0 : _a.type) || Boolean(String(value || "").replace(/<[^>]*>/g, "").trim());
212
+ }).when("type", ([type], schema) => {
478
213
  if (type === "step.sms.send") {
479
214
  return schema.required("Message is required").max(1500).label("Message");
480
215
  }
@@ -498,21 +233,254 @@ const workflowSchema = import_yup.default.object({
498
233
  })
499
234
  )
500
235
  });
236
+ const samples = [
237
+ {
238
+ key: "New lead",
239
+ value: "lead"
240
+ },
241
+ {
242
+ key: "Verified their email",
243
+ value: "verified"
244
+ }
245
+ ];
246
+ const useEmailPreview = ({ campaign, confirmation = false, event, message, organization, sample, subject, text }) => {
247
+ const asked = JSON.stringify({ ...confirmation && { confirmation }, message, sample, subject, text });
248
+ const [settled, setSettled] = (0, import_react.useState)(asked);
249
+ (0, import_react.useEffect)(() => {
250
+ const timer = setTimeout(() => setSettled(asked), 400);
251
+ return () => clearTimeout(timer);
252
+ }, [asked]);
253
+ const preview = (0, import_react_query.useQuery)({
254
+ enabled: Boolean(organization && campaign && event),
255
+ placeholderData: import_react_query.keepPreviousData,
256
+ queryFn: async () => {
257
+ const { result } = await (0, import_fetch.request)({
258
+ body: JSON.parse(settled),
259
+ endpoint: "/organization/" + organization + "/campaign/" + campaign + "/workflow/" + event + "/preview",
260
+ method: "POST"
261
+ });
262
+ return result;
263
+ },
264
+ queryKey: ["workflow-email-preview", organization, campaign, event, settled]
265
+ });
266
+ return preview.data;
267
+ };
268
+ const EmailStepCard = ({
269
+ card,
270
+ children,
271
+ control,
272
+ off,
273
+ email: {
274
+ campaign,
275
+ confirmation,
276
+ event,
277
+ name,
278
+ organization
279
+ }
280
+ }) => {
281
+ const [sample, setSample] = (0, import_react.useState)(samples[0].value);
282
+ const [subject, message, text] = (0, import_form.useWatch)({
283
+ control,
284
+ name: [name + ".subject", name + ".message", name + ".text"]
285
+ });
286
+ const preview = useEmailPreview({ campaign, confirmation, event, message, organization, sample, subject, text });
287
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
288
+ import_card_section.default,
289
+ {
290
+ ...{
291
+ ...card,
292
+ columns: 2
293
+ },
294
+ children: [
295
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
296
+ "div",
297
+ {
298
+ ...{
299
+ className: "space-y-6"
300
+ },
301
+ children: [
302
+ children,
303
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
304
+ import_accordion.default,
305
+ {
306
+ ...{
307
+ className: "pt-6 border-t border-gray",
308
+ classNamePanel: "mt-6",
309
+ title: "Plain-text version"
310
+ },
311
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
312
+ "pre",
313
+ {
314
+ ...{
315
+ className: "p-4 rounded border border-gray bg-white text-sm whitespace-pre-wrap wrap-anywhere"
316
+ },
317
+ children: preview == null ? void 0 : preview.text
318
+ }
319
+ )
320
+ }
321
+ )
322
+ ]
323
+ }
324
+ ),
325
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
326
+ "div",
327
+ {
328
+ ...{
329
+ className: off ? "opacity-50" : ""
330
+ },
331
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
332
+ import_preview.default,
333
+ {
334
+ ...{
335
+ states: {
336
+ onChange: setSample,
337
+ options: samples,
338
+ value: sample
339
+ }
340
+ },
341
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
342
+ "iframe",
343
+ {
344
+ ...{
345
+ // The rendered email, as a mail app shows it.
346
+ className: "block w-full h-full border-0 bg-white",
347
+ srcDoc: (preview == null ? void 0 : preview.html) || "",
348
+ title: "Send email"
349
+ }
350
+ }
351
+ )
352
+ }
353
+ )
354
+ }
355
+ )
356
+ ]
357
+ }
358
+ );
359
+ };
360
+ const SAMPLE = {
361
+ email: "sam.rivera@example.com",
362
+ name: "Sam Rivera",
363
+ order: "House espresso \xD7 2, Holiday blend \xD7 1",
364
+ phone: "+14165550142"
365
+ };
366
+ const webhookSample = ({ campaign }) => JSON.stringify({
367
+ campaign: {
368
+ id: (campaign == null ? void 0 : campaign.id) || "cmp_sample",
369
+ title: (campaign == null ? void 0 : campaign.title) || "Your campaign"
370
+ },
371
+ email: SAMPLE.email,
372
+ id: "lead_sample",
373
+ name: SAMPLE.name,
374
+ phone: {
375
+ number: SAMPLE.phone
376
+ }
377
+ }, null, 2);
378
+ const teamSample = ({ campaign, event, organization }) => event === "order.insert" ? {
379
+ lines: ["New order for " + ((campaign == null ? void 0 : campaign.title) || "your campaign") + " at " + ((organization == null ? void 0 : organization.title) || "your organization") + ": " + SAMPLE.order + ".", "Estimated total $55.00.", "Pickup: Saturday, 9 am to noon.", "Note: Please grind the Holiday blend for a French press."],
380
+ title: "New order \u2014 " + ((campaign == null ? void 0 : campaign.title) || "your campaign")
381
+ } : {
382
+ lines: [SAMPLE.name + " (" + SAMPLE.email + ") entered " + ((campaign == null ? void 0 : campaign.title) || "your campaign") + "."],
383
+ title: "1 new entry \u2014 " + ((campaign == null ? void 0 : campaign.title) || "your campaign")
384
+ };
385
+ const StepPreview = ({ campaign, control, event, image, name, organization, type }) => {
386
+ const [message] = (0, import_form.useWatch)({
387
+ control,
388
+ name: [name + ".message"]
389
+ });
390
+ if (type === "step.sms.send") return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "p-6 font-sans", children: [
391
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "mb-4 text-xs text-center text-gray-dark", children: organization == null ? void 0 : organization.title }),
392
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "max-w-xs px-4 py-3 rounded-2xl rounded-bl-sm bg-gray-light text-black", children: [
393
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "whitespace-pre-wrap", children: message }),
394
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "mt-2", children: "Reply STOP to opt out" })
395
+ ] })
396
+ ] });
397
+ if (type === "step.webhook.send") return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "p-6 text-xs whitespace-pre-wrap break-all font-mono", children: "X-Drawbridge-Signature: t=\u2026,v1=\u2026\n\n" + webhookSample({ campaign }) });
398
+ if (teamSteps.includes(type)) {
399
+ const { lines, title } = teamSample({ campaign, event, organization });
400
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "p-6 space-y-3 font-sans", children: [
401
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-lg font-bold", children: title }),
402
+ lines.map((line) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: line }, line))
403
+ ] });
404
+ }
405
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "min-h-screen flex flex-col items-center justify-center gap-3 p-6 text-gray-dark", children: [
406
+ image && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
407
+ import_image.default,
408
+ {
409
+ ...{
410
+ alt: "",
411
+ className: "w-12 h-12 object-contain",
412
+ height: 48,
413
+ src: image,
414
+ unoptimized: true,
415
+ width: 48
416
+ }
417
+ }
418
+ ),
419
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "No preview available" })
420
+ ] });
421
+ };
422
+ const StepCard = ({
423
+ children,
424
+ control,
425
+ email,
426
+ off,
427
+ preview,
428
+ ...card
429
+ }) => email ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
430
+ EmailStepCard,
431
+ {
432
+ ...{
433
+ card,
434
+ control,
435
+ email,
436
+ off
437
+ },
438
+ children
439
+ }
440
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
441
+ import_card_section.default,
442
+ {
443
+ ...{
444
+ ...card,
445
+ columns: preview ? 2 : 1
446
+ },
447
+ children: [
448
+ children,
449
+ preview && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
450
+ "div",
451
+ {
452
+ ...{
453
+ className: off ? "opacity-50" : ""
454
+ },
455
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_preview.default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
456
+ StepPreview,
457
+ {
458
+ ...{
459
+ control,
460
+ ...preview
461
+ }
462
+ }
463
+ ) })
464
+ }
465
+ )
466
+ ]
467
+ }
468
+ );
501
469
  const FormOrganizationWorkflowEdit = ({
470
+ catalog,
502
471
  disabled,
503
- onClose,
504
472
  onError,
505
473
  onSuccess,
506
474
  values
507
475
  }) => {
508
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
509
- const { catalog, catalogList, triggerOptions } = useWorkflowCatalog(values == null ? void 0 : values.organization, (_a = values == null ? void 0 : values.trigger) == null ? void 0 : _a.event);
476
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
477
+ const event = (_a = values == null ? void 0 : values.trigger) == null ? void 0 : _a.event;
510
478
  const { items: memberItems, loading: membersLoading } = useOrganizationMembers(values == null ? void 0 : values.organization);
511
479
  const queryClient = (0, import_react_query.useQueryClient)();
512
480
  const organizationData = queryClient.getQueryData(["organization", values == null ? void 0 : values.organization]);
513
481
  const ownerEmail = organizationData.owner.email;
514
482
  const smsActive = (0, import_sms.smsNumberActive)(organizationData);
515
- const commerceConnectionId = ((_b = catalogList.flatMap((item) => item.steps || []).find(
483
+ const commerceConnectionId = ((_b = ((catalog == null ? void 0 : catalog.steps) || []).find(
516
484
  (s) => s.value === "step.commerce.customer.insert" || s.value === "step.commerce.code.issue"
517
485
  )) == null ? void 0 : _b.connectionId) || null;
518
486
  const commerceConnection = (0, import_react_query.useQuery)({
@@ -538,38 +506,29 @@ const FormOrganizationWorkflowEdit = ({
538
506
  );
539
507
  const { control, formState, getValues, handleSubmit, setValue } = (0, import_form.useForm)({
540
508
  values: {
541
- steps: defaultSteps,
542
- filterCampaigns: campaignFilterIds((_g = values == null ? void 0 : values.trigger) == null ? void 0 : _g.filters),
543
- // Stored and returned as a plain id — extend.workflow() $lookup-hydrates
544
- // only the campaign — but read through the same reducer, so the field
545
- // stays right if the segment is ever hydrated too.
546
- filterSegment: campaignFilterId((_i = (_h = values == null ? void 0 : values.trigger) == null ? void 0 : _h.filters) == null ? void 0 : _i.segment),
547
- title: (values == null ? void 0 : values.title) || "",
548
- triggerEvent: ((_j = values == null ? void 0 : values.trigger) == null ? void 0 : _j.event) || ""
509
+ steps: defaultSteps
549
510
  },
550
511
  resolver: (0, import_yup.resolver)(workflowSchema)
551
512
  });
552
- const watchedTrigger = (0, import_form.useWatch)({
553
- control,
554
- name: "triggerEvent"
555
- });
556
513
  const watchedSteps = (0, import_form.useWatch)({
557
514
  control,
558
515
  name: "steps"
559
516
  });
560
- const issueIndex = ((_k = values == null ? void 0 : values.issue) == null ? void 0 : _k.step) ? (watchedSteps || []).findIndex((step) => (step == null ? void 0 : step.type) === values.issue.step) : -1;
561
- const selectedTriggerEntry = catalogList.find((item) => item.trigger === watchedTrigger) || null;
562
- const getAvailableVariables = (index) => {
563
- return watchedSteps.slice(0, index).flatMap((watchedStep) => {
564
- const stepDef = ((selectedTriggerEntry == null ? void 0 : selectedTriggerEntry.steps) || []).find((s) => s.value === watchedStep.type);
565
- return (stepDef == null ? void 0 : stepDef.returns) || [];
566
- });
567
- };
517
+ const issueIndex = ((_g = values == null ? void 0 : values.issue) == null ? void 0 : _g.step) ? (watchedSteps || []).findIndex((step) => (step == null ? void 0 : step.type) === values.issue.step) : -1;
518
+ const getAvailableVariables = (index) => stepVariables(catalog, watchedSteps, index);
519
+ const loading = membersLoading || commerceConnection.isLoading;
520
+ const prefilled = (0, import_react.useRef)(false);
521
+ (0, import_react.useEffect)(() => {
522
+ if (loading || disabled || prefilled.current) return;
523
+ prefilled.current = true;
524
+ const row = prefillRow({ entry: catalog, step: values == null ? void 0 : values.step, steps: getValues("steps") });
525
+ if (row) setValue("steps", [...getValues("steps"), row], { shouldDirty: true });
526
+ }, [catalog, disabled, getValues, loading, setValue, values == null ? void 0 : values.step]);
568
527
  const getStepOptions = (index) => {
569
528
  const usedTypes = watchedSteps.map((s, i) => i !== index ? s.type : null).filter(Boolean);
570
529
  return [
571
530
  { key: "Select a step", value: "" },
572
- ...((selectedTriggerEntry == null ? void 0 : selectedTriggerEntry.steps) || []).filter((step) => !usedTypes.includes(step.value)).filter((step) => {
531
+ ...((catalog == null ? void 0 : catalog.steps) || []).filter((step) => !usedTypes.includes(step.value)).filter((step) => {
573
532
  var _a2;
574
533
  return !step.ownerOnly || step.value === ((_a2 = watchedSteps[index]) == null ? void 0 : _a2.type);
575
534
  }).sort((a, b) => String(a.key).localeCompare(String(b.key))).map((step) => ({
@@ -586,7 +545,7 @@ const FormOrganizationWorkflowEdit = ({
586
545
  // connectionless and sendgrid is gone — but the rule is about any
587
546
  // two entries sharing a type, so it stays.
588
547
  value: step.connectionId ? step.value + "::" + step.connectionId : step.slug ? step.value + "::" + step.slug : step.value,
589
- ...step.disabled ? {
548
+ ...step.disabled && !step.reason ? {
590
549
  badge: {
591
550
  text: "Enable connection"
592
551
  },
@@ -594,8 +553,7 @@ const FormOrganizationWorkflowEdit = ({
594
553
  element: import_link.default,
595
554
  key: step == null ? void 0 : step.key,
596
555
  props: {
597
- href: "/organizations/" + (values == null ? void 0 : values.organization) + "/connections/" + step.slug,
598
- onClick: onClose
556
+ href: "/organizations/" + (values == null ? void 0 : values.organization) + "/connections/" + step.slug
599
557
  }
600
558
  } : {},
601
559
  // The same link-shaped option, greyed: it cannot be picked, and
@@ -610,14 +568,29 @@ const FormOrganizationWorkflowEdit = ({
610
568
  key: step == null ? void 0 : step.key,
611
569
  props: {
612
570
  "aria-disabled": true,
613
- href: "/organizations/" + (values == null ? void 0 : values.organization) + "/settings",
614
- onClick: onClose
571
+ href: "/organizations/" + (values == null ? void 0 : values.organization) + "/settings"
572
+ }
573
+ } : {},
574
+ // @story workflows/edit
575
+ // A step the form cannot feed: greyed with its reason, and a
576
+ // click opens the campaign's Form page, where the field is added.
577
+ ...step.reason ? {
578
+ badge: {
579
+ text: step.reason
580
+ },
581
+ className: "opacity-50",
582
+ disabled: false,
583
+ element: import_link.default,
584
+ key: step == null ? void 0 : step.key,
585
+ props: {
586
+ "aria-disabled": true,
587
+ href: "/organizations/" + (values == null ? void 0 : values.organization) + "/campaigns/" + (values == null ? void 0 : values.campaign) + "/form"
615
588
  }
616
589
  } : {}
617
590
  }))
618
591
  ];
619
592
  };
620
- const lockedStep = (index) => ((selectedTriggerEntry == null ? void 0 : selectedTriggerEntry.steps) || []).some((s) => {
593
+ const lockedStep = (index) => ((catalog == null ? void 0 : catalog.steps) || []).some((s) => {
621
594
  var _a2;
622
595
  return s.ownerOnly && s.value === ((_a2 = watchedSteps[index]) == null ? void 0 : _a2.type);
623
596
  });
@@ -631,7 +604,7 @@ const FormOrganizationWorkflowEdit = ({
631
604
  return match ? match.value : "";
632
605
  };
633
606
  const getStepConnection = (field) => {
634
- const steps = (selectedTriggerEntry == null ? void 0 : selectedTriggerEntry.steps) || [];
607
+ const steps = (catalog == null ? void 0 : catalog.steps) || [];
635
608
  const def = field.connectionId && steps.find((s) => s.connectionId === field.connectionId) || field.slug && steps.find((s) => s.slug === field.slug && s.value === field.type) || steps.find((s) => s.value === field.type);
636
609
  if (!def) return null;
637
610
  const connected = Boolean(def.connectionId);
@@ -644,6 +617,19 @@ const FormOrganizationWorkflowEdit = ({
644
617
  };
645
618
  };
646
619
  const renderStepBadge = (field) => {
620
+ const reason = stepReason({ entry: catalog, saved: values == null ? void 0 : values.steps, type: field == null ? void 0 : field.type });
621
+ if (reason) {
622
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
623
+ import_badge.default,
624
+ {
625
+ ...{
626
+ size: "small",
627
+ type: "error"
628
+ },
629
+ children: reason
630
+ }
631
+ );
632
+ }
647
633
  const conn = getStepConnection(field);
648
634
  if (!conn) return null;
649
635
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -658,15 +644,11 @@ const FormOrganizationWorkflowEdit = ({
658
644
  );
659
645
  };
660
646
  const onSubmit = async ({
661
- steps,
662
- filterCampaigns,
663
- filterSegment,
664
- title,
665
- triggerEvent
647
+ steps
666
648
  }) => {
667
649
  try {
668
650
  const body = {
669
- steps: steps.map(({ connectionId, discount, members, message, score, slug, subject, text, type, url }, index) => {
651
+ steps: steps.map(({ confirmation, connectionId, discount, enabled, members, message, score, slug, subject, text, type, url }, index) => {
670
652
  const settings = {};
671
653
  if (type === "step.webhook.send") settings.url = url;
672
654
  if (emailSteps.includes(type)) settings.subject = subject;
@@ -678,29 +660,24 @@ const FormOrganizationWorkflowEdit = ({
678
660
  }
679
661
  if (teamSteps.includes(type)) settings.members = (members || []).map((member) => member == null ? void 0 : member.id).filter(Boolean);
680
662
  if (type === "step.commerce.code.issue") settings.discount = discount;
681
- const catalogSteps = (selectedTriggerEntry == null ? void 0 : selectedTriggerEntry.steps) || [];
663
+ const catalogSteps = (catalog == null ? void 0 : catalog.steps) || [];
682
664
  const catalogStep = connectionId && catalogSteps.find((s) => s.connectionId === connectionId) || slug && catalogSteps.find((s) => s.slug === slug && s.value === type) || catalogSteps.find((s) => s.value === type);
683
665
  const resolvedConnectionId = (catalogStep == null ? void 0 : catalogStep.connectionId) || connectionId || null;
684
666
  const resolvedSlug = (catalogStep == null ? void 0 : catalogStep.slug) || slug || null;
685
667
  return {
668
+ // The System email row names itself; the api keeps it only where it was.
669
+ ...confirmation && { confirmation: true },
686
670
  ...resolvedConnectionId && { connectionId: resolvedConnectionId },
671
+ enabled: enabled !== false,
687
672
  ...resolvedSlug && { slug: resolvedSlug },
688
673
  settings,
689
674
  type
690
675
  };
691
- }),
692
- title,
693
- trigger: {
694
- event: triggerEvent,
695
- filters: {
696
- campaigns: filterCampaigns || [],
697
- segment: filterSegment || null
698
- }
699
- }
676
+ })
700
677
  };
701
678
  const response = await (0, import_fetch.request)({
702
679
  body,
703
- endpoint: "/organization/" + (values == null ? void 0 : values.organization) + "/workflow/" + values.id,
680
+ endpoint: "/organization/" + (values == null ? void 0 : values.organization) + "/campaign/" + (values == null ? void 0 : values.campaign) + "/workflow/" + event,
704
681
  method: "PUT"
705
682
  });
706
683
  onSuccess(response);
@@ -708,7 +685,7 @@ const FormOrganizationWorkflowEdit = ({
708
685
  onError(error);
709
686
  }
710
687
  };
711
- if (catalog.isLoading || membersLoading || commerceConnection.isLoading) {
688
+ if (loading) {
712
689
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_loader.LoaderDynamic, {});
713
690
  }
714
691
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -735,65 +712,32 @@ const FormOrganizationWorkflowEdit = ({
735
712
  }
736
713
  }
737
714
  ),
738
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
739
- WorkflowTriggerField,
740
- {
741
- ...{
742
- control,
743
- formState,
744
- catalogList,
745
- triggerOptions,
746
- getValues,
747
- setValue
748
- }
749
- }
750
- ),
751
- watchedTrigger && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
752
- WorkflowTitleField,
753
- {
754
- ...{
755
- control,
756
- formState
757
- }
758
- }
759
- ),
760
- watchedTrigger === "lead.insert" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
761
- WorkflowFilterField,
715
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
716
+ import_card_section.default,
762
717
  {
763
718
  ...{
764
- collection: "campaigns",
765
- control,
766
- label: "Campaigns",
767
- message: "Only runs for leads from the campaigns you add. With none added, it runs for every campaign.",
768
- model: "campaign",
769
- multiple: true,
770
- name: "filterCampaigns",
771
- organization: values == null ? void 0 : values.organization,
772
- resource: "campaign",
773
- seeds: (_m = (_l = values == null ? void 0 : values.trigger) == null ? void 0 : _l.filters) == null ? void 0 : _m.campaigns
774
- }
775
- }
776
- ),
777
- watchedTrigger === "segment.contact.add" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
778
- WorkflowFilterField,
779
- {
780
- ...{
781
- collection: "segments",
782
- control,
783
- label: "Segment",
784
- message: "Only trigger when a contact joins a specific segment. Leaving blank will trigger for all segments.",
785
- model: "segment",
786
- name: "filterSegment",
787
- organization: values == null ? void 0 : values.organization,
788
- resource: "segment"
789
- }
719
+ "data-trigger": true,
720
+ title: "Trigger"
721
+ },
722
+ children: [
723
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: values == null ? void 0 : values.title }),
724
+ (values == null ? void 0 : values.description) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
725
+ "p",
726
+ {
727
+ ...{
728
+ className: "text-sm text-gray-dark"
729
+ },
730
+ children: values.description
731
+ }
732
+ )
733
+ ]
790
734
  }
791
735
  ),
792
736
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
793
737
  import_input_group.default,
794
738
  {
795
739
  ...{
796
- error: (_o = (_n = formState == null ? void 0 : formState.errors) == null ? void 0 : _n.steps) == null ? void 0 : _o.message,
740
+ error: (_i = (_h = formState == null ? void 0 : formState.errors) == null ? void 0 : _h.steps) == null ? void 0 : _i.message,
797
741
  input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
798
742
  import_input_array.InputArraySortable,
799
743
  {
@@ -805,7 +749,6 @@ const FormOrganizationWorkflowEdit = ({
805
749
  import_input_array.InputArrayButton,
806
750
  {
807
751
  ...{
808
- disabled: !watchedTrigger,
809
752
  onClick: () => append(stepRow()),
810
753
  text: "Add step"
811
754
  }
@@ -813,319 +756,397 @@ const FormOrganizationWorkflowEdit = ({
813
756
  )
814
757
  },
815
758
  children: ({ field, handle, index, remove }) => {
759
+ var _a2;
816
760
  const step = (watchedSteps == null ? void 0 : watchedSteps[index]) || field;
817
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
818
- "div",
819
- {
820
- ...{
821
- className: "w-full bg-white border border-gray rounded p-4 space-y-3"
822
- },
823
- children: [
824
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
825
- "div",
826
- {
827
- ...{
828
- className: "flex items-center justify-between"
829
- },
830
- children: [
831
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
832
- "div",
833
- {
834
- ...{
835
- className: "flex items-center space-x-2"
761
+ return (
762
+ // @story workflows/edit
763
+ // EACH STEP IS ITS OWN CARD in the flow under the Trigger card,
764
+ // edited in place: the drag handle left of Step N, as every
765
+ // sortable list has it, then its connection badge and Remove
766
+ // in the card's head, its fields in the body.
767
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
768
+ StepCard,
769
+ {
770
+ ...{
771
+ control,
772
+ // @story workflows/send-email
773
+ // A Send email step shows its email beside its form.
774
+ off: step.enabled === false,
775
+ // Every other step with a type has its preview too.
776
+ preview: step.type && !emailSteps.includes(step.type) && {
777
+ campaign: queryClient.getQueryData(["campaign", values == null ? void 0 : values.campaign]),
778
+ event,
779
+ image: ((_a2 = ((catalog == null ? void 0 : catalog.steps) || []).find((entry) => entry.value === step.type)) == null ? void 0 : _a2.image) || null,
780
+ name: `steps.${index}`,
781
+ organization: organizationData,
782
+ type: step.type
783
+ },
784
+ email: emailSteps.includes(step.type) && {
785
+ campaign: values == null ? void 0 : values.campaign,
786
+ confirmation: step.confirmation,
787
+ event,
788
+ name: `steps.${index}`,
789
+ organization: values == null ? void 0 : values.organization
790
+ },
791
+ cta: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
792
+ "span",
793
+ {
794
+ ...{
795
+ className: "flex items-center gap-2"
796
+ },
797
+ children: [
798
+ renderStepBadge(step),
799
+ !lockedStep(index) && !step.confirmation && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
800
+ import_input_array.InputArrayControl,
801
+ {
802
+ ...{
803
+ onClick: () => remove(index),
804
+ icon: import_trash.default
805
+ }
836
806
  },
837
- children: [
838
- handle,
839
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
807
+ "remove"
808
+ ),
809
+ step.confirmation ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
810
+ import_tooltip.default,
811
+ {
812
+ ...{
813
+ content: "System email"
814
+ },
815
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
840
816
  "span",
841
817
  {
842
818
  ...{
843
- className: "text-sm font-medium"
819
+ className: "inline-flex pointer-events-none"
844
820
  },
845
- children: [
846
- "Step ",
847
- index + 1
848
- ]
821
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
822
+ import_input_switch.default,
823
+ {
824
+ ...{
825
+ "aria-label": "System email, always on",
826
+ disabled: true,
827
+ onChange: () => {
828
+ },
829
+ small: true,
830
+ value: true
831
+ }
832
+ }
833
+ )
849
834
  }
850
835
  )
851
- ]
836
+ }
837
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
838
+ import_form.Controller,
839
+ {
840
+ ...{
841
+ control,
842
+ name: `steps.${index}.enabled`,
843
+ render: ({ field: { onChange, value } }) => {
844
+ var _a3;
845
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
846
+ import_input_switch.default,
847
+ {
848
+ ...{
849
+ "aria-label": ((_a3 = ((catalog == null ? void 0 : catalog.steps) || []).find((entry) => entry.value === step.type)) == null ? void 0 : _a3.key) || "Step " + (index + 1),
850
+ disabled: disabled || (formState == null ? void 0 : formState.isSubmitting),
851
+ onChange,
852
+ small: true,
853
+ value: value !== false
854
+ }
855
+ }
856
+ );
857
+ }
858
+ }
859
+ }
860
+ )
861
+ ]
862
+ }
863
+ ),
864
+ "data-step": index + 1,
865
+ title: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
866
+ "span",
867
+ {
868
+ ...{
869
+ className: "flex items-center gap-2"
870
+ },
871
+ children: [
872
+ handle,
873
+ "Step " + (index + 1)
874
+ ]
875
+ }
876
+ )
877
+ },
878
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
879
+ "div",
880
+ {
881
+ ...{
882
+ // A step switched off is greyed; its settings are kept.
883
+ className: "space-y-3" + (step.enabled === false ? " opacity-50" : "")
884
+ },
885
+ children: [
886
+ issueIndex === index && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
887
+ import_error.default,
888
+ {
889
+ ...{
890
+ error: values.issue.message
891
+ }
852
892
  }
853
893
  ),
854
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
855
- "div",
894
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
895
+ import_form.Controller,
856
896
  {
857
897
  ...{
858
- className: "flex items-center space-x-2"
859
- },
860
- children: [
861
- renderStepBadge(step),
862
- !lockedStep(index) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
863
- import_input_array.InputArrayControl,
864
- {
865
- ...{
866
- onClick: () => remove(index),
867
- icon: import_trash.default
868
- }
869
- },
870
- "remove"
871
- )
872
- ]
873
- }
874
- )
875
- ]
876
- }
877
- ),
878
- issueIndex === index && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
879
- import_error.default,
880
- {
881
- ...{
882
- error: values.issue.message
883
- }
884
- }
885
- ),
886
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
887
- import_form.Controller,
888
- {
889
- ...{
890
- control,
891
- name: `steps.${index}.type`,
892
- render: ({ field: { onChange } }) => {
893
- var _a2, _b2, _c2, _d2;
894
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
895
- import_input_group.default,
896
- {
897
- ...{
898
- error: (_d2 = (_c2 = (_b2 = (_a2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a2.steps) == null ? void 0 : _b2[index]) == null ? void 0 : _c2.type) == null ? void 0 : _d2.message,
899
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
900
- import_input_combobox.default,
898
+ control,
899
+ name: `steps.${index}.type`,
900
+ render: ({ field: { onChange } }) => {
901
+ var _a3, _b2, _c2, _d2;
902
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
903
+ import_input_group.default,
901
904
  {
902
905
  ...{
903
- onChange: (val) => {
904
- const [type] = val.split("::");
905
- const option = getStepOptions(index).find((o) => o.value === val);
906
- onChange(type);
907
- setValue(`steps.${index}.connectionId`, (option == null ? void 0 : option.connectionId) || "");
908
- setValue(`steps.${index}.slug`, (option == null ? void 0 : option.slug) || "");
909
- },
910
- disabled: lockedStep(index),
911
- options: getStepOptions(index),
912
- // Resolved from the WHOLE ROW, not from this path: the
913
- // option value carries a connection the type alone cannot
914
- // name.
915
- value: getStepValue(step, index)
906
+ error: (_d2 = (_c2 = (_b2 = (_a3 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a3.steps) == null ? void 0 : _b2[index]) == null ? void 0 : _c2.type) == null ? void 0 : _d2.message,
907
+ input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
908
+ import_input_combobox.default,
909
+ {
910
+ ...{
911
+ onChange: (val) => {
912
+ const [type] = val.split("::");
913
+ const option = getStepOptions(index).find((o) => o.value === val);
914
+ onChange(type);
915
+ setValue(`steps.${index}.connectionId`, (option == null ? void 0 : option.connectionId) || "");
916
+ setValue(`steps.${index}.slug`, (option == null ? void 0 : option.slug) || "");
917
+ },
918
+ // The System email is always a Send email.
919
+ disabled: lockedStep(index) || Boolean(step.confirmation),
920
+ options: getStepOptions(index),
921
+ // Resolved from the WHOLE ROW, not from this path: the
922
+ // option value carries a connection the type alone cannot
923
+ // name.
924
+ value: getStepValue(step, index)
925
+ }
926
+ }
927
+ ),
928
+ label: "Step"
916
929
  }
917
930
  }
918
- ),
919
- label: "Step"
931
+ );
920
932
  }
921
933
  }
922
- );
923
- }
924
- }
925
- }
926
- ),
927
- step.type === "step.webhook.send" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
928
- import_form.Controller,
929
- {
930
- ...{
931
- control,
932
- name: `steps.${index}.url`,
933
- render: ({ field: { value, onChange } }) => {
934
- var _a2, _b2, _c2, _d2;
935
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
936
- import_input_group.default,
937
- {
938
- ...{
939
- error: (_d2 = (_c2 = (_b2 = (_a2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a2.steps) == null ? void 0 : _b2[index]) == null ? void 0 : _c2.url) == null ? void 0 : _d2.message,
940
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
941
- import_input_url.default,
934
+ }
935
+ ),
936
+ step.type === "step.webhook.send" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
937
+ import_form.Controller,
938
+ {
939
+ ...{
940
+ control,
941
+ name: `steps.${index}.url`,
942
+ render: ({ field: { value, onChange } }) => {
943
+ var _a3, _b2, _c2, _d2;
944
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
945
+ import_input_group.default,
942
946
  {
943
947
  ...{
944
- onChange,
945
- value: value || ""
948
+ error: (_d2 = (_c2 = (_b2 = (_a3 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a3.steps) == null ? void 0 : _b2[index]) == null ? void 0 : _c2.url) == null ? void 0 : _d2.message,
949
+ input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
950
+ import_input_url.default,
951
+ {
952
+ ...{
953
+ onChange,
954
+ value: value || ""
955
+ }
956
+ }
957
+ ),
958
+ label: "Webhook URL"
946
959
  }
947
960
  }
948
- ),
949
- label: "Webhook URL"
961
+ );
950
962
  }
951
963
  }
952
- );
953
- }
954
- }
955
- }
956
- ),
957
- teamSteps.includes(step.type) && lockedStep(index) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-sm text-gray-500", children: "Recipients are chosen by the organization owner." }),
958
- teamSteps.includes(step.type) && !lockedStep(index) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
959
- import_form.Controller,
960
- {
961
- ...{
962
- control,
963
- name: `steps.${index}.members`,
964
- render: ({ field: { value, onChange } }) => {
965
- var _a2, _b2, _c2, _d2;
966
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
967
- import_input_group.default,
968
- {
969
- ...{
970
- error: (_d2 = (_c2 = (_b2 = (_a2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a2.steps) == null ? void 0 : _b2[index]) == null ? void 0 : _c2.members) == null ? void 0 : _d2.message,
971
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
972
- import_input_resource.default,
964
+ }
965
+ ),
966
+ teamSteps.includes(step.type) && lockedStep(index) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-sm text-gray-500", children: "Recipients are chosen by the organization owner." }),
967
+ teamSteps.includes(step.type) && !lockedStep(index) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
968
+ import_form.Controller,
969
+ {
970
+ ...{
971
+ control,
972
+ name: `steps.${index}.members`,
973
+ render: ({ field: { value, onChange } }) => {
974
+ var _a3, _b2, _c2, _d2;
975
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
976
+ import_input_group.default,
973
977
  {
974
978
  ...{
975
- empty: "No members to add",
976
- endpoint: "/organization/" + (values == null ? void 0 : values.organization) + "/members",
977
- // The owner is a chip like the others, only it cannot be
978
- // removed: they are always a recipient and it is resolved
979
- // in sync. Shaped like a member so `render` labels it the
980
- // same way.
981
- fixed: [{ email: ownerEmail }],
982
- model: "member",
983
- multiple: true,
984
- onChange,
985
- params: memberParams,
986
- render: memberLabel,
987
- // The row shows the name ( memberLabel ), so the search has
988
- // to hit the name too. The members endpoint joins `user`
989
- // before its search stage, so the nested keys resolve.
990
- // Email stays for invitees who have not registered yet.
991
- // ponytail: a full "First Last" query matches neither key;
992
- // a $concat'd name on the API side if that comes up.
993
- searchKeys: ["email", "user.firstName", "user.lastName"],
994
- value: value || []
979
+ error: (_d2 = (_c2 = (_b2 = (_a3 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a3.steps) == null ? void 0 : _b2[index]) == null ? void 0 : _c2.members) == null ? void 0 : _d2.message,
980
+ input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
981
+ import_input_resource.default,
982
+ {
983
+ ...{
984
+ empty: "No members to add",
985
+ endpoint: "/organization/" + (values == null ? void 0 : values.organization) + "/members",
986
+ // The owner is a chip like the others, only it cannot be
987
+ // removed: they are always a recipient and it is resolved
988
+ // in sync. Shaped like a member so `render` labels it the
989
+ // same way.
990
+ fixed: [{ email: ownerEmail }],
991
+ model: "member",
992
+ multiple: true,
993
+ onChange,
994
+ params: memberParams,
995
+ render: memberLabel,
996
+ // The row shows the name ( memberLabel ), so the search has
997
+ // to hit the name too. The members endpoint joins `user`
998
+ // before its search stage, so the nested keys resolve.
999
+ // Email stays for invitees who have not registered yet.
1000
+ // ponytail: a full "First Last" query matches neither key;
1001
+ // a $concat'd name on the API side if that comes up.
1002
+ searchKeys: ["email", "user.firstName", "user.lastName"],
1003
+ value: value || []
1004
+ }
1005
+ }
1006
+ ),
1007
+ label: "Recipients"
995
1008
  }
996
1009
  }
997
- ),
998
- label: "Recipients"
1010
+ );
999
1011
  }
1000
1012
  }
1001
- );
1002
- }
1003
- }
1004
- }
1005
- ),
1006
- emailSteps.includes(step.type) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1007
- import_form_notification.FormNotification,
1008
- {
1009
- ...{
1010
- control,
1011
- // As the Fieldset above: the Message editor is a
1012
- // contenteditable, which a disabled fieldset never reaches.
1013
- disabled: disabled || (formState == null ? void 0 : formState.isSubmitting),
1014
- formState,
1015
- onChecking,
1016
- setValue,
1017
- values: {
1018
- id: field.id,
1019
- name: `steps.${index}`,
1020
- organization: values == null ? void 0 : values.organization,
1021
- variables: getAvailableVariables(index)
1022
- }
1023
- }
1024
- }
1025
- ),
1026
- step.type === "step.sms.send" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1027
- import_form.Controller,
1028
- {
1029
- ...{
1030
- control,
1031
- name: `steps.${index}.message`,
1032
- render: ({ field: { value, onChange } }) => {
1033
- var _a2, _b2, _c2, _d2;
1034
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1035
- import_input_group.default,
1036
- {
1037
- ...{
1038
- error: (_d2 = (_c2 = (_b2 = (_a2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a2.steps) == null ? void 0 : _b2[index]) == null ? void 0 : _c2.message) == null ? void 0 : _d2.message,
1039
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1040
- import_input_textarea.default,
1013
+ }
1014
+ ),
1015
+ emailSteps.includes(step.type) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1016
+ import_form_notification.FormNotification,
1017
+ {
1018
+ ...{
1019
+ control,
1020
+ // As the Fieldset above: the Message editor is a
1021
+ // contenteditable, which a disabled fieldset never reaches.
1022
+ disabled: disabled || (formState == null ? void 0 : formState.isSubmitting),
1023
+ formState,
1024
+ onChecking,
1025
+ setValue,
1026
+ values: {
1027
+ id: field.id,
1028
+ name: `steps.${index}`,
1029
+ organization: values == null ? void 0 : values.organization,
1030
+ variables: getAvailableVariables(index)
1031
+ }
1032
+ }
1033
+ }
1034
+ ),
1035
+ step.confirmation && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1036
+ "p",
1037
+ {
1038
+ ...{
1039
+ className: "text-sm text-gray-dark"
1040
+ },
1041
+ children: "Drawbridge adds the entrant's order and missions under your message. You can't edit or remove them."
1042
+ }
1043
+ ),
1044
+ step.type === "step.sms.send" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1045
+ import_form.Controller,
1046
+ {
1047
+ ...{
1048
+ control,
1049
+ name: `steps.${index}.message`,
1050
+ render: ({ field: { value, onChange } }) => {
1051
+ var _a3, _b2, _c2, _d2;
1052
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1053
+ import_input_group.default,
1041
1054
  {
1042
1055
  ...{
1043
- onChange,
1044
- rows: 3,
1045
- value: value || ""
1056
+ error: (_d2 = (_c2 = (_b2 = (_a3 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a3.steps) == null ? void 0 : _b2[index]) == null ? void 0 : _c2.message) == null ? void 0 : _d2.message,
1057
+ input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1058
+ import_input_textarea.default,
1059
+ {
1060
+ ...{
1061
+ onChange,
1062
+ rows: 3,
1063
+ value: value || ""
1064
+ }
1065
+ }
1066
+ ),
1067
+ label: "Message"
1046
1068
  }
1047
1069
  }
1048
- ),
1049
- label: "Message"
1070
+ );
1050
1071
  }
1051
1072
  }
1052
- );
1053
- }
1054
- }
1055
- }
1056
- ),
1057
- step.type === "step.commerce.code.issue" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1058
- import_form.Controller,
1059
- {
1060
- ...{
1061
- control,
1062
- name: `steps.${index}.discount`,
1063
- render: ({ field: { value, onChange } }) => {
1064
- var _a2, _b2, _c2, _d2;
1065
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1066
- import_input_group.default,
1067
- {
1068
- ...{
1069
- error: (_d2 = (_c2 = (_b2 = (_a2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a2.steps) == null ? void 0 : _b2[index]) == null ? void 0 : _c2.discount) == null ? void 0 : _d2.message,
1070
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1071
- import_input_resource.default,
1073
+ }
1074
+ ),
1075
+ step.type === "step.commerce.code.issue" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1076
+ import_form.Controller,
1077
+ {
1078
+ ...{
1079
+ control,
1080
+ name: `steps.${index}.discount`,
1081
+ render: ({ field: { value, onChange } }) => {
1082
+ var _a3, _b2, _c2, _d2;
1083
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1084
+ import_input_group.default,
1072
1085
  {
1073
1086
  ...{
1074
- endpoint: "/organization/" + (values == null ? void 0 : values.organization) + "/connection/" + commerceConnectionId + "/hook/browse.promotions",
1075
- model: "discount",
1076
- onChange,
1077
- // A DISCOUNT THE STORE CANNOT BACK IS SHOWN AND EXPLAINED, never
1078
- // filtered out. The merchant can see it in Shopify admin, so a row
1079
- // missing here with no reason reads as our bug rather than their
1080
- // setting — and the reason names the fix.
1081
- render: (item) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
1082
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: (item == null ? void 0 : item.blocked) ? "text-gray-dark" : void 0, children: item == null ? void 0 : item.title }),
1083
- ((item == null ? void 0 : item.blocked) || (item == null ? void 0 : item.warning)) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "block text-sm text-gray-dark", children: item.blocked || item.warning })
1084
- ] }),
1085
- renderButton: ({ button, item }) => (
1086
- // The list's small inline Add, unless the list says otherwise.
1087
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1088
- import_button.default,
1089
- {
1090
- ...{
1091
- inline: true,
1092
- size: "small",
1093
- ...button.props,
1094
- disabled: Boolean(item == null ? void 0 : item.blocked),
1095
- title: (item == null ? void 0 : item.blocked) || void 0
1096
- },
1097
- children: button.text
1087
+ error: (_d2 = (_c2 = (_b2 = (_a3 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a3.steps) == null ? void 0 : _b2[index]) == null ? void 0 : _c2.discount) == null ? void 0 : _d2.message,
1088
+ input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1089
+ import_input_resource.default,
1090
+ {
1091
+ ...{
1092
+ endpoint: "/organization/" + (values == null ? void 0 : values.organization) + "/connection/" + commerceConnectionId + "/hook/browse.promotions",
1093
+ model: "discount",
1094
+ onChange,
1095
+ // A DISCOUNT THE STORE CANNOT BACK IS SHOWN AND EXPLAINED, never
1096
+ // filtered out. The merchant can see it in Shopify admin, so a row
1097
+ // missing here with no reason reads as our bug rather than their
1098
+ // setting — and the reason names the fix.
1099
+ render: (item) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
1100
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: (item == null ? void 0 : item.blocked) ? "text-gray-dark" : void 0, children: item == null ? void 0 : item.title }),
1101
+ ((item == null ? void 0 : item.blocked) || (item == null ? void 0 : item.warning)) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "block text-sm text-gray-dark", children: item.blocked || item.warning })
1102
+ ] }),
1103
+ renderButton: ({ button, item }) => (
1104
+ // The list's small inline Add, unless the list says otherwise.
1105
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1106
+ import_button.default,
1107
+ {
1108
+ ...{
1109
+ inline: true,
1110
+ size: "small",
1111
+ ...button.props,
1112
+ disabled: Boolean(item == null ? void 0 : item.blocked),
1113
+ title: (item == null ? void 0 : item.blocked) || void 0
1114
+ },
1115
+ children: button.text
1116
+ }
1117
+ )
1118
+ ),
1119
+ value: value || null
1098
1120
  }
1099
- )
1121
+ }
1100
1122
  ),
1101
- value: value || null
1123
+ label: "Discount",
1124
+ // "Issue" means MINT, not send — this step creates the code and saves
1125
+ // it to the lead, and nothing reaches them until a later email step
1126
+ // names the variable. Said here because the step picker says nothing:
1127
+ // QA read "Issue a discount code", built the one-step workflow that
1128
+ // describes, and reported the codes as never arriving.
1129
+ message: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [
1130
+ "Creates the code and saves it to the lead. To send it, add an email step after this one with ",
1131
+ "{{shopifyDiscountCode}}",
1132
+ " in the message.",
1133
+ commerceDomain ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [
1134
+ " ",
1135
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { href: "https://" + commerceDomain + "/admin/discounts", rel: "noopener noreferrer", target: "_blank", children: "Manage discounts" })
1136
+ ] }) : null
1137
+ ] })
1102
1138
  }
1103
1139
  }
1104
- ),
1105
- label: "Discount",
1106
- // "Issue" means MINT, not send — this step creates the code and saves
1107
- // it to the lead, and nothing reaches them until a later email step
1108
- // names the variable. Said here because the step picker says nothing:
1109
- // QA read "Issue a discount code", built the one-step workflow that
1110
- // describes, and reported the codes as never arriving.
1111
- message: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [
1112
- "Creates the code and saves it to the lead. To send it, add an email step after this one with ",
1113
- "{{shopifyDiscountCode}}",
1114
- " in the message.",
1115
- commerceDomain ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [
1116
- " ",
1117
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { href: "https://" + commerceDomain + "/admin/discounts", rel: "noopener noreferrer", target: "_blank", children: "Manage discounts" })
1118
- ] }) : null
1119
- ] })
1140
+ );
1120
1141
  }
1121
1142
  }
1122
- );
1123
- }
1124
- }
1143
+ }
1144
+ )
1145
+ ]
1125
1146
  }
1126
1147
  )
1127
- ]
1128
- }
1148
+ }
1149
+ )
1129
1150
  );
1130
1151
  }
1131
1152
  }
@@ -1153,13 +1174,13 @@ const FormOrganizationWorkflowEdit = ({
1153
1174
  };
1154
1175
  // Annotate the CommonJS export names for ESM import in node:
1155
1176
  0 && (module.exports = {
1156
- FormOrganizationWorkflow,
1157
1177
  FormOrganizationWorkflowEdit,
1158
- campaignFilterId,
1159
- campaignFilterIds,
1160
- filterMissing,
1161
- filterRows,
1162
- filterSeed,
1178
+ SAMPLE,
1179
+ prefillRow,
1180
+ stepReason,
1163
1181
  stepRow,
1182
+ stepVariables,
1183
+ teamSample,
1184
+ webhookSample,
1164
1185
  workflowSchema
1165
1186
  });