@drawbridge/components 0.1.13 → 0.1.14

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 (236) 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 +538 -0
  13. package/dist/bridge/form-subdomain-missions.mjs +502 -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 +265 -0
  47. package/dist/dashboard/card-campaign-switch.mjs +231 -0
  48. package/dist/dashboard/card-order.js +28 -11
  49. package/dist/dashboard/card-order.mjs +28 -11
  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 +196 -0
  55. package/dist/dashboard/connection-workflows.mjs +162 -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-integration-age.js +6 -12
  81. package/dist/dashboard/form-organization-campaign-integration-age.mjs +6 -12
  82. package/dist/dashboard/form-organization-campaign-integration-enable.js +52 -24
  83. package/dist/dashboard/form-organization-campaign-integration-enable.mjs +54 -26
  84. package/dist/dashboard/form-organization-campaign-integration-geocode.js +6 -12
  85. package/dist/dashboard/form-organization-campaign-integration-geocode.mjs +6 -12
  86. package/dist/dashboard/form-organization-campaign-integration-gtm.js +6 -12
  87. package/dist/dashboard/form-organization-campaign-integration-gtm.mjs +6 -12
  88. package/dist/dashboard/form-organization-campaign-link.js +7 -1
  89. package/dist/dashboard/form-organization-campaign-link.mjs +7 -1
  90. package/dist/dashboard/form-organization-campaign-mission.js +291 -0
  91. package/dist/dashboard/form-organization-campaign-mission.mjs +258 -0
  92. package/dist/dashboard/form-organization-campaign-page-embed.js +13 -2
  93. package/dist/dashboard/form-organization-campaign-page-embed.mjs +12 -1
  94. package/dist/dashboard/form-organization-campaign-page.js +20 -11
  95. package/dist/dashboard/form-organization-campaign-page.mjs +20 -11
  96. package/dist/dashboard/form-organization-campaign-prize-edit.js +12 -1
  97. package/dist/dashboard/form-organization-campaign-prize-edit.mjs +12 -1
  98. package/dist/dashboard/form-organization-campaign-section.js +223 -0
  99. package/dist/dashboard/form-organization-campaign-section.mjs +194 -0
  100. package/dist/dashboard/form-organization-campaign.js +114 -469
  101. package/dist/dashboard/form-organization-campaign.mjs +113 -467
  102. package/dist/dashboard/form-organization-export.js +4 -7
  103. package/dist/dashboard/form-organization-export.mjs +4 -7
  104. package/dist/dashboard/form-organization-identity.js +46 -51
  105. package/dist/dashboard/form-organization-identity.mjs +46 -51
  106. package/dist/dashboard/form-organization-workflow.js +518 -686
  107. package/dist/dashboard/form-organization-workflow.mjs +517 -682
  108. package/dist/dashboard/form-organization.js +82 -110
  109. package/dist/dashboard/form-organization.mjs +81 -109
  110. package/dist/dashboard/form-otc.js +4 -5
  111. package/dist/dashboard/form-otc.mjs +4 -5
  112. package/dist/dashboard/form-payment-methods.js +20 -9
  113. package/dist/dashboard/form-payment-methods.mjs +20 -9
  114. package/dist/dashboard/form-stripe.js +30 -0
  115. package/dist/dashboard/form-stripe.mjs +26 -0
  116. package/dist/dashboard/input-array.js +4 -2
  117. package/dist/dashboard/input-array.mjs +4 -2
  118. package/dist/dashboard/input-combobox.js +7 -3
  119. package/dist/dashboard/input-combobox.mjs +7 -3
  120. package/dist/dashboard/input-date.js +7 -0
  121. package/dist/dashboard/input-date.mjs +7 -0
  122. package/dist/dashboard/input-fields.js +80 -20
  123. package/dist/dashboard/input-fields.mjs +80 -20
  124. package/dist/dashboard/input-file.js +21 -1
  125. package/dist/dashboard/input-file.mjs +21 -1
  126. package/dist/dashboard/input-font.js +10 -1
  127. package/dist/dashboard/input-font.mjs +10 -1
  128. package/dist/dashboard/lib/item-list.js +57 -0
  129. package/dist/dashboard/lib/item-list.mjs +33 -0
  130. package/dist/dashboard/lib/menu.js +50 -0
  131. package/dist/dashboard/lib/menu.mjs +26 -0
  132. package/dist/dashboard/locked.js +82 -0
  133. package/dist/dashboard/locked.mjs +53 -0
  134. package/dist/dashboard/menu.js +72 -19
  135. package/dist/dashboard/menu.mjs +72 -19
  136. package/dist/dashboard/note-ai.js +69 -0
  137. package/dist/dashboard/note-ai.mjs +36 -0
  138. package/dist/dashboard/preview.js +419 -0
  139. package/dist/dashboard/preview.mjs +384 -0
  140. package/dist/dashboard/steps.js +39 -13
  141. package/dist/dashboard/steps.mjs +37 -12
  142. package/dist/dashboard/table-contacts.js +136 -0
  143. package/dist/dashboard/table-contacts.mjs +103 -0
  144. package/dist/dashboard/template-not-found.js +4 -2
  145. package/dist/dashboard/template-not-found.mjs +4 -2
  146. package/dist/dashboard/template-socket.js +20 -7
  147. package/dist/dashboard/template-socket.mjs +20 -7
  148. package/dist/icons/desktop.js +46 -0
  149. package/dist/icons/desktop.mjs +27 -0
  150. package/dist/icons/phone.js +46 -0
  151. package/dist/icons/phone.mjs +27 -0
  152. package/dist/icons/puzzle-piece.js +46 -0
  153. package/dist/icons/puzzle-piece.mjs +27 -0
  154. package/dist/icons/tablet.js +46 -0
  155. package/dist/icons/tablet.mjs +27 -0
  156. package/dist/icons/users.js +46 -0
  157. package/dist/icons/users.mjs +27 -0
  158. package/dist/input-checkbox.js +1 -0
  159. package/dist/input-checkbox.mjs +1 -0
  160. package/dist/input-code.js +101 -0
  161. package/dist/input-code.mjs +78 -0
  162. package/dist/input-text.js +2 -1
  163. package/dist/input-text.mjs +2 -1
  164. package/dist/shared/input-checkbox-list.js +0 -1
  165. package/dist/shared/input-checkbox-list.mjs +0 -1
  166. package/dist/shared/input-switch.js +6 -1
  167. package/dist/shared/input-switch.mjs +6 -1
  168. package/dist/shared/lib/campaign.js +117 -0
  169. package/dist/shared/lib/campaign.mjs +91 -0
  170. package/dist/shared/lib/helpers.js +14 -2
  171. package/dist/shared/lib/helpers.mjs +13 -2
  172. package/package.json +133 -13
  173. package/types/bridge/form-subdomain-header.d.ts +2 -0
  174. package/types/bridge/form-subdomain-missions.d.ts +36 -0
  175. package/types/bridge/form-subdomain.d.ts +23 -1
  176. package/types/bridge/lib/entry.d.ts +26 -0
  177. package/types/bridge/lib/location.d.ts +13 -0
  178. package/types/bridge/lib/order.d.ts +30 -0
  179. package/types/bridge/lib/url.d.ts +19 -0
  180. package/types/bridge/template-modal.d.ts +1 -1
  181. package/types/bridge/template-preview.d.ts +10 -0
  182. package/types/bridge/template-subdomain-link.d.ts +2 -0
  183. package/types/dashboard/accordion.d.ts +2 -0
  184. package/types/dashboard/avatar.d.ts +18 -2
  185. package/types/dashboard/buttons-subscription.d.ts +22 -0
  186. package/types/dashboard/card-campaign-switch.d.ts +32 -0
  187. package/types/dashboard/card-order.d.ts +11 -0
  188. package/types/dashboard/card-section.d.ts +2 -0
  189. package/types/dashboard/connection-workflows.d.ts +33 -0
  190. package/types/dashboard/device.d.ts +12 -0
  191. package/types/dashboard/form-admin-campaign.d.ts +3 -2
  192. package/types/dashboard/form-ai.d.ts +2 -2
  193. package/types/dashboard/form-organization-campaign-agreement.d.ts +18 -12
  194. package/types/dashboard/form-organization-campaign-field-email.d.ts +1 -2
  195. package/types/dashboard/form-organization-campaign-field-list.d.ts +36 -0
  196. package/types/dashboard/form-organization-campaign-field-phone.d.ts +1 -2
  197. package/types/dashboard/form-organization-campaign-field-remove.d.ts +22 -0
  198. package/types/dashboard/form-organization-campaign-field-select.d.ts +2 -1
  199. package/types/dashboard/form-organization-campaign-field-textarea.d.ts +2 -1
  200. package/types/dashboard/form-organization-campaign-integration-age.d.ts +3 -3
  201. package/types/dashboard/form-organization-campaign-integration-enable.d.ts +3 -3
  202. package/types/dashboard/form-organization-campaign-mission.d.ts +40 -0
  203. package/types/dashboard/form-organization-campaign-section.d.ts +27 -0
  204. package/types/dashboard/form-organization-campaign.d.ts +27 -17
  205. package/types/dashboard/form-organization-identity.d.ts +2 -0
  206. package/types/dashboard/form-organization-workflow.d.ts +43 -47
  207. package/types/dashboard/form-organization.d.ts +7 -2
  208. package/types/dashboard/form-stripe.d.ts +3 -0
  209. package/types/dashboard/input-combobox.d.ts +2 -0
  210. package/types/dashboard/input-date.d.ts +2 -0
  211. package/types/dashboard/input-fields.d.ts +3 -2
  212. package/types/dashboard/input-file.d.ts +4 -0
  213. package/types/dashboard/lib/item-list.d.ts +14 -0
  214. package/types/dashboard/lib/menu.d.ts +17 -0
  215. package/types/dashboard/locked.d.ts +10 -0
  216. package/types/dashboard/menu.d.ts +10 -2
  217. package/types/dashboard/note-ai.d.ts +15 -0
  218. package/types/dashboard/preview.d.ts +33 -0
  219. package/types/dashboard/steps.d.ts +19 -4
  220. package/types/dashboard/table-cell-title.d.ts +2 -2
  221. package/types/dashboard/table-contacts.d.ts +2 -0
  222. package/types/icons/desktop.d.ts +5 -0
  223. package/types/icons/phone.d.ts +5 -0
  224. package/types/icons/puzzle-piece.d.ts +5 -0
  225. package/types/icons/tablet.d.ts +5 -0
  226. package/types/icons/users.d.ts +5 -0
  227. package/types/input-code.d.ts +23 -0
  228. package/types/shared/input-switch.d.ts +2 -0
  229. package/types/shared/lib/campaign.d.ts +35 -0
  230. package/types/shared/lib/helpers.d.ts +3 -0
  231. package/dist/dashboard/card-integration.js +0 -187
  232. package/dist/dashboard/card-integration.mjs +0 -158
  233. package/dist/dashboard/iframe.js +0 -159
  234. package/dist/dashboard/iframe.mjs +0 -130
  235. package/types/dashboard/card-integration.d.ts +0 -24
  236. 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,16 @@ 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 CardSection from "./card-section.mjs";
21
+ import Accordion from "./accordion.mjs";
22
+ import Preview from "./preview.mjs";
21
23
  import CardTask from "./card-task.mjs";
22
24
  import { LoaderDynamic } from "../shared/loader.mjs";
23
25
  import { smsNumberActive } from "./lib/sms.mjs";
24
26
  import Trash from "../icons/trash.mjs";
25
27
  import Button from "../shared/button.mjs";
26
- const emailSteps = ["step.email.send", "step.email.digest"];
27
- const teamSteps = ["step.email.notify", "step.email.digest"];
28
+ const emailSteps = ["step.email.send"];
29
+ const teamSteps = ["step.email.notify"];
28
30
  const messageSteps = [...emailSteps, "step.sms.send"];
29
31
  const defaultScore = {
30
32
  rules: [
@@ -43,16 +45,8 @@ const stepPrefills = {
43
45
  subject: "Thanks for entering",
44
46
  text: "Thanks for entering. We have your entry and will be in touch."
45
47
  },
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
- }
48
+ // Nothing to prefill: the step writes its own copy.
49
+ "step.email.notify": {}
56
50
  };
57
51
  const memberParams = {
58
52
  filters: {
@@ -90,188 +84,27 @@ const memberLabel = (member) => {
90
84
  var _a, _b, _c;
91
85
  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
86
  };
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
87
+ const stepVariables = (entry, steps = [], index = 0) => [
88
+ ...(entry == null ? void 0 : entry.variables) || [],
89
+ ...steps.slice(0, index).flatMap((step) => {
90
+ var _a;
91
+ return ((_a = ((entry == null ? void 0 : entry.steps) || []).find((option) => option.value === (step == null ? void 0 : step.type))) == null ? void 0 : _a.returns) || [];
92
+ })
93
+ ];
94
+ const prefillRow = ({ entry, step, steps = [] }) => {
95
+ if (!step || steps.some((row) => (row == null ? void 0 : row.type) === step)) return null;
96
+ const option = ((entry == null ? void 0 : entry.steps) || []).find((each) => each.value === step);
97
+ if (!option || option.ownerOnly || option.disabled) return null;
98
+ return stepRow({
99
+ connectionId: option.connectionId,
100
+ settings: stepPrefills[step] || {},
101
+ slug: option.slug,
102
+ type: step
104
103
  });
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
104
  };
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
- };
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
- );
105
+ const stepReason = ({ entry, saved = [], type }) => {
106
+ var _a, _b;
107
+ 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
108
  };
276
109
  const stepRow = (step = {}, members = []) => {
277
110
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
@@ -306,119 +139,7 @@ const stepRow = (step = {}, members = []) => {
306
139
  url: ((_i = step.settings) == null ? void 0 : _i.url) || ""
307
140
  };
308
141
  };
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
142
  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
143
  steps: yup.array().of(
423
144
  yup.object({
424
145
  type: yup.string().label("Step").required("A step is required"),
@@ -434,7 +155,13 @@ const workflowSchema = yup.object({
434
155
  }
435
156
  return schema;
436
157
  }),
437
- message: yup.string().when("type", ([type], schema) => {
158
+ // @story workflows/edit
159
+ // The editor writes an empty message as "<p></p>", which a plain
160
+ // required() accepts: a message needs words, not only markup.
161
+ message: yup.string().test("words", "Message is required", function(value) {
162
+ var _a;
163
+ return !messageSteps.includes((_a = this.parent) == null ? void 0 : _a.type) || Boolean(String(value || "").replace(/<[^>]*>/g, "").trim());
164
+ }).when("type", ([type], schema) => {
438
165
  if (type === "step.sms.send") {
439
166
  return schema.required("Message is required").max(1500).label("Message");
440
167
  }
@@ -458,21 +185,157 @@ const workflowSchema = yup.object({
458
185
  })
459
186
  )
460
187
  });
188
+ const samples = [
189
+ {
190
+ key: "New lead",
191
+ value: "lead"
192
+ },
193
+ {
194
+ key: "Verified their email",
195
+ value: "verified"
196
+ }
197
+ ];
198
+ const useEmailPreview = ({ campaign, event, message, organization, sample, subject, text }) => {
199
+ const asked = JSON.stringify({ message, sample, subject, text });
200
+ const [settled, setSettled] = useState(asked);
201
+ useEffect(() => {
202
+ const timer = setTimeout(() => setSettled(asked), 400);
203
+ return () => clearTimeout(timer);
204
+ }, [asked]);
205
+ const preview = useQuery({
206
+ enabled: Boolean(organization && campaign && event),
207
+ placeholderData: keepPreviousData,
208
+ queryFn: async () => {
209
+ const { result } = await request({
210
+ body: JSON.parse(settled),
211
+ endpoint: "/organization/" + organization + "/campaign/" + campaign + "/workflow/" + event + "/preview",
212
+ method: "POST"
213
+ });
214
+ return result;
215
+ },
216
+ queryKey: ["workflow-email-preview", organization, campaign, event, settled]
217
+ });
218
+ return preview.data;
219
+ };
220
+ const EmailStepCard = ({
221
+ card,
222
+ children,
223
+ control,
224
+ email: {
225
+ campaign,
226
+ event,
227
+ name,
228
+ organization
229
+ }
230
+ }) => {
231
+ const [sample, setSample] = useState(samples[0].value);
232
+ const [subject, message, text] = useWatch({
233
+ control,
234
+ name: [name + ".subject", name + ".message", name + ".text"]
235
+ });
236
+ const preview = useEmailPreview({ campaign, event, message, organization, sample, subject, text });
237
+ return /* @__PURE__ */ jsxs(
238
+ CardSection,
239
+ {
240
+ ...{
241
+ ...card,
242
+ columns: 2
243
+ },
244
+ children: [
245
+ /* @__PURE__ */ jsxs(
246
+ "div",
247
+ {
248
+ ...{
249
+ className: "space-y-6"
250
+ },
251
+ children: [
252
+ children,
253
+ /* @__PURE__ */ jsx(
254
+ Accordion,
255
+ {
256
+ ...{
257
+ className: "pt-6 border-t border-gray",
258
+ classNamePanel: "mt-6",
259
+ title: "Plain-text version"
260
+ },
261
+ children: /* @__PURE__ */ jsx(
262
+ "pre",
263
+ {
264
+ ...{
265
+ className: "p-4 rounded border border-gray bg-white text-sm whitespace-pre-wrap wrap-anywhere"
266
+ },
267
+ children: preview == null ? void 0 : preview.text
268
+ }
269
+ )
270
+ }
271
+ )
272
+ ]
273
+ }
274
+ ),
275
+ /* @__PURE__ */ jsx(
276
+ Preview,
277
+ {
278
+ ...{
279
+ states: {
280
+ onChange: setSample,
281
+ options: samples,
282
+ value: sample
283
+ }
284
+ },
285
+ children: /* @__PURE__ */ jsx(
286
+ "iframe",
287
+ {
288
+ ...{
289
+ // The rendered email, as a mail app shows it.
290
+ className: "block w-full h-full border-0 bg-white",
291
+ srcDoc: (preview == null ? void 0 : preview.html) || "",
292
+ title: "Send email"
293
+ }
294
+ }
295
+ )
296
+ }
297
+ )
298
+ ]
299
+ }
300
+ );
301
+ };
302
+ const StepCard = ({
303
+ children,
304
+ control,
305
+ email,
306
+ ...card
307
+ }) => email ? /* @__PURE__ */ jsx(
308
+ EmailStepCard,
309
+ {
310
+ ...{
311
+ card,
312
+ control,
313
+ email
314
+ },
315
+ children
316
+ }
317
+ ) : /* @__PURE__ */ jsx(
318
+ CardSection,
319
+ {
320
+ ...card,
321
+ children
322
+ }
323
+ );
461
324
  const FormOrganizationWorkflowEdit = ({
325
+ catalog,
462
326
  disabled,
463
- onClose,
464
327
  onError,
465
328
  onSuccess,
466
329
  values
467
330
  }) => {
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);
331
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
332
+ const event = (_a = values == null ? void 0 : values.trigger) == null ? void 0 : _a.event;
470
333
  const { items: memberItems, loading: membersLoading } = useOrganizationMembers(values == null ? void 0 : values.organization);
471
334
  const queryClient = useQueryClient();
472
335
  const organizationData = queryClient.getQueryData(["organization", values == null ? void 0 : values.organization]);
473
336
  const ownerEmail = organizationData.owner.email;
474
337
  const smsActive = smsNumberActive(organizationData);
475
- const commerceConnectionId = ((_b = catalogList.flatMap((item) => item.steps || []).find(
338
+ const commerceConnectionId = ((_b = ((catalog == null ? void 0 : catalog.steps) || []).find(
476
339
  (s) => s.value === "step.commerce.customer.insert" || s.value === "step.commerce.code.issue"
477
340
  )) == null ? void 0 : _b.connectionId) || null;
478
341
  const commerceConnection = useQuery({
@@ -498,38 +361,29 @@ const FormOrganizationWorkflowEdit = ({
498
361
  );
499
362
  const { control, formState, getValues, handleSubmit, setValue } = useForm({
500
363
  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) || ""
364
+ steps: defaultSteps
509
365
  },
510
366
  resolver: resolver(workflowSchema)
511
367
  });
512
- const watchedTrigger = useWatch({
513
- control,
514
- name: "triggerEvent"
515
- });
516
368
  const watchedSteps = useWatch({
517
369
  control,
518
370
  name: "steps"
519
371
  });
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
- };
372
+ 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;
373
+ const getAvailableVariables = (index) => stepVariables(catalog, watchedSteps, index);
374
+ const loading = membersLoading || commerceConnection.isLoading;
375
+ const prefilled = useRef(false);
376
+ useEffect(() => {
377
+ if (loading || disabled || prefilled.current) return;
378
+ prefilled.current = true;
379
+ const row = prefillRow({ entry: catalog, step: values == null ? void 0 : values.step, steps: getValues("steps") });
380
+ if (row) setValue("steps", [...getValues("steps"), row], { shouldDirty: true });
381
+ }, [catalog, disabled, getValues, loading, setValue, values == null ? void 0 : values.step]);
528
382
  const getStepOptions = (index) => {
529
383
  const usedTypes = watchedSteps.map((s, i) => i !== index ? s.type : null).filter(Boolean);
530
384
  return [
531
385
  { key: "Select a step", value: "" },
532
- ...((selectedTriggerEntry == null ? void 0 : selectedTriggerEntry.steps) || []).filter((step) => !usedTypes.includes(step.value)).filter((step) => {
386
+ ...((catalog == null ? void 0 : catalog.steps) || []).filter((step) => !usedTypes.includes(step.value)).filter((step) => {
533
387
  var _a2;
534
388
  return !step.ownerOnly || step.value === ((_a2 = watchedSteps[index]) == null ? void 0 : _a2.type);
535
389
  }).sort((a, b) => String(a.key).localeCompare(String(b.key))).map((step) => ({
@@ -546,7 +400,7 @@ const FormOrganizationWorkflowEdit = ({
546
400
  // connectionless and sendgrid is gone — but the rule is about any
547
401
  // two entries sharing a type, so it stays.
548
402
  value: step.connectionId ? step.value + "::" + step.connectionId : step.slug ? step.value + "::" + step.slug : step.value,
549
- ...step.disabled ? {
403
+ ...step.disabled && !step.reason ? {
550
404
  badge: {
551
405
  text: "Enable connection"
552
406
  },
@@ -554,8 +408,7 @@ const FormOrganizationWorkflowEdit = ({
554
408
  element: Link,
555
409
  key: step == null ? void 0 : step.key,
556
410
  props: {
557
- href: "/organizations/" + (values == null ? void 0 : values.organization) + "/connections/" + step.slug,
558
- onClick: onClose
411
+ href: "/organizations/" + (values == null ? void 0 : values.organization) + "/connections/" + step.slug
559
412
  }
560
413
  } : {},
561
414
  // The same link-shaped option, greyed: it cannot be picked, and
@@ -570,14 +423,29 @@ const FormOrganizationWorkflowEdit = ({
570
423
  key: step == null ? void 0 : step.key,
571
424
  props: {
572
425
  "aria-disabled": true,
573
- href: "/organizations/" + (values == null ? void 0 : values.organization) + "/settings",
574
- onClick: onClose
426
+ href: "/organizations/" + (values == null ? void 0 : values.organization) + "/settings"
427
+ }
428
+ } : {},
429
+ // @story workflows/edit
430
+ // A step the form cannot feed: greyed with its reason, and a
431
+ // click opens the campaign's Form page, where the field is added.
432
+ ...step.reason ? {
433
+ badge: {
434
+ text: step.reason
435
+ },
436
+ className: "opacity-50",
437
+ disabled: false,
438
+ element: Link,
439
+ key: step == null ? void 0 : step.key,
440
+ props: {
441
+ "aria-disabled": true,
442
+ href: "/organizations/" + (values == null ? void 0 : values.organization) + "/campaigns/" + (values == null ? void 0 : values.campaign) + "/form"
575
443
  }
576
444
  } : {}
577
445
  }))
578
446
  ];
579
447
  };
580
- const lockedStep = (index) => ((selectedTriggerEntry == null ? void 0 : selectedTriggerEntry.steps) || []).some((s) => {
448
+ const lockedStep = (index) => ((catalog == null ? void 0 : catalog.steps) || []).some((s) => {
581
449
  var _a2;
582
450
  return s.ownerOnly && s.value === ((_a2 = watchedSteps[index]) == null ? void 0 : _a2.type);
583
451
  });
@@ -591,7 +459,7 @@ const FormOrganizationWorkflowEdit = ({
591
459
  return match ? match.value : "";
592
460
  };
593
461
  const getStepConnection = (field) => {
594
- const steps = (selectedTriggerEntry == null ? void 0 : selectedTriggerEntry.steps) || [];
462
+ const steps = (catalog == null ? void 0 : catalog.steps) || [];
595
463
  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
464
  if (!def) return null;
597
465
  const connected = Boolean(def.connectionId);
@@ -604,6 +472,19 @@ const FormOrganizationWorkflowEdit = ({
604
472
  };
605
473
  };
606
474
  const renderStepBadge = (field) => {
475
+ const reason = stepReason({ entry: catalog, saved: values == null ? void 0 : values.steps, type: field == null ? void 0 : field.type });
476
+ if (reason) {
477
+ return /* @__PURE__ */ jsx(
478
+ Badge,
479
+ {
480
+ ...{
481
+ size: "small",
482
+ type: "error"
483
+ },
484
+ children: reason
485
+ }
486
+ );
487
+ }
607
488
  const conn = getStepConnection(field);
608
489
  if (!conn) return null;
609
490
  return /* @__PURE__ */ jsx(
@@ -618,11 +499,7 @@ const FormOrganizationWorkflowEdit = ({
618
499
  );
619
500
  };
620
501
  const onSubmit = async ({
621
- steps,
622
- filterCampaigns,
623
- filterSegment,
624
- title,
625
- triggerEvent
502
+ steps
626
503
  }) => {
627
504
  try {
628
505
  const body = {
@@ -638,7 +515,7 @@ const FormOrganizationWorkflowEdit = ({
638
515
  }
639
516
  if (teamSteps.includes(type)) settings.members = (members || []).map((member) => member == null ? void 0 : member.id).filter(Boolean);
640
517
  if (type === "step.commerce.code.issue") settings.discount = discount;
641
- const catalogSteps = (selectedTriggerEntry == null ? void 0 : selectedTriggerEntry.steps) || [];
518
+ const catalogSteps = (catalog == null ? void 0 : catalog.steps) || [];
642
519
  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
520
  const resolvedConnectionId = (catalogStep == null ? void 0 : catalogStep.connectionId) || connectionId || null;
644
521
  const resolvedSlug = (catalogStep == null ? void 0 : catalogStep.slug) || slug || null;
@@ -648,19 +525,11 @@ const FormOrganizationWorkflowEdit = ({
648
525
  settings,
649
526
  type
650
527
  };
651
- }),
652
- title,
653
- trigger: {
654
- event: triggerEvent,
655
- filters: {
656
- campaigns: filterCampaigns || [],
657
- segment: filterSegment || null
658
- }
659
- }
528
+ })
660
529
  };
661
530
  const response = await request({
662
531
  body,
663
- endpoint: "/organization/" + (values == null ? void 0 : values.organization) + "/workflow/" + values.id,
532
+ endpoint: "/organization/" + (values == null ? void 0 : values.organization) + "/campaign/" + (values == null ? void 0 : values.campaign) + "/workflow/" + event,
664
533
  method: "PUT"
665
534
  });
666
535
  onSuccess(response);
@@ -668,7 +537,7 @@ const FormOrganizationWorkflowEdit = ({
668
537
  onError(error);
669
538
  }
670
539
  };
671
- if (catalog.isLoading || membersLoading || commerceConnection.isLoading) {
540
+ if (loading) {
672
541
  return /* @__PURE__ */ jsx(LoaderDynamic, {});
673
542
  }
674
543
  return /* @__PURE__ */ jsx(
@@ -695,65 +564,32 @@ const FormOrganizationWorkflowEdit = ({
695
564
  }
696
565
  }
697
566
  ),
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,
567
+ /* @__PURE__ */ jsxs(
568
+ CardSection,
713
569
  {
714
570
  ...{
715
- control,
716
- formState
717
- }
718
- }
719
- ),
720
- watchedTrigger === "lead.insert" && /* @__PURE__ */ jsx(
721
- WorkflowFilterField,
722
- {
723
- ...{
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
- }
571
+ "data-trigger": true,
572
+ title: "Trigger"
573
+ },
574
+ children: [
575
+ /* @__PURE__ */ jsx("p", { children: values == null ? void 0 : values.title }),
576
+ (values == null ? void 0 : values.description) && /* @__PURE__ */ jsx(
577
+ "p",
578
+ {
579
+ ...{
580
+ className: "text-sm text-gray-dark"
581
+ },
582
+ children: values.description
583
+ }
584
+ )
585
+ ]
750
586
  }
751
587
  ),
752
588
  /* @__PURE__ */ jsx(
753
589
  InputGroup,
754
590
  {
755
591
  ...{
756
- error: (_o = (_n = formState == null ? void 0 : formState.errors) == null ? void 0 : _n.steps) == null ? void 0 : _o.message,
592
+ error: (_i = (_h = formState == null ? void 0 : formState.errors) == null ? void 0 : _h.steps) == null ? void 0 : _i.message,
757
593
  input: /* @__PURE__ */ jsx(
758
594
  InputArraySortable,
759
595
  {
@@ -765,7 +601,6 @@ const FormOrganizationWorkflowEdit = ({
765
601
  InputArrayButton,
766
602
  {
767
603
  ...{
768
- disabled: !watchedTrigger,
769
604
  onClick: () => append(stepRow()),
770
605
  text: "Add step"
771
606
  }
@@ -774,318 +609,321 @@ const FormOrganizationWorkflowEdit = ({
774
609
  },
775
610
  children: ({ field, handle, index, remove }) => {
776
611
  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(
612
+ return (
613
+ // @story workflows/edit
614
+ // EACH STEP IS ITS OWN CARD in the flow under the Trigger card,
615
+ // edited in place: the drag handle left of Step N, as every
616
+ // sortable list has it, then its connection badge and Remove
617
+ // in the card's head, its fields in the body.
618
+ /* @__PURE__ */ jsx(
619
+ StepCard,
620
+ {
621
+ ...{
622
+ control,
623
+ // @story workflows/send-email
624
+ // A Send email step shows its email beside its form.
625
+ email: emailSteps.includes(step.type) && {
626
+ campaign: values == null ? void 0 : values.campaign,
627
+ event,
628
+ name: `steps.${index}`,
629
+ organization: values == null ? void 0 : values.organization
630
+ },
631
+ cta: /* @__PURE__ */ jsxs(
632
+ "span",
633
+ {
634
+ ...{
635
+ className: "flex items-center gap-2"
636
+ },
637
+ children: [
638
+ renderStepBadge(step),
639
+ !lockedStep(index) && /* @__PURE__ */ jsx(
640
+ InputArrayControl,
641
+ {
642
+ ...{
643
+ onClick: () => remove(index),
644
+ icon: Trash
645
+ }
646
+ },
647
+ "remove"
648
+ )
649
+ ]
650
+ }
651
+ ),
652
+ "data-step": index + 1,
653
+ title: /* @__PURE__ */ jsxs(
654
+ "span",
655
+ {
656
+ ...{
657
+ className: "flex items-center gap-2"
658
+ },
659
+ children: [
660
+ handle,
661
+ "Step " + (index + 1)
662
+ ]
663
+ }
664
+ )
665
+ },
666
+ children: /* @__PURE__ */ jsxs(
785
667
  "div",
786
668
  {
787
669
  ...{
788
- className: "flex items-center justify-between"
670
+ className: "space-y-3"
789
671
  },
790
672
  children: [
791
- /* @__PURE__ */ jsxs(
792
- "div",
673
+ issueIndex === index && /* @__PURE__ */ jsx(
674
+ Error,
793
675
  {
794
676
  ...{
795
- className: "flex items-center space-x-2"
796
- },
797
- children: [
798
- handle,
799
- /* @__PURE__ */ jsxs(
800
- "span",
801
- {
802
- ...{
803
- className: "text-sm font-medium"
804
- },
805
- children: [
806
- "Step ",
807
- index + 1
808
- ]
809
- }
810
- )
811
- ]
677
+ error: values.issue.message
678
+ }
812
679
  }
813
680
  ),
814
- /* @__PURE__ */ jsxs(
815
- "div",
681
+ /* @__PURE__ */ jsx(
682
+ Controller,
816
683
  {
817
684
  ...{
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,
685
+ control,
686
+ name: `steps.${index}.type`,
687
+ render: ({ field: { onChange } }) => {
688
+ var _a2, _b2, _c2, _d2;
689
+ return /* @__PURE__ */ jsx(
690
+ InputGroup,
861
691
  {
862
692
  ...{
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)
693
+ 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,
694
+ input: /* @__PURE__ */ jsx(
695
+ InputCombobox,
696
+ {
697
+ ...{
698
+ onChange: (val) => {
699
+ const [type] = val.split("::");
700
+ const option = getStepOptions(index).find((o) => o.value === val);
701
+ onChange(type);
702
+ setValue(`steps.${index}.connectionId`, (option == null ? void 0 : option.connectionId) || "");
703
+ setValue(`steps.${index}.slug`, (option == null ? void 0 : option.slug) || "");
704
+ },
705
+ disabled: lockedStep(index),
706
+ options: getStepOptions(index),
707
+ // Resolved from the WHOLE ROW, not from this path: the
708
+ // option value carries a connection the type alone cannot
709
+ // name.
710
+ value: getStepValue(step, index)
711
+ }
712
+ }
713
+ ),
714
+ label: "Step"
876
715
  }
877
716
  }
878
- ),
879
- label: "Step"
717
+ );
880
718
  }
881
719
  }
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,
720
+ }
721
+ ),
722
+ step.type === "step.webhook.send" && /* @__PURE__ */ jsx(
723
+ Controller,
724
+ {
725
+ ...{
726
+ control,
727
+ name: `steps.${index}.url`,
728
+ render: ({ field: { value, onChange } }) => {
729
+ var _a2, _b2, _c2, _d2;
730
+ return /* @__PURE__ */ jsx(
731
+ InputGroup,
902
732
  {
903
733
  ...{
904
- onChange,
905
- value: value || ""
734
+ 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,
735
+ input: /* @__PURE__ */ jsx(
736
+ InputUrl,
737
+ {
738
+ ...{
739
+ onChange,
740
+ value: value || ""
741
+ }
742
+ }
743
+ ),
744
+ label: "Webhook URL"
906
745
  }
907
746
  }
908
- ),
909
- label: "Webhook URL"
747
+ );
910
748
  }
911
749
  }
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,
750
+ }
751
+ ),
752
+ teamSteps.includes(step.type) && lockedStep(index) && /* @__PURE__ */ jsx("p", { className: "text-sm text-gray-500", children: "Recipients are chosen by the organization owner." }),
753
+ teamSteps.includes(step.type) && !lockedStep(index) && /* @__PURE__ */ jsx(
754
+ Controller,
755
+ {
756
+ ...{
757
+ control,
758
+ name: `steps.${index}.members`,
759
+ render: ({ field: { value, onChange } }) => {
760
+ var _a2, _b2, _c2, _d2;
761
+ return /* @__PURE__ */ jsx(
762
+ InputGroup,
933
763
  {
934
764
  ...{
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 || []
765
+ 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,
766
+ input: /* @__PURE__ */ jsx(
767
+ InputResource,
768
+ {
769
+ ...{
770
+ empty: "No members to add",
771
+ endpoint: "/organization/" + (values == null ? void 0 : values.organization) + "/members",
772
+ // The owner is a chip like the others, only it cannot be
773
+ // removed: they are always a recipient and it is resolved
774
+ // in sync. Shaped like a member so `render` labels it the
775
+ // same way.
776
+ fixed: [{ email: ownerEmail }],
777
+ model: "member",
778
+ multiple: true,
779
+ onChange,
780
+ params: memberParams,
781
+ render: memberLabel,
782
+ // The row shows the name ( memberLabel ), so the search has
783
+ // to hit the name too. The members endpoint joins `user`
784
+ // before its search stage, so the nested keys resolve.
785
+ // Email stays for invitees who have not registered yet.
786
+ // ponytail: a full "First Last" query matches neither key;
787
+ // a $concat'd name on the API side if that comes up.
788
+ searchKeys: ["email", "user.firstName", "user.lastName"],
789
+ value: value || []
790
+ }
791
+ }
792
+ ),
793
+ label: "Recipients"
955
794
  }
956
795
  }
957
- ),
958
- label: "Recipients"
796
+ );
959
797
  }
960
798
  }
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,
799
+ }
800
+ ),
801
+ emailSteps.includes(step.type) && /* @__PURE__ */ jsx(
802
+ FormNotification,
803
+ {
804
+ ...{
805
+ control,
806
+ // As the Fieldset above: the Message editor is a
807
+ // contenteditable, which a disabled fieldset never reaches.
808
+ disabled: disabled || (formState == null ? void 0 : formState.isSubmitting),
809
+ formState,
810
+ onChecking,
811
+ setValue,
812
+ values: {
813
+ id: field.id,
814
+ name: `steps.${index}`,
815
+ organization: values == null ? void 0 : values.organization,
816
+ variables: getAvailableVariables(index)
817
+ }
818
+ }
819
+ }
820
+ ),
821
+ step.type === "step.sms.send" && /* @__PURE__ */ jsx(
822
+ Controller,
823
+ {
824
+ ...{
825
+ control,
826
+ name: `steps.${index}.message`,
827
+ render: ({ field: { value, onChange } }) => {
828
+ var _a2, _b2, _c2, _d2;
829
+ return /* @__PURE__ */ jsx(
830
+ InputGroup,
1001
831
  {
1002
832
  ...{
1003
- onChange,
1004
- rows: 3,
1005
- value: value || ""
833
+ 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,
834
+ input: /* @__PURE__ */ jsx(
835
+ InputTextarea,
836
+ {
837
+ ...{
838
+ onChange,
839
+ rows: 3,
840
+ value: value || ""
841
+ }
842
+ }
843
+ ),
844
+ label: "Message"
1006
845
  }
1007
846
  }
1008
- ),
1009
- label: "Message"
847
+ );
1010
848
  }
1011
849
  }
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,
850
+ }
851
+ ),
852
+ step.type === "step.commerce.code.issue" && /* @__PURE__ */ jsx(
853
+ Controller,
854
+ {
855
+ ...{
856
+ control,
857
+ name: `steps.${index}.discount`,
858
+ render: ({ field: { value, onChange } }) => {
859
+ var _a2, _b2, _c2, _d2;
860
+ return /* @__PURE__ */ jsx(
861
+ InputGroup,
1032
862
  {
1033
863
  ...{
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
864
+ 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,
865
+ input: /* @__PURE__ */ jsx(
866
+ InputResource,
867
+ {
868
+ ...{
869
+ endpoint: "/organization/" + (values == null ? void 0 : values.organization) + "/connection/" + commerceConnectionId + "/hook/browse.promotions",
870
+ model: "discount",
871
+ onChange,
872
+ // A DISCOUNT THE STORE CANNOT BACK IS SHOWN AND EXPLAINED, never
873
+ // filtered out. The merchant can see it in Shopify admin, so a row
874
+ // missing here with no reason reads as our bug rather than their
875
+ // setting — and the reason names the fix.
876
+ render: (item) => /* @__PURE__ */ jsxs("div", { children: [
877
+ /* @__PURE__ */ jsx("span", { className: (item == null ? void 0 : item.blocked) ? "text-gray-dark" : void 0, children: item == null ? void 0 : item.title }),
878
+ ((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 })
879
+ ] }),
880
+ renderButton: ({ button, item }) => (
881
+ // The list's small inline Add, unless the list says otherwise.
882
+ /* @__PURE__ */ jsx(
883
+ Button,
884
+ {
885
+ ...{
886
+ inline: true,
887
+ size: "small",
888
+ ...button.props,
889
+ disabled: Boolean(item == null ? void 0 : item.blocked),
890
+ title: (item == null ? void 0 : item.blocked) || void 0
891
+ },
892
+ children: button.text
893
+ }
894
+ )
895
+ ),
896
+ value: value || null
1058
897
  }
1059
- )
898
+ }
1060
899
  ),
1061
- value: value || null
900
+ label: "Discount",
901
+ // "Issue" means MINT, not send — this step creates the code and saves
902
+ // it to the lead, and nothing reaches them until a later email step
903
+ // names the variable. Said here because the step picker says nothing:
904
+ // QA read "Issue a discount code", built the one-step workflow that
905
+ // describes, and reported the codes as never arriving.
906
+ message: /* @__PURE__ */ jsxs(Fragment, { children: [
907
+ "Creates the code and saves it to the lead. To send it, add an email step after this one with ",
908
+ "{{shopifyDiscountCode}}",
909
+ " in the message.",
910
+ commerceDomain ? /* @__PURE__ */ jsxs(Fragment, { children: [
911
+ " ",
912
+ /* @__PURE__ */ jsx("a", { href: "https://" + commerceDomain + "/admin/discounts", rel: "noopener noreferrer", target: "_blank", children: "Manage discounts" })
913
+ ] }) : null
914
+ ] })
1062
915
  }
1063
916
  }
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
- ] })
917
+ );
1080
918
  }
1081
919
  }
1082
- );
1083
- }
1084
- }
920
+ }
921
+ )
922
+ ]
1085
923
  }
1086
924
  )
1087
- ]
1088
- }
925
+ }
926
+ )
1089
927
  );
1090
928
  }
1091
929
  }
@@ -1112,13 +950,10 @@ const FormOrganizationWorkflowEdit = ({
1112
950
  );
1113
951
  };
1114
952
  export {
1115
- FormOrganizationWorkflow,
1116
953
  FormOrganizationWorkflowEdit,
1117
- campaignFilterId,
1118
- campaignFilterIds,
1119
- filterMissing,
1120
- filterRows,
1121
- filterSeed,
954
+ prefillRow,
955
+ stepReason,
1122
956
  stepRow,
957
+ stepVariables,
1123
958
  workflowSchema
1124
959
  };