@drawbridge/components 0.1.15 → 0.1.16

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 (32) hide show
  1. package/dist/bridge/lib/url.js +3 -3
  2. package/dist/bridge/lib/url.mjs +3 -3
  3. package/dist/bridge/share-button.js +12 -2
  4. package/dist/bridge/share-button.mjs +12 -2
  5. package/dist/bridge/template-layout.js +1 -1
  6. package/dist/bridge/template-layout.mjs +1 -1
  7. package/dist/dashboard/answer-rows.js +77 -0
  8. package/dist/dashboard/answer-rows.mjs +41 -0
  9. package/dist/dashboard/card-order.js +186 -243
  10. package/dist/dashboard/card-order.mjs +186 -243
  11. package/dist/dashboard/form-organization-campaign-field-list.js +8 -49
  12. package/dist/dashboard/form-organization-campaign-field-list.mjs +8 -49
  13. package/dist/dashboard/form-organization-workflow.js +70 -120
  14. package/dist/dashboard/form-organization-workflow.mjs +68 -120
  15. package/dist/dashboard/item-row.js +92 -0
  16. package/dist/dashboard/item-row.mjs +63 -0
  17. package/dist/dashboard/lib/sms.js +3 -0
  18. package/dist/dashboard/lib/sms.mjs +2 -0
  19. package/dist/dashboard/order-sections.js +220 -0
  20. package/dist/dashboard/order-sections.mjs +185 -0
  21. package/dist/dashboard/preview.js +29 -2
  22. package/dist/dashboard/preview.mjs +28 -2
  23. package/dist/shared/lib/helpers.js +7 -0
  24. package/dist/shared/lib/helpers.mjs +7 -0
  25. package/package.json +19 -4
  26. package/types/bridge/lib/url.d.ts +5 -4
  27. package/types/dashboard/answer-rows.d.ts +30 -0
  28. package/types/dashboard/card-order.d.ts +16 -14
  29. package/types/dashboard/form-organization-workflow.d.ts +2 -0
  30. package/types/dashboard/item-row.d.ts +25 -0
  31. package/types/dashboard/order-sections.d.ts +36 -0
  32. package/types/shared/lib/helpers.d.ts +1 -1
@@ -29,11 +29,13 @@ var form_organization_workflow_exports = {};
29
29
  __export(form_organization_workflow_exports, {
30
30
  FormOrganizationWorkflowEdit: () => FormOrganizationWorkflowEdit,
31
31
  SAMPLE: () => SAMPLE,
32
+ TextPreview: () => TextPreview,
33
+ firstEntryOnly: () => firstEntryOnly,
34
+ pickedCopy: () => pickedCopy,
32
35
  prefillRow: () => prefillRow,
33
36
  stepReason: () => stepReason,
34
37
  stepRow: () => stepRow,
35
38
  stepVariables: () => stepVariables,
36
- teamSample: () => teamSample,
37
39
  webhookSample: () => webhookSample,
38
40
  workflowSchema: () => workflowSchema
39
41
  });
@@ -42,6 +44,7 @@ var import_jsx_runtime = require("react/jsx-runtime");
42
44
  var import_image = __toESM(require("next/image"));
43
45
  var import_link = __toESM(require("./link"));
44
46
  var import_react = require("react");
47
+ var import_drawbridge_utils = require("@drawbridge/drawbridge-utils");
45
48
  var import_fetch = require("@drawbridge/drawbridge-utils/fetch");
46
49
  var import_form = require("../shared/lib/form");
47
50
  var import_react_query = require("@tanstack/react-query");
@@ -58,7 +61,6 @@ var import_form_notification = require("./form-notification");
58
61
  var import_input_array = require("./input-array");
59
62
  var import_badge = __toESM(require("../shared/badge"));
60
63
  var import_input_switch = __toESM(require("../shared/input-switch"));
61
- var import_tooltip = __toESM(require("../shared/tooltip"));
62
64
  var import_card_section = __toESM(require("./card-section"));
63
65
  var import_accordion = __toESM(require("./accordion"));
64
66
  var import_preview = __toESM(require("./preview"));
@@ -70,22 +72,18 @@ var import_button = __toESM(require("../shared/button"));
70
72
  const emailSteps = ["step.email.send"];
71
73
  const teamSteps = ["step.email.notify"];
72
74
  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
75
+ const renderedSteps = [...emailSteps, ...teamSteps];
76
+ const firstEntryOnly = ({ campaign, event, type }) => {
77
+ var _a, _b;
78
+ if (event !== "lead.insert" || !type || emailSteps.includes(type)) return false;
79
+ 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
+ return true;
82
81
  };
83
82
  const stepPrefills = {
84
83
  "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."
84
+ message: import_drawbridge_utils.constants.campaign.confirmation.message,
85
+ subject: import_drawbridge_utils.constants.campaign.confirmation.subject,
86
+ text: import_drawbridge_utils.constants.campaign.confirmation.text
89
87
  },
90
88
  // Nothing to prefill: the step writes its own copy.
91
89
  "step.email.notify": {}
@@ -144,6 +142,13 @@ const prefillRow = ({ entry, step, steps = [] }) => {
144
142
  type: step
145
143
  });
146
144
  };
145
+ const pickedCopy = ({ row, type }) => {
146
+ const previous = stepPrefills[row == null ? void 0 : row.type];
147
+ const untouched = !!(previous == null ? void 0 : previous.subject) && (row == null ? void 0 : row.subject) === previous.subject && (row == null ? void 0 : row.message) === previous.message;
148
+ const { message = "", subject = "", text = "" } = stepPrefills[type] || {};
149
+ if (!untouched && ((row == null ? void 0 : row.subject) || (row == null ? void 0 : row.message))) return null;
150
+ return subject || untouched ? { message, subject, text } : null;
151
+ };
147
152
  const stepReason = ({ entry, saved = [], type }) => {
148
153
  var _a, _b;
149
154
  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;
@@ -151,9 +156,6 @@ const stepReason = ({ entry, saved = [], type }) => {
151
156
  const stepRow = (step = {}, members = []) => {
152
157
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
153
158
  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
159
  connectionId: step.connectionId || "",
158
160
  discount: ((_a = step.settings) == null ? void 0 : _a.discount) || null,
159
161
  // @story workflows/step-switch
@@ -233,18 +235,8 @@ const workflowSchema = import_yup.default.object({
233
235
  })
234
236
  )
235
237
  });
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 });
238
+ const useEmailPreview = ({ campaign, event, message, organization, subject, text, type }) => {
239
+ const asked = JSON.stringify(teamSteps.includes(type) ? { type } : { message, subject, text });
248
240
  const [settled, setSettled] = (0, import_react.useState)(asked);
249
241
  (0, import_react.useEffect)(() => {
250
242
  const timer = setTimeout(() => setSettled(asked), 400);
@@ -272,18 +264,18 @@ const EmailStepCard = ({
272
264
  off,
273
265
  email: {
274
266
  campaign,
275
- confirmation,
276
267
  event,
277
268
  name,
278
- organization
269
+ organization,
270
+ title,
271
+ type
279
272
  }
280
273
  }) => {
281
- const [sample, setSample] = (0, import_react.useState)(samples[0].value);
282
274
  const [subject, message, text] = (0, import_form.useWatch)({
283
275
  control,
284
276
  name: [name + ".subject", name + ".message", name + ".text"]
285
277
  });
286
- const preview = useEmailPreview({ campaign, confirmation, event, message, organization, sample, subject, text });
278
+ const preview = useEmailPreview({ campaign, event, message, organization, subject, text, type });
287
279
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
288
280
  import_card_section.default,
289
281
  {
@@ -300,7 +292,7 @@ const EmailStepCard = ({
300
292
  },
301
293
  children: [
302
294
  children,
303
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
295
+ emailSteps.includes(type) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
304
296
  import_accordion.default,
305
297
  {
306
298
  ...{
@@ -328,29 +320,17 @@ const EmailStepCard = ({
328
320
  ...{
329
321
  className: off ? "opacity-50" : ""
330
322
  },
331
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
332
- import_preview.default,
323
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_preview.default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
324
+ "iframe",
333
325
  {
334
326
  ...{
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
- )
327
+ // The rendered email, as a mail app shows it.
328
+ className: "block w-full h-full border-0 bg-white",
329
+ srcDoc: (preview == null ? void 0 : preview.html) || "",
330
+ title
331
+ }
352
332
  }
353
- )
333
+ ) })
354
334
  }
355
335
  )
356
336
  ]
@@ -360,7 +340,6 @@ const EmailStepCard = ({
360
340
  const SAMPLE = {
361
341
  email: "sam.rivera@example.com",
362
342
  name: "Sam Rivera",
363
- order: "House espresso \xD7 2, Holiday blend \xD7 1",
364
343
  phone: "+14165550142"
365
344
  };
366
345
  const webhookSample = ({ campaign }) => JSON.stringify({
@@ -375,33 +354,20 @@ const webhookSample = ({ campaign }) => JSON.stringify({
375
354
  number: SAMPLE.phone
376
355
  }
377
356
  }, 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 }) => {
357
+ 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 }) });
358
+ const StepPreview = ({ campaign, control, image, name, organization, type }) => {
386
359
  const [message] = (0, import_form.useWatch)({
387
360
  control,
388
361
  name: [name + ".message"]
389
362
  });
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
- ] })
363
+ const brand = (0, import_sms.smsBrandLine)(organization == null ? void 0 : organization.title, message);
364
+ if (type === "step.sms.send") return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextPreview, { children: [
365
+ brand && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: brand }),
366
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "whitespace-pre-wrap", children: message }),
367
+ (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" }),
368
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "mt-2", children: "Reply STOP to opt out" })
396
369
  ] });
397
370
  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
371
  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
372
  image && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
407
373
  import_image.default,
@@ -480,6 +446,7 @@ const FormOrganizationWorkflowEdit = ({
480
446
  const organizationData = queryClient.getQueryData(["organization", values == null ? void 0 : values.organization]);
481
447
  const ownerEmail = organizationData.owner.email;
482
448
  const smsActive = (0, import_sms.smsNumberActive)(organizationData);
449
+ const campaignData = queryClient.getQueryData(["campaign", values == null ? void 0 : values.campaign]);
483
450
  const commerceConnectionId = ((_b = ((catalog == null ? void 0 : catalog.steps) || []).find(
484
451
  (s) => s.value === "step.commerce.customer.insert" || s.value === "step.commerce.code.issue"
485
452
  )) == null ? void 0 : _b.connectionId) || null;
@@ -648,7 +615,7 @@ const FormOrganizationWorkflowEdit = ({
648
615
  }) => {
649
616
  try {
650
617
  const body = {
651
- steps: steps.map(({ confirmation, connectionId, discount, enabled, members, message, score, slug, subject, text, type, url }, index) => {
618
+ steps: steps.map(({ connectionId, discount, enabled, members, message, score, slug, subject, text, type, url }, index) => {
652
619
  const settings = {};
653
620
  if (type === "step.webhook.send") settings.url = url;
654
621
  if (emailSteps.includes(type)) settings.subject = subject;
@@ -665,8 +632,6 @@ const FormOrganizationWorkflowEdit = ({
665
632
  const resolvedConnectionId = (catalogStep == null ? void 0 : catalogStep.connectionId) || connectionId || null;
666
633
  const resolvedSlug = (catalogStep == null ? void 0 : catalogStep.slug) || slug || null;
667
634
  return {
668
- // The System email row names itself; the api keeps it only where it was.
669
- ...confirmation && { confirmation: true },
670
635
  ...resolvedConnectionId && { connectionId: resolvedConnectionId },
671
636
  enabled: enabled !== false,
672
637
  ...resolvedSlug && { slug: resolvedSlug },
@@ -773,20 +738,21 @@ const FormOrganizationWorkflowEdit = ({
773
738
  // A Send email step shows its email beside its form.
774
739
  off: step.enabled === false,
775
740
  // 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,
741
+ preview: step.type && !renderedSteps.includes(step.type) && {
742
+ campaign: campaignData,
779
743
  image: ((_a2 = ((catalog == null ? void 0 : catalog.steps) || []).find((entry) => entry.value === step.type)) == null ? void 0 : _a2.image) || null,
780
744
  name: `steps.${index}`,
781
745
  organization: organizationData,
782
746
  type: step.type
783
747
  },
784
- email: emailSteps.includes(step.type) && {
748
+ // Send email and Email notification show the email the api renders.
749
+ email: renderedSteps.includes(step.type) && {
785
750
  campaign: values == null ? void 0 : values.campaign,
786
- confirmation: step.confirmation,
787
751
  event,
788
752
  name: `steps.${index}`,
789
- organization: values == null ? void 0 : values.organization
753
+ organization: values == null ? void 0 : values.organization,
754
+ title: emailSteps.includes(step.type) ? "Send email" : "Email notification",
755
+ type: step.type
790
756
  },
791
757
  cta: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
792
758
  "span",
@@ -796,7 +762,7 @@ const FormOrganizationWorkflowEdit = ({
796
762
  },
797
763
  children: [
798
764
  renderStepBadge(step),
799
- !lockedStep(index) && !step.confirmation && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
765
+ !lockedStep(index) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
800
766
  import_input_array.InputArrayControl,
801
767
  {
802
768
  ...{
@@ -806,35 +772,7 @@ const FormOrganizationWorkflowEdit = ({
806
772
  },
807
773
  "remove"
808
774
  ),
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)(
775
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
838
776
  import_form.Controller,
839
777
  {
840
778
  ...{
@@ -911,12 +849,13 @@ const FormOrganizationWorkflowEdit = ({
911
849
  onChange: (val) => {
912
850
  const [type] = val.split("::");
913
851
  const option = getStepOptions(index).find((o) => o.value === val);
852
+ const copy = pickedCopy({ row: getValues(`steps.${index}`), type });
914
853
  onChange(type);
915
854
  setValue(`steps.${index}.connectionId`, (option == null ? void 0 : option.connectionId) || "");
916
855
  setValue(`steps.${index}.slug`, (option == null ? void 0 : option.slug) || "");
856
+ if (copy) Object.entries(copy).forEach(([key, value]) => setValue(`steps.${index}.${key}`, value));
917
857
  },
918
- // The System email is always a Send email.
919
- disabled: lockedStep(index) || Boolean(step.confirmation),
858
+ disabled: lockedStep(index),
920
859
  options: getStepOptions(index),
921
860
  // Resolved from the WHOLE ROW, not from this path: the
922
861
  // option value carries a connection the type alone cannot
@@ -933,6 +872,15 @@ const FormOrganizationWorkflowEdit = ({
933
872
  }
934
873
  }
935
874
  ),
875
+ firstEntryOnly({ campaign: campaignData, event, type: step.type }) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
876
+ "p",
877
+ {
878
+ ...{
879
+ className: "text-sm text-gray-dark"
880
+ },
881
+ children: "Runs on a person's first entry only."
882
+ }
883
+ ),
936
884
  step.type === "step.webhook.send" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
937
885
  import_form.Controller,
938
886
  {
@@ -1032,7 +980,7 @@ const FormOrganizationWorkflowEdit = ({
1032
980
  }
1033
981
  }
1034
982
  ),
1035
- step.confirmation && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
983
+ event === "lead.insert" && emailSteps.includes(step.type) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1036
984
  "p",
1037
985
  {
1038
986
  ...{
@@ -1176,11 +1124,13 @@ const FormOrganizationWorkflowEdit = ({
1176
1124
  0 && (module.exports = {
1177
1125
  FormOrganizationWorkflowEdit,
1178
1126
  SAMPLE,
1127
+ TextPreview,
1128
+ firstEntryOnly,
1129
+ pickedCopy,
1179
1130
  prefillRow,
1180
1131
  stepReason,
1181
1132
  stepRow,
1182
1133
  stepVariables,
1183
- teamSample,
1184
1134
  webhookSample,
1185
1135
  workflowSchema
1186
1136
  });