@drawbridge/components 0.1.15 → 0.1.17

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 (49) hide show
  1. package/dist/bridge/form-subdomain-missions.js +43 -34
  2. package/dist/bridge/form-subdomain-missions.mjs +43 -34
  3. package/dist/bridge/lib/url.js +3 -3
  4. package/dist/bridge/lib/url.mjs +3 -3
  5. package/dist/bridge/share-button.js +12 -2
  6. package/dist/bridge/share-button.mjs +12 -2
  7. package/dist/bridge/template-layout.js +1 -1
  8. package/dist/bridge/template-layout.mjs +1 -1
  9. package/dist/dashboard/answer-rows.js +77 -0
  10. package/dist/dashboard/answer-rows.mjs +41 -0
  11. package/dist/dashboard/card-order.js +186 -243
  12. package/dist/dashboard/card-order.mjs +186 -243
  13. package/dist/dashboard/form-organization-campaign-agreement.js +2 -2
  14. package/dist/dashboard/form-organization-campaign-agreement.mjs +2 -2
  15. package/dist/dashboard/form-organization-campaign-field-list.js +8 -49
  16. package/dist/dashboard/form-organization-campaign-field-list.mjs +8 -49
  17. package/dist/dashboard/form-organization-workflow.js +588 -157
  18. package/dist/dashboard/form-organization-workflow.mjs +578 -157
  19. package/dist/dashboard/form-otc.js +7 -4
  20. package/dist/dashboard/form-otc.mjs +8 -5
  21. package/dist/dashboard/input-editor.js +46 -10
  22. package/dist/dashboard/input-editor.mjs +44 -9
  23. package/dist/dashboard/item-row.js +92 -0
  24. package/dist/dashboard/item-row.mjs +63 -0
  25. package/dist/dashboard/lib/sms.js +3 -0
  26. package/dist/dashboard/lib/sms.mjs +2 -0
  27. package/dist/dashboard/order-sections.js +231 -0
  28. package/dist/dashboard/order-sections.mjs +196 -0
  29. package/dist/dashboard/preview.js +29 -2
  30. package/dist/dashboard/preview.mjs +28 -2
  31. package/dist/dashboard/steps.js +5 -0
  32. package/dist/dashboard/steps.mjs +5 -0
  33. package/dist/dashboard/template-socket.js +6 -0
  34. package/dist/dashboard/template-socket.mjs +6 -0
  35. package/dist/input-code.js +2 -8
  36. package/dist/input-code.mjs +2 -8
  37. package/dist/shared/lib/helpers.js +7 -0
  38. package/dist/shared/lib/helpers.mjs +7 -0
  39. package/package.json +19 -4
  40. package/types/bridge/lib/url.d.ts +5 -4
  41. package/types/dashboard/answer-rows.d.ts +30 -0
  42. package/types/dashboard/card-order.d.ts +16 -14
  43. package/types/dashboard/form-organization-workflow.d.ts +46 -0
  44. package/types/dashboard/input-editor.d.ts +7 -1
  45. package/types/dashboard/item-row.d.ts +25 -0
  46. package/types/dashboard/order-sections.d.ts +36 -0
  47. package/types/dashboard/steps.d.ts +2 -0
  48. package/types/input-code.d.ts +0 -2
  49. package/types/shared/lib/helpers.d.ts +1 -1
@@ -28,12 +28,22 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
28
28
  var form_organization_workflow_exports = {};
29
29
  __export(form_organization_workflow_exports, {
30
30
  FormOrganizationWorkflowEdit: () => FormOrganizationWorkflowEdit,
31
+ RESPONSE: () => RESPONSE,
31
32
  SAMPLE: () => SAMPLE,
33
+ TextPreview: () => TextPreview,
34
+ firstEntryOnly: () => firstEntryOnly,
35
+ issueRow: () => issueRow,
36
+ partToStart: () => partToStart,
37
+ pickedCopy: () => pickedCopy,
38
+ plainHtml: () => plainHtml,
32
39
  prefillRow: () => prefillRow,
40
+ responseParts: () => responseParts,
41
+ responseSave: () => responseSave,
42
+ responseStart: () => responseStart,
43
+ stepAfterPart: () => stepAfterPart,
33
44
  stepReason: () => stepReason,
34
45
  stepRow: () => stepRow,
35
46
  stepVariables: () => stepVariables,
36
- teamSample: () => teamSample,
37
47
  webhookSample: () => webhookSample,
38
48
  workflowSchema: () => workflowSchema
39
49
  });
@@ -42,7 +52,9 @@ var import_jsx_runtime = require("react/jsx-runtime");
42
52
  var import_image = __toESM(require("next/image"));
43
53
  var import_link = __toESM(require("./link"));
44
54
  var import_react = require("react");
55
+ var import_drawbridge_utils = require("@drawbridge/drawbridge-utils");
45
56
  var import_fetch = require("@drawbridge/drawbridge-utils/fetch");
57
+ var import_html = require("@drawbridge/drawbridge-utils/html");
46
58
  var import_form = require("../shared/lib/form");
47
59
  var import_react_query = require("@tanstack/react-query");
48
60
  var import_yup = __toESM(require("../shared/lib/yup"));
@@ -55,10 +67,10 @@ var import_input_url = __toESM(require("../shared/input-url"));
55
67
  var import_input_resource = __toESM(require("./input-resource"));
56
68
  var import_input_combobox = __toESM(require("./input-combobox"));
57
69
  var import_form_notification = require("./form-notification");
70
+ var import_input_editor = __toESM(require("./input-editor"));
58
71
  var import_input_array = require("./input-array");
59
72
  var import_badge = __toESM(require("../shared/badge"));
60
73
  var import_input_switch = __toESM(require("../shared/input-switch"));
61
- var import_tooltip = __toESM(require("../shared/tooltip"));
62
74
  var import_card_section = __toESM(require("./card-section"));
63
75
  var import_accordion = __toESM(require("./accordion"));
64
76
  var import_preview = __toESM(require("./preview"));
@@ -70,22 +82,19 @@ var import_button = __toESM(require("../shared/button"));
70
82
  const emailSteps = ["step.email.send"];
71
83
  const teamSteps = ["step.email.notify"];
72
84
  const messageSteps = [...emailSteps, "step.sms.send"];
73
- const defaultScore = {
74
- rules: [
75
- { description: "From: domain has series of non-vowel letters", score: 0.5 },
76
- { description: "Informational: message was not relayed via SMTP", score: 0 },
77
- { description: "Informational: message has no Received headers", score: 0 }
78
- ],
79
- subtotal: 0,
80
- threshold: 5,
81
- total: 0.5
85
+ const renderedSteps = [...emailSteps, ...teamSteps];
86
+ const RESPONSE = "step.response.send";
87
+ const firstEntryOnly = ({ campaign, event, type }) => {
88
+ var _a, _b;
89
+ if (event !== "lead.insert" || !type || emailSteps.includes(type) || type === RESPONSE) return false;
90
+ if (type === "step.sms.send") return (((_a = campaign == null ? void 0 : campaign.form) == null ? void 0 : _a.submissionLeadPrimaryKey) ?? ((_b = campaign == null ? void 0 : campaign.settings) == null ? void 0 : _b.submissionLeadPrimaryKey)) !== "phone";
91
+ return true;
82
92
  };
83
93
  const stepPrefills = {
84
94
  "step.email.send": {
85
- message: "Thanks for entering. We have your entry and will be in touch.",
86
- score: defaultScore,
87
- subject: "Thanks for entering",
88
- text: "Thanks for entering. We have your entry and will be in touch."
95
+ message: import_drawbridge_utils.constants.campaign.confirmation.message,
96
+ subject: import_drawbridge_utils.constants.campaign.confirmation.subject,
97
+ text: import_drawbridge_utils.constants.campaign.confirmation.text
89
98
  },
90
99
  // Nothing to prefill: the step writes its own copy.
91
100
  "step.email.notify": {}
@@ -144,16 +153,120 @@ const prefillRow = ({ entry, step, steps = [] }) => {
144
153
  type: step
145
154
  });
146
155
  };
156
+ const pickedCopy = ({ row, type }) => {
157
+ const previous = stepPrefills[row == null ? void 0 : row.type];
158
+ const untouched = !!(previous == null ? void 0 : previous.subject) && (row == null ? void 0 : row.subject) === previous.subject && (row == null ? void 0 : row.message) === previous.message;
159
+ const { message = "", subject = "", text = "" } = stepPrefills[type] || {};
160
+ if (!untouched && ((row == null ? void 0 : row.subject) || (row == null ? void 0 : row.message))) return null;
161
+ return subject || untouched ? { message, subject, text } : null;
162
+ };
147
163
  const stepReason = ({ entry, saved = [], type }) => {
148
164
  var _a, _b;
149
165
  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;
150
166
  };
167
+ const responseStart = (number) => ({
168
+ email: {
169
+ enabled: true,
170
+ message: import_drawbridge_utils.constants.campaign.confirmation.message,
171
+ score: null,
172
+ subject: import_drawbridge_utils.constants.campaign.confirmation.subject,
173
+ text: import_drawbridge_utils.constants.campaign.confirmation.text
174
+ },
175
+ sms: {
176
+ enabled: number === "verified",
177
+ message: import_drawbridge_utils.constants.campaign.confirmation.sms.giveaway
178
+ }
179
+ });
180
+ const responseParts = ({ autoResponse, campaign, organization, settings }) => {
181
+ var _a, _b;
182
+ const { fields, number } = autoResponse || {};
183
+ const base = "/organizations/" + organization;
184
+ const addField = {
185
+ href: base + "/campaigns/" + campaign + "/form",
186
+ text: "Add field"
187
+ };
188
+ const numberTask = () => {
189
+ if (number === "verified") return null;
190
+ if (number === "error") return {
191
+ button: {
192
+ href: base + "/settings",
193
+ text: "View number"
194
+ },
195
+ message: "Your SMS number wasn't approved.",
196
+ type: "error"
197
+ };
198
+ if (number) return {
199
+ message: "Your SMS number is waiting for approval.",
200
+ type: "warning"
201
+ };
202
+ return {
203
+ button: {
204
+ href: base + "/settings",
205
+ text: "Get a number"
206
+ },
207
+ message: "Texts need an SMS number."
208
+ };
209
+ };
210
+ const emailCan = Boolean(fields == null ? void 0 : fields.email);
211
+ const smsCan = Boolean(fields == null ? void 0 : fields.phone) && number === "verified";
212
+ return {
213
+ can: emailCan || smsCan,
214
+ email: {
215
+ can: emailCan,
216
+ hidden: !(fields == null ? void 0 : fields.email),
217
+ on: emailCan && ((_a = settings == null ? void 0 : settings.email) == null ? void 0 : _a.enabled) === true,
218
+ task: (fields == null ? void 0 : fields.email) ? null : {
219
+ button: addField,
220
+ message: "Emails need an Email field on the form."
221
+ }
222
+ },
223
+ sms: {
224
+ can: smsCan,
225
+ hidden: !(fields == null ? void 0 : fields.phone),
226
+ on: smsCan && ((_b = settings == null ? void 0 : settings.sms) == null ? void 0 : _b.enabled) === true,
227
+ task: (fields == null ? void 0 : fields.phone) ? numberTask() : {
228
+ button: addField,
229
+ message: "Texts need a Phone field on the form."
230
+ }
231
+ }
232
+ };
233
+ };
234
+ const stepAfterPart = ({ enabled, next, other }) => next || enabled !== false && other === true;
235
+ const partToStart = (parts) => {
236
+ if (parts.email.on || parts.sms.on) return null;
237
+ return parts.email.can ? "email" : "sms";
238
+ };
239
+ const issueRow = ({ issue, steps = [] }) => (issue == null ? void 0 : issue.step) ? steps.findIndex((step) => (step == null ? void 0 : step.type) === issue.step || (step == null ? void 0 : step.type) === RESPONSE && messageSteps.includes(issue.step)) : -1;
240
+ const scoreHolds = ({ message, score, subject }) => Boolean(score) && score.subject === subject && score.message === message;
241
+ const responseSave = ({ email, sms }) => ({
242
+ email: {
243
+ enabled: email.enabled,
244
+ message: email.message,
245
+ ...scoreHolds(email) && {
246
+ score: email.score
247
+ },
248
+ subject: email.subject,
249
+ ...email.text && {
250
+ text: email.text
251
+ }
252
+ },
253
+ sms: {
254
+ enabled: sms.enabled,
255
+ message: sms.message
256
+ }
257
+ });
258
+ const plainHtml = (text) => String(text || "").split("\n").map((line) => {
259
+ const marked = line.match(/^\[(.+)\]$/);
260
+ return "<p>" + (marked ? '<span data-variable="placeholder" key="placeholder" label="' + (0, import_html.escapeHtml)(marked[1]) + '"></span>' : (0, import_html.escapeHtml)(line)) + "</p>";
261
+ }).join("");
262
+ const taggedScore = (settings) => (settings == null ? void 0 : settings.score) ? {
263
+ ...settings.score,
264
+ message: (settings == null ? void 0 : settings.message) || "",
265
+ subject: (settings == null ? void 0 : settings.subject) || ""
266
+ } : null;
151
267
  const stepRow = (step = {}, members = []) => {
152
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
268
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
153
269
  return {
154
- // @story workflows/entry-confirmation
155
- // The System email: no remove and no switch ( the api keeps it on ).
156
- confirmation: Boolean(step.confirmation),
157
270
  connectionId: step.connectionId || "",
158
271
  discount: ((_a = step.settings) == null ? void 0 : _a.discount) || null,
159
272
  // @story workflows/step-switch
@@ -165,28 +278,32 @@ const stepRow = (step = {}, members = []) => {
165
278
  // render as an unlabelled chip nobody could identify.
166
279
  members: (((_b = step.settings) == null ? void 0 : _b.members) || []).map((id) => members.find((member) => (member == null ? void 0 : member.id) === id)).filter(Boolean),
167
280
  message: ((_c = step.settings) == null ? void 0 : _c.message) || "",
168
- // THE LAST SPAM CHECK, RE-TAGGED WITH THE COPY IT MEASURED.
169
- //
170
- // The api stores a score without that copy and tests the tag again on the
171
- // way back in, so seeding a bare score would fail the test and clear the
172
- // stored result on every save. Putting the pair back on is the other half of
173
- // a round trip the api already expects — and it is what lets the step panel
174
- // open showing the last result instead of spending a request on a free
175
- // service to be told what is already in the fields.
176
- score: ((_d = step.settings) == null ? void 0 : _d.score) ? {
177
- ...step.settings.score,
178
- message: ((_e = step.settings) == null ? void 0 : _e.message) || "",
179
- subject: ((_f = step.settings) == null ? void 0 : _f.subject) || ""
281
+ score: taggedScore(step.settings),
282
+ // @story workflows/auto-response
283
+ // Its two parts; null on every other row, so every row holds the same keys.
284
+ settings: step.type === RESPONSE ? {
285
+ email: {
286
+ enabled: ((_e = (_d = step.settings) == null ? void 0 : _d.email) == null ? void 0 : _e.enabled) === true,
287
+ message: ((_g = (_f = step.settings) == null ? void 0 : _f.email) == null ? void 0 : _g.message) || "",
288
+ score: taggedScore((_h = step.settings) == null ? void 0 : _h.email),
289
+ subject: ((_j = (_i = step.settings) == null ? void 0 : _i.email) == null ? void 0 : _j.subject) || "",
290
+ text: ((_l = (_k = step.settings) == null ? void 0 : _k.email) == null ? void 0 : _l.text) || ""
291
+ },
292
+ sms: {
293
+ enabled: ((_n = (_m = step.settings) == null ? void 0 : _m.sms) == null ? void 0 : _n.enabled) === true,
294
+ message: ((_p = (_o = step.settings) == null ? void 0 : _o.sms) == null ? void 0 : _p.message) || ""
295
+ }
180
296
  } : null,
181
297
  slug: step.slug || "",
182
- subject: ((_g = step.settings) == null ? void 0 : _g.subject) || "",
298
+ subject: ((_q = step.settings) == null ? void 0 : _q.subject) || "",
183
299
  // The editor writes this only when the merchant touches it, so without a
184
300
  // seed an untouched save dropped the plain rendering of the message.
185
- text: ((_h = step.settings) == null ? void 0 : _h.text) || "",
301
+ text: ((_r = step.settings) == null ? void 0 : _r.text) || "",
186
302
  type: step.type || "",
187
- url: ((_i = step.settings) == null ? void 0 : _i.url) || ""
303
+ url: ((_s = step.settings) == null ? void 0 : _s.url) || ""
188
304
  };
189
305
  };
306
+ const hasWords = (value) => Boolean(String(value || "").replace(/<[^>]*>/g, "").trim());
190
307
  const workflowSchema = import_yup.default.object({
191
308
  steps: import_yup.default.array().of(
192
309
  import_yup.default.object({
@@ -204,11 +321,9 @@ const workflowSchema = import_yup.default.object({
204
321
  return schema;
205
322
  }),
206
323
  // @story workflows/edit
207
- // The editor writes an empty message as "<p></p>", which a plain
208
- // required() accepts: a message needs words, not only markup.
209
324
  message: import_yup.default.string().test("words", "Message is required", function(value) {
210
325
  var _a;
211
- return !messageSteps.includes((_a = this.parent) == null ? void 0 : _a.type) || Boolean(String(value || "").replace(/<[^>]*>/g, "").trim());
326
+ return !messageSteps.includes((_a = this.parent) == null ? void 0 : _a.type) || hasWords(value);
212
327
  }).when("type", ([type], schema) => {
213
328
  if (type === "step.sms.send") {
214
329
  return schema.required("Message is required").max(1500).label("Message");
@@ -218,6 +333,28 @@ const workflowSchema = import_yup.default.object({
218
333
  }
219
334
  return schema;
220
335
  }),
336
+ // @story workflows/auto-response
337
+ // A part's fields are required only while that part is on, with the
338
+ // limits the step declares in utils, so the api never refuses a save
339
+ // the form allowed.
340
+ settings: import_yup.default.object().nullable().when("type", ([type], schema) => type === RESPONSE ? schema.shape({
341
+ email: import_yup.default.object({
342
+ message: import_yup.default.string().when("enabled", {
343
+ is: true,
344
+ then: (part) => part.test("words", "Message is required", hasWords).max(2e3).label("Message")
345
+ }),
346
+ subject: import_yup.default.string().when("enabled", {
347
+ is: true,
348
+ then: (part) => part.required("Subject is required").max(150).label("Subject")
349
+ })
350
+ }),
351
+ sms: import_yup.default.object({
352
+ message: import_yup.default.string().when("enabled", {
353
+ is: true,
354
+ then: (part) => part.required("Message is required").max(1500).label("Message")
355
+ })
356
+ })
357
+ }) : schema),
221
358
  // No minimum. The organization owner is always a recipient, so a
222
359
  // step with no members chosen is complete — requiring one here
223
360
  // made the step unsaveable for a solo merchant, who has no
@@ -233,18 +370,8 @@ const workflowSchema = import_yup.default.object({
233
370
  })
234
371
  )
235
372
  });
236
- const samples = [
237
- {
238
- key: "New lead",
239
- value: "lead"
240
- },
241
- {
242
- key: "Verified their email",
243
- value: "verified"
244
- }
245
- ];
246
- const useEmailPreview = ({ campaign, confirmation = false, event, message, organization, sample, subject, text }) => {
247
- const asked = JSON.stringify({ ...confirmation && { confirmation }, message, sample, subject, text });
373
+ const useEmailPreview = ({ campaign, event, message, organization, subject, text, type }) => {
374
+ const asked = JSON.stringify(teamSteps.includes(type) ? { type } : { message, subject, text });
248
375
  const [settled, setSettled] = (0, import_react.useState)(asked);
249
376
  (0, import_react.useEffect)(() => {
250
377
  const timer = setTimeout(() => setSettled(asked), 400);
@@ -272,18 +399,18 @@ const EmailStepCard = ({
272
399
  off,
273
400
  email: {
274
401
  campaign,
275
- confirmation,
276
402
  event,
277
403
  name,
278
- organization
404
+ organization,
405
+ title,
406
+ type
279
407
  }
280
408
  }) => {
281
- const [sample, setSample] = (0, import_react.useState)(samples[0].value);
282
409
  const [subject, message, text] = (0, import_form.useWatch)({
283
410
  control,
284
411
  name: [name + ".subject", name + ".message", name + ".text"]
285
412
  });
286
- const preview = useEmailPreview({ campaign, confirmation, event, message, organization, sample, subject, text });
413
+ const preview = useEmailPreview({ campaign, event, message, organization, subject, text, type });
287
414
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
288
415
  import_card_section.default,
289
416
  {
@@ -300,7 +427,7 @@ const EmailStepCard = ({
300
427
  },
301
428
  children: [
302
429
  children,
303
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
430
+ emailSteps.includes(type) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
304
431
  import_accordion.default,
305
432
  {
306
433
  ...{
@@ -328,29 +455,17 @@ const EmailStepCard = ({
328
455
  ...{
329
456
  className: off ? "opacity-50" : ""
330
457
  },
331
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
332
- import_preview.default,
458
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_preview.default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
459
+ "iframe",
333
460
  {
334
461
  ...{
335
- states: {
336
- onChange: setSample,
337
- options: samples,
338
- value: sample
339
- }
340
- },
341
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
342
- "iframe",
343
- {
344
- ...{
345
- // The rendered email, as a mail app shows it.
346
- className: "block w-full h-full border-0 bg-white",
347
- srcDoc: (preview == null ? void 0 : preview.html) || "",
348
- title: "Send email"
349
- }
350
- }
351
- )
462
+ // The rendered email, as a mail app shows it.
463
+ className: "block w-full h-full border-0 bg-white",
464
+ srcDoc: (preview == null ? void 0 : preview.html) || "",
465
+ title
466
+ }
352
467
  }
353
- )
468
+ ) })
354
469
  }
355
470
  )
356
471
  ]
@@ -360,7 +475,6 @@ const EmailStepCard = ({
360
475
  const SAMPLE = {
361
476
  email: "sam.rivera@example.com",
362
477
  name: "Sam Rivera",
363
- order: "House espresso \xD7 2, Holiday blend \xD7 1",
364
478
  phone: "+14165550142"
365
479
  };
366
480
  const webhookSample = ({ campaign }) => JSON.stringify({
@@ -375,33 +489,20 @@ const webhookSample = ({ campaign }) => JSON.stringify({
375
489
  number: SAMPLE.phone
376
490
  }
377
491
  }, null, 2);
378
- const teamSample = ({ campaign, event, organization }) => event === "order.insert" ? {
379
- lines: ["New order for " + ((campaign == null ? void 0 : campaign.title) || "your campaign") + " at " + ((organization == null ? void 0 : organization.title) || "your organization") + ": " + SAMPLE.order + ".", "Estimated total $55.00.", "Pickup: Saturday, 9 am to noon.", "Note: Please grind the Holiday blend for a French press."],
380
- title: "New order \u2014 " + ((campaign == null ? void 0 : campaign.title) || "your campaign")
381
- } : {
382
- lines: [SAMPLE.name + " (" + SAMPLE.email + ") entered " + ((campaign == null ? void 0 : campaign.title) || "your campaign") + "."],
383
- title: "1 new entry \u2014 " + ((campaign == null ? void 0 : campaign.title) || "your campaign")
384
- };
385
- const StepPreview = ({ campaign, control, event, image, name, organization, type }) => {
492
+ const TextPreview = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "p-6 font-sans", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "max-w-xs px-4 py-3 rounded-2xl rounded-bl-sm bg-gray-light text-black break-words", children }) });
493
+ const StepPreview = ({ campaign, control, image, name, organization, type }) => {
386
494
  const [message] = (0, import_form.useWatch)({
387
495
  control,
388
496
  name: [name + ".message"]
389
497
  });
390
- if (type === "step.sms.send") return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "p-6 font-sans", children: [
391
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "mb-4 text-xs text-center text-gray-dark", children: organization == null ? void 0 : organization.title }),
392
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "max-w-xs px-4 py-3 rounded-2xl rounded-bl-sm bg-gray-light text-black", children: [
393
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "whitespace-pre-wrap", children: message }),
394
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "mt-2", children: "Reply STOP to opt out" })
395
- ] })
498
+ const brand = (0, import_sms.smsBrandLine)(organization == null ? void 0 : organization.title, message);
499
+ if (type === "step.sms.send") return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextPreview, { children: [
500
+ brand && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: brand }),
501
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "whitespace-pre-wrap", children: message }),
502
+ (campaign == null ? void 0 : campaign.awarding) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "mt-2 px-2 py-1 rounded border border-dashed border-gray-dark text-gray-dark", children: "The entrant's missions appear here" }),
503
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "mt-2", children: "Reply STOP to opt out" })
396
504
  ] });
397
505
  if (type === "step.webhook.send") return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "p-6 text-xs whitespace-pre-wrap break-all font-mono", children: "X-Drawbridge-Signature: t=\u2026,v1=\u2026\n\n" + webhookSample({ campaign }) });
398
- if (teamSteps.includes(type)) {
399
- const { lines, title } = teamSample({ campaign, event, organization });
400
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "p-6 space-y-3 font-sans", children: [
401
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-lg font-bold", children: title }),
402
- lines.map((line) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: line }, line))
403
- ] });
404
- }
405
506
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "min-h-screen flex flex-col items-center justify-center gap-3 p-6 text-gray-dark", children: [
406
507
  image && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
407
508
  import_image.default,
@@ -419,14 +520,330 @@ const StepPreview = ({ campaign, control, event, image, name, organization, type
419
520
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "No preview available" })
420
521
  ] });
421
522
  };
523
+ const LeadEmailNote = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
524
+ "p",
525
+ {
526
+ ...{
527
+ className: "text-sm text-gray-dark"
528
+ },
529
+ children: "Drawbridge adds the entrant's order and missions under your message. You can't edit or remove them."
530
+ }
531
+ );
532
+ const RESPONSE_STATES = [
533
+ {
534
+ key: "Email",
535
+ value: "email"
536
+ },
537
+ {
538
+ key: "Text",
539
+ value: "sms"
540
+ }
541
+ ];
542
+ const ResponseText = ({ className, id, text }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
543
+ "div",
544
+ {
545
+ ...{
546
+ className,
547
+ id
548
+ },
549
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
550
+ import_input_editor.EditorView,
551
+ {
552
+ ...{
553
+ value: plainHtml(text)
554
+ }
555
+ }
556
+ )
557
+ }
558
+ );
559
+ const ResponseStepCard = ({
560
+ card,
561
+ children,
562
+ control,
563
+ disabled,
564
+ formState,
565
+ off,
566
+ onChecking,
567
+ response: {
568
+ autoResponse,
569
+ campaign,
570
+ enabled,
571
+ event,
572
+ id,
573
+ index,
574
+ organization,
575
+ settings,
576
+ title,
577
+ variables
578
+ },
579
+ setValue
580
+ }) => {
581
+ var _a, _b, _c, _d, _e;
582
+ const [picked, setPicked] = (0, import_react.useState)("email");
583
+ const name = `steps.${index}`;
584
+ const parts = responseParts({ autoResponse, campaign, organization, settings });
585
+ const shown = parts.email.hidden ? "sms" : parts.sms.hidden ? "email" : picked;
586
+ const placeholders = autoResponse == null ? void 0 : autoResponse.placeholders;
587
+ const preview = useEmailPreview({
588
+ campaign,
589
+ event: parts.email.hidden ? null : event,
590
+ message: (_a = settings == null ? void 0 : settings.email) == null ? void 0 : _a.message,
591
+ organization,
592
+ subject: (_b = settings == null ? void 0 : settings.email) == null ? void 0 : _b.subject,
593
+ text: (_c = settings == null ? void 0 : settings.email) == null ? void 0 : _c.text
594
+ });
595
+ const brand = (0, import_sms.smsBrandLine)(title, (_d = settings == null ? void 0 : settings.sms) == null ? void 0 : _d.message);
596
+ const partSwitch = ({ label, message, other, part }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
597
+ import_form.Controller,
598
+ {
599
+ ...{
600
+ control,
601
+ name: name + ".settings." + part + ".enabled",
602
+ render: ({ field: { onChange, value } }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
603
+ import_input_group.default,
604
+ {
605
+ ...{
606
+ input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
607
+ import_input_switch.default,
608
+ {
609
+ ...{
610
+ "aria-label": label,
611
+ disabled: disabled || !parts[part].can,
612
+ onChange: (next) => {
613
+ var _a2;
614
+ onChange(next);
615
+ setValue(name + ".enabled", stepAfterPart({ enabled, next, other: (_a2 = settings == null ? void 0 : settings[other]) == null ? void 0 : _a2.enabled }));
616
+ setPicked(part);
617
+ },
618
+ value: parts[part].can && value === true
619
+ }
620
+ }
621
+ ),
622
+ label,
623
+ message
624
+ }
625
+ }
626
+ )
627
+ }
628
+ }
629
+ );
630
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
631
+ import_card_section.default,
632
+ {
633
+ ...{
634
+ ...card,
635
+ columns: 2
636
+ },
637
+ children: [
638
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
639
+ "div",
640
+ {
641
+ ...{
642
+ className: "space-y-6" + (off ? " opacity-50" : "")
643
+ },
644
+ children: [
645
+ children,
646
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
647
+ "div",
648
+ {
649
+ ...{
650
+ className: "pt-6 border-t border-gray space-y-6"
651
+ },
652
+ children: [
653
+ partSwitch({ label: "Email", other: "sms", part: "email" }),
654
+ parts.email.task && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_card_task.default, { ...parts.email.task }),
655
+ !parts.email.hidden && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [
656
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
657
+ "div",
658
+ {
659
+ ...{
660
+ className: "space-y-3" + (parts.email.on ? "" : " opacity-50")
661
+ },
662
+ children: [
663
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
664
+ import_form_notification.FormNotification,
665
+ {
666
+ ...{
667
+ control,
668
+ disabled: disabled || !parts.email.on,
669
+ formState,
670
+ onChecking,
671
+ setValue,
672
+ values: {
673
+ id,
674
+ name: name + ".settings.email",
675
+ organization,
676
+ variables
677
+ }
678
+ }
679
+ }
680
+ ),
681
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LeadEmailNote, {})
682
+ ]
683
+ }
684
+ ),
685
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
686
+ import_input_group.default,
687
+ {
688
+ ...{
689
+ input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
690
+ ResponseText,
691
+ {
692
+ ...{
693
+ className: "w-full border border-inherit rounded px-3 py-2 disabled",
694
+ text: preview == null ? void 0 : preview.text
695
+ }
696
+ }
697
+ ),
698
+ label: "Plain-text version"
699
+ }
700
+ }
701
+ )
702
+ ] })
703
+ ]
704
+ }
705
+ ),
706
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
707
+ "div",
708
+ {
709
+ ...{
710
+ className: "mt-10 pt-10 border-t border-gray-dark space-y-6"
711
+ },
712
+ children: [
713
+ partSwitch({
714
+ label: "Text",
715
+ // The line goes with the part's fields when the form lacks the field.
716
+ message: !parts.sms.hidden && "Sends to entrants who agree to texts. Each text costs 2 actions, and a long text costs more.",
717
+ other: "email",
718
+ part: "sms"
719
+ }),
720
+ parts.sms.task && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_card_task.default, { ...parts.sms.task }),
721
+ !parts.sms.hidden && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
722
+ import_form.Controller,
723
+ {
724
+ ...{
725
+ control,
726
+ name: name + ".settings.sms.message",
727
+ render: ({ field: { onChange, value } }) => {
728
+ var _a2, _b2, _c2, _d2, _e2, _f;
729
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
730
+ "div",
731
+ {
732
+ ...{
733
+ className: parts.sms.on ? "" : "opacity-50"
734
+ },
735
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
736
+ import_input_group.default,
737
+ {
738
+ ...{
739
+ error: (_f = (_e2 = (_d2 = (_c2 = (_b2 = (_a2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a2.steps) == null ? void 0 : _b2[index]) == null ? void 0 : _c2.settings) == null ? void 0 : _d2.sms) == null ? void 0 : _e2.message) == null ? void 0 : _f.message,
740
+ input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
741
+ import_input_editor.default,
742
+ {
743
+ ...{
744
+ disabled: disabled || !parts.sms.on,
745
+ ...(placeholders == null ? void 0 : placeholders.missions) && {
746
+ locked: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ResponseText, { ...{ text: "[" + placeholders.missions + "]" } })
747
+ },
748
+ onChange: ({ text }) => onChange(text),
749
+ plain: true,
750
+ value: value || ""
751
+ }
752
+ }
753
+ ),
754
+ label: "Message"
755
+ }
756
+ }
757
+ )
758
+ }
759
+ );
760
+ }
761
+ }
762
+ }
763
+ )
764
+ ]
765
+ }
766
+ )
767
+ ]
768
+ }
769
+ ),
770
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
771
+ "div",
772
+ {
773
+ ...{
774
+ className: off || !parts[shown].on ? "opacity-50" : ""
775
+ },
776
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
777
+ import_preview.default,
778
+ {
779
+ ...{
780
+ ...!parts.email.hidden && !parts.sms.hidden && {
781
+ states: {
782
+ onChange: setPicked,
783
+ options: RESPONSE_STATES,
784
+ value: shown
785
+ }
786
+ }
787
+ },
788
+ children: shown === "email" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
789
+ "iframe",
790
+ {
791
+ ...{
792
+ className: "block w-full h-full border-0 bg-white",
793
+ srcDoc: (preview == null ? void 0 : preview.html) || "",
794
+ title: "Auto response"
795
+ }
796
+ }
797
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextPreview, { children: [
798
+ brand && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: brand }),
799
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "whitespace-pre-wrap", children: (_e = settings == null ? void 0 : settings.sms) == null ? void 0 : _e.message }),
800
+ (placeholders == null ? void 0 : placeholders.missions) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
801
+ ResponseText,
802
+ {
803
+ ...{
804
+ className: "mt-2",
805
+ text: "[" + placeholders.missions + "]"
806
+ }
807
+ }
808
+ ),
809
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "mt-2", children: "Reply STOP to opt out" })
810
+ ] })
811
+ }
812
+ )
813
+ }
814
+ )
815
+ ]
816
+ }
817
+ );
818
+ };
422
819
  const StepCard = ({
423
820
  children,
424
821
  control,
822
+ disabled,
425
823
  email,
824
+ formState,
426
825
  off,
826
+ onChecking,
427
827
  preview,
828
+ response,
829
+ setValue,
428
830
  ...card
429
- }) => email ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
831
+ }) => response ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
832
+ ResponseStepCard,
833
+ {
834
+ ...{
835
+ card,
836
+ control,
837
+ disabled,
838
+ formState,
839
+ off,
840
+ onChecking,
841
+ response,
842
+ setValue
843
+ },
844
+ children
845
+ }
846
+ ) : email ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
430
847
  EmailStepCard,
431
848
  {
432
849
  ...{
@@ -473,13 +890,14 @@ const FormOrganizationWorkflowEdit = ({
473
890
  onSuccess,
474
891
  values
475
892
  }) => {
476
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
893
+ var _a, _b, _c, _d, _e, _f, _g, _h;
477
894
  const event = (_a = values == null ? void 0 : values.trigger) == null ? void 0 : _a.event;
478
895
  const { items: memberItems, loading: membersLoading } = useOrganizationMembers(values == null ? void 0 : values.organization);
479
896
  const queryClient = (0, import_react_query.useQueryClient)();
480
897
  const organizationData = queryClient.getQueryData(["organization", values == null ? void 0 : values.organization]);
481
898
  const ownerEmail = organizationData.owner.email;
482
899
  const smsActive = (0, import_sms.smsNumberActive)(organizationData);
900
+ const campaignData = queryClient.getQueryData(["campaign", values == null ? void 0 : values.campaign]);
483
901
  const commerceConnectionId = ((_b = ((catalog == null ? void 0 : catalog.steps) || []).find(
484
902
  (s) => s.value === "step.commerce.customer.insert" || s.value === "step.commerce.code.issue"
485
903
  )) == null ? void 0 : _b.connectionId) || null;
@@ -514,7 +932,7 @@ const FormOrganizationWorkflowEdit = ({
514
932
  control,
515
933
  name: "steps"
516
934
  });
517
- const issueIndex = ((_g = values == null ? void 0 : values.issue) == null ? void 0 : _g.step) ? (watchedSteps || []).findIndex((step) => (step == null ? void 0 : step.type) === values.issue.step) : -1;
935
+ const issueIndex = issueRow({ issue: values == null ? void 0 : values.issue, steps: watchedSteps || [] });
518
936
  const getAvailableVariables = (index) => stepVariables(catalog, watchedSteps, index);
519
937
  const loading = membersLoading || commerceConnection.isLoading;
520
938
  const prefilled = (0, import_react.useRef)(false);
@@ -648,13 +1066,14 @@ const FormOrganizationWorkflowEdit = ({
648
1066
  }) => {
649
1067
  try {
650
1068
  const body = {
651
- steps: steps.map(({ confirmation, connectionId, discount, enabled, members, message, score, slug, subject, text, type, url }, index) => {
652
- const settings = {};
1069
+ steps: steps.map(({ connectionId, discount, enabled, members, message, score, settings: parts, slug, subject, text, type, url }, index) => {
1070
+ const settings = type === RESPONSE ? responseSave(parts) : {};
1071
+ if (type === RESPONSE && parts.email.score && !settings.email.score) setValue("steps." + index + ".settings.email.score", null);
653
1072
  if (type === "step.webhook.send") settings.url = url;
654
1073
  if (emailSteps.includes(type)) settings.subject = subject;
655
1074
  if (messageSteps.includes(type)) settings.message = message;
656
1075
  if (emailSteps.includes(type)) {
657
- if (score && score.subject === subject && score.message === message) settings.score = score;
1076
+ if (scoreHolds({ message, score, subject })) settings.score = score;
658
1077
  else if (score) setValue("steps." + index + ".score", null);
659
1078
  if (text) settings.text = text;
660
1079
  }
@@ -665,8 +1084,6 @@ const FormOrganizationWorkflowEdit = ({
665
1084
  const resolvedConnectionId = (catalogStep == null ? void 0 : catalogStep.connectionId) || connectionId || null;
666
1085
  const resolvedSlug = (catalogStep == null ? void 0 : catalogStep.slug) || slug || null;
667
1086
  return {
668
- // The System email row names itself; the api keeps it only where it was.
669
- ...confirmation && { confirmation: true },
670
1087
  ...resolvedConnectionId && { connectionId: resolvedConnectionId },
671
1088
  enabled: enabled !== false,
672
1089
  ...resolvedSlug && { slug: resolvedSlug },
@@ -737,7 +1154,7 @@ const FormOrganizationWorkflowEdit = ({
737
1154
  import_input_group.default,
738
1155
  {
739
1156
  ...{
740
- error: (_i = (_h = formState == null ? void 0 : formState.errors) == null ? void 0 : _h.steps) == null ? void 0 : _i.message,
1157
+ error: (_h = (_g = formState == null ? void 0 : formState.errors) == null ? void 0 : _g.steps) == null ? void 0 : _h.message,
741
1158
  input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
742
1159
  import_input_array.InputArraySortable,
743
1160
  {
@@ -758,6 +1175,12 @@ const FormOrganizationWorkflowEdit = ({
758
1175
  children: ({ field, handle, index, remove }) => {
759
1176
  var _a2;
760
1177
  const step = (watchedSteps == null ? void 0 : watchedSteps[index]) || field;
1178
+ const parts = step.type === RESPONSE && responseParts({
1179
+ autoResponse: values == null ? void 0 : values.autoResponse,
1180
+ campaign: values == null ? void 0 : values.campaign,
1181
+ organization: values == null ? void 0 : values.organization,
1182
+ settings: step.settings
1183
+ });
761
1184
  return (
762
1185
  // @story workflows/edit
763
1186
  // EACH STEP IS ITS OWN CARD in the flow under the Trigger card,
@@ -769,24 +1192,42 @@ const FormOrganizationWorkflowEdit = ({
769
1192
  {
770
1193
  ...{
771
1194
  control,
1195
+ disabled: disabled || (formState == null ? void 0 : formState.isSubmitting),
1196
+ formState,
1197
+ onChecking,
1198
+ setValue,
1199
+ // @story workflows/auto-response
1200
+ response: step.type === RESPONSE && {
1201
+ autoResponse: values == null ? void 0 : values.autoResponse,
1202
+ campaign: values == null ? void 0 : values.campaign,
1203
+ enabled: step.enabled,
1204
+ event,
1205
+ id: field.id,
1206
+ index,
1207
+ organization: values == null ? void 0 : values.organization,
1208
+ settings: step.settings,
1209
+ title: organizationData == null ? void 0 : organizationData.title,
1210
+ variables: getAvailableVariables(index)
1211
+ },
772
1212
  // @story workflows/send-email
773
1213
  // A Send email step shows its email beside its form.
774
1214
  off: step.enabled === false,
775
1215
  // Every other step with a type has its preview too.
776
- preview: step.type && !emailSteps.includes(step.type) && {
777
- campaign: queryClient.getQueryData(["campaign", values == null ? void 0 : values.campaign]),
778
- event,
1216
+ preview: step.type && !renderedSteps.includes(step.type) && {
1217
+ campaign: campaignData,
779
1218
  image: ((_a2 = ((catalog == null ? void 0 : catalog.steps) || []).find((entry) => entry.value === step.type)) == null ? void 0 : _a2.image) || null,
780
1219
  name: `steps.${index}`,
781
1220
  organization: organizationData,
782
1221
  type: step.type
783
1222
  },
784
- email: emailSteps.includes(step.type) && {
1223
+ // Send email and Email notification show the email the api renders.
1224
+ email: renderedSteps.includes(step.type) && {
785
1225
  campaign: values == null ? void 0 : values.campaign,
786
- confirmation: step.confirmation,
787
1226
  event,
788
1227
  name: `steps.${index}`,
789
- organization: values == null ? void 0 : values.organization
1228
+ organization: values == null ? void 0 : values.organization,
1229
+ title: emailSteps.includes(step.type) ? "Send email" : "Email notification",
1230
+ type: step.type
790
1231
  },
791
1232
  cta: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
792
1233
  "span",
@@ -796,7 +1237,7 @@ const FormOrganizationWorkflowEdit = ({
796
1237
  },
797
1238
  children: [
798
1239
  renderStepBadge(step),
799
- !lockedStep(index) && !step.confirmation && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1240
+ !lockedStep(index) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
800
1241
  import_input_array.InputArrayControl,
801
1242
  {
802
1243
  ...{
@@ -806,35 +1247,7 @@ const FormOrganizationWorkflowEdit = ({
806
1247
  },
807
1248
  "remove"
808
1249
  ),
809
- step.confirmation ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
810
- import_tooltip.default,
811
- {
812
- ...{
813
- content: "System email"
814
- },
815
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
816
- "span",
817
- {
818
- ...{
819
- className: "inline-flex pointer-events-none"
820
- },
821
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
822
- import_input_switch.default,
823
- {
824
- ...{
825
- "aria-label": "System email, always on",
826
- disabled: true,
827
- onChange: () => {
828
- },
829
- small: true,
830
- value: true
831
- }
832
- }
833
- )
834
- }
835
- )
836
- }
837
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1250
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
838
1251
  import_form.Controller,
839
1252
  {
840
1253
  ...{
@@ -847,10 +1260,13 @@ const FormOrganizationWorkflowEdit = ({
847
1260
  {
848
1261
  ...{
849
1262
  "aria-label": ((_a3 = ((catalog == null ? void 0 : catalog.steps) || []).find((entry) => entry.value === step.type)) == null ? void 0 : _a3.key) || "Step " + (index + 1),
850
- disabled: disabled || (formState == null ? void 0 : formState.isSubmitting),
851
- onChange,
1263
+ disabled: disabled || (formState == null ? void 0 : formState.isSubmitting) || parts && !parts.can,
1264
+ onChange: (next) => {
1265
+ onChange(next);
1266
+ if (parts && next && partToStart(parts)) setValue(`steps.${index}.settings.${partToStart(parts)}.enabled`, true);
1267
+ },
852
1268
  small: true,
853
- value: value !== false
1269
+ value: value !== false && (!parts || parts.can)
854
1270
  }
855
1271
  }
856
1272
  );
@@ -880,7 +1296,8 @@ const FormOrganizationWorkflowEdit = ({
880
1296
  {
881
1297
  ...{
882
1298
  // A step switched off is greyed; its settings are kept.
883
- className: "space-y-3" + (step.enabled === false ? " opacity-50" : "")
1299
+ // Auto response's whole card greys, its parts as well.
1300
+ className: "space-y-3" + (step.enabled === false && !parts ? " opacity-50" : "")
884
1301
  },
885
1302
  children: [
886
1303
  issueIndex === index && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -909,14 +1326,17 @@ const FormOrganizationWorkflowEdit = ({
909
1326
  {
910
1327
  ...{
911
1328
  onChange: (val) => {
1329
+ var _a4;
912
1330
  const [type] = val.split("::");
913
1331
  const option = getStepOptions(index).find((o) => o.value === val);
1332
+ const copy = pickedCopy({ row: getValues(`steps.${index}`), type });
1333
+ setValue(`steps.${index}.settings`, type === RESPONSE ? responseStart((_a4 = values == null ? void 0 : values.autoResponse) == null ? void 0 : _a4.number) : null);
914
1334
  onChange(type);
915
1335
  setValue(`steps.${index}.connectionId`, (option == null ? void 0 : option.connectionId) || "");
916
1336
  setValue(`steps.${index}.slug`, (option == null ? void 0 : option.slug) || "");
1337
+ if (copy) Object.entries(copy).forEach(([key, value]) => setValue(`steps.${index}.${key}`, value));
917
1338
  },
918
- // The System email is always a Send email.
919
- disabled: lockedStep(index) || Boolean(step.confirmation),
1339
+ disabled: lockedStep(index),
920
1340
  options: getStepOptions(index),
921
1341
  // Resolved from the WHOLE ROW, not from this path: the
922
1342
  // option value carries a connection the type alone cannot
@@ -933,6 +1353,15 @@ const FormOrganizationWorkflowEdit = ({
933
1353
  }
934
1354
  }
935
1355
  ),
1356
+ firstEntryOnly({ campaign: campaignData, event, type: step.type }) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1357
+ "p",
1358
+ {
1359
+ ...{
1360
+ className: "text-sm text-gray-dark"
1361
+ },
1362
+ children: "Runs on a person's first entry only."
1363
+ }
1364
+ ),
936
1365
  step.type === "step.webhook.send" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
937
1366
  import_form.Controller,
938
1367
  {
@@ -1032,15 +1461,7 @@ const FormOrganizationWorkflowEdit = ({
1032
1461
  }
1033
1462
  }
1034
1463
  ),
1035
- step.confirmation && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1036
- "p",
1037
- {
1038
- ...{
1039
- className: "text-sm text-gray-dark"
1040
- },
1041
- children: "Drawbridge adds the entrant's order and missions under your message. You can't edit or remove them."
1042
- }
1043
- ),
1464
+ event === "lead.insert" && emailSteps.includes(step.type) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LeadEmailNote, {}),
1044
1465
  step.type === "step.sms.send" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1045
1466
  import_form.Controller,
1046
1467
  {
@@ -1175,12 +1596,22 @@ const FormOrganizationWorkflowEdit = ({
1175
1596
  // Annotate the CommonJS export names for ESM import in node:
1176
1597
  0 && (module.exports = {
1177
1598
  FormOrganizationWorkflowEdit,
1599
+ RESPONSE,
1178
1600
  SAMPLE,
1601
+ TextPreview,
1602
+ firstEntryOnly,
1603
+ issueRow,
1604
+ partToStart,
1605
+ pickedCopy,
1606
+ plainHtml,
1179
1607
  prefillRow,
1608
+ responseParts,
1609
+ responseSave,
1610
+ responseStart,
1611
+ stepAfterPart,
1180
1612
  stepReason,
1181
1613
  stepRow,
1182
1614
  stepVariables,
1183
- teamSample,
1184
1615
  webhookSample,
1185
1616
  workflowSchema
1186
1617
  });