@drawbridge/components 0.1.46 → 0.1.48
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.
- package/dist/bridge/cart-drawer.js +152 -0
- package/dist/bridge/cart-drawer.mjs +123 -0
- package/dist/bridge/fields.js +278 -0
- package/dist/bridge/fields.mjs +276 -1
- package/dist/bridge/form-subdomain-checkout.js +687 -0
- package/dist/bridge/form-subdomain-checkout.mjs +665 -0
- package/dist/bridge/form-subdomain-shop-modal.js +234 -274
- package/dist/bridge/form-subdomain-shop-modal.mjs +233 -275
- package/dist/bridge/form-subdomain-shop.js +4 -1
- package/dist/bridge/form-subdomain-shop.mjs +4 -1
- package/dist/bridge/form-subdomain.js +24 -5
- package/dist/bridge/form-subdomain.mjs +25 -6
- package/dist/bridge/lib/age-gate.js +12 -0
- package/dist/bridge/lib/age-gate.mjs +11 -0
- package/dist/bridge/lib/cart.js +79 -0
- package/dist/bridge/lib/cart.mjs +48 -0
- package/dist/bridge/lib/checkout-kit.js +2 -32
- package/dist/bridge/lib/checkout-kit.mjs +2 -32
- package/dist/bridge/lib/entry.js +41 -0
- package/dist/bridge/lib/entry.mjs +40 -0
- package/dist/bridge/product-tile.js +13 -6
- package/dist/bridge/product-tile.mjs +13 -6
- package/dist/bridge/template-layout.js +263 -129
- package/dist/bridge/template-layout.mjs +264 -130
- package/dist/bridge/template-modal.js +39 -74
- package/dist/bridge/template-modal.mjs +40 -75
- package/dist/dashboard/avatar.js +2 -3
- package/dist/dashboard/avatar.mjs +2 -3
- package/dist/dashboard/buttons-subscription.js +1 -1
- package/dist/dashboard/buttons-subscription.mjs +1 -1
- package/dist/dashboard/campaign-form.js +179 -155
- package/dist/dashboard/campaign-form.mjs +179 -155
- package/dist/dashboard/campaign-share.js +347 -0
- package/dist/dashboard/campaign-share.mjs +314 -0
- package/dist/dashboard/card-affiliate.js +1 -1
- package/dist/dashboard/card-affiliate.mjs +1 -1
- package/dist/dashboard/card-campaign-switch.js +4 -1
- package/dist/dashboard/card-campaign-switch.mjs +4 -1
- package/dist/dashboard/card-order.js +22 -4
- package/dist/dashboard/card-order.mjs +22 -4
- package/dist/dashboard/embed-stripe.js +145 -0
- package/dist/dashboard/embed-stripe.mjs +116 -0
- package/dist/dashboard/form-admin-provider.js +71 -17
- package/dist/dashboard/form-admin-provider.mjs +71 -17
- package/dist/dashboard/form-file-upload.js +3 -2
- package/dist/dashboard/form-file-upload.mjs +4 -3
- package/dist/dashboard/form-organization-campaign-advertisements.js +47 -6
- package/dist/dashboard/form-organization-campaign-advertisements.mjs +47 -6
- package/dist/dashboard/form-organization-campaign-field-birthday.js +193 -0
- package/dist/dashboard/form-organization-campaign-field-birthday.mjs +164 -0
- package/dist/dashboard/form-organization-campaign-field-rating.js +246 -0
- package/dist/dashboard/form-organization-campaign-field-rating.mjs +217 -0
- package/dist/dashboard/form-organization-campaign-page.js +73 -39
- package/dist/dashboard/form-organization-campaign-page.mjs +73 -39
- package/dist/dashboard/form-organization-campaign.js +82 -0
- package/dist/dashboard/form-organization-campaign.mjs +81 -0
- package/dist/dashboard/form-organization-connection.js +48 -6
- package/dist/dashboard/form-organization-connection.mjs +48 -7
- package/dist/dashboard/form-organization-product.js +1461 -0
- package/dist/dashboard/form-organization-product.mjs +1425 -0
- package/dist/dashboard/form-organization-workflow.js +72 -1
- package/dist/dashboard/form-organization-workflow.mjs +69 -1
- package/dist/dashboard/form-otc.js +4 -5
- package/dist/dashboard/form-otc.mjs +4 -5
- package/dist/dashboard/form-stripe.js +12 -5
- package/dist/dashboard/form-stripe.mjs +12 -5
- package/dist/dashboard/input-combobox.js +6 -0
- package/dist/dashboard/input-combobox.mjs +6 -0
- package/dist/dashboard/input-fields.js +37 -161
- package/dist/dashboard/input-fields.mjs +37 -161
- package/dist/dashboard/input-file.js +21 -4
- package/dist/dashboard/input-file.mjs +21 -4
- package/dist/dashboard/input-font.js +2 -0
- package/dist/dashboard/input-font.mjs +2 -0
- package/dist/dashboard/input-gallery.js +201 -0
- package/dist/dashboard/input-gallery.mjs +172 -0
- package/dist/dashboard/input-group-ai.js +15 -3
- package/dist/dashboard/input-group-ai.mjs +15 -3
- package/dist/dashboard/lib/ab-tests.js +2 -2
- package/dist/dashboard/lib/ab-tests.mjs +2 -2
- package/dist/dashboard/lib/connection-controls.js +5 -2
- package/dist/dashboard/lib/connection-controls.mjs +3 -1
- package/dist/dashboard/lib/form-page.js +1 -1
- package/dist/dashboard/lib/form-page.mjs +1 -1
- package/dist/dashboard/lib/menu.js +19 -0
- package/dist/dashboard/lib/menu.mjs +18 -0
- package/dist/dashboard/lib/products.js +169 -0
- package/dist/dashboard/lib/products.mjs +135 -0
- package/dist/dashboard/lib/settings-paths.js +35 -0
- package/dist/dashboard/lib/settings-paths.mjs +11 -0
- package/dist/dashboard/lib/uppy.js +10 -1
- package/dist/dashboard/lib/uppy.mjs +11 -2
- package/dist/dashboard/menu.js +13 -2
- package/dist/dashboard/menu.mjs +13 -2
- package/dist/dashboard/order-sections.js +456 -6
- package/dist/dashboard/order-sections.mjs +453 -7
- package/dist/dashboard/preview.js +119 -52
- package/dist/dashboard/preview.mjs +119 -52
- package/dist/dashboard/provider-ui.js +9 -7
- package/dist/dashboard/provider-ui.mjs +9 -7
- package/dist/dashboard/recharts.js +10 -4
- package/dist/dashboard/recharts.mjs +10 -4
- package/dist/dashboard/shipping-rates.js +404 -0
- package/dist/dashboard/shipping-rates.mjs +371 -0
- package/dist/dashboard/template-buyer.js +301 -0
- package/dist/dashboard/template-buyer.mjs +267 -0
- package/dist/dashboard/template-dashboard.js +11 -1
- package/dist/dashboard/template-dashboard.mjs +11 -1
- package/dist/dashboard/template-design.js +209 -130
- package/dist/dashboard/template-design.mjs +210 -131
- package/dist/dashboard/template-ui.js +157 -55
- package/dist/dashboard/template-ui.mjs +158 -56
- package/dist/icons/flags.js +134 -0
- package/dist/icons/flags.mjs +115 -0
- package/dist/input-checkbox.js +28 -10
- package/dist/input-checkbox.mjs +28 -10
- package/dist/product.js +96 -24
- package/dist/product.mjs +97 -25
- package/dist/shared/carousel.js +14 -5
- package/dist/shared/carousel.mjs +14 -5
- package/dist/shared/lib/helpers.js +54 -6
- package/dist/shared/lib/helpers.mjs +53 -8
- package/dist/shared/order-summary.js +139 -0
- package/dist/shared/order-summary.mjs +110 -0
- package/package.json +84 -4
- package/types/bridge/cart-drawer.d.ts +31 -0
- package/types/bridge/fields.d.ts +14 -2
- package/types/bridge/form-subdomain-checkout.d.ts +20 -0
- package/types/bridge/form-subdomain-shop-modal.d.ts +27 -3
- package/types/bridge/form-subdomain.d.ts +13 -0
- package/types/bridge/lib/age-gate.d.ts +5 -0
- package/types/bridge/lib/cart.d.ts +44 -0
- package/types/bridge/lib/checkout-kit.d.ts +2 -10
- package/types/bridge/lib/entry.d.ts +5 -0
- package/types/bridge/product-tile.d.ts +2 -0
- package/types/dashboard/campaign-share.d.ts +16 -0
- package/types/dashboard/card-order.d.ts +6 -0
- package/types/dashboard/embed-stripe.d.ts +25 -0
- package/types/dashboard/form-admin-provider.d.ts +9 -2
- package/types/dashboard/form-file-upload.d.ts +2 -1
- package/types/dashboard/form-organization-campaign-advertisements.d.ts +3 -0
- package/types/dashboard/form-organization-campaign-field-birthday.d.ts +31 -0
- package/types/dashboard/form-organization-campaign-field-rating.d.ts +33 -0
- package/types/dashboard/form-organization-campaign-page.d.ts +8 -1
- package/types/dashboard/form-organization-campaign.d.ts +3 -0
- package/types/dashboard/form-organization-connection.d.ts +11 -0
- package/types/dashboard/form-organization-product.d.ts +24 -0
- package/types/dashboard/form-otc.d.ts +5 -1
- package/types/dashboard/form-stripe.d.ts +3 -2
- package/types/dashboard/input-combobox.d.ts +2 -0
- package/types/dashboard/input-file.d.ts +2 -0
- package/types/dashboard/input-gallery.d.ts +14 -0
- package/types/dashboard/lib/products.d.ts +14 -0
- package/types/dashboard/lib/settings-paths.d.ts +5 -0
- package/types/dashboard/order-sections.d.ts +24 -1
- package/types/dashboard/preview.d.ts +11 -3
- package/types/dashboard/shipping-rates.d.ts +26 -0
- package/types/dashboard/template-buyer.d.ts +50 -0
- package/types/icons/flags.d.ts +5 -0
- package/types/input-checkbox.d.ts +2 -0
- package/types/shared/lib/helpers.d.ts +4 -0
- package/types/shared/order-summary.d.ts +19 -0
|
@@ -16,10 +16,26 @@ import Link from "next/link";
|
|
|
16
16
|
import { request } from "@drawbridge/drawbridge-utils/fetch";
|
|
17
17
|
import constants from "./lib/constants.mjs";
|
|
18
18
|
import { checkout as checkoutKit, ensureCheckoutKit } from "./lib/checkout-kit.mjs";
|
|
19
|
+
import { cartAlive, cartCount as countOf, cartKey, withQuantity } from "./lib/cart.mjs";
|
|
19
20
|
import { useTracking } from "./provider-analytics.mjs";
|
|
20
|
-
import { afterOrder, awardingOn, buttonText, copy, formOn } from "./lib/entry.mjs";
|
|
21
|
+
import { afterOrder, awardingOn, buttonText, copy, formOn, previewStep } from "./lib/entry.mjs";
|
|
21
22
|
import { leadEndpoint } from "./lib/url.mjs";
|
|
22
23
|
const TemplateModal = dynamic(() => import("./template-modal.mjs"), { ssr: false });
|
|
24
|
+
const CartDrawer = dynamic(() => import("./cart-drawer.mjs"), { ssr: false });
|
|
25
|
+
const stored = (key) => {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(window.localStorage.getItem(key) || "null");
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const store = (key, value) => {
|
|
33
|
+
try {
|
|
34
|
+
if (value) window.localStorage.setItem(key, JSON.stringify(value));
|
|
35
|
+
else window.localStorage.removeItem(key);
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
};
|
|
23
39
|
const TemplateLayout = ({
|
|
24
40
|
params,
|
|
25
41
|
result,
|
|
@@ -40,9 +56,15 @@ const TemplateLayout = ({
|
|
|
40
56
|
);
|
|
41
57
|
const [data, setData] = useState(result);
|
|
42
58
|
const [iframe, setIframe] = useState(false);
|
|
59
|
+
const [face, setFace] = useState(null);
|
|
43
60
|
const style = data == null ? void 0 : data.style;
|
|
44
61
|
const [cart, setCart] = useState(null);
|
|
45
62
|
const [cartLoading, setCartLoading] = useState(true);
|
|
63
|
+
const [drawer, setDrawer] = useState({ open: false, pay: null });
|
|
64
|
+
const [drawerOpened, setDrawerOpened] = useState(false);
|
|
65
|
+
const [cut, setCut] = useState([]);
|
|
66
|
+
const [submitted, setSubmitted] = useState(null);
|
|
67
|
+
const leadCode = searchParams.get("m");
|
|
46
68
|
const [modal, setModal] = useState(Boolean(submissionId));
|
|
47
69
|
const [opened, setOpened] = useState(Boolean(submissionId));
|
|
48
70
|
const [panel, setPanel] = useState(submissionId ? {
|
|
@@ -61,45 +83,86 @@ const TemplateLayout = ({
|
|
|
61
83
|
name: null,
|
|
62
84
|
data: {}
|
|
63
85
|
});
|
|
64
|
-
const cartCount =
|
|
65
|
-
() => ((cart == null ? void 0 : cart.lines) || []).reduce((sum, line) => sum + (line.quantity || 0), 0),
|
|
66
|
-
[cart]
|
|
67
|
-
);
|
|
86
|
+
const cartCount = countOf(cart);
|
|
68
87
|
const cartRoot = "/subdomain/" + (params == null ? void 0 : params.subdomain) + "/page/" + (params == null ? void 0 : params.slug) + "/cart";
|
|
69
|
-
const cartStorageKey =
|
|
70
|
-
const
|
|
71
|
-
(
|
|
72
|
-
affiliate,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
88
|
+
const cartStorageKey = cartKey({ campaign: result == null ? void 0 : result.campaign, subdomain: params == null ? void 0 : params.subdomain });
|
|
89
|
+
const who = useMemo(
|
|
90
|
+
() => ({
|
|
91
|
+
...affiliate && { affiliate },
|
|
92
|
+
...leadCode && { code: leadCode },
|
|
93
|
+
...(data == null ? void 0 : data.page) && { page: data.page },
|
|
94
|
+
...submitted && { submission: submitted }
|
|
95
|
+
}),
|
|
96
|
+
[affiliate, data == null ? void 0 : data.page, leadCode, submitted]
|
|
97
|
+
);
|
|
98
|
+
const openDrawer = useCallback(
|
|
99
|
+
(pay = null) => {
|
|
100
|
+
setDrawerOpened(true);
|
|
101
|
+
setDrawer({ open: true, pay });
|
|
102
|
+
},
|
|
103
|
+
[]
|
|
104
|
+
);
|
|
105
|
+
const closeDrawer = useCallback(() => setDrawer((current) => ({ ...current, open: false })), []);
|
|
106
|
+
const paid = useCallback(
|
|
107
|
+
(id) => {
|
|
108
|
+
if (!id || id === (cart == null ? void 0 : cart.id)) {
|
|
109
|
+
store(cartStorageKey, null);
|
|
80
110
|
setCart(null);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
111
|
+
setCut([]);
|
|
112
|
+
}
|
|
113
|
+
;
|
|
114
|
+
setDrawer({ open: false, pay: null });
|
|
115
|
+
setPanel({
|
|
116
|
+
name: "purchase",
|
|
117
|
+
data: {
|
|
118
|
+
message: copy(data, "purchase")
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
setModal(true);
|
|
122
|
+
},
|
|
123
|
+
[cart == null ? void 0 : cart.id, cartStorageKey, data]
|
|
124
|
+
);
|
|
125
|
+
const storeCheckout = useCallback(
|
|
126
|
+
(paying) => checkoutKit({
|
|
127
|
+
checkoutUrl: paying == null ? void 0 : paying.checkoutUrl,
|
|
128
|
+
onComplete: () => paid(paying == null ? void 0 : paying.id),
|
|
129
|
+
onOpen: () => {
|
|
130
|
+
setModal(false);
|
|
131
|
+
closeDrawer();
|
|
88
132
|
},
|
|
89
|
-
|
|
90
|
-
onRedirect: redirectToCheckout,
|
|
91
|
-
organization: data == null ? void 0 : data.organization,
|
|
92
|
-
page: data == null ? void 0 : data.page,
|
|
93
|
-
slug: params == null ? void 0 : params.slug,
|
|
94
|
-
subdomain: params == null ? void 0 : params.subdomain,
|
|
95
|
-
...args
|
|
133
|
+
onRedirect: redirectToCheckout
|
|
96
134
|
}),
|
|
97
|
-
[
|
|
135
|
+
[closeDrawer, paid, redirectToCheckout]
|
|
136
|
+
);
|
|
137
|
+
const startCheckout = useCallback(
|
|
138
|
+
(paying) => (paying == null ? void 0 : paying.checkoutUrl) ? storeCheckout(paying) : openDrawer(paying),
|
|
139
|
+
[openDrawer, storeCheckout]
|
|
140
|
+
);
|
|
141
|
+
const checkout = useCallback(
|
|
142
|
+
async (args = {}) => {
|
|
143
|
+
var _a2;
|
|
144
|
+
if (!args.lines) return args.checkoutUrl ? storeCheckout({ checkoutUrl: args.checkoutUrl }) : null;
|
|
145
|
+
const response = await request({
|
|
146
|
+
body: {
|
|
147
|
+
...who,
|
|
148
|
+
...args.advertisement && { advertisement: args.advertisement },
|
|
149
|
+
lines: args.lines
|
|
150
|
+
},
|
|
151
|
+
endpoint: cartRoot,
|
|
152
|
+
method: "POST"
|
|
153
|
+
});
|
|
154
|
+
if (!((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id)) return null;
|
|
155
|
+
setModal(false);
|
|
156
|
+
startCheckout(response.result);
|
|
157
|
+
return response.result;
|
|
158
|
+
},
|
|
159
|
+
[cartRoot, startCheckout, storeCheckout, who]
|
|
98
160
|
);
|
|
99
161
|
const openCheckout = useCallback(
|
|
100
162
|
(checkoutUrl) => checkout({ checkoutUrl }),
|
|
101
163
|
[checkout]
|
|
102
164
|
);
|
|
165
|
+
if (drawer.open && !drawerOpened) setDrawerOpened(true);
|
|
103
166
|
if ((modal || (panel == null ? void 0 : panel.name)) && !opened) setOpened(true);
|
|
104
167
|
useEffect(
|
|
105
168
|
() => {
|
|
@@ -139,140 +202,138 @@ const TemplateLayout = ({
|
|
|
139
202
|
useEffect(
|
|
140
203
|
() => {
|
|
141
204
|
if (typeof window === "undefined") return;
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if (!cartId || expired) {
|
|
146
|
-
if (cartId && expired) {
|
|
147
|
-
window.localStorage.removeItem(cartStorageKey);
|
|
148
|
-
window.localStorage.removeItem(cartStorageKey + "_expiry");
|
|
149
|
-
}
|
|
150
|
-
;
|
|
205
|
+
const kept = stored(cartStorageKey);
|
|
206
|
+
if (!(kept == null ? void 0 : kept.id) || !cartAlive(kept.made)) {
|
|
207
|
+
if (kept) store(cartStorageKey, null);
|
|
151
208
|
setCartLoading(false);
|
|
152
209
|
return;
|
|
153
210
|
}
|
|
154
211
|
;
|
|
155
212
|
request({
|
|
156
|
-
endpoint: cartRoot + "?cartId=" + encodeURIComponent(
|
|
213
|
+
endpoint: cartRoot + "?cartId=" + encodeURIComponent(kept.id),
|
|
157
214
|
method: "GET"
|
|
158
215
|
}).then(({ result: result2 }) => {
|
|
159
216
|
if (result2 == null ? void 0 : result2.id) {
|
|
160
217
|
setCart(result2);
|
|
161
218
|
} else {
|
|
162
|
-
|
|
163
|
-
window.localStorage.removeItem(cartStorageKey + "_expiry");
|
|
219
|
+
store(cartStorageKey, null);
|
|
164
220
|
}
|
|
165
221
|
;
|
|
166
222
|
}).catch(() => {
|
|
167
|
-
|
|
168
|
-
window.localStorage.removeItem(cartStorageKey + "_expiry");
|
|
223
|
+
store(cartStorageKey, null);
|
|
169
224
|
}).finally(() => {
|
|
170
225
|
setCartLoading(false);
|
|
171
226
|
});
|
|
172
227
|
},
|
|
173
228
|
[cartRoot, cartStorageKey]
|
|
174
229
|
);
|
|
230
|
+
const linkedCart = searchParams.get("drwbrdg_cart");
|
|
231
|
+
useEffect(
|
|
232
|
+
() => {
|
|
233
|
+
if (!linkedCart) return;
|
|
234
|
+
request({
|
|
235
|
+
endpoint: cartRoot + "?cartId=" + encodeURIComponent(linkedCart),
|
|
236
|
+
method: "GET"
|
|
237
|
+
}).then(({ result: result2 }) => {
|
|
238
|
+
var _a2;
|
|
239
|
+
if ((result2 == null ? void 0 : result2.id) && ((_a2 = result2.lines) == null ? void 0 : _a2.length)) startCheckout(result2);
|
|
240
|
+
}).catch(() => {
|
|
241
|
+
});
|
|
242
|
+
},
|
|
243
|
+
// Once per cart named: startCheckout changes with the page's cart.
|
|
244
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
245
|
+
[cartRoot, linkedCart]
|
|
246
|
+
);
|
|
175
247
|
const onAddToCart = useCallback(
|
|
176
248
|
async ({ variant }) => {
|
|
177
249
|
var _a2;
|
|
178
|
-
const attributes = [
|
|
179
|
-
...(data == null ? void 0 : data.campaign) ? [{ key: "_drwbrdg_ca", value: data.campaign }] : [],
|
|
180
|
-
...(data == null ? void 0 : data.organization) ? [{ key: "_drwbrdg_or", value: data.organization }] : [],
|
|
181
|
-
...affiliate ? [{ key: "_drwbrdg_af", value: affiliate }] : [],
|
|
182
|
-
...(data == null ? void 0 : data.page) ? [{ key: "_drwbrdg_pg", value: data.page }] : []
|
|
183
|
-
];
|
|
184
250
|
const line = {
|
|
185
|
-
attributes,
|
|
186
251
|
merchandiseId: variant.id,
|
|
187
252
|
quantity: 1
|
|
188
253
|
};
|
|
254
|
+
const create = () => request({
|
|
255
|
+
body: {
|
|
256
|
+
...who,
|
|
257
|
+
lines: [line]
|
|
258
|
+
},
|
|
259
|
+
endpoint: cartRoot,
|
|
260
|
+
method: "POST"
|
|
261
|
+
});
|
|
189
262
|
let response;
|
|
190
263
|
if (cart == null ? void 0 : cart.id) {
|
|
191
264
|
try {
|
|
192
265
|
response = await request({
|
|
193
266
|
body: {
|
|
267
|
+
...who,
|
|
194
268
|
cartId: cart.id,
|
|
195
269
|
lines: [line]
|
|
196
270
|
},
|
|
197
271
|
endpoint: cartRoot + "/lines",
|
|
198
272
|
method: "POST"
|
|
199
273
|
});
|
|
200
|
-
} catch {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
lines: [line]
|
|
204
|
-
},
|
|
205
|
-
endpoint: cartRoot,
|
|
206
|
-
method: "POST"
|
|
207
|
-
});
|
|
274
|
+
} catch (error) {
|
|
275
|
+
if ((error == null ? void 0 : error.status) === 400) throw error;
|
|
276
|
+
response = await create();
|
|
208
277
|
}
|
|
209
278
|
} else {
|
|
210
|
-
response = await
|
|
211
|
-
body: {
|
|
212
|
-
lines: [line]
|
|
213
|
-
},
|
|
214
|
-
endpoint: cartRoot,
|
|
215
|
-
method: "POST"
|
|
216
|
-
});
|
|
279
|
+
response = await create();
|
|
217
280
|
}
|
|
218
281
|
;
|
|
219
282
|
if ((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id) {
|
|
220
|
-
if (
|
|
221
|
-
window.localStorage.setItem(cartStorageKey, response.result.id);
|
|
222
|
-
window.localStorage.setItem(cartStorageKey + "_expiry", String(Date.now()));
|
|
223
|
-
}
|
|
224
|
-
;
|
|
283
|
+
if (response.result.id !== (cart == null ? void 0 : cart.id)) store(cartStorageKey, { id: response.result.id, made: Date.now() });
|
|
225
284
|
setCart(response.result);
|
|
226
|
-
|
|
285
|
+
setCut([]);
|
|
286
|
+
setModal(false);
|
|
287
|
+
openDrawer();
|
|
227
288
|
}
|
|
228
289
|
;
|
|
229
290
|
return response == null ? void 0 : response.result;
|
|
230
291
|
},
|
|
231
|
-
[
|
|
292
|
+
[cart, cartRoot, cartStorageKey, openDrawer, who]
|
|
232
293
|
);
|
|
233
|
-
const
|
|
234
|
-
async (lineId, quantity) => {
|
|
294
|
+
const changeLine = useCallback(
|
|
295
|
+
async (lineId, quantity, send) => {
|
|
235
296
|
var _a2;
|
|
236
297
|
if (!(cart == null ? void 0 : cart.id)) return;
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
},
|
|
247
|
-
endpoint: cartRoot + "/lines",
|
|
248
|
-
method: "PUT"
|
|
249
|
-
});
|
|
250
|
-
if ((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id) setCart(response.result);
|
|
298
|
+
const before = cart;
|
|
299
|
+
setCart(withQuantity(cart, lineId, quantity));
|
|
300
|
+
try {
|
|
301
|
+
const response = await send();
|
|
302
|
+
if ((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id) setCart(response.result);
|
|
303
|
+
} catch (error) {
|
|
304
|
+
setCart(before);
|
|
305
|
+
throw error;
|
|
306
|
+
}
|
|
251
307
|
},
|
|
252
|
-
[cart
|
|
308
|
+
[cart]
|
|
309
|
+
);
|
|
310
|
+
const onCartLineUpdate = useCallback(
|
|
311
|
+
(lineId, quantity) => changeLine(lineId, quantity, () => request({
|
|
312
|
+
body: {
|
|
313
|
+
...who,
|
|
314
|
+
cartId: cart == null ? void 0 : cart.id,
|
|
315
|
+
lines: [
|
|
316
|
+
{
|
|
317
|
+
id: lineId,
|
|
318
|
+
quantity
|
|
319
|
+
}
|
|
320
|
+
]
|
|
321
|
+
},
|
|
322
|
+
endpoint: cartRoot + "/lines",
|
|
323
|
+
method: "PUT"
|
|
324
|
+
})),
|
|
325
|
+
[cart == null ? void 0 : cart.id, cartRoot, changeLine, who]
|
|
253
326
|
);
|
|
254
327
|
const onCartLineRemove = useCallback(
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
method: "DELETE"
|
|
265
|
-
});
|
|
266
|
-
if ((_a2 = response == null ? void 0 : response.result) == null ? void 0 : _a2.id) {
|
|
267
|
-
setCart(response.result);
|
|
268
|
-
if (!((_b2 = response.result.lines) == null ? void 0 : _b2.length) && typeof window !== "undefined") {
|
|
269
|
-
window.localStorage.removeItem(cartStorageKey);
|
|
270
|
-
}
|
|
271
|
-
;
|
|
272
|
-
}
|
|
273
|
-
;
|
|
274
|
-
},
|
|
275
|
-
[cart, cartRoot, cartStorageKey]
|
|
328
|
+
(lineId) => changeLine(lineId, 0, () => request({
|
|
329
|
+
body: {
|
|
330
|
+
cartId: cart == null ? void 0 : cart.id,
|
|
331
|
+
lineIds: [lineId]
|
|
332
|
+
},
|
|
333
|
+
endpoint: cartRoot + "/lines",
|
|
334
|
+
method: "DELETE"
|
|
335
|
+
})),
|
|
336
|
+
[cart == null ? void 0 : cart.id, cartRoot, changeLine]
|
|
276
337
|
);
|
|
277
338
|
const tracking = useTracking({
|
|
278
339
|
params,
|
|
@@ -284,7 +345,7 @@ const TemplateLayout = ({
|
|
|
284
345
|
event,
|
|
285
346
|
preview: preview2
|
|
286
347
|
}) => {
|
|
287
|
-
var _a2, _b2, _c2, _d2, _e, _f, _g;
|
|
348
|
+
var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k;
|
|
288
349
|
let trusted = false;
|
|
289
350
|
try {
|
|
290
351
|
trusted = Boolean(
|
|
@@ -296,16 +357,34 @@ const TemplateLayout = ({
|
|
|
296
357
|
if (preview2 && trusted) {
|
|
297
358
|
setIframe(true);
|
|
298
359
|
}
|
|
299
|
-
if (preview2 && trusted && ((_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.
|
|
300
|
-
const
|
|
360
|
+
if (preview2 && trusted && ((_b2 = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.open) == null ? void 0 : _b2.step)) {
|
|
361
|
+
const shown = previewStep({
|
|
362
|
+
...result,
|
|
363
|
+
...(_c2 = event == null ? void 0 : event.data) == null ? void 0 : _c2.update
|
|
364
|
+
}, event.data.open);
|
|
365
|
+
setFace(shown.face);
|
|
366
|
+
setModal(shown.modal);
|
|
367
|
+
if (((_d2 = shown.panel) == null ? void 0 : _d2.name) === "submission") setPanel({
|
|
368
|
+
name: "submission",
|
|
369
|
+
data: {
|
|
370
|
+
...shown.panel.data,
|
|
371
|
+
preview: preview2,
|
|
372
|
+
style: result == null ? void 0 : result.style,
|
|
373
|
+
...params
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
else if (shown.panel) setPanel(shown.panel);
|
|
377
|
+
}
|
|
378
|
+
if (preview2 && trusted && ((_e = event == null ? void 0 : event.data) == null ? void 0 : _e.update)) {
|
|
379
|
+
const headline = ((_g = (_f = event == null ? void 0 : event.data) == null ? void 0 : _f.update) == null ? void 0 : _g.headline) || ((_h = result == null ? void 0 : result.data) == null ? void 0 : _h.headline) || ((_j = (_i = constants) == null ? void 0 : _i.form) == null ? void 0 : _j.headline);
|
|
301
380
|
setData({
|
|
302
381
|
...result,
|
|
303
|
-
...(
|
|
382
|
+
...(_k = event == null ? void 0 : event.data) == null ? void 0 : _k.update,
|
|
304
383
|
headline
|
|
305
384
|
});
|
|
306
385
|
}
|
|
307
386
|
},
|
|
308
|
-
[result]
|
|
387
|
+
[params, result]
|
|
309
388
|
);
|
|
310
389
|
useEffect(
|
|
311
390
|
() => {
|
|
@@ -361,8 +440,21 @@ const TemplateLayout = ({
|
|
|
361
440
|
}
|
|
362
441
|
});
|
|
363
442
|
setModal(true);
|
|
443
|
+
if (id) {
|
|
444
|
+
setSubmitted(id);
|
|
445
|
+
if (cart == null ? void 0 : cart.id) request({
|
|
446
|
+
body: {
|
|
447
|
+
cartId: cart.id,
|
|
448
|
+
submission: id
|
|
449
|
+
},
|
|
450
|
+
endpoint: cartRoot,
|
|
451
|
+
method: "PUT"
|
|
452
|
+
}).catch(() => {
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
;
|
|
364
456
|
},
|
|
365
|
-
[affiliate, data, params, preview, style]
|
|
457
|
+
[affiliate, cart == null ? void 0 : cart.id, cartRoot, data, params, preview, style]
|
|
366
458
|
);
|
|
367
459
|
const leadMission = searchParams.get("open");
|
|
368
460
|
const leadUrl = submissionId ? null : leadEndpoint({ code: searchParams.get("m"), slug: params == null ? void 0 : params.slug, subdomain: params == null ? void 0 : params.subdomain, token });
|
|
@@ -435,7 +527,7 @@ const TemplateLayout = ({
|
|
|
435
527
|
return {
|
|
436
528
|
branding: branding(),
|
|
437
529
|
brandingCompact: branding(true),
|
|
438
|
-
close: (name) => {
|
|
530
|
+
close: (name, onClose) => {
|
|
439
531
|
var _a3, _b3, _c3, _d3, _e2, _f2, _g2, _h2, _i2, _j2, _k2;
|
|
440
532
|
return /* @__PURE__ */ jsx(
|
|
441
533
|
Button,
|
|
@@ -444,7 +536,7 @@ const TemplateLayout = ({
|
|
|
444
536
|
"aria-label": "Close Modal",
|
|
445
537
|
inline: true,
|
|
446
538
|
onClick: () => {
|
|
447
|
-
setModal(false);
|
|
539
|
+
(onClose || (() => setModal(false)))();
|
|
448
540
|
tracking.track({
|
|
449
541
|
name: "button-" + name + "-close"
|
|
450
542
|
});
|
|
@@ -484,7 +576,7 @@ const TemplateLayout = ({
|
|
|
484
576
|
Button,
|
|
485
577
|
{
|
|
486
578
|
...{
|
|
487
|
-
disabled: !preview && !(data == null ? void 0 : data.valid),
|
|
579
|
+
disabled: !preview && !(data == null ? void 0 : data.valid) || face === "inactive",
|
|
488
580
|
onClick: () => {
|
|
489
581
|
setPanel({
|
|
490
582
|
name: "enter"
|
|
@@ -496,7 +588,7 @@ const TemplateLayout = ({
|
|
|
496
588
|
},
|
|
497
589
|
style
|
|
498
590
|
},
|
|
499
|
-
children: buttonText(data, preview || Boolean(data == null ? void 0 : data.valid))
|
|
591
|
+
children: face ? copy(data, face) : buttonText(data, preview || Boolean(data == null ? void 0 : data.valid))
|
|
500
592
|
}
|
|
501
593
|
),
|
|
502
594
|
menu: /* @__PURE__ */ jsx(
|
|
@@ -595,10 +687,7 @@ const TemplateLayout = ({
|
|
|
595
687
|
"aria-label": "Open Shop",
|
|
596
688
|
inline: true,
|
|
597
689
|
onClick: () => {
|
|
598
|
-
|
|
599
|
-
name
|
|
600
|
-
});
|
|
601
|
-
setModal(true);
|
|
690
|
+
openDrawer();
|
|
602
691
|
tracking.track({
|
|
603
692
|
name: "button-" + name + "-open"
|
|
604
693
|
});
|
|
@@ -652,7 +741,7 @@ const TemplateLayout = ({
|
|
|
652
741
|
}
|
|
653
742
|
};
|
|
654
743
|
},
|
|
655
|
-
[cartCount, cartLoading, data, preview, style, tracking]
|
|
744
|
+
[cartCount, cartLoading, data, face, openDrawer, preview, style, tracking]
|
|
656
745
|
);
|
|
657
746
|
const props = {
|
|
658
747
|
affiliate,
|
|
@@ -704,20 +793,65 @@ const TemplateLayout = ({
|
|
|
704
793
|
}
|
|
705
794
|
}
|
|
706
795
|
),
|
|
796
|
+
drawerOpened && /* @__PURE__ */ jsx(
|
|
797
|
+
CartDrawer,
|
|
798
|
+
{
|
|
799
|
+
...{
|
|
800
|
+
button: buttons.close("cart", closeDrawer),
|
|
801
|
+
cart,
|
|
802
|
+
cut,
|
|
803
|
+
fonts,
|
|
804
|
+
// The back arrow on the first step: the cart, as it was.
|
|
805
|
+
onBack: () => setDrawer({ open: true, pay: null }),
|
|
806
|
+
onCart: (next) => {
|
|
807
|
+
if ((next == null ? void 0 : next.id) && next.id === (cart == null ? void 0 : cart.id)) {
|
|
808
|
+
setCart(next);
|
|
809
|
+
setCut(next.cut || []);
|
|
810
|
+
}
|
|
811
|
+
;
|
|
812
|
+
},
|
|
813
|
+
onCheckout: startCheckout,
|
|
814
|
+
onClose: closeDrawer,
|
|
815
|
+
onLineRemove: onCartLineRemove,
|
|
816
|
+
onLineUpdate: onCartLineUpdate,
|
|
817
|
+
// @story shop/recommended-products
|
|
818
|
+
// A recommended row opens its product over the cart.
|
|
819
|
+
onOpenProduct: (product) => {
|
|
820
|
+
setPanel({
|
|
821
|
+
name: "product",
|
|
822
|
+
data: {
|
|
823
|
+
product
|
|
824
|
+
}
|
|
825
|
+
});
|
|
826
|
+
setModal(true);
|
|
827
|
+
},
|
|
828
|
+
onPaid: () => {
|
|
829
|
+
var _a3;
|
|
830
|
+
return paid((_a3 = drawer.pay) == null ? void 0 : _a3.id);
|
|
831
|
+
},
|
|
832
|
+
open: drawer.open,
|
|
833
|
+
params: {
|
|
834
|
+
...params,
|
|
835
|
+
token
|
|
836
|
+
},
|
|
837
|
+
pay: drawer.pay,
|
|
838
|
+
preview,
|
|
839
|
+
style,
|
|
840
|
+
tracking
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
),
|
|
707
844
|
opened && /* @__PURE__ */ jsx(
|
|
708
845
|
TemplateModal,
|
|
709
846
|
{
|
|
710
847
|
...{
|
|
711
848
|
buttons,
|
|
712
|
-
cart,
|
|
713
849
|
checkout,
|
|
714
850
|
data,
|
|
715
851
|
fonts,
|
|
716
852
|
iframe,
|
|
717
853
|
modal,
|
|
718
854
|
onAddToCart,
|
|
719
|
-
onCartLineRemove,
|
|
720
|
-
onCartLineUpdate,
|
|
721
855
|
openCheckout,
|
|
722
856
|
panel,
|
|
723
857
|
params,
|