@drawbridge/components 0.1.14 → 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 (52) hide show
  1. package/dist/bridge/form-subdomain-missions.js +77 -38
  2. package/dist/bridge/form-subdomain-missions.mjs +76 -38
  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-campaign-switch.js +55 -43
  12. package/dist/dashboard/card-campaign-switch.mjs +56 -44
  13. package/dist/dashboard/card-order.js +248 -120
  14. package/dist/dashboard/card-order.mjs +248 -120
  15. package/dist/dashboard/connection-workflows.js +13 -4
  16. package/dist/dashboard/connection-workflows.mjs +13 -4
  17. package/dist/dashboard/form-organization-campaign-field-list.js +8 -49
  18. package/dist/dashboard/form-organization-campaign-field-list.mjs +8 -49
  19. package/dist/dashboard/form-organization-campaign-field-select.js +51 -5
  20. package/dist/dashboard/form-organization-campaign-field-select.mjs +51 -5
  21. package/dist/dashboard/form-organization-campaign-field-textarea.js +46 -8
  22. package/dist/dashboard/form-organization-campaign-field-textarea.mjs +46 -8
  23. package/dist/dashboard/form-organization-campaign-section.js +24 -4
  24. package/dist/dashboard/form-organization-campaign-section.mjs +24 -4
  25. package/dist/dashboard/form-organization-workflow.js +195 -56
  26. package/dist/dashboard/form-organization-workflow.mjs +191 -57
  27. package/dist/dashboard/item-row.js +92 -0
  28. package/dist/dashboard/item-row.mjs +63 -0
  29. package/dist/dashboard/lib/sms.js +3 -0
  30. package/dist/dashboard/lib/sms.mjs +2 -0
  31. package/dist/dashboard/order-sections.js +220 -0
  32. package/dist/dashboard/order-sections.mjs +185 -0
  33. package/dist/dashboard/preview.js +29 -2
  34. package/dist/dashboard/preview.mjs +28 -2
  35. package/dist/input-code.js +35 -53
  36. package/dist/input-code.mjs +26 -54
  37. package/dist/shared/button.js +1 -1
  38. package/dist/shared/button.mjs +1 -1
  39. package/dist/shared/lib/campaign.js +9 -3
  40. package/dist/shared/lib/campaign.mjs +7 -2
  41. package/dist/shared/lib/helpers.js +7 -0
  42. package/dist/shared/lib/helpers.mjs +7 -0
  43. package/package.json +19 -4
  44. package/types/bridge/form-subdomain-missions.d.ts +3 -1
  45. package/types/bridge/lib/url.d.ts +5 -4
  46. package/types/dashboard/answer-rows.d.ts +30 -0
  47. package/types/dashboard/card-order.d.ts +18 -3
  48. package/types/dashboard/form-organization-campaign-section.d.ts +2 -0
  49. package/types/dashboard/form-organization-workflow.d.ts +15 -0
  50. package/types/dashboard/item-row.d.ts +25 -0
  51. package/types/dashboard/order-sections.d.ts +36 -0
  52. package/types/shared/lib/helpers.d.ts +1 -1
@@ -1,23 +1,253 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { formatCurrency, formatDateString, formatNumber } from "@drawbridge/drawbridge-utils";
3
3
  import CardDataItem from "./card-data-item.mjs";
4
+ import ItemRow from "./item-row.mjs";
5
+ import { answerRows } from "./answer-rows.mjs";
4
6
  const className = "p-3 bg-white rounded shadow-[0_1px_3px_0_rgb(0_0_0/0.1),0_1px_2px_-1px_rgb(0_0_0/0.1)]";
5
7
  const attributions = {
6
8
  conversion: "A campaign link brought the buyer to checkout, so the conversion fee applies.",
7
9
  redemption: "The buyer used one of your discount codes, so no fee applies."
8
10
  };
11
+ const date = (value) => value ? formatDateString({
12
+ date: value,
13
+ options: {
14
+ day: "numeric",
15
+ month: "short",
16
+ year: "numeric"
17
+ }
18
+ }) : "\u2014";
19
+ const Item = ({ label, value }) => /* @__PURE__ */ jsx(
20
+ CardDataItem,
21
+ {
22
+ ...{
23
+ className: ["flex flex-col min-w-0", className].join(" "),
24
+ classNameSlotLeft: "text-sm disabled",
25
+ classNameSlotRight: "w-full break-words",
26
+ label,
27
+ value: value || "\u2014"
28
+ }
29
+ }
30
+ );
31
+ const lineSummary = ({ code, price, quantity = 0, variantTitle }) => [
32
+ variantTitle,
33
+ typeof price === "number" ? formatNumber(quantity) + " \xD7 " + formatCurrency({ code, value: price }) : "Quantity " + formatNumber(quantity)
34
+ ].filter(Boolean).join(" \xB7 ");
35
+ const Lines = ({ code, label, lines, untitled }) => lines.length > 0 && /* @__PURE__ */ jsxs(
36
+ "div",
37
+ {
38
+ ...{
39
+ className: "space-y-2"
40
+ },
41
+ children: [
42
+ /* @__PURE__ */ jsx(
43
+ "p",
44
+ {
45
+ ...{
46
+ className: "text-sm disabled"
47
+ },
48
+ children: label
49
+ }
50
+ ),
51
+ /* @__PURE__ */ jsx(
52
+ "div",
53
+ {
54
+ ...{
55
+ className: "space-y-3"
56
+ },
57
+ children: lines.map((line, key) => /* @__PURE__ */ jsx(
58
+ "div",
59
+ {
60
+ ...{
61
+ className
62
+ },
63
+ children: /* @__PURE__ */ jsx(
64
+ ItemRow,
65
+ {
66
+ ...{
67
+ image: line.image,
68
+ name: line.title || untitled,
69
+ summary: lineSummary({ code, ...line })
70
+ }
71
+ }
72
+ )
73
+ },
74
+ key
75
+ ))
76
+ }
77
+ )
78
+ ]
79
+ }
80
+ );
81
+ const statuses = {
82
+ canceled: "Canceled",
83
+ completed: "Completed",
84
+ open: "Open"
85
+ };
86
+ const StackedRows = ({ rows }) => /* @__PURE__ */ jsx(
87
+ "div",
88
+ {
89
+ ...{
90
+ className: "divide-y divide-gray"
91
+ },
92
+ children: rows.map(({ after, label, value }, index) => /* @__PURE__ */ jsxs(
93
+ "div",
94
+ {
95
+ ...{
96
+ className: "flex items-center gap-4 py-3 first:pt-0 last:pb-0"
97
+ },
98
+ children: [
99
+ /* @__PURE__ */ jsx(
100
+ CardDataItem,
101
+ {
102
+ ...{
103
+ // CardDataItem is `w-full grow-0`: `flex-1` here would lose to
104
+ // that `grow-0` and leave the value no width at all.
105
+ className: "flex flex-col min-w-0",
106
+ classNameSlotLeft: "text-sm disabled",
107
+ classNameSlotRight: "break-words",
108
+ element: "div",
109
+ label,
110
+ value
111
+ }
112
+ }
113
+ ),
114
+ after
115
+ ]
116
+ },
117
+ label + index
118
+ ))
119
+ }
120
+ );
121
+ const Stacked = ({ rows, title }) => rows.length > 0 && /* @__PURE__ */ jsxs(
122
+ "div",
123
+ {
124
+ ...{
125
+ className: "space-y-3"
126
+ },
127
+ children: [
128
+ /* @__PURE__ */ jsx(
129
+ "p",
130
+ {
131
+ ...{
132
+ className: "text-sm text-gray-dark"
133
+ },
134
+ children: title
135
+ }
136
+ ),
137
+ /* @__PURE__ */ jsx(StackedRows, { ...{ rows } })
138
+ ]
139
+ }
140
+ );
141
+ const FormOrder = ({ answers, children, code, cta, fields = [], gross, lines, purchasedAt, status }) => {
142
+ const priced = lines.some((line) => typeof (line == null ? void 0 : line.price) === "number");
143
+ const rows = answerRows(fields.filter((item) => (item == null ? void 0 : item.slug) !== "list"), answers);
144
+ const details = [
145
+ {
146
+ label: "Date",
147
+ value: date(purchasedAt)
148
+ },
149
+ priced && {
150
+ label: "Estimated total",
151
+ value: formatCurrency({ code, value: gross })
152
+ }
153
+ ].filter(Boolean);
154
+ return /* @__PURE__ */ jsxs(
155
+ "div",
156
+ {
157
+ ...{
158
+ className: "space-y-6"
159
+ },
160
+ children: [
161
+ /* @__PURE__ */ jsx(
162
+ StackedRows,
163
+ {
164
+ ...{
165
+ rows: [
166
+ {
167
+ after: cta || void 0,
168
+ label: "Status",
169
+ value: statuses[status] || statuses.open
170
+ }
171
+ ]
172
+ }
173
+ }
174
+ ),
175
+ children,
176
+ /* @__PURE__ */ jsx(
177
+ Lines,
178
+ {
179
+ ...{
180
+ code,
181
+ label: "Items",
182
+ lines,
183
+ untitled: "Untitled item"
184
+ }
185
+ }
186
+ ),
187
+ /* @__PURE__ */ jsx(
188
+ Stacked,
189
+ {
190
+ ...{
191
+ rows: [...rows("lead"), ...rows("additional")],
192
+ title: "Answers"
193
+ }
194
+ }
195
+ ),
196
+ /* @__PURE__ */ jsx(
197
+ Stacked,
198
+ {
199
+ ...{
200
+ rows: rows("order"),
201
+ title: "Order"
202
+ }
203
+ }
204
+ ),
205
+ /* @__PURE__ */ jsx(
206
+ Stacked,
207
+ {
208
+ ...{
209
+ rows: details,
210
+ title: "Details"
211
+ }
212
+ }
213
+ )
214
+ ]
215
+ }
216
+ );
217
+ };
9
218
  const CardOrder = ({
219
+ answers,
220
+ children,
221
+ cta,
10
222
  currency,
11
223
  fee = 0,
224
+ fields,
12
225
  gross = 0,
13
226
  lines = [],
14
227
  net = 0,
15
228
  provider,
16
229
  purchasedAt,
17
230
  rate,
231
+ status,
18
232
  type
19
233
  }) => {
20
234
  const code = (currency || "usd").toUpperCase();
235
+ if (type === "form") return /* @__PURE__ */ jsx(
236
+ FormOrder,
237
+ {
238
+ ...{
239
+ answers,
240
+ children,
241
+ code,
242
+ cta,
243
+ fields,
244
+ gross,
245
+ lines,
246
+ purchasedAt,
247
+ status
248
+ }
249
+ }
250
+ );
21
251
  return /* @__PURE__ */ jsxs(
22
252
  "div",
23
253
  {
@@ -34,84 +264,63 @@ const CardOrder = ({
34
264
  },
35
265
  children: [
36
266
  /* @__PURE__ */ jsx(
37
- CardDataItem,
267
+ Item,
38
268
  {
39
269
  ...{
40
- className: ["flex flex-col", className].join(" "),
41
- classNameSlotLeft: "text-sm disabled",
42
270
  label: "Order number",
43
- value: (provider == null ? void 0 : provider.name) || "\u2014"
271
+ value: provider == null ? void 0 : provider.name
44
272
  }
45
273
  }
46
274
  ),
47
275
  /* @__PURE__ */ jsx(
48
- CardDataItem,
276
+ Item,
49
277
  {
50
278
  ...{
51
- className: ["flex flex-col", className].join(" "),
52
- classNameSlotLeft: "text-sm disabled",
53
279
  label: "Order ID",
54
- value: (provider == null ? void 0 : provider.id) || "\u2014"
280
+ value: provider == null ? void 0 : provider.id
55
281
  }
56
282
  }
57
283
  ),
58
284
  /* @__PURE__ */ jsx(
59
- CardDataItem,
285
+ Item,
60
286
  {
61
287
  ...{
62
- className: ["flex flex-col", className].join(" "),
63
- classNameSlotLeft: "text-sm disabled",
64
288
  label: "Date",
65
- value: purchasedAt ? formatDateString({
66
- date: purchasedAt,
67
- options: {
68
- day: "numeric",
69
- month: "short",
70
- year: "numeric"
71
- }
72
- }) : "\u2014"
289
+ value: date(purchasedAt)
73
290
  }
74
291
  }
75
292
  ),
76
293
  /* @__PURE__ */ jsx(
77
- CardDataItem,
294
+ Item,
78
295
  {
79
296
  ...{
80
- className: ["flex flex-col", className].join(" "),
81
- classNameSlotLeft: "text-sm disabled",
82
297
  label: "Currency",
83
298
  value: code
84
299
  }
85
300
  }
86
301
  ),
87
302
  /* @__PURE__ */ jsx(
88
- CardDataItem,
303
+ Item,
89
304
  {
90
305
  ...{
91
- className: ["flex flex-col", className].join(" "),
92
- classNameSlotLeft: "text-sm disabled",
93
306
  label: "Gross",
94
307
  value: formatCurrency({ code, value: gross })
95
308
  }
96
309
  }
97
310
  ),
98
311
  /* @__PURE__ */ jsx(
99
- CardDataItem,
312
+ Item,
100
313
  {
101
314
  ...{
102
- className: ["flex flex-col", className].join(" "),
103
- classNameSlotLeft: "text-sm disabled",
104
315
  label: "Net",
105
316
  value: formatCurrency({ code, value: net })
106
317
  }
107
318
  }
108
319
  ),
109
320
  /* @__PURE__ */ jsx(
110
- CardDataItem,
321
+ Item,
111
322
  {
112
323
  ...{
113
- className: ["flex flex-col", className].join(" "),
114
- classNameSlotLeft: "text-sm disabled",
115
324
  label: "Fee",
116
325
  // A redemption is charged no fee, so it shows no rate ( rateCell in table.js ).
117
326
  value: formatCurrency({ code, value: fee }) + (type !== "redemption" && (rate || rate === 0) ? " (" + rate + "%)" : "")
@@ -121,97 +330,16 @@ const CardOrder = ({
121
330
  ]
122
331
  }
123
332
  ),
124
- lines.length > 0 && /* @__PURE__ */ jsxs(
125
- "div",
333
+ /* @__PURE__ */ jsx(
334
+ Lines,
126
335
  {
127
336
  ...{
128
- className: "space-y-2"
129
- },
130
- children: [
131
- /* @__PURE__ */ jsx(
132
- "p",
133
- {
134
- ...{
135
- className: "text-sm disabled"
136
- },
137
- children: "Products"
138
- }
139
- ),
140
- /* @__PURE__ */ jsx(
141
- "div",
142
- {
143
- ...{
144
- className: "space-y-3"
145
- },
146
- children: lines.map(({ price = 0, quantity = 0, title, variantTitle }, key) => /* @__PURE__ */ jsxs(
147
- "div",
148
- {
149
- ...{
150
- className: ["space-y-3", className].join(" ")
151
- },
152
- children: [
153
- /* @__PURE__ */ jsxs("div", { children: [
154
- /* @__PURE__ */ jsx("p", { children: title || "Untitled product" }),
155
- variantTitle && /* @__PURE__ */ jsx(
156
- "p",
157
- {
158
- ...{
159
- className: "text-sm text-gray-dark"
160
- },
161
- children: variantTitle
162
- }
163
- )
164
- ] }),
165
- /* @__PURE__ */ jsxs(
166
- "div",
167
- {
168
- ...{
169
- className: "grid grid-cols-3 gap-6"
170
- },
171
- children: [
172
- /* @__PURE__ */ jsx(
173
- CardDataItem,
174
- {
175
- ...{
176
- className: "flex flex-col",
177
- classNameSlotLeft: "text-sm disabled",
178
- label: "Quantity",
179
- value: formatNumber(quantity)
180
- }
181
- }
182
- ),
183
- /* @__PURE__ */ jsx(
184
- CardDataItem,
185
- {
186
- ...{
187
- className: "flex flex-col",
188
- classNameSlotLeft: "text-sm disabled",
189
- label: "Price",
190
- value: formatCurrency({ code, value: price })
191
- }
192
- }
193
- ),
194
- /* @__PURE__ */ jsx(
195
- CardDataItem,
196
- {
197
- ...{
198
- className: "flex flex-col",
199
- classNameSlotLeft: "text-sm disabled",
200
- label: "Total",
201
- value: formatCurrency({ code, value: price * quantity })
202
- }
203
- }
204
- )
205
- ]
206
- }
207
- )
208
- ]
209
- },
210
- key
211
- ))
212
- }
213
- )
214
- ]
337
+ code,
338
+ label: "Products",
339
+ // A store line always has a price.
340
+ lines: lines.map((line) => ({ ...line, price: line.price || 0 })),
341
+ untitled: "Untitled product"
342
+ }
215
343
  }
216
344
  )
217
345
  ]
@@ -98,7 +98,7 @@ const ConnectionWorkflows = ({
98
98
  className: "divide-y divide-gray"
99
99
  },
100
100
  children: items.map((row) => {
101
- var _a, _b, _c;
101
+ var _a, _b, _c, _d;
102
102
  const badge = (0, import_helpers.statusBadge)("workflow", row == null ? void 0 : row.status);
103
103
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
104
104
  "div",
@@ -151,11 +151,20 @@ const ConnectionWorkflows = ({
151
151
  },
152
152
  children: workflowLine(row)
153
153
  }
154
+ ),
155
+ ((_b = row == null ? void 0 : row.issue) == null ? void 0 : _b.message) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
156
+ "p",
157
+ {
158
+ ...{
159
+ className: "text-sm text-red-dark"
160
+ },
161
+ children: row.issue.message
162
+ }
154
163
  )
155
164
  ]
156
165
  }
157
166
  ),
158
- (row == null ? void 0 : row.locked) || !((_b = row == null ? void 0 : row.campaign) == null ? void 0 : _b.id) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
167
+ (row == null ? void 0 : row.locked) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
159
168
  import_badge.default,
160
169
  {
161
170
  ...{
@@ -164,12 +173,12 @@ const ConnectionWorkflows = ({
164
173
  },
165
174
  children: "Locked"
166
175
  }
167
- ) : view && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
176
+ ) : view && ((_c = row == null ? void 0 : row.campaign) == null ? void 0 : _c.id) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
168
177
  import_button.default,
169
178
  {
170
179
  ...{
171
180
  element: import_link.default,
172
- href: "/organizations/" + organization + "/campaigns/" + row.campaign.id + "/workflows/" + ((_c = row == null ? void 0 : row.trigger) == null ? void 0 : _c.event),
181
+ href: "/organizations/" + organization + "/campaigns/" + row.campaign.id + "/workflows/" + ((_d = row == null ? void 0 : row.trigger) == null ? void 0 : _d.event),
173
182
  inline: true,
174
183
  onClick: drawer.close,
175
184
  size: "small",
@@ -64,7 +64,7 @@ const ConnectionWorkflows = ({
64
64
  className: "divide-y divide-gray"
65
65
  },
66
66
  children: items.map((row) => {
67
- var _a, _b, _c;
67
+ var _a, _b, _c, _d;
68
68
  const badge = statusBadge("workflow", row == null ? void 0 : row.status);
69
69
  return /* @__PURE__ */ jsxs(
70
70
  "div",
@@ -117,11 +117,20 @@ const ConnectionWorkflows = ({
117
117
  },
118
118
  children: workflowLine(row)
119
119
  }
120
+ ),
121
+ ((_b = row == null ? void 0 : row.issue) == null ? void 0 : _b.message) && /* @__PURE__ */ jsx(
122
+ "p",
123
+ {
124
+ ...{
125
+ className: "text-sm text-red-dark"
126
+ },
127
+ children: row.issue.message
128
+ }
120
129
  )
121
130
  ]
122
131
  }
123
132
  ),
124
- (row == null ? void 0 : row.locked) || !((_b = row == null ? void 0 : row.campaign) == null ? void 0 : _b.id) ? /* @__PURE__ */ jsx(
133
+ (row == null ? void 0 : row.locked) ? /* @__PURE__ */ jsx(
125
134
  Badge,
126
135
  {
127
136
  ...{
@@ -130,12 +139,12 @@ const ConnectionWorkflows = ({
130
139
  },
131
140
  children: "Locked"
132
141
  }
133
- ) : view && /* @__PURE__ */ jsx(
142
+ ) : view && ((_c = row == null ? void 0 : row.campaign) == null ? void 0 : _c.id) && /* @__PURE__ */ jsx(
134
143
  Button,
135
144
  {
136
145
  ...{
137
146
  element: Link,
138
- href: "/organizations/" + organization + "/campaigns/" + row.campaign.id + "/workflows/" + ((_c = row == null ? void 0 : row.trigger) == null ? void 0 : _c.event),
147
+ href: "/organizations/" + organization + "/campaigns/" + row.campaign.id + "/workflows/" + ((_d = row == null ? void 0 : row.trigger) == null ? void 0 : _d.event),
139
148
  inline: true,
140
149
  onClick: drawer.close,
141
150
  size: "small",
@@ -44,7 +44,7 @@ var import_input_number = __toESM(require("../input-number"));
44
44
  var import_input_file = __toESM(require("./input-file"));
45
45
  var import_input_array = require("./input-array");
46
46
  var import_dropdown = __toESM(require("./dropdown"));
47
- var import_card_asset = __toESM(require("../shared/card-asset"));
47
+ var import_item_row = __toESM(require("./item-row"));
48
48
  var import_ellipsis = __toESM(require("../icons/ellipsis"));
49
49
  var import_arrow_left = __toESM(require("../icons/arrow-left"));
50
50
  var import_button = __toESM(require("../shared/button"));
@@ -269,58 +269,17 @@ const FormOrganizationCampaignFieldList = ({
269
269
  }
270
270
  },
271
271
  children: ({ handle, index }) => {
272
- var _a2;
273
272
  const row = (items == null ? void 0 : items[index]) || {};
274
- const summary = (0, import_item_list.itemSummary)(row, prices, currency);
275
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
276
- "div",
273
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
274
+ import_item_row.default,
277
275
  {
278
276
  ...{
279
- className: "flex items-center min-w-0 flex-1 gap-3"
280
- },
281
- children: [
277
+ description: row.description,
282
278
  handle,
283
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
284
- import_card_asset.default,
285
- {
286
- ...{
287
- asset: row.image || null,
288
- className: "w-10 h-10",
289
- classNameContainer: "bg-gray-light border border-gray",
290
- sizes: "40px",
291
- title: row.description || ((_a2 = row.image) == null ? void 0 : _a2.filename)
292
- }
293
- }
294
- ),
295
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
296
- "span",
297
- {
298
- ...{
299
- className: "flex flex-col min-w-0"
300
- },
301
- children: [
302
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
303
- "span",
304
- {
305
- ...{
306
- className: "truncate"
307
- },
308
- children: row.name || "Untitled item"
309
- }
310
- ),
311
- summary && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
312
- "span",
313
- {
314
- ...{
315
- className: "text-sm text-gray-dark truncate"
316
- },
317
- children: summary
318
- }
319
- )
320
- ]
321
- }
322
- )
323
- ]
279
+ image: row.image,
280
+ name: row.name || "Untitled item",
281
+ summary: (0, import_item_list.itemSummary)(row, prices, currency)
282
+ }
324
283
  }
325
284
  );
326
285
  }