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