@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.
@@ -4,6 +4,7 @@ import Link from "./link.mjs";
4
4
  import { Fragment, useCallback, useEffect, useRef, useState } from "react";
5
5
  import { constants } from "@drawbridge/drawbridge-utils";
6
6
  import { request } from "@drawbridge/drawbridge-utils/fetch";
7
+ import { escapeHtml } from "@drawbridge/drawbridge-utils/html";
7
8
  import { useForm, useWatch, Controller } from "../shared/lib/form.mjs";
8
9
  import { keepPreviousData, useQuery, useQueryClient } from "@tanstack/react-query";
9
10
  import yup, { resolver } from "../shared/lib/yup.mjs";
@@ -16,6 +17,7 @@ import InputUrl from "../shared/input-url.mjs";
16
17
  import InputResource from "./input-resource.mjs";
17
18
  import InputCombobox from "./input-combobox.mjs";
18
19
  import { FormNotification } from "./form-notification.mjs";
20
+ import InputEditor, { EditorView } from "./input-editor.mjs";
19
21
  import { InputArrayButton, InputArrayControl, InputArraySortable } from "./input-array.mjs";
20
22
  import Badge from "../shared/badge.mjs";
21
23
  import InputSwitch from "../shared/input-switch.mjs";
@@ -31,9 +33,10 @@ const emailSteps = ["step.email.send"];
31
33
  const teamSteps = ["step.email.notify"];
32
34
  const messageSteps = [...emailSteps, "step.sms.send"];
33
35
  const renderedSteps = [...emailSteps, ...teamSteps];
36
+ const RESPONSE = "step.response.send";
34
37
  const firstEntryOnly = ({ campaign, event, type }) => {
35
38
  var _a, _b;
36
- if (event !== "lead.insert" || !type || emailSteps.includes(type)) return false;
39
+ if (event !== "lead.insert" || !type || emailSteps.includes(type) || type === RESPONSE) return false;
37
40
  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";
38
41
  return true;
39
42
  };
@@ -111,8 +114,108 @@ const stepReason = ({ entry, saved = [], type }) => {
111
114
  var _a, _b;
112
115
  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;
113
116
  };
117
+ const responseStart = (number) => ({
118
+ email: {
119
+ enabled: true,
120
+ message: constants.campaign.confirmation.message,
121
+ score: null,
122
+ subject: constants.campaign.confirmation.subject,
123
+ text: constants.campaign.confirmation.text
124
+ },
125
+ sms: {
126
+ enabled: number === "verified",
127
+ message: constants.campaign.confirmation.sms.giveaway
128
+ }
129
+ });
130
+ const responseParts = ({ autoResponse, campaign, organization, settings }) => {
131
+ var _a, _b;
132
+ const { fields, number } = autoResponse || {};
133
+ const base = "/organizations/" + organization;
134
+ const addField = {
135
+ href: base + "/campaigns/" + campaign + "/form",
136
+ text: "Add field"
137
+ };
138
+ const numberTask = () => {
139
+ if (number === "verified") return null;
140
+ if (number === "error") return {
141
+ button: {
142
+ href: base + "/settings",
143
+ text: "View number"
144
+ },
145
+ message: "Your SMS number wasn't approved.",
146
+ type: "error"
147
+ };
148
+ if (number) return {
149
+ message: "Your SMS number is waiting for approval.",
150
+ type: "warning"
151
+ };
152
+ return {
153
+ button: {
154
+ href: base + "/settings",
155
+ text: "Get a number"
156
+ },
157
+ message: "Texts need an SMS number."
158
+ };
159
+ };
160
+ const emailCan = Boolean(fields == null ? void 0 : fields.email);
161
+ const smsCan = Boolean(fields == null ? void 0 : fields.phone) && number === "verified";
162
+ return {
163
+ can: emailCan || smsCan,
164
+ email: {
165
+ can: emailCan,
166
+ hidden: !(fields == null ? void 0 : fields.email),
167
+ on: emailCan && ((_a = settings == null ? void 0 : settings.email) == null ? void 0 : _a.enabled) === true,
168
+ task: (fields == null ? void 0 : fields.email) ? null : {
169
+ button: addField,
170
+ message: "Emails need an Email field on the form."
171
+ }
172
+ },
173
+ sms: {
174
+ can: smsCan,
175
+ hidden: !(fields == null ? void 0 : fields.phone),
176
+ on: smsCan && ((_b = settings == null ? void 0 : settings.sms) == null ? void 0 : _b.enabled) === true,
177
+ task: (fields == null ? void 0 : fields.phone) ? numberTask() : {
178
+ button: addField,
179
+ message: "Texts need a Phone field on the form."
180
+ }
181
+ }
182
+ };
183
+ };
184
+ const stepAfterPart = ({ enabled, next, other }) => next || enabled !== false && other === true;
185
+ const partToStart = (parts) => {
186
+ if (parts.email.on || parts.sms.on) return null;
187
+ return parts.email.can ? "email" : "sms";
188
+ };
189
+ 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;
190
+ const scoreHolds = ({ message, score, subject }) => Boolean(score) && score.subject === subject && score.message === message;
191
+ const responseSave = ({ email, sms }) => ({
192
+ email: {
193
+ enabled: email.enabled,
194
+ message: email.message,
195
+ ...scoreHolds(email) && {
196
+ score: email.score
197
+ },
198
+ subject: email.subject,
199
+ ...email.text && {
200
+ text: email.text
201
+ }
202
+ },
203
+ sms: {
204
+ enabled: sms.enabled,
205
+ message: sms.message
206
+ }
207
+ });
208
+ const plainHtml = (text) => String(text || "").split("\n").map((line) => {
209
+ const marked = line.match(/^\[(.+)\]$/);
210
+ return "<p>" + (marked ? '<span data-variable="placeholder" key="placeholder" label="' + escapeHtml(marked[1]) + '"></span>' : escapeHtml(line)) + "</p>";
211
+ }).join("");
212
+ const taggedScore = (settings) => (settings == null ? void 0 : settings.score) ? {
213
+ ...settings.score,
214
+ message: (settings == null ? void 0 : settings.message) || "",
215
+ subject: (settings == null ? void 0 : settings.subject) || ""
216
+ } : null;
114
217
  const stepRow = (step = {}, members = []) => {
115
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
218
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
116
219
  return {
117
220
  connectionId: step.connectionId || "",
118
221
  discount: ((_a = step.settings) == null ? void 0 : _a.discount) || null,
@@ -125,28 +228,32 @@ const stepRow = (step = {}, members = []) => {
125
228
  // render as an unlabelled chip nobody could identify.
126
229
  members: (((_b = step.settings) == null ? void 0 : _b.members) || []).map((id) => members.find((member) => (member == null ? void 0 : member.id) === id)).filter(Boolean),
127
230
  message: ((_c = step.settings) == null ? void 0 : _c.message) || "",
128
- // THE LAST SPAM CHECK, RE-TAGGED WITH THE COPY IT MEASURED.
129
- //
130
- // The api stores a score without that copy and tests the tag again on the
131
- // way back in, so seeding a bare score would fail the test and clear the
132
- // stored result on every save. Putting the pair back on is the other half of
133
- // a round trip the api already expects — and it is what lets the step panel
134
- // open showing the last result instead of spending a request on a free
135
- // service to be told what is already in the fields.
136
- score: ((_d = step.settings) == null ? void 0 : _d.score) ? {
137
- ...step.settings.score,
138
- message: ((_e = step.settings) == null ? void 0 : _e.message) || "",
139
- subject: ((_f = step.settings) == null ? void 0 : _f.subject) || ""
231
+ score: taggedScore(step.settings),
232
+ // @story workflows/auto-response
233
+ // Its two parts; null on every other row, so every row holds the same keys.
234
+ settings: step.type === RESPONSE ? {
235
+ email: {
236
+ enabled: ((_e = (_d = step.settings) == null ? void 0 : _d.email) == null ? void 0 : _e.enabled) === true,
237
+ message: ((_g = (_f = step.settings) == null ? void 0 : _f.email) == null ? void 0 : _g.message) || "",
238
+ score: taggedScore((_h = step.settings) == null ? void 0 : _h.email),
239
+ subject: ((_j = (_i = step.settings) == null ? void 0 : _i.email) == null ? void 0 : _j.subject) || "",
240
+ text: ((_l = (_k = step.settings) == null ? void 0 : _k.email) == null ? void 0 : _l.text) || ""
241
+ },
242
+ sms: {
243
+ enabled: ((_n = (_m = step.settings) == null ? void 0 : _m.sms) == null ? void 0 : _n.enabled) === true,
244
+ message: ((_p = (_o = step.settings) == null ? void 0 : _o.sms) == null ? void 0 : _p.message) || ""
245
+ }
140
246
  } : null,
141
247
  slug: step.slug || "",
142
- subject: ((_g = step.settings) == null ? void 0 : _g.subject) || "",
248
+ subject: ((_q = step.settings) == null ? void 0 : _q.subject) || "",
143
249
  // The editor writes this only when the merchant touches it, so without a
144
250
  // seed an untouched save dropped the plain rendering of the message.
145
- text: ((_h = step.settings) == null ? void 0 : _h.text) || "",
251
+ text: ((_r = step.settings) == null ? void 0 : _r.text) || "",
146
252
  type: step.type || "",
147
- url: ((_i = step.settings) == null ? void 0 : _i.url) || ""
253
+ url: ((_s = step.settings) == null ? void 0 : _s.url) || ""
148
254
  };
149
255
  };
256
+ const hasWords = (value) => Boolean(String(value || "").replace(/<[^>]*>/g, "").trim());
150
257
  const workflowSchema = yup.object({
151
258
  steps: yup.array().of(
152
259
  yup.object({
@@ -164,11 +271,9 @@ const workflowSchema = yup.object({
164
271
  return schema;
165
272
  }),
166
273
  // @story workflows/edit
167
- // The editor writes an empty message as "<p></p>", which a plain
168
- // required() accepts: a message needs words, not only markup.
169
274
  message: yup.string().test("words", "Message is required", function(value) {
170
275
  var _a;
171
- return !messageSteps.includes((_a = this.parent) == null ? void 0 : _a.type) || Boolean(String(value || "").replace(/<[^>]*>/g, "").trim());
276
+ return !messageSteps.includes((_a = this.parent) == null ? void 0 : _a.type) || hasWords(value);
172
277
  }).when("type", ([type], schema) => {
173
278
  if (type === "step.sms.send") {
174
279
  return schema.required("Message is required").max(1500).label("Message");
@@ -178,6 +283,28 @@ const workflowSchema = yup.object({
178
283
  }
179
284
  return schema;
180
285
  }),
286
+ // @story workflows/auto-response
287
+ // A part's fields are required only while that part is on, with the
288
+ // limits the step declares in utils, so the api never refuses a save
289
+ // the form allowed.
290
+ settings: yup.object().nullable().when("type", ([type], schema) => type === RESPONSE ? schema.shape({
291
+ email: yup.object({
292
+ message: yup.string().when("enabled", {
293
+ is: true,
294
+ then: (part) => part.test("words", "Message is required", hasWords).max(2e3).label("Message")
295
+ }),
296
+ subject: yup.string().when("enabled", {
297
+ is: true,
298
+ then: (part) => part.required("Subject is required").max(150).label("Subject")
299
+ })
300
+ }),
301
+ sms: yup.object({
302
+ message: yup.string().when("enabled", {
303
+ is: true,
304
+ then: (part) => part.required("Message is required").max(1500).label("Message")
305
+ })
306
+ })
307
+ }) : schema),
181
308
  // No minimum. The organization owner is always a recipient, so a
182
309
  // step with no members chosen is complete — requiring one here
183
310
  // made the step unsaveable for a solo merchant, who has no
@@ -343,14 +470,330 @@ const StepPreview = ({ campaign, control, image, name, organization, type }) =>
343
470
  /* @__PURE__ */ jsx("p", { children: "No preview available" })
344
471
  ] });
345
472
  };
473
+ const LeadEmailNote = () => /* @__PURE__ */ jsx(
474
+ "p",
475
+ {
476
+ ...{
477
+ className: "text-sm text-gray-dark"
478
+ },
479
+ children: "Drawbridge adds the entrant's order and missions under your message. You can't edit or remove them."
480
+ }
481
+ );
482
+ const RESPONSE_STATES = [
483
+ {
484
+ key: "Email",
485
+ value: "email"
486
+ },
487
+ {
488
+ key: "Text",
489
+ value: "sms"
490
+ }
491
+ ];
492
+ const ResponseText = ({ className, id, text }) => /* @__PURE__ */ jsx(
493
+ "div",
494
+ {
495
+ ...{
496
+ className,
497
+ id
498
+ },
499
+ children: /* @__PURE__ */ jsx(
500
+ EditorView,
501
+ {
502
+ ...{
503
+ value: plainHtml(text)
504
+ }
505
+ }
506
+ )
507
+ }
508
+ );
509
+ const ResponseStepCard = ({
510
+ card,
511
+ children,
512
+ control,
513
+ disabled,
514
+ formState,
515
+ off,
516
+ onChecking,
517
+ response: {
518
+ autoResponse,
519
+ campaign,
520
+ enabled,
521
+ event,
522
+ id,
523
+ index,
524
+ organization,
525
+ settings,
526
+ title,
527
+ variables
528
+ },
529
+ setValue
530
+ }) => {
531
+ var _a, _b, _c, _d, _e;
532
+ const [picked, setPicked] = useState("email");
533
+ const name = `steps.${index}`;
534
+ const parts = responseParts({ autoResponse, campaign, organization, settings });
535
+ const shown = parts.email.hidden ? "sms" : parts.sms.hidden ? "email" : picked;
536
+ const placeholders = autoResponse == null ? void 0 : autoResponse.placeholders;
537
+ const preview = useEmailPreview({
538
+ campaign,
539
+ event: parts.email.hidden ? null : event,
540
+ message: (_a = settings == null ? void 0 : settings.email) == null ? void 0 : _a.message,
541
+ organization,
542
+ subject: (_b = settings == null ? void 0 : settings.email) == null ? void 0 : _b.subject,
543
+ text: (_c = settings == null ? void 0 : settings.email) == null ? void 0 : _c.text
544
+ });
545
+ const brand = smsBrandLine(title, (_d = settings == null ? void 0 : settings.sms) == null ? void 0 : _d.message);
546
+ const partSwitch = ({ label, message, other, part }) => /* @__PURE__ */ jsx(
547
+ Controller,
548
+ {
549
+ ...{
550
+ control,
551
+ name: name + ".settings." + part + ".enabled",
552
+ render: ({ field: { onChange, value } }) => /* @__PURE__ */ jsx(
553
+ InputGroup,
554
+ {
555
+ ...{
556
+ input: /* @__PURE__ */ jsx(
557
+ InputSwitch,
558
+ {
559
+ ...{
560
+ "aria-label": label,
561
+ disabled: disabled || !parts[part].can,
562
+ onChange: (next) => {
563
+ var _a2;
564
+ onChange(next);
565
+ setValue(name + ".enabled", stepAfterPart({ enabled, next, other: (_a2 = settings == null ? void 0 : settings[other]) == null ? void 0 : _a2.enabled }));
566
+ setPicked(part);
567
+ },
568
+ value: parts[part].can && value === true
569
+ }
570
+ }
571
+ ),
572
+ label,
573
+ message
574
+ }
575
+ }
576
+ )
577
+ }
578
+ }
579
+ );
580
+ return /* @__PURE__ */ jsxs(
581
+ CardSection,
582
+ {
583
+ ...{
584
+ ...card,
585
+ columns: 2
586
+ },
587
+ children: [
588
+ /* @__PURE__ */ jsxs(
589
+ "div",
590
+ {
591
+ ...{
592
+ className: "space-y-6" + (off ? " opacity-50" : "")
593
+ },
594
+ children: [
595
+ children,
596
+ /* @__PURE__ */ jsxs(
597
+ "div",
598
+ {
599
+ ...{
600
+ className: "pt-6 border-t border-gray space-y-6"
601
+ },
602
+ children: [
603
+ partSwitch({ label: "Email", other: "sms", part: "email" }),
604
+ parts.email.task && /* @__PURE__ */ jsx(CardTask, { ...parts.email.task }),
605
+ !parts.email.hidden && /* @__PURE__ */ jsxs(Fragment, { children: [
606
+ /* @__PURE__ */ jsxs(
607
+ "div",
608
+ {
609
+ ...{
610
+ className: "space-y-3" + (parts.email.on ? "" : " opacity-50")
611
+ },
612
+ children: [
613
+ /* @__PURE__ */ jsx(
614
+ FormNotification,
615
+ {
616
+ ...{
617
+ control,
618
+ disabled: disabled || !parts.email.on,
619
+ formState,
620
+ onChecking,
621
+ setValue,
622
+ values: {
623
+ id,
624
+ name: name + ".settings.email",
625
+ organization,
626
+ variables
627
+ }
628
+ }
629
+ }
630
+ ),
631
+ /* @__PURE__ */ jsx(LeadEmailNote, {})
632
+ ]
633
+ }
634
+ ),
635
+ /* @__PURE__ */ jsx(
636
+ InputGroup,
637
+ {
638
+ ...{
639
+ input: /* @__PURE__ */ jsx(
640
+ ResponseText,
641
+ {
642
+ ...{
643
+ className: "w-full border border-inherit rounded px-3 py-2 disabled",
644
+ text: preview == null ? void 0 : preview.text
645
+ }
646
+ }
647
+ ),
648
+ label: "Plain-text version"
649
+ }
650
+ }
651
+ )
652
+ ] })
653
+ ]
654
+ }
655
+ ),
656
+ /* @__PURE__ */ jsxs(
657
+ "div",
658
+ {
659
+ ...{
660
+ className: "mt-10 pt-10 border-t border-gray-dark space-y-6"
661
+ },
662
+ children: [
663
+ partSwitch({
664
+ label: "Text",
665
+ // The line goes with the part's fields when the form lacks the field.
666
+ message: !parts.sms.hidden && "Sends to entrants who agree to texts. Each text costs 2 actions, and a long text costs more.",
667
+ other: "email",
668
+ part: "sms"
669
+ }),
670
+ parts.sms.task && /* @__PURE__ */ jsx(CardTask, { ...parts.sms.task }),
671
+ !parts.sms.hidden && /* @__PURE__ */ jsx(
672
+ Controller,
673
+ {
674
+ ...{
675
+ control,
676
+ name: name + ".settings.sms.message",
677
+ render: ({ field: { onChange, value } }) => {
678
+ var _a2, _b2, _c2, _d2, _e2, _f;
679
+ return /* @__PURE__ */ jsx(
680
+ "div",
681
+ {
682
+ ...{
683
+ className: parts.sms.on ? "" : "opacity-50"
684
+ },
685
+ children: /* @__PURE__ */ jsx(
686
+ InputGroup,
687
+ {
688
+ ...{
689
+ 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,
690
+ input: /* @__PURE__ */ jsx(
691
+ InputEditor,
692
+ {
693
+ ...{
694
+ disabled: disabled || !parts.sms.on,
695
+ ...(placeholders == null ? void 0 : placeholders.missions) && {
696
+ locked: /* @__PURE__ */ jsx(ResponseText, { ...{ text: "[" + placeholders.missions + "]" } })
697
+ },
698
+ onChange: ({ text }) => onChange(text),
699
+ plain: true,
700
+ value: value || ""
701
+ }
702
+ }
703
+ ),
704
+ label: "Message"
705
+ }
706
+ }
707
+ )
708
+ }
709
+ );
710
+ }
711
+ }
712
+ }
713
+ )
714
+ ]
715
+ }
716
+ )
717
+ ]
718
+ }
719
+ ),
720
+ /* @__PURE__ */ jsx(
721
+ "div",
722
+ {
723
+ ...{
724
+ className: off || !parts[shown].on ? "opacity-50" : ""
725
+ },
726
+ children: /* @__PURE__ */ jsx(
727
+ Preview,
728
+ {
729
+ ...{
730
+ ...!parts.email.hidden && !parts.sms.hidden && {
731
+ states: {
732
+ onChange: setPicked,
733
+ options: RESPONSE_STATES,
734
+ value: shown
735
+ }
736
+ }
737
+ },
738
+ children: shown === "email" ? /* @__PURE__ */ jsx(
739
+ "iframe",
740
+ {
741
+ ...{
742
+ className: "block w-full h-full border-0 bg-white",
743
+ srcDoc: (preview == null ? void 0 : preview.html) || "",
744
+ title: "Auto response"
745
+ }
746
+ }
747
+ ) : /* @__PURE__ */ jsxs(TextPreview, { children: [
748
+ brand && /* @__PURE__ */ jsx("p", { children: brand }),
749
+ /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap", children: (_e = settings == null ? void 0 : settings.sms) == null ? void 0 : _e.message }),
750
+ (placeholders == null ? void 0 : placeholders.missions) && /* @__PURE__ */ jsx(
751
+ ResponseText,
752
+ {
753
+ ...{
754
+ className: "mt-2",
755
+ text: "[" + placeholders.missions + "]"
756
+ }
757
+ }
758
+ ),
759
+ /* @__PURE__ */ jsx("p", { className: "mt-2", children: "Reply STOP to opt out" })
760
+ ] })
761
+ }
762
+ )
763
+ }
764
+ )
765
+ ]
766
+ }
767
+ );
768
+ };
346
769
  const StepCard = ({
347
770
  children,
348
771
  control,
772
+ disabled,
349
773
  email,
774
+ formState,
350
775
  off,
776
+ onChecking,
351
777
  preview,
778
+ response,
779
+ setValue,
352
780
  ...card
353
- }) => email ? /* @__PURE__ */ jsx(
781
+ }) => response ? /* @__PURE__ */ jsx(
782
+ ResponseStepCard,
783
+ {
784
+ ...{
785
+ card,
786
+ control,
787
+ disabled,
788
+ formState,
789
+ off,
790
+ onChecking,
791
+ response,
792
+ setValue
793
+ },
794
+ children
795
+ }
796
+ ) : email ? /* @__PURE__ */ jsx(
354
797
  EmailStepCard,
355
798
  {
356
799
  ...{
@@ -397,7 +840,7 @@ const FormOrganizationWorkflowEdit = ({
397
840
  onSuccess,
398
841
  values
399
842
  }) => {
400
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
843
+ var _a, _b, _c, _d, _e, _f, _g, _h;
401
844
  const event = (_a = values == null ? void 0 : values.trigger) == null ? void 0 : _a.event;
402
845
  const { items: memberItems, loading: membersLoading } = useOrganizationMembers(values == null ? void 0 : values.organization);
403
846
  const queryClient = useQueryClient();
@@ -439,7 +882,7 @@ const FormOrganizationWorkflowEdit = ({
439
882
  control,
440
883
  name: "steps"
441
884
  });
442
- 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;
885
+ const issueIndex = issueRow({ issue: values == null ? void 0 : values.issue, steps: watchedSteps || [] });
443
886
  const getAvailableVariables = (index) => stepVariables(catalog, watchedSteps, index);
444
887
  const loading = membersLoading || commerceConnection.isLoading;
445
888
  const prefilled = useRef(false);
@@ -573,13 +1016,14 @@ const FormOrganizationWorkflowEdit = ({
573
1016
  }) => {
574
1017
  try {
575
1018
  const body = {
576
- steps: steps.map(({ connectionId, discount, enabled, members, message, score, slug, subject, text, type, url }, index) => {
577
- const settings = {};
1019
+ steps: steps.map(({ connectionId, discount, enabled, members, message, score, settings: parts, slug, subject, text, type, url }, index) => {
1020
+ const settings = type === RESPONSE ? responseSave(parts) : {};
1021
+ if (type === RESPONSE && parts.email.score && !settings.email.score) setValue("steps." + index + ".settings.email.score", null);
578
1022
  if (type === "step.webhook.send") settings.url = url;
579
1023
  if (emailSteps.includes(type)) settings.subject = subject;
580
1024
  if (messageSteps.includes(type)) settings.message = message;
581
1025
  if (emailSteps.includes(type)) {
582
- if (score && score.subject === subject && score.message === message) settings.score = score;
1026
+ if (scoreHolds({ message, score, subject })) settings.score = score;
583
1027
  else if (score) setValue("steps." + index + ".score", null);
584
1028
  if (text) settings.text = text;
585
1029
  }
@@ -660,7 +1104,7 @@ const FormOrganizationWorkflowEdit = ({
660
1104
  InputGroup,
661
1105
  {
662
1106
  ...{
663
- error: (_i = (_h = formState == null ? void 0 : formState.errors) == null ? void 0 : _h.steps) == null ? void 0 : _i.message,
1107
+ error: (_h = (_g = formState == null ? void 0 : formState.errors) == null ? void 0 : _g.steps) == null ? void 0 : _h.message,
664
1108
  input: /* @__PURE__ */ jsx(
665
1109
  InputArraySortable,
666
1110
  {
@@ -681,6 +1125,12 @@ const FormOrganizationWorkflowEdit = ({
681
1125
  children: ({ field, handle, index, remove }) => {
682
1126
  var _a2;
683
1127
  const step = (watchedSteps == null ? void 0 : watchedSteps[index]) || field;
1128
+ const parts = step.type === RESPONSE && responseParts({
1129
+ autoResponse: values == null ? void 0 : values.autoResponse,
1130
+ campaign: values == null ? void 0 : values.campaign,
1131
+ organization: values == null ? void 0 : values.organization,
1132
+ settings: step.settings
1133
+ });
684
1134
  return (
685
1135
  // @story workflows/edit
686
1136
  // EACH STEP IS ITS OWN CARD in the flow under the Trigger card,
@@ -692,6 +1142,23 @@ const FormOrganizationWorkflowEdit = ({
692
1142
  {
693
1143
  ...{
694
1144
  control,
1145
+ disabled: disabled || (formState == null ? void 0 : formState.isSubmitting),
1146
+ formState,
1147
+ onChecking,
1148
+ setValue,
1149
+ // @story workflows/auto-response
1150
+ response: step.type === RESPONSE && {
1151
+ autoResponse: values == null ? void 0 : values.autoResponse,
1152
+ campaign: values == null ? void 0 : values.campaign,
1153
+ enabled: step.enabled,
1154
+ event,
1155
+ id: field.id,
1156
+ index,
1157
+ organization: values == null ? void 0 : values.organization,
1158
+ settings: step.settings,
1159
+ title: organizationData == null ? void 0 : organizationData.title,
1160
+ variables: getAvailableVariables(index)
1161
+ },
695
1162
  // @story workflows/send-email
696
1163
  // A Send email step shows its email beside its form.
697
1164
  off: step.enabled === false,
@@ -743,10 +1210,13 @@ const FormOrganizationWorkflowEdit = ({
743
1210
  {
744
1211
  ...{
745
1212
  "aria-label": ((_a3 = ((catalog == null ? void 0 : catalog.steps) || []).find((entry) => entry.value === step.type)) == null ? void 0 : _a3.key) || "Step " + (index + 1),
746
- disabled: disabled || (formState == null ? void 0 : formState.isSubmitting),
747
- onChange,
1213
+ disabled: disabled || (formState == null ? void 0 : formState.isSubmitting) || parts && !parts.can,
1214
+ onChange: (next) => {
1215
+ onChange(next);
1216
+ if (parts && next && partToStart(parts)) setValue(`steps.${index}.settings.${partToStart(parts)}.enabled`, true);
1217
+ },
748
1218
  small: true,
749
- value: value !== false
1219
+ value: value !== false && (!parts || parts.can)
750
1220
  }
751
1221
  }
752
1222
  );
@@ -776,7 +1246,8 @@ const FormOrganizationWorkflowEdit = ({
776
1246
  {
777
1247
  ...{
778
1248
  // A step switched off is greyed; its settings are kept.
779
- className: "space-y-3" + (step.enabled === false ? " opacity-50" : "")
1249
+ // Auto response's whole card greys, its parts as well.
1250
+ className: "space-y-3" + (step.enabled === false && !parts ? " opacity-50" : "")
780
1251
  },
781
1252
  children: [
782
1253
  issueIndex === index && /* @__PURE__ */ jsx(
@@ -805,9 +1276,11 @@ const FormOrganizationWorkflowEdit = ({
805
1276
  {
806
1277
  ...{
807
1278
  onChange: (val) => {
1279
+ var _a4;
808
1280
  const [type] = val.split("::");
809
1281
  const option = getStepOptions(index).find((o) => o.value === val);
810
1282
  const copy = pickedCopy({ row: getValues(`steps.${index}`), type });
1283
+ setValue(`steps.${index}.settings`, type === RESPONSE ? responseStart((_a4 = values == null ? void 0 : values.autoResponse) == null ? void 0 : _a4.number) : null);
811
1284
  onChange(type);
812
1285
  setValue(`steps.${index}.connectionId`, (option == null ? void 0 : option.connectionId) || "");
813
1286
  setValue(`steps.${index}.slug`, (option == null ? void 0 : option.slug) || "");
@@ -938,15 +1411,7 @@ const FormOrganizationWorkflowEdit = ({
938
1411
  }
939
1412
  }
940
1413
  ),
941
- event === "lead.insert" && emailSteps.includes(step.type) && /* @__PURE__ */ jsx(
942
- "p",
943
- {
944
- ...{
945
- className: "text-sm text-gray-dark"
946
- },
947
- children: "Drawbridge adds the entrant's order and missions under your message. You can't edit or remove them."
948
- }
949
- ),
1414
+ event === "lead.insert" && emailSteps.includes(step.type) && /* @__PURE__ */ jsx(LeadEmailNote, {}),
950
1415
  step.type === "step.sms.send" && /* @__PURE__ */ jsx(
951
1416
  Controller,
952
1417
  {
@@ -1080,11 +1545,19 @@ const FormOrganizationWorkflowEdit = ({
1080
1545
  };
1081
1546
  export {
1082
1547
  FormOrganizationWorkflowEdit,
1548
+ RESPONSE,
1083
1549
  SAMPLE,
1084
1550
  TextPreview,
1085
1551
  firstEntryOnly,
1552
+ issueRow,
1553
+ partToStart,
1086
1554
  pickedCopy,
1555
+ plainHtml,
1087
1556
  prefillRow,
1557
+ responseParts,
1558
+ responseSave,
1559
+ responseStart,
1560
+ stepAfterPart,
1088
1561
  stepReason,
1089
1562
  stepRow,
1090
1563
  stepVariables,