@drawbridge/components 0.1.48 → 0.1.49

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 (125) hide show
  1. package/dist/bridge/fields.js +0 -278
  2. package/dist/bridge/fields.mjs +1 -276
  3. package/dist/bridge/form-subdomain-shop-modal.js +274 -234
  4. package/dist/bridge/form-subdomain-shop-modal.mjs +275 -233
  5. package/dist/bridge/form-subdomain.js +0 -7
  6. package/dist/bridge/form-subdomain.mjs +2 -9
  7. package/dist/bridge/lib/age-gate.js +0 -12
  8. package/dist/bridge/lib/age-gate.mjs +0 -11
  9. package/dist/bridge/lib/checkout-kit.js +32 -2
  10. package/dist/bridge/lib/checkout-kit.mjs +32 -2
  11. package/dist/bridge/lib/entry.js +0 -3
  12. package/dist/bridge/lib/entry.mjs +0 -2
  13. package/dist/bridge/product-tile.js +6 -9
  14. package/dist/bridge/product-tile.mjs +6 -9
  15. package/dist/bridge/template-layout.js +122 -237
  16. package/dist/bridge/template-layout.mjs +122 -237
  17. package/dist/bridge/template-modal.js +73 -28
  18. package/dist/bridge/template-modal.mjs +74 -29
  19. package/dist/dashboard/buttons-subscription.js +1 -1
  20. package/dist/dashboard/buttons-subscription.mjs +1 -1
  21. package/dist/dashboard/campaign-form.js +2 -7
  22. package/dist/dashboard/campaign-form.mjs +2 -7
  23. package/dist/dashboard/card-order.js +4 -22
  24. package/dist/dashboard/card-order.mjs +4 -22
  25. package/dist/dashboard/document-blocks.js +17 -4
  26. package/dist/dashboard/document-blocks.mjs +17 -4
  27. package/dist/dashboard/form-admin-provider.js +17 -71
  28. package/dist/dashboard/form-admin-provider.mjs +17 -71
  29. package/dist/dashboard/form-file-upload.js +2 -3
  30. package/dist/dashboard/form-file-upload.mjs +3 -4
  31. package/dist/dashboard/form-organization-campaign-advertisements.js +6 -47
  32. package/dist/dashboard/form-organization-campaign-advertisements.mjs +6 -47
  33. package/dist/dashboard/form-organization-campaign-agreement.js +121 -83
  34. package/dist/dashboard/form-organization-campaign-agreement.mjs +121 -83
  35. package/dist/dashboard/form-organization-campaign.js +0 -82
  36. package/dist/dashboard/form-organization-campaign.mjs +0 -81
  37. package/dist/dashboard/form-organization-connection.js +6 -48
  38. package/dist/dashboard/form-organization-connection.mjs +7 -48
  39. package/dist/dashboard/form-organization-workflow.js +1 -72
  40. package/dist/dashboard/form-organization-workflow.mjs +1 -69
  41. package/dist/dashboard/form-otc.js +5 -4
  42. package/dist/dashboard/form-otc.mjs +5 -4
  43. package/dist/dashboard/form-stripe.js +5 -12
  44. package/dist/dashboard/form-stripe.mjs +5 -12
  45. package/dist/dashboard/input-fields.js +158 -11
  46. package/dist/dashboard/input-fields.mjs +158 -11
  47. package/dist/dashboard/input-file.js +4 -21
  48. package/dist/dashboard/input-file.mjs +4 -21
  49. package/dist/dashboard/lib/connection-controls.js +2 -5
  50. package/dist/dashboard/lib/connection-controls.mjs +1 -3
  51. package/dist/dashboard/lib/form-page.js +1 -1
  52. package/dist/dashboard/lib/form-page.mjs +1 -1
  53. package/dist/dashboard/lib/uppy.js +1 -10
  54. package/dist/dashboard/lib/uppy.mjs +2 -11
  55. package/dist/dashboard/order-sections.js +6 -456
  56. package/dist/dashboard/order-sections.mjs +7 -453
  57. package/dist/dashboard/provider-ui.js +7 -9
  58. package/dist/dashboard/provider-ui.mjs +7 -9
  59. package/dist/dashboard/template-ui.js +12 -4
  60. package/dist/dashboard/template-ui.mjs +12 -4
  61. package/dist/input-checkbox.js +10 -28
  62. package/dist/input-checkbox.mjs +10 -28
  63. package/dist/product.js +24 -96
  64. package/dist/product.mjs +25 -97
  65. package/dist/shared/lib/helpers.js +6 -54
  66. package/dist/shared/lib/helpers.mjs +8 -53
  67. package/package.json +4 -74
  68. package/types/bridge/fields.d.ts +2 -14
  69. package/types/bridge/form-subdomain-shop-modal.d.ts +3 -27
  70. package/types/bridge/lib/age-gate.d.ts +0 -5
  71. package/types/bridge/lib/checkout-kit.d.ts +10 -2
  72. package/types/bridge/lib/entry.d.ts +0 -3
  73. package/types/dashboard/card-order.d.ts +0 -6
  74. package/types/dashboard/document-blocks.d.ts +3 -2
  75. package/types/dashboard/form-admin-provider.d.ts +2 -9
  76. package/types/dashboard/form-file-upload.d.ts +1 -2
  77. package/types/dashboard/form-organization-campaign-advertisements.d.ts +0 -3
  78. package/types/dashboard/form-organization-campaign-agreement.d.ts +5 -2
  79. package/types/dashboard/form-organization-campaign.d.ts +0 -3
  80. package/types/dashboard/form-organization-connection.d.ts +0 -11
  81. package/types/dashboard/form-otc.d.ts +1 -5
  82. package/types/dashboard/form-stripe.d.ts +2 -3
  83. package/types/dashboard/input-file.d.ts +0 -2
  84. package/types/dashboard/order-sections.d.ts +1 -24
  85. package/types/input-checkbox.d.ts +0 -2
  86. package/types/shared/lib/helpers.d.ts +0 -4
  87. package/dist/bridge/cart-drawer.js +0 -152
  88. package/dist/bridge/cart-drawer.mjs +0 -123
  89. package/dist/bridge/form-subdomain-checkout.js +0 -687
  90. package/dist/bridge/form-subdomain-checkout.mjs +0 -665
  91. package/dist/bridge/lib/cart.js +0 -79
  92. package/dist/bridge/lib/cart.mjs +0 -48
  93. package/dist/dashboard/embed-stripe.js +0 -145
  94. package/dist/dashboard/embed-stripe.mjs +0 -116
  95. package/dist/dashboard/form-organization-campaign-field-birthday.js +0 -193
  96. package/dist/dashboard/form-organization-campaign-field-birthday.mjs +0 -164
  97. package/dist/dashboard/form-organization-campaign-field-rating.js +0 -246
  98. package/dist/dashboard/form-organization-campaign-field-rating.mjs +0 -217
  99. package/dist/dashboard/form-organization-product.js +0 -1461
  100. package/dist/dashboard/form-organization-product.mjs +0 -1425
  101. package/dist/dashboard/input-gallery.js +0 -201
  102. package/dist/dashboard/input-gallery.mjs +0 -172
  103. package/dist/dashboard/lib/products.js +0 -169
  104. package/dist/dashboard/lib/products.mjs +0 -135
  105. package/dist/dashboard/lib/settings-paths.js +0 -35
  106. package/dist/dashboard/lib/settings-paths.mjs +0 -11
  107. package/dist/dashboard/shipping-rates.js +0 -404
  108. package/dist/dashboard/shipping-rates.mjs +0 -371
  109. package/dist/dashboard/template-buyer.js +0 -301
  110. package/dist/dashboard/template-buyer.mjs +0 -267
  111. package/dist/shared/order-summary.js +0 -139
  112. package/dist/shared/order-summary.mjs +0 -110
  113. package/types/bridge/cart-drawer.d.ts +0 -31
  114. package/types/bridge/form-subdomain-checkout.d.ts +0 -20
  115. package/types/bridge/lib/cart.d.ts +0 -44
  116. package/types/dashboard/embed-stripe.d.ts +0 -25
  117. package/types/dashboard/form-organization-campaign-field-birthday.d.ts +0 -31
  118. package/types/dashboard/form-organization-campaign-field-rating.d.ts +0 -33
  119. package/types/dashboard/form-organization-product.d.ts +0 -24
  120. package/types/dashboard/input-gallery.d.ts +0 -14
  121. package/types/dashboard/lib/products.d.ts +0 -14
  122. package/types/dashboard/lib/settings-paths.d.ts +0 -5
  123. package/types/dashboard/shipping-rates.d.ts +0 -26
  124. package/types/dashboard/template-buyer.d.ts +0 -50
  125. package/types/shared/order-summary.d.ts +0 -19
@@ -1,1461 +0,0 @@
1
- "use client";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var form_organization_product_exports = {};
30
- __export(form_organization_product_exports, {
31
- FormOrganizationProduct: () => FormOrganizationProduct,
32
- FormOrganizationProductCreate: () => FormOrganizationProductCreate,
33
- FormProductOption: () => FormProductOption,
34
- FormProductVariant: () => FormProductVariant,
35
- default: () => form_organization_product_default
36
- });
37
- module.exports = __toCommonJS(form_organization_product_exports);
38
- var import_jsx_runtime = require("react/jsx-runtime");
39
- var import_react = require("react");
40
- var import_react_query = require("@tanstack/react-query");
41
- var import_fetch = require("@drawbridge/drawbridge-utils/fetch");
42
- var import_products = require("@drawbridge/drawbridge-utils/products");
43
- var import_form = require("../shared/lib/form");
44
- var import_yup = __toESM(require("../shared/lib/yup"));
45
- var import_form2 = __toESM(require("../shared/form"));
46
- var import_fieldset = __toESM(require("../shared/fieldset"));
47
- var import_button = __toESM(require("../shared/button"));
48
- var import_badge = __toESM(require("../shared/badge"));
49
- var import_empty = __toESM(require("../shared/empty"));
50
- var import_input_switch = __toESM(require("../shared/input-switch"));
51
- var import_input_group = __toESM(require("../input-group"));
52
- var import_input_text = __toESM(require("../input-text"));
53
- var import_input_textarea = __toESM(require("../input-textarea"));
54
- var import_input_number = __toESM(require("../input-number"));
55
- var import_input_select = __toESM(require("../input-select"));
56
- var import_input_checkbox = __toESM(require("../input-checkbox"));
57
- var import_card_section = __toESM(require("./card-section"));
58
- var import_table = __toESM(require("./table"));
59
- var import_table_cell_title = __toESM(require("./table-cell-title"));
60
- var import_input_gallery = __toESM(require("./input-gallery"));
61
- var import_input_file = __toESM(require("./input-file"));
62
- var import_input_array = require("./input-array");
63
- var import_list_resource = __toESM(require("./list-resource"));
64
- var import_helpers = require("../shared/lib/helpers");
65
- var import_hooks = require("./lib/hooks");
66
- var import_products2 = require("./lib/products");
67
- var import_chevron_down = __toESM(require("../icons/chevron-down"));
68
- var import_chevron_up = __toESM(require("../icons/chevron-up"));
69
- var import_external = __toESM(require("../icons/external"));
70
- var import_pencil = __toESM(require("../icons/pencil"));
71
- var import_plus = __toESM(require("../icons/plus"));
72
- var import_trash = __toESM(require("../icons/trash"));
73
- const FormOrganizationProductCreate = ({
74
- campaign,
75
- onError,
76
- onSuccess,
77
- organization
78
- }) => {
79
- const { control, formState, handleSubmit } = (0, import_form.useForm)({
80
- defaultValues: {
81
- title: ""
82
- },
83
- resolver: (0, import_yup.resolver)(
84
- import_yup.default.object({
85
- title: import_yup.default.string().trim().max(255).required("Title is required")
86
- })
87
- )
88
- });
89
- const onSubmit = async ({ title }) => {
90
- try {
91
- const response = await (0, import_fetch.request)({
92
- body: {
93
- title
94
- },
95
- endpoint: "/organization/" + organization + "/campaign/" + campaign + "/product",
96
- method: "POST"
97
- });
98
- onSuccess(response);
99
- } catch (error) {
100
- onError(error);
101
- }
102
- };
103
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
104
- import_form2.default,
105
- {
106
- ...{
107
- className: "relative w-full space-y-6",
108
- onSubmit: handleSubmit(onSubmit)
109
- },
110
- children: [
111
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
112
- import_fieldset.default,
113
- {
114
- ...{
115
- disabled: formState == null ? void 0 : formState.isSubmitting
116
- },
117
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
118
- import_form.Controller,
119
- {
120
- ...{
121
- control,
122
- name: "title",
123
- render: ({ field: { onChange, value } }) => {
124
- var _a, _b;
125
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
126
- import_input_group.default,
127
- {
128
- ...{
129
- error: (_b = (_a = formState == null ? void 0 : formState.errors) == null ? void 0 : _a.title) == null ? void 0 : _b.message,
130
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
131
- import_input_text.default,
132
- {
133
- ...{
134
- onChange,
135
- placeholder: "House blend",
136
- value: value || ""
137
- }
138
- }
139
- ),
140
- label: "Title"
141
- }
142
- }
143
- );
144
- }
145
- }
146
- }
147
- )
148
- }
149
- ),
150
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fieldset.default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
151
- import_button.default,
152
- {
153
- ...{
154
- loading: formState == null ? void 0 : formState.isSubmitting,
155
- type: "submit"
156
- },
157
- children: "Submit"
158
- }
159
- ) })
160
- ]
161
- }
162
- );
163
- };
164
- const statuses = [
165
- {
166
- label: "Published",
167
- value: "published"
168
- },
169
- {
170
- label: "Drafted",
171
- value: "drafted"
172
- }
173
- ];
174
- const field = ({ control, input, label, name }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
175
- import_form.Controller,
176
- {
177
- ...{
178
- control,
179
- name,
180
- render: ({ field: { onChange, value } }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
181
- import_input_group.default,
182
- {
183
- ...{
184
- input: input({
185
- onChange,
186
- value
187
- }),
188
- label
189
- }
190
- }
191
- )
192
- }
193
- }
194
- );
195
- const VariantFields = ({ control, digital, inline = false, prefix = "", setValue }) => {
196
- const path = (key) => prefix + key;
197
- const quantity = (0, import_form.useWatch)({
198
- control,
199
- name: path("inventoryQuantity")
200
- });
201
- const tracked = quantity !== null && quantity !== void 0;
202
- const money = ({ onChange, value }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
203
- import_input_number.default,
204
- {
205
- ...{
206
- min: 0,
207
- onChange,
208
- step: 0.01,
209
- value: value ?? ""
210
- }
211
- }
212
- );
213
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
214
- "div",
215
- {
216
- ...{
217
- className: "space-y-6"
218
- },
219
- children: [
220
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
221
- "div",
222
- {
223
- ...{
224
- className: inline ? "grid grid-cols-2 gap-4" : ""
225
- },
226
- children: [
227
- inline && field({ control, input: money, label: "Price", name: path("price") }),
228
- field({ control, input: money, label: "Original price", name: path("sale") })
229
- ]
230
- }
231
- ),
232
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
233
- import_form.Controller,
234
- {
235
- ...{
236
- control,
237
- name: path("taxable"),
238
- render: ({ field: { onChange, value } }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
239
- import_input_checkbox.default,
240
- {
241
- ...{
242
- label: inline ? "Charge tax on this product" : "Charge tax on this variant",
243
- onChange,
244
- value: value !== false
245
- }
246
- }
247
- )
248
- }
249
- }
250
- ),
251
- field({
252
- control,
253
- input: ({ onChange, value }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
254
- import_input_text.default,
255
- {
256
- ...{
257
- onChange,
258
- value: value || ""
259
- }
260
- }
261
- ),
262
- label: "SKU",
263
- name: path("sku")
264
- }),
265
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
266
- import_input_group.default,
267
- {
268
- ...{
269
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
270
- "div",
271
- {
272
- ...{
273
- className: "flex items-center gap-3"
274
- },
275
- children: [
276
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
277
- import_input_switch.default,
278
- {
279
- ...{
280
- onChange: (on) => setValue(path("inventoryQuantity"), on ? 0 : null, { shouldDirty: true }),
281
- value: tracked
282
- }
283
- }
284
- ),
285
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
286
- "div",
287
- {
288
- ...{
289
- className: "flex-1"
290
- },
291
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
292
- import_input_number.default,
293
- {
294
- ...{
295
- "aria-label": "Quantity",
296
- disabled: !tracked,
297
- min: 0,
298
- onChange: (value) => setValue(path("inventoryQuantity"), Number.isFinite(value) ? Math.max(0, Math.round(value)) : 0, { shouldDirty: true }),
299
- value: tracked ? quantity : ""
300
- }
301
- }
302
- )
303
- }
304
- )
305
- ]
306
- }
307
- ),
308
- label: "Track quantity"
309
- }
310
- }
311
- ),
312
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
313
- import_form.Controller,
314
- {
315
- ...{
316
- control,
317
- name: path("requiresShipping"),
318
- render: ({ field: { onChange, value } }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
319
- import_input_group.default,
320
- {
321
- ...{
322
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
323
- import_input_switch.default,
324
- {
325
- ...{
326
- onChange,
327
- value: value !== false
328
- }
329
- }
330
- ),
331
- label: "Physical product"
332
- }
333
- }
334
- )
335
- }
336
- }
337
- ),
338
- digital && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
339
- import_form.Controller,
340
- {
341
- ...{
342
- control,
343
- name: path("file"),
344
- render: ({ field: { onChange, value } }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
345
- import_input_group.default,
346
- {
347
- ...{
348
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
349
- import_input_file.default,
350
- {
351
- ...{
352
- button: {
353
- text: "Upload a file"
354
- },
355
- digital: true,
356
- endpoint: digital.endpoint,
357
- onChange: (file) => onChange(file || null),
358
- value
359
- }
360
- }
361
- ),
362
- label: "Digital file"
363
- }
364
- }
365
- )
366
- }
367
- }
368
- )
369
- ]
370
- }
371
- );
372
- };
373
- const FormProductVariant = ({
374
- digital,
375
- disabled = false,
376
- onDone,
377
- values
378
- }) => {
379
- const { control, handleSubmit, setValue } = (0, import_form.useForm)({
380
- guard: false,
381
- values
382
- });
383
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
384
- import_form2.default,
385
- {
386
- ...{
387
- className: "relative w-full space-y-6",
388
- onSubmit: handleSubmit(onDone)
389
- },
390
- children: [
391
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
392
- import_fieldset.default,
393
- {
394
- ...{
395
- disabled
396
- },
397
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
398
- VariantFields,
399
- {
400
- ...{
401
- control,
402
- digital,
403
- setValue
404
- }
405
- }
406
- )
407
- }
408
- ),
409
- !disabled && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fieldset.default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
410
- import_button.default,
411
- {
412
- ...{
413
- type: "submit"
414
- },
415
- children: "Done"
416
- }
417
- ) })
418
- ]
419
- }
420
- );
421
- };
422
- const FormProductOption = ({
423
- disabled = false,
424
- onDone,
425
- others = [],
426
- values = {
427
- name: "",
428
- values: []
429
- }
430
- }) => {
431
- var _a, _b;
432
- const { control, formState, handleSubmit, setError } = (0, import_form.useForm)({
433
- defaultValues: {
434
- name: values.name,
435
- values: (values.values || []).map((value) => ({
436
- value
437
- }))
438
- },
439
- guard: false,
440
- resolver: (0, import_yup.resolver)(
441
- import_yup.default.object({
442
- name: import_yup.default.string().trim().max(100).required("Option name is required"),
443
- values: import_yup.default.array().of(
444
- import_yup.default.object({
445
- value: import_yup.default.string().trim().max(100)
446
- })
447
- )
448
- })
449
- )
450
- });
451
- const onSubmit = (submitted) => {
452
- const option = {
453
- name: submitted.name.trim(),
454
- values: [...new Set(submitted.values.map((item) => (item.value || "").trim()).filter(Boolean))]
455
- };
456
- if (others.some((other) => other.name.toLowerCase() === option.name.toLowerCase())) {
457
- return setError("name", { message: "Another option has this name" });
458
- }
459
- if (!option.values.length) {
460
- return setError("values", { message: "Add at least one value" });
461
- }
462
- if ((0, import_products2.variantCount)([...others, option]) > import_products.MAX_VARIANTS) {
463
- return setError("values", { message: "A product can have up to 2,048 variants" });
464
- }
465
- onDone(option);
466
- };
467
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
468
- import_form2.default,
469
- {
470
- ...{
471
- className: "relative w-full space-y-6",
472
- onSubmit: handleSubmit(onSubmit)
473
- },
474
- children: [
475
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
476
- import_fieldset.default,
477
- {
478
- ...{
479
- disabled
480
- },
481
- children: [
482
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
483
- import_form.Controller,
484
- {
485
- ...{
486
- control,
487
- name: "name",
488
- render: ({ field: { onChange, value } }) => {
489
- var _a2, _b2;
490
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
491
- import_input_group.default,
492
- {
493
- ...{
494
- error: (_b2 = (_a2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a2.name) == null ? void 0 : _b2.message,
495
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
496
- import_input_text.default,
497
- {
498
- ...{
499
- onChange,
500
- placeholder: "Size",
501
- value: value || ""
502
- }
503
- }
504
- ),
505
- label: "Option name"
506
- }
507
- }
508
- );
509
- }
510
- }
511
- }
512
- ),
513
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
514
- import_input_group.default,
515
- {
516
- ...{
517
- error: (_b = (_a = formState == null ? void 0 : formState.errors) == null ? void 0 : _a.values) == null ? void 0 : _b.message,
518
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
519
- import_input_array.InputArraySortable,
520
- {
521
- ...{
522
- control,
523
- empty: "No values yet",
524
- name: "values",
525
- renderButton: (append) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
526
- import_button.default,
527
- {
528
- ...{
529
- icon: import_plus.default,
530
- justify: "between",
531
- onClick: () => append({
532
- value: ""
533
- }),
534
- variant: "secondary"
535
- },
536
- children: "Add another value"
537
- }
538
- ),
539
- renderControls: ({ index, remove }) => [
540
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
541
- import_input_array.InputArrayControl,
542
- {
543
- ...{
544
- icon: import_trash.default,
545
- onClick: () => remove(index)
546
- }
547
- },
548
- "value-remove-" + index
549
- )
550
- ]
551
- },
552
- children: ({ field: item, handle, index, update }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
553
- "div",
554
- {
555
- ...{
556
- className: "flex items-center min-w-0 flex-1 space-x-3"
557
- },
558
- children: [
559
- handle,
560
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
561
- "div",
562
- {
563
- ...{
564
- className: "flex-1"
565
- },
566
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
567
- import_input_text.default,
568
- {
569
- ...{
570
- "aria-label": "Option value",
571
- onChange: (value) => update(index, {
572
- value
573
- }),
574
- value: item.value || ""
575
- }
576
- }
577
- )
578
- }
579
- )
580
- ]
581
- }
582
- )
583
- }
584
- ),
585
- label: "Option values"
586
- }
587
- }
588
- )
589
- ]
590
- }
591
- ),
592
- !disabled && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fieldset.default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
593
- import_button.default,
594
- {
595
- ...{
596
- type: "submit"
597
- },
598
- children: "Done"
599
- }
600
- ) })
601
- ]
602
- }
603
- );
604
- };
605
- const ShopifyImages = ({ images = [], updatedAt }) => images.length ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
606
- import_table.default,
607
- {
608
- ...{
609
- columns: [
610
- {
611
- cell: ({ row }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
612
- import_table_cell_title.default,
613
- {
614
- ...{
615
- asset: {
616
- mimetype: "image",
617
- sizes: {
618
- "100x100": row.original.url
619
- },
620
- updatedAt
621
- },
622
- title: row.original.description || "Image " + (row.index + 1)
623
- }
624
- }
625
- ),
626
- header: "Image",
627
- id: "image",
628
- sortable: false
629
- }
630
- ],
631
- data: images,
632
- headers: false
633
- }
634
- }
635
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
636
- import_empty.default,
637
- {
638
- ...{
639
- variant: "secondary"
640
- },
641
- children: "Gallery is empty"
642
- }
643
- );
644
- const recommendedTitle = (item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
645
- import_table_cell_title.default,
646
- {
647
- ...{
648
- asset: (0, import_helpers.productAsset)(item),
649
- subtitle: (0, import_products2.priceText)((item == null ? void 0 : item.variants) || []),
650
- title: (item == null ? void 0 : item.title) || "Untitled"
651
- }
652
- }
653
- );
654
- const FormOrganizationProduct = ({
655
- campaign,
656
- disabled: readOnly = false,
657
- onDelete,
658
- onError,
659
- onSuccess,
660
- organization,
661
- product
662
- }) => {
663
- var _a, _b, _c, _d;
664
- const queryClient = (0, import_react_query.useQueryClient)();
665
- const modal = (0, import_hooks.useModal)({ queryClient });
666
- const editable = Boolean(product == null ? void 0 : product.editable) && !readOnly;
667
- const currency = ((_c = (_b = (_a = product == null ? void 0 : product.variants) == null ? void 0 : _a[0]) == null ? void 0 : _b.currency) == null ? void 0 : _c.toUpperCase()) || null;
668
- const digital = (product == null ? void 0 : product.editable) ? {
669
- endpoint: "/organization/" + (organization == null ? void 0 : organization.id)
670
- } : null;
671
- const methods = (0, import_form.useForm)({
672
- values: {
673
- description: (product == null ? void 0 : product.description) || "",
674
- gallery: ((product == null ? void 0 : product.images) || []).filter((item) => item == null ? void 0 : item.file),
675
- options: (product == null ? void 0 : product.options) || [],
676
- recommendations: (product == null ? void 0 : product.recommended) || [],
677
- status: (product == null ? void 0 : product.status) || "drafted",
678
- title: (product == null ? void 0 : product.title) || "",
679
- variants: (product == null ? void 0 : product.variants) || []
680
- }
681
- });
682
- const { control, formState, getValues, handleSubmit, setValue } = methods;
683
- const options = (0, import_form.useWatch)({ control, name: "options" }) || [];
684
- const variants = (0, import_form.useWatch)({ control, name: "variants" }) || [];
685
- const recommendations = (0, import_form.useWatch)({ control, name: "recommendations" }) || [];
686
- const [group, setGroup] = (0, import_react.useState)(null);
687
- const [expanded, setExpanded] = (0, import_react.useState)([]);
688
- const grouping = options.some((option) => option.name === group) ? group : (_d = options[0]) == null ? void 0 : _d.name;
689
- const changeOptions = (next) => {
690
- setValue("options", next, { shouldDirty: true });
691
- setValue("variants", (0, import_products2.variantsFor)(next, getValues("variants")), { shouldDirty: true });
692
- };
693
- const openOption = (index) => {
694
- const current = getValues("options");
695
- modal.open({
696
- message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
697
- FormProductOption,
698
- {
699
- ...{
700
- disabled: !editable,
701
- onDone: (option) => {
702
- changeOptions(index === null ? [...current, option] : current.map((item, key) => key === index ? option : item));
703
- modal.close();
704
- },
705
- others: current.filter((item, key) => key !== index),
706
- ...index !== null && {
707
- values: current[index]
708
- }
709
- }
710
- }
711
- ),
712
- title: index === null ? "Add option" : "Edit option"
713
- });
714
- };
715
- const openVariant = (index) => {
716
- const variant = getValues("variants." + index);
717
- modal.open({
718
- message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
719
- FormProductVariant,
720
- {
721
- ...{
722
- digital,
723
- disabled: !editable,
724
- onDone: (values) => {
725
- setValue("variants." + index, {
726
- ...variant,
727
- file: values.file || null,
728
- inventoryQuantity: values.inventoryQuantity ?? null,
729
- requiresShipping: values.requiresShipping !== false,
730
- sale: Number.isFinite(values.sale) ? values.sale : null,
731
- sku: values.sku || null,
732
- taxable: values.taxable !== false
733
- }, { shouldDirty: true });
734
- modal.close();
735
- },
736
- values: variant
737
- }
738
- }
739
- ),
740
- title: (variant == null ? void 0 : variant.title) || "Variant"
741
- });
742
- };
743
- const onSubmit = async (values) => {
744
- try {
745
- const response = await (0, import_fetch.request)({
746
- body: (0, import_products2.productBody)(values, product == null ? void 0 : product.variants),
747
- endpoint: "/organization/" + (organization == null ? void 0 : organization.id) + "/product/" + product.id,
748
- method: "PUT"
749
- });
750
- onSuccess(response);
751
- } catch (error) {
752
- onError(error);
753
- }
754
- };
755
- const openRecommendation = () => {
756
- const current = getValues("recommendations") || [];
757
- modal.open({
758
- message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
759
- import_list_resource.default,
760
- {
761
- ...{
762
- endpoint: "/organization/" + (organization == null ? void 0 : organization.id) + "/products",
763
- model: "product",
764
- onChange: (item) => {
765
- setValue("recommendations", [...current, item].slice(0, import_products.MAX_RECOMMENDATIONS), { shouldDirty: true });
766
- modal.close();
767
- },
768
- params: {
769
- // Left out by the api, so the pages count only what is listed.
770
- exclude: [product == null ? void 0 : product.id, ...current.map((item) => item == null ? void 0 : item.id)].filter(Boolean),
771
- provider: import_products.PRODUCT_PROVIDER.stripe
772
- },
773
- render: recommendedTitle,
774
- selected: current
775
- }
776
- }
777
- ),
778
- title: "Select a product"
779
- });
780
- };
781
- const setPrice = (indexes, price) => indexes.forEach((index) => setValue("variants." + index + ".price", price, { shouldDirty: true }));
782
- const rows = (0, import_products2.variantRows)({ expanded, group: grouping, options, variants });
783
- const priceCell = (row) => row.price === null && row.range ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
784
- "span",
785
- {
786
- ...{
787
- className: "text-gray-dark"
788
- },
789
- children: row.range
790
- }
791
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
792
- "div",
793
- {
794
- ...{
795
- className: "w-36"
796
- },
797
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
798
- import_input_number.default,
799
- {
800
- ...{
801
- "aria-label": "Price for " + row.title,
802
- disabled: !editable,
803
- min: 0,
804
- onChange: (value) => setPrice(row.group ? row.children : [row.index], value),
805
- step: 0.01,
806
- value: row.price ?? ""
807
- }
808
- }
809
- )
810
- }
811
- );
812
- const quantityCell = (row) => {
813
- if (row.group) return row.inventoryQuantity;
814
- if (row.inventoryQuantity === null || row.inventoryQuantity === void 0) return "\u2014";
815
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
816
- "div",
817
- {
818
- ...{
819
- className: "w-36"
820
- },
821
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
822
- import_input_number.default,
823
- {
824
- ...{
825
- "aria-label": "Quantity for " + row.title,
826
- disabled: !editable,
827
- min: 0,
828
- onChange: (value) => setValue("variants." + row.index + ".inventoryQuantity", Number.isFinite(value) ? Math.max(0, Math.round(value)) : 0, { shouldDirty: true }),
829
- value: row.inventoryQuantity
830
- }
831
- }
832
- )
833
- }
834
- );
835
- };
836
- const columns = [
837
- {
838
- cell: ({ row }) => {
839
- const item = row.original;
840
- const soldOut = !item.group && item.inventoryQuantity === 0;
841
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
842
- "div",
843
- {
844
- ...{
845
- className: item.child ? "pl-5" : ""
846
- },
847
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
848
- import_table_cell_title.default,
849
- {
850
- ...{
851
- status: soldOut ? {
852
- text: "Sold out",
853
- type: "error"
854
- } : null,
855
- subtitle: item.group ? item.variants + (item.variants === 1 ? " variant" : " variants") : null,
856
- title: item.title
857
- }
858
- }
859
- )
860
- }
861
- );
862
- },
863
- header: "Variant",
864
- id: "title",
865
- meta: {
866
- className: "w-full px-4 text-left"
867
- },
868
- sortable: false
869
- },
870
- {
871
- cell: ({ row }) => priceCell(row.original),
872
- header: "Price",
873
- id: "price",
874
- meta: {
875
- className: "w-44 px-4 text-left"
876
- },
877
- sortable: false
878
- },
879
- {
880
- cell: ({ row }) => quantityCell(row.original),
881
- header: "Quantity",
882
- id: "inventory",
883
- meta: {
884
- className: "w-44 px-4 text-left"
885
- },
886
- sortable: false
887
- }
888
- ];
889
- const toggle = (value) => setExpanded(expanded.includes(value) ? expanded.filter((item) => item !== value) : [...expanded, value]);
890
- const campaigns = [
891
- ...((product == null ? void 0 : product.campaigns) || []).filter((item) => item.id === campaign).map((item) => ({
892
- ...item,
893
- current: true
894
- })),
895
- ...((product == null ? void 0 : product.campaigns) || []).filter((item) => item.id !== campaign)
896
- ];
897
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_form.FormProvider, { ...methods, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
898
- import_form2.default,
899
- {
900
- ...{
901
- className: "grid grid-cols-1 gap-6 xl:grid-cols-3",
902
- onSubmit: handleSubmit(onSubmit)
903
- },
904
- children: [
905
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
906
- "div",
907
- {
908
- ...{
909
- className: "space-y-6 xl:col-span-2"
910
- },
911
- children: [
912
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
913
- import_card_section.default,
914
- {
915
- ...{
916
- className: "shrink-0"
917
- },
918
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
919
- import_fieldset.default,
920
- {
921
- ...{
922
- disabled: !editable
923
- },
924
- children: [
925
- field({
926
- control,
927
- input: ({ onChange, value }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
928
- import_input_text.default,
929
- {
930
- ...{
931
- onChange,
932
- placeholder: "House blend",
933
- value: value || ""
934
- }
935
- }
936
- ),
937
- label: "Title",
938
- name: "title"
939
- }),
940
- field({
941
- control,
942
- input: ({ onChange, value }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
943
- import_input_textarea.default,
944
- {
945
- ...{
946
- onChange,
947
- rows: 4,
948
- value: value || ""
949
- }
950
- }
951
- ),
952
- label: "Description",
953
- name: "description"
954
- })
955
- ]
956
- }
957
- )
958
- }
959
- ),
960
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
961
- import_card_section.default,
962
- {
963
- ...{
964
- className: "shrink-0",
965
- title: "Gallery"
966
- },
967
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: editable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
968
- import_input_gallery.default,
969
- {
970
- ...{
971
- endpoint: "/organization/" + (organization == null ? void 0 : organization.id),
972
- label: null,
973
- organization
974
- }
975
- }
976
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
977
- ShopifyImages,
978
- {
979
- ...{
980
- images: ((product == null ? void 0 : product.images) || []).filter((item) => item == null ? void 0 : item.url),
981
- updatedAt: product == null ? void 0 : product.updatedAt
982
- }
983
- }
984
- ) })
985
- }
986
- ),
987
- !options.length && variants.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
988
- import_card_section.default,
989
- {
990
- ...{
991
- className: "shrink-0",
992
- title: "Price"
993
- },
994
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
995
- import_fieldset.default,
996
- {
997
- ...{
998
- disabled: !editable
999
- },
1000
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1001
- VariantFields,
1002
- {
1003
- ...{
1004
- control,
1005
- digital,
1006
- inline: true,
1007
- prefix: "variants.0.",
1008
- setValue
1009
- }
1010
- }
1011
- )
1012
- }
1013
- )
1014
- }
1015
- ),
1016
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1017
- import_card_section.default,
1018
- {
1019
- ...{
1020
- className: "shrink-0",
1021
- ...editable && options.length < import_products.MAX_OPTIONS && {
1022
- cta: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1023
- import_button.default,
1024
- {
1025
- ...{
1026
- icon: import_plus.default,
1027
- inline: true,
1028
- onClick: () => openOption(null),
1029
- size: "small",
1030
- variant: "secondary"
1031
- },
1032
- children: "Add another option"
1033
- }
1034
- )
1035
- },
1036
- title: "Variants"
1037
- },
1038
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1039
- "div",
1040
- {
1041
- ...{
1042
- className: "space-y-4"
1043
- },
1044
- children: [
1045
- options.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1046
- "div",
1047
- {
1048
- ...{
1049
- className: "divide-y divide-gray rounded border border-gray"
1050
- },
1051
- children: options.map((option, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1052
- "div",
1053
- {
1054
- ...{
1055
- className: "flex w-full items-start gap-3 p-4"
1056
- },
1057
- children: [
1058
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1059
- "div",
1060
- {
1061
- ...{
1062
- className: "flex-1 min-w-0"
1063
- },
1064
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1065
- import_button.default,
1066
- {
1067
- ...{
1068
- "aria-label": "Edit " + option.name,
1069
- justify: "start",
1070
- onClick: () => openOption(index),
1071
- variant: "link"
1072
- },
1073
- children: [
1074
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1075
- "span",
1076
- {
1077
- ...{
1078
- className: "block"
1079
- },
1080
- children: option.name
1081
- }
1082
- ),
1083
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1084
- "span",
1085
- {
1086
- ...{
1087
- className: "flex flex-wrap gap-2"
1088
- },
1089
- children: option.values.map((value) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_badge.default, { children: value }, value))
1090
- }
1091
- )
1092
- ]
1093
- }
1094
- )
1095
- }
1096
- ),
1097
- editable && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1098
- import_input_array.InputArrayControl,
1099
- {
1100
- ...{
1101
- "aria-label": "Remove " + option.name,
1102
- icon: import_trash.default,
1103
- onClick: () => changeOptions(options.filter((item, key) => key !== index))
1104
- }
1105
- }
1106
- )
1107
- ]
1108
- },
1109
- "option-" + option.name
1110
- ))
1111
- }
1112
- ),
1113
- !options.length && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1114
- import_empty.default,
1115
- {
1116
- ...{
1117
- variant: "secondary"
1118
- },
1119
- children: "No options yet"
1120
- }
1121
- ),
1122
- options.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1123
- "div",
1124
- {
1125
- ...{
1126
- className: "space-y-4"
1127
- },
1128
- children: [
1129
- options.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1130
- "div",
1131
- {
1132
- ...{
1133
- className: "w-48"
1134
- },
1135
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1136
- import_input_group.default,
1137
- {
1138
- ...{
1139
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1140
- import_input_select.default,
1141
- {
1142
- ...{
1143
- onChange: setGroup,
1144
- options: options.map((option) => ({
1145
- label: option.name,
1146
- value: option.name
1147
- })),
1148
- value: grouping
1149
- }
1150
- }
1151
- ),
1152
- label: "Group by"
1153
- }
1154
- }
1155
- )
1156
- }
1157
- ),
1158
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1159
- "div",
1160
- {
1161
- ...{
1162
- className: "overflow-x-auto"
1163
- },
1164
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1165
- import_table.default,
1166
- {
1167
- ...{
1168
- actions: (row) => row.group ? {
1169
- button: {
1170
- "aria-label": (expanded.includes(row.title) ? "Close " : "Open ") + row.title,
1171
- element: "button",
1172
- icon: expanded.includes(row.title) ? import_chevron_up.default : import_chevron_down.default,
1173
- onClick: () => toggle(row.title),
1174
- text: null
1175
- }
1176
- } : {
1177
- button: {
1178
- "aria-label": "More for " + row.title,
1179
- element: "button",
1180
- icon: import_pencil.default,
1181
- onClick: () => openVariant(row.index),
1182
- text: null
1183
- }
1184
- },
1185
- columns,
1186
- data: rows
1187
- }
1188
- }
1189
- )
1190
- }
1191
- ),
1192
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1193
- "p",
1194
- {
1195
- ...{
1196
- className: "text-sm text-gray-dark"
1197
- },
1198
- children: "Total quantity: " + (0, import_products2.totalQuantity)(variants)
1199
- }
1200
- )
1201
- ]
1202
- }
1203
- )
1204
- ]
1205
- }
1206
- )
1207
- }
1208
- ),
1209
- ((product == null ? void 0 : product.editable) || recommendations.length > 0) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1210
- import_card_section.default,
1211
- {
1212
- ...{
1213
- className: "shrink-0",
1214
- // @story products/recommended
1215
- // A Drawbridge product's plus, until 10 are chosen; a Shopify
1216
- // product's picks are changed in Shopify.
1217
- ...editable && recommendations.length < import_products.MAX_RECOMMENDATIONS && {
1218
- cta: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1219
- import_button.default,
1220
- {
1221
- ...{
1222
- "aria-label": "Add a recommended product",
1223
- icon: import_plus.default,
1224
- inline: true,
1225
- onClick: openRecommendation,
1226
- size: "small",
1227
- variant: "secondary"
1228
- }
1229
- }
1230
- )
1231
- },
1232
- ...!(product == null ? void 0 : product.editable) && (product == null ? void 0 : product.edit) && {
1233
- cta: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1234
- import_button.default,
1235
- {
1236
- ...{
1237
- element: "a",
1238
- href: product.edit,
1239
- icon: import_external.default,
1240
- inline: true,
1241
- size: "small",
1242
- target: "_blank",
1243
- variant: "secondary"
1244
- },
1245
- children: "Edit in Shopify"
1246
- }
1247
- )
1248
- },
1249
- title: "Recommended products"
1250
- },
1251
- children: recommendations.length ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1252
- import_table.default,
1253
- {
1254
- ...{
1255
- actions: (row) => editable ? {
1256
- button: {
1257
- "aria-label": "Remove " + (row.title || "product"),
1258
- element: "button",
1259
- icon: import_trash.default,
1260
- onClick: () => setValue("recommendations", recommendations.filter((item) => item.id !== row.id), { shouldDirty: true }),
1261
- text: null
1262
- }
1263
- } : null,
1264
- columns: [
1265
- {
1266
- cell: ({ row }) => recommendedTitle(row.original),
1267
- header: "Product",
1268
- id: "title",
1269
- sortable: false
1270
- }
1271
- ],
1272
- data: recommendations,
1273
- headers: false
1274
- }
1275
- }
1276
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1277
- import_empty.default,
1278
- {
1279
- ...{
1280
- variant: "secondary"
1281
- },
1282
- children: "No recommended products"
1283
- }
1284
- )
1285
- }
1286
- ),
1287
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1288
- import_card_section.default,
1289
- {
1290
- ...{
1291
- className: "shrink-0",
1292
- title: "Campaigns"
1293
- },
1294
- children: campaigns.length ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1295
- import_table.default,
1296
- {
1297
- ...{
1298
- actions: (row) => row.current ? null : {
1299
- button: {
1300
- href: "/organizations/" + (organization == null ? void 0 : organization.id) + "/campaigns/" + row.id + "/shop"
1301
- }
1302
- },
1303
- columns: [
1304
- {
1305
- cell: ({ row }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1306
- import_table_cell_title.default,
1307
- {
1308
- ...{
1309
- status: row.original.current ? {
1310
- text: "This campaign",
1311
- type: "secondary"
1312
- } : null,
1313
- title: row.original.title
1314
- }
1315
- }
1316
- ),
1317
- header: "Campaign",
1318
- id: "title",
1319
- sortable: false
1320
- }
1321
- ],
1322
- data: campaigns,
1323
- headers: false
1324
- }
1325
- }
1326
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1327
- import_empty.default,
1328
- {
1329
- ...{
1330
- variant: "secondary"
1331
- },
1332
- children: "Not on any campaign"
1333
- }
1334
- )
1335
- }
1336
- )
1337
- ]
1338
- }
1339
- ),
1340
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1341
- "div",
1342
- {
1343
- ...{
1344
- className: "space-y-6"
1345
- },
1346
- children: [
1347
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1348
- import_card_section.default,
1349
- {
1350
- ...{
1351
- className: "shrink-0",
1352
- title: "Status"
1353
- },
1354
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1355
- "div",
1356
- {
1357
- ...{
1358
- className: "space-y-6"
1359
- },
1360
- children: [
1361
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1362
- import_fieldset.default,
1363
- {
1364
- ...{
1365
- disabled: !editable
1366
- },
1367
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1368
- import_form.Controller,
1369
- {
1370
- ...{
1371
- control,
1372
- name: "status",
1373
- render: ({ field: { onChange, value } }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1374
- import_input_select.default,
1375
- {
1376
- ...{
1377
- "aria-label": "Status",
1378
- onChange,
1379
- options: statuses,
1380
- value
1381
- }
1382
- }
1383
- )
1384
- }
1385
- }
1386
- )
1387
- }
1388
- ),
1389
- editable && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1390
- import_button.default,
1391
- {
1392
- ...{
1393
- loading: formState == null ? void 0 : formState.isSubmitting,
1394
- type: "submit"
1395
- },
1396
- children: "Save"
1397
- }
1398
- ),
1399
- (product == null ? void 0 : product.edit) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1400
- import_button.default,
1401
- {
1402
- ...{
1403
- element: "a",
1404
- href: product.edit,
1405
- icon: import_external.default,
1406
- target: "_blank",
1407
- variant: "secondary"
1408
- },
1409
- children: "Edit in Shopify"
1410
- }
1411
- ),
1412
- editable && onDelete && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1413
- import_button.default,
1414
- {
1415
- ...{
1416
- icon: import_trash.default,
1417
- onClick: onDelete,
1418
- variant: "error"
1419
- },
1420
- children: "Delete"
1421
- }
1422
- )
1423
- ]
1424
- }
1425
- )
1426
- }
1427
- ),
1428
- currency && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1429
- import_card_section.default,
1430
- {
1431
- ...{
1432
- className: "shrink-0",
1433
- title: "Currency"
1434
- },
1435
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1436
- import_input_text.default,
1437
- {
1438
- ...{
1439
- "aria-label": "Currency",
1440
- readOnly: true,
1441
- value: currency
1442
- }
1443
- }
1444
- )
1445
- }
1446
- )
1447
- ]
1448
- }
1449
- )
1450
- ]
1451
- }
1452
- ) });
1453
- };
1454
- var form_organization_product_default = FormOrganizationProduct;
1455
- // Annotate the CommonJS export names for ESM import in node:
1456
- 0 && (module.exports = {
1457
- FormOrganizationProduct,
1458
- FormOrganizationProductCreate,
1459
- FormProductOption,
1460
- FormProductVariant
1461
- });