@drawbridge/components 0.1.16 → 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.
@@ -28,11 +28,19 @@ 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,
32
33
  TextPreview: () => TextPreview,
33
34
  firstEntryOnly: () => firstEntryOnly,
35
+ issueRow: () => issueRow,
36
+ partToStart: () => partToStart,
34
37
  pickedCopy: () => pickedCopy,
38
+ plainHtml: () => plainHtml,
35
39
  prefillRow: () => prefillRow,
40
+ responseParts: () => responseParts,
41
+ responseSave: () => responseSave,
42
+ responseStart: () => responseStart,
43
+ stepAfterPart: () => stepAfterPart,
36
44
  stepReason: () => stepReason,
37
45
  stepRow: () => stepRow,
38
46
  stepVariables: () => stepVariables,
@@ -46,6 +54,7 @@ var import_link = __toESM(require("./link"));
46
54
  var import_react = require("react");
47
55
  var import_drawbridge_utils = require("@drawbridge/drawbridge-utils");
48
56
  var import_fetch = require("@drawbridge/drawbridge-utils/fetch");
57
+ var import_html = require("@drawbridge/drawbridge-utils/html");
49
58
  var import_form = require("../shared/lib/form");
50
59
  var import_react_query = require("@tanstack/react-query");
51
60
  var import_yup = __toESM(require("../shared/lib/yup"));
@@ -58,6 +67,7 @@ var import_input_url = __toESM(require("../shared/input-url"));
58
67
  var import_input_resource = __toESM(require("./input-resource"));
59
68
  var import_input_combobox = __toESM(require("./input-combobox"));
60
69
  var import_form_notification = require("./form-notification");
70
+ var import_input_editor = __toESM(require("./input-editor"));
61
71
  var import_input_array = require("./input-array");
62
72
  var import_badge = __toESM(require("../shared/badge"));
63
73
  var import_input_switch = __toESM(require("../shared/input-switch"));
@@ -73,9 +83,10 @@ const emailSteps = ["step.email.send"];
73
83
  const teamSteps = ["step.email.notify"];
74
84
  const messageSteps = [...emailSteps, "step.sms.send"];
75
85
  const renderedSteps = [...emailSteps, ...teamSteps];
86
+ const RESPONSE = "step.response.send";
76
87
  const firstEntryOnly = ({ campaign, event, type }) => {
77
88
  var _a, _b;
78
- if (event !== "lead.insert" || !type || emailSteps.includes(type)) return false;
89
+ if (event !== "lead.insert" || !type || emailSteps.includes(type) || type === RESPONSE) return false;
79
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";
80
91
  return true;
81
92
  };
@@ -153,8 +164,108 @@ const stepReason = ({ entry, saved = [], type }) => {
153
164
  var _a, _b;
154
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;
155
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;
156
267
  const stepRow = (step = {}, members = []) => {
157
- 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;
158
269
  return {
159
270
  connectionId: step.connectionId || "",
160
271
  discount: ((_a = step.settings) == null ? void 0 : _a.discount) || null,
@@ -167,28 +278,32 @@ const stepRow = (step = {}, members = []) => {
167
278
  // render as an unlabelled chip nobody could identify.
168
279
  members: (((_b = step.settings) == null ? void 0 : _b.members) || []).map((id) => members.find((member) => (member == null ? void 0 : member.id) === id)).filter(Boolean),
169
280
  message: ((_c = step.settings) == null ? void 0 : _c.message) || "",
170
- // THE LAST SPAM CHECK, RE-TAGGED WITH THE COPY IT MEASURED.
171
- //
172
- // The api stores a score without that copy and tests the tag again on the
173
- // way back in, so seeding a bare score would fail the test and clear the
174
- // stored result on every save. Putting the pair back on is the other half of
175
- // a round trip the api already expects — and it is what lets the step panel
176
- // open showing the last result instead of spending a request on a free
177
- // service to be told what is already in the fields.
178
- score: ((_d = step.settings) == null ? void 0 : _d.score) ? {
179
- ...step.settings.score,
180
- message: ((_e = step.settings) == null ? void 0 : _e.message) || "",
181
- 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
+ }
182
296
  } : null,
183
297
  slug: step.slug || "",
184
- subject: ((_g = step.settings) == null ? void 0 : _g.subject) || "",
298
+ subject: ((_q = step.settings) == null ? void 0 : _q.subject) || "",
185
299
  // The editor writes this only when the merchant touches it, so without a
186
300
  // seed an untouched save dropped the plain rendering of the message.
187
- text: ((_h = step.settings) == null ? void 0 : _h.text) || "",
301
+ text: ((_r = step.settings) == null ? void 0 : _r.text) || "",
188
302
  type: step.type || "",
189
- url: ((_i = step.settings) == null ? void 0 : _i.url) || ""
303
+ url: ((_s = step.settings) == null ? void 0 : _s.url) || ""
190
304
  };
191
305
  };
306
+ const hasWords = (value) => Boolean(String(value || "").replace(/<[^>]*>/g, "").trim());
192
307
  const workflowSchema = import_yup.default.object({
193
308
  steps: import_yup.default.array().of(
194
309
  import_yup.default.object({
@@ -206,11 +321,9 @@ const workflowSchema = import_yup.default.object({
206
321
  return schema;
207
322
  }),
208
323
  // @story workflows/edit
209
- // The editor writes an empty message as "<p></p>", which a plain
210
- // required() accepts: a message needs words, not only markup.
211
324
  message: import_yup.default.string().test("words", "Message is required", function(value) {
212
325
  var _a;
213
- 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);
214
327
  }).when("type", ([type], schema) => {
215
328
  if (type === "step.sms.send") {
216
329
  return schema.required("Message is required").max(1500).label("Message");
@@ -220,6 +333,28 @@ const workflowSchema = import_yup.default.object({
220
333
  }
221
334
  return schema;
222
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),
223
358
  // No minimum. The organization owner is always a recipient, so a
224
359
  // step with no members chosen is complete — requiring one here
225
360
  // made the step unsaveable for a solo merchant, who has no
@@ -385,14 +520,330 @@ const StepPreview = ({ campaign, control, image, name, organization, type }) =>
385
520
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "No preview available" })
386
521
  ] });
387
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
+ };
388
819
  const StepCard = ({
389
820
  children,
390
821
  control,
822
+ disabled,
391
823
  email,
824
+ formState,
392
825
  off,
826
+ onChecking,
393
827
  preview,
828
+ response,
829
+ setValue,
394
830
  ...card
395
- }) => 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)(
396
847
  EmailStepCard,
397
848
  {
398
849
  ...{
@@ -439,7 +890,7 @@ const FormOrganizationWorkflowEdit = ({
439
890
  onSuccess,
440
891
  values
441
892
  }) => {
442
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
893
+ var _a, _b, _c, _d, _e, _f, _g, _h;
443
894
  const event = (_a = values == null ? void 0 : values.trigger) == null ? void 0 : _a.event;
444
895
  const { items: memberItems, loading: membersLoading } = useOrganizationMembers(values == null ? void 0 : values.organization);
445
896
  const queryClient = (0, import_react_query.useQueryClient)();
@@ -481,7 +932,7 @@ const FormOrganizationWorkflowEdit = ({
481
932
  control,
482
933
  name: "steps"
483
934
  });
484
- 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 || [] });
485
936
  const getAvailableVariables = (index) => stepVariables(catalog, watchedSteps, index);
486
937
  const loading = membersLoading || commerceConnection.isLoading;
487
938
  const prefilled = (0, import_react.useRef)(false);
@@ -615,13 +1066,14 @@ const FormOrganizationWorkflowEdit = ({
615
1066
  }) => {
616
1067
  try {
617
1068
  const body = {
618
- steps: steps.map(({ connectionId, discount, enabled, members, message, score, slug, subject, text, type, url }, index) => {
619
- 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);
620
1072
  if (type === "step.webhook.send") settings.url = url;
621
1073
  if (emailSteps.includes(type)) settings.subject = subject;
622
1074
  if (messageSteps.includes(type)) settings.message = message;
623
1075
  if (emailSteps.includes(type)) {
624
- if (score && score.subject === subject && score.message === message) settings.score = score;
1076
+ if (scoreHolds({ message, score, subject })) settings.score = score;
625
1077
  else if (score) setValue("steps." + index + ".score", null);
626
1078
  if (text) settings.text = text;
627
1079
  }
@@ -702,7 +1154,7 @@ const FormOrganizationWorkflowEdit = ({
702
1154
  import_input_group.default,
703
1155
  {
704
1156
  ...{
705
- 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,
706
1158
  input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
707
1159
  import_input_array.InputArraySortable,
708
1160
  {
@@ -723,6 +1175,12 @@ const FormOrganizationWorkflowEdit = ({
723
1175
  children: ({ field, handle, index, remove }) => {
724
1176
  var _a2;
725
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
+ });
726
1184
  return (
727
1185
  // @story workflows/edit
728
1186
  // EACH STEP IS ITS OWN CARD in the flow under the Trigger card,
@@ -734,6 +1192,23 @@ const FormOrganizationWorkflowEdit = ({
734
1192
  {
735
1193
  ...{
736
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
+ },
737
1212
  // @story workflows/send-email
738
1213
  // A Send email step shows its email beside its form.
739
1214
  off: step.enabled === false,
@@ -785,10 +1260,13 @@ const FormOrganizationWorkflowEdit = ({
785
1260
  {
786
1261
  ...{
787
1262
  "aria-label": ((_a3 = ((catalog == null ? void 0 : catalog.steps) || []).find((entry) => entry.value === step.type)) == null ? void 0 : _a3.key) || "Step " + (index + 1),
788
- disabled: disabled || (formState == null ? void 0 : formState.isSubmitting),
789
- 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
+ },
790
1268
  small: true,
791
- value: value !== false
1269
+ value: value !== false && (!parts || parts.can)
792
1270
  }
793
1271
  }
794
1272
  );
@@ -818,7 +1296,8 @@ const FormOrganizationWorkflowEdit = ({
818
1296
  {
819
1297
  ...{
820
1298
  // A step switched off is greyed; its settings are kept.
821
- 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" : "")
822
1301
  },
823
1302
  children: [
824
1303
  issueIndex === index && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -847,9 +1326,11 @@ const FormOrganizationWorkflowEdit = ({
847
1326
  {
848
1327
  ...{
849
1328
  onChange: (val) => {
1329
+ var _a4;
850
1330
  const [type] = val.split("::");
851
1331
  const option = getStepOptions(index).find((o) => o.value === val);
852
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);
853
1334
  onChange(type);
854
1335
  setValue(`steps.${index}.connectionId`, (option == null ? void 0 : option.connectionId) || "");
855
1336
  setValue(`steps.${index}.slug`, (option == null ? void 0 : option.slug) || "");
@@ -980,15 +1461,7 @@ const FormOrganizationWorkflowEdit = ({
980
1461
  }
981
1462
  }
982
1463
  ),
983
- event === "lead.insert" && emailSteps.includes(step.type) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
984
- "p",
985
- {
986
- ...{
987
- className: "text-sm text-gray-dark"
988
- },
989
- children: "Drawbridge adds the entrant's order and missions under your message. You can't edit or remove them."
990
- }
991
- ),
1464
+ event === "lead.insert" && emailSteps.includes(step.type) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LeadEmailNote, {}),
992
1465
  step.type === "step.sms.send" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
993
1466
  import_form.Controller,
994
1467
  {
@@ -1123,11 +1596,19 @@ const FormOrganizationWorkflowEdit = ({
1123
1596
  // Annotate the CommonJS export names for ESM import in node:
1124
1597
  0 && (module.exports = {
1125
1598
  FormOrganizationWorkflowEdit,
1599
+ RESPONSE,
1126
1600
  SAMPLE,
1127
1601
  TextPreview,
1128
1602
  firstEntryOnly,
1603
+ issueRow,
1604
+ partToStart,
1129
1605
  pickedCopy,
1606
+ plainHtml,
1130
1607
  prefillRow,
1608
+ responseParts,
1609
+ responseSave,
1610
+ responseStart,
1611
+ stepAfterPart,
1131
1612
  stepReason,
1132
1613
  stepRow,
1133
1614
  stepVariables,