@disconetwork/shopify 0.0.1 → 0.0.3
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/README.md +3 -4
- package/dist/DiscoRecommendations-i3RGOqOq.js +1546 -0
- package/dist/DiscoRecommendations-i3RGOqOq.js.map +1 -0
- package/dist/index.d.ts +5 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1534
- package/dist/internal.d.ts +19 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +17 -0
- package/dist/internal.js.map +1 -0
- package/package.json +7 -3
- package/dist/index.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,1535 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createContext } from "preact";
|
|
3
|
-
import { DiscoProvider, ScreensRenderer, useDiscoClient, useFetchRecommendations, useRendererContext } from "@disconetwork/react/internal/headless";
|
|
4
|
-
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
|
|
5
|
-
import { useApi, useBillingAddress, useCartLines, useCheckoutToken, useCustomer, useDiscountCodes, useEmail, usePhone, usePurchasingCompany, useShippingAddress, useShop, useSubscription, useTotalAmount } from "@shopify/ui-extensions/checkout/preact";
|
|
6
|
-
import { useApi as useApi$1, useBillingAddress as useBillingAddress$1, useCartLines as useCartLines$1, useCustomer as useCustomer$1, useDiscountCodes as useDiscountCodes$1, useEmail as useEmail$1, useOrder, usePhone as usePhone$1, usePurchasingCompany as usePurchasingCompany$1, useShippingAddress as useShippingAddress$1, useShop as useShop$1, useSubscription as useSubscription$1, useTotalAmount as useTotalAmount$1 } from "@shopify/ui-extensions/customer-account/preact";
|
|
7
|
-
import { INTERNAL_BASE_URL } from "@disconetwork/core/internal";
|
|
8
|
-
//#region src/managers/RecommendationsTrackingManager/index.tsx
|
|
9
|
-
const RecommendationsTrackingManagerContext = createContext(null);
|
|
10
|
-
function RecommendationsTrackingManager({ children, tracker }) {
|
|
11
|
-
return /* @__PURE__ */ jsx(RecommendationsTrackingManagerContext.Provider, {
|
|
12
|
-
value: tracker,
|
|
13
|
-
children
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
function useEventTracker() {
|
|
17
|
-
const ctx = useContext(RecommendationsTrackingManagerContext);
|
|
18
|
-
if (!ctx) throw new Error("useEventTracker must be used inside RecommendationsTrackingManager");
|
|
19
|
-
return ctx;
|
|
20
|
-
}
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/hooks/usePayload.tsx
|
|
23
|
-
const usePayload = () => {
|
|
24
|
-
const data = useContext(PayloadContext);
|
|
25
|
-
if (!data) throw new Error("No wrapper Payload context found");
|
|
26
|
-
return data;
|
|
27
|
-
};
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region src/utils/dataManagerUtils.ts
|
|
30
|
-
const getShopIdentifier = (shopGid) => {
|
|
31
|
-
return shopGid.replace("gid://shopify/Shop/", "");
|
|
32
|
-
};
|
|
33
|
-
const shopifyOrderIdFormatter = (inp) => typeof inp === "string" ? inp.replace("gid://shopify/Order/", "") : inp;
|
|
34
|
-
const getRecommendationsRequest = ({ payload }) => {
|
|
35
|
-
return {
|
|
36
|
-
user: {
|
|
37
|
-
email: payload.buyerEmail,
|
|
38
|
-
firstName: payload.extrapolatedFirstName,
|
|
39
|
-
lastName: payload.customerLastName,
|
|
40
|
-
phone: payload.extrapolatedPhone
|
|
41
|
-
},
|
|
42
|
-
placement: {
|
|
43
|
-
displayMode: "INLINE",
|
|
44
|
-
view: payload.target
|
|
45
|
-
},
|
|
46
|
-
order: {
|
|
47
|
-
amount: payload.totalCost,
|
|
48
|
-
currencyCode: payload.currencyCode,
|
|
49
|
-
id: shopifyOrderIdFormatter(payload.orderId) ?? void 0
|
|
50
|
-
},
|
|
51
|
-
purchases: payload.cartLines.map((cartLine) => {
|
|
52
|
-
return {
|
|
53
|
-
name: cartLine.merchandise.title,
|
|
54
|
-
type: cartLine.merchandise.product.productType,
|
|
55
|
-
variant: cartLine.merchandise.subtitle,
|
|
56
|
-
quantity: cartLine.quantity,
|
|
57
|
-
amount: cartLine.cost.totalAmount.amount,
|
|
58
|
-
currencyCode: cartLine.cost.totalAmount.currencyCode,
|
|
59
|
-
productId: cartLine.merchandise.product.id.replace("gid://shopify/Product/", "")
|
|
60
|
-
};
|
|
61
|
-
})
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
//#endregion
|
|
65
|
-
//#region src/components/CardContainer.tsx
|
|
66
|
-
const CardContainer = ({ children, ...rest }) => {
|
|
67
|
-
return /* @__PURE__ */ jsx("s-box", {
|
|
68
|
-
border: "base",
|
|
69
|
-
borderWidth: "base",
|
|
70
|
-
borderRadius: "large",
|
|
71
|
-
...rest,
|
|
72
|
-
children
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region src/components/DiscoFeed/DummyDiscoFeed.tsx
|
|
77
|
-
const DISCO_FEED_CARD_PADDING = "base";
|
|
78
|
-
const DummyDiscoFeedRow = () => {
|
|
79
|
-
const productSize = 118;
|
|
80
|
-
return /* @__PURE__ */ jsxs("s-stack", {
|
|
81
|
-
gap: "base",
|
|
82
|
-
children: [/* @__PURE__ */ jsxs("s-stack", {
|
|
83
|
-
direction: "inline",
|
|
84
|
-
gap: "small-200",
|
|
85
|
-
alignItems: "center",
|
|
86
|
-
children: [/* @__PURE__ */ jsx("s-box", {
|
|
87
|
-
blockSize: "18px",
|
|
88
|
-
inlineSize: "18px",
|
|
89
|
-
background: "subdued",
|
|
90
|
-
borderRadius: "base"
|
|
91
|
-
}), /* @__PURE__ */ jsx("s-skeleton-paragraph", { content: "Brand" })]
|
|
92
|
-
}), /* @__PURE__ */ jsx("s-scroll-box", { children: /* @__PURE__ */ jsx("s-grid", {
|
|
93
|
-
gridTemplateColumns: `repeat(10, ${productSize}px)`,
|
|
94
|
-
gap: "small-200",
|
|
95
|
-
children: Array.from({ length: 10 }, (_, index) => /* @__PURE__ */ jsx("s-box", {
|
|
96
|
-
blockSize: `${productSize}px`,
|
|
97
|
-
inlineSize: `${productSize}px`,
|
|
98
|
-
background: "subdued",
|
|
99
|
-
borderRadius: "base"
|
|
100
|
-
}, index))
|
|
101
|
-
}) })]
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
const DummyDiscoFeedContent = ({ isPadded = false, brandCount = 3, showHeading = false }) => /* @__PURE__ */ jsxs("s-stack", {
|
|
105
|
-
padding: isPadded ? DISCO_FEED_CARD_PADDING : void 0,
|
|
106
|
-
gap: "large-500",
|
|
107
|
-
children: [showHeading && /* @__PURE__ */ jsx("s-skeleton-paragraph", { content: "Recommendations" }), Array.from({ length: brandCount }, (_, index) => /* @__PURE__ */ jsx(DummyDiscoFeedRow, {}, index))]
|
|
108
|
-
});
|
|
109
|
-
const DummyDiscoFeed = () => /* @__PURE__ */ jsx(CardContainer, {
|
|
110
|
-
background: "base",
|
|
111
|
-
children: /* @__PURE__ */ jsx(DummyDiscoFeedContent, {
|
|
112
|
-
brandCount: 4,
|
|
113
|
-
showHeading: true,
|
|
114
|
-
isPadded: true
|
|
115
|
-
})
|
|
116
|
-
});
|
|
117
|
-
//#endregion
|
|
118
|
-
//#region src/managers/DataManager.tsx
|
|
119
|
-
const MIN_LOADING_VIEW_HEIGHT = 800;
|
|
120
|
-
const DataManager = ({ apiKey, env, children }) => {
|
|
121
|
-
const payload = usePayload();
|
|
122
|
-
return /* @__PURE__ */ jsx(DiscoProvider, {
|
|
123
|
-
...apiKey ? {
|
|
124
|
-
apiKey,
|
|
125
|
-
surface: "shopify"
|
|
126
|
-
} : {
|
|
127
|
-
shopGid: payload.shopGid,
|
|
128
|
-
env
|
|
129
|
-
},
|
|
130
|
-
children: /* @__PURE__ */ jsx(RecommendationsContent, {
|
|
131
|
-
request: getRecommendationsRequest({ payload }),
|
|
132
|
-
children
|
|
133
|
-
})
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
const RecommendationsContent = ({ children, request }) => {
|
|
137
|
-
const { state: recommendations, tracker } = useFetchRecommendations(request);
|
|
138
|
-
if (recommendations.status === "error") return null;
|
|
139
|
-
if (recommendations.status === "loading" || !tracker) return /* @__PURE__ */ jsx("s-box", {
|
|
140
|
-
minBlockSize: `${MIN_LOADING_VIEW_HEIGHT}px`,
|
|
141
|
-
children: /* @__PURE__ */ jsx(DummyDiscoFeed, {}, "dummy-feed")
|
|
142
|
-
});
|
|
143
|
-
return /* @__PURE__ */ jsx(RecommendationsDataContext.Provider, {
|
|
144
|
-
value: recommendations.data,
|
|
145
|
-
children: /* @__PURE__ */ jsx(RecommendationsTrackingManager, {
|
|
146
|
-
tracker,
|
|
147
|
-
children
|
|
148
|
-
})
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
//#endregion
|
|
152
|
-
//#region src/managers/PayloadManager.tsx
|
|
153
|
-
const GenericPayloadProvider = ({ target, children, payload, additionalPayload, isB2BPurchase }) => {
|
|
154
|
-
useEffect(() => {
|
|
155
|
-
if (!isB2BPurchase) return;
|
|
156
|
-
throw new Error("[Disco]: Disabling for B2B purchase");
|
|
157
|
-
}, [isB2BPurchase]);
|
|
158
|
-
if (isB2BPurchase) return null;
|
|
159
|
-
return /* @__PURE__ */ jsx(PayloadContext.Provider, {
|
|
160
|
-
value: {
|
|
161
|
-
...payload,
|
|
162
|
-
...additionalPayload || {},
|
|
163
|
-
target
|
|
164
|
-
},
|
|
165
|
-
children
|
|
166
|
-
});
|
|
167
|
-
};
|
|
168
|
-
function createGenericPayload({ buyerPhone, buyerEmail, customer, shippingAddress, billingAddress, totalAmount, cartLines, checkoutToken, discountCodes, shopGid, extensionTarget }) {
|
|
169
|
-
const derivedFirstName = billingAddress?.firstName || shippingAddress?.firstName;
|
|
170
|
-
return {
|
|
171
|
-
buyerPhone,
|
|
172
|
-
buyerEmail,
|
|
173
|
-
customerId: customer?.id,
|
|
174
|
-
customerFirstName: customer?.firstName,
|
|
175
|
-
customerLastName: customer?.lastName,
|
|
176
|
-
customerFullName: customer?.fullName,
|
|
177
|
-
derivedFirstName,
|
|
178
|
-
billingFirstName: billingAddress?.firstName,
|
|
179
|
-
billingLastName: billingAddress?.lastName,
|
|
180
|
-
billingZipCode: billingAddress?.zip,
|
|
181
|
-
shippingZipCode: shippingAddress?.zip,
|
|
182
|
-
extrapolatedFirstName: customer?.firstName || derivedFirstName,
|
|
183
|
-
extrapolatedPhone: buyerPhone || shippingAddress?.phone || billingAddress?.phone || "",
|
|
184
|
-
totalCost: totalAmount.amount,
|
|
185
|
-
currencyCode: totalAmount.currencyCode,
|
|
186
|
-
cartLines,
|
|
187
|
-
checkoutToken,
|
|
188
|
-
discountCodes,
|
|
189
|
-
shopGid,
|
|
190
|
-
target: PAYLOAD_MANAGER_TARGET.GENERIC,
|
|
191
|
-
extensionTarget
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
const ThankYouPayloadManager = ({ children }) => {
|
|
195
|
-
const target = PAYLOAD_MANAGER_TARGET.THANK_YOU;
|
|
196
|
-
const customer = useCustomer();
|
|
197
|
-
const buyerEmail = useEmail();
|
|
198
|
-
const buyerPhone = usePhone();
|
|
199
|
-
const purchasingCompany = usePurchasingCompany();
|
|
200
|
-
const shippingAddress = useShippingAddress();
|
|
201
|
-
const billingAddress = useBillingAddress();
|
|
202
|
-
const totalAmount = useTotalAmount();
|
|
203
|
-
const cartLines = useCartLines();
|
|
204
|
-
const checkoutToken = useCheckoutToken();
|
|
205
|
-
const discountCodes = useDiscountCodes();
|
|
206
|
-
const shop = useShop();
|
|
207
|
-
const api = useApi();
|
|
208
|
-
const orderId = useSubscription(api.orderConfirmation).order.id.split("/").pop();
|
|
209
|
-
if (!orderId) console.warn("[Disco]: Order ID not found in thank you page");
|
|
210
|
-
return /* @__PURE__ */ jsx(GenericPayloadProvider, {
|
|
211
|
-
target,
|
|
212
|
-
payload: createGenericPayload({
|
|
213
|
-
buyerPhone,
|
|
214
|
-
buyerEmail,
|
|
215
|
-
customer,
|
|
216
|
-
shippingAddress,
|
|
217
|
-
billingAddress,
|
|
218
|
-
totalAmount,
|
|
219
|
-
cartLines,
|
|
220
|
-
checkoutToken,
|
|
221
|
-
discountCodes,
|
|
222
|
-
shopGid: shop.id,
|
|
223
|
-
extensionTarget: api.extension.target
|
|
224
|
-
}),
|
|
225
|
-
additionalPayload: {
|
|
226
|
-
orderId,
|
|
227
|
-
target
|
|
228
|
-
},
|
|
229
|
-
isB2BPurchase: Boolean(purchasingCompany?.company),
|
|
230
|
-
children
|
|
231
|
-
});
|
|
232
|
-
};
|
|
233
|
-
const OrderStatusPayloadManager = ({ children }) => {
|
|
234
|
-
const target = PAYLOAD_MANAGER_TARGET.ORDER_STATUS;
|
|
235
|
-
const customer = useCustomer$1();
|
|
236
|
-
const buyerEmail = useEmail$1();
|
|
237
|
-
const buyerPhone = usePhone$1();
|
|
238
|
-
const purchasingCompany = usePurchasingCompany$1();
|
|
239
|
-
const shippingAddress = useShippingAddress$1();
|
|
240
|
-
const billingAddress = useBillingAddress$1();
|
|
241
|
-
const totalAmount = useTotalAmount$1();
|
|
242
|
-
const cartLines = useCartLines$1();
|
|
243
|
-
const discountCodes = useDiscountCodes$1();
|
|
244
|
-
const shop = useShop$1();
|
|
245
|
-
const order = useOrder();
|
|
246
|
-
const api = useApi$1();
|
|
247
|
-
return /* @__PURE__ */ jsx(GenericPayloadProvider, {
|
|
248
|
-
target,
|
|
249
|
-
payload: createGenericPayload({
|
|
250
|
-
buyerPhone,
|
|
251
|
-
buyerEmail,
|
|
252
|
-
customer,
|
|
253
|
-
shippingAddress,
|
|
254
|
-
billingAddress,
|
|
255
|
-
totalAmount,
|
|
256
|
-
cartLines,
|
|
257
|
-
checkoutToken: useSubscription$1(api.checkoutToken),
|
|
258
|
-
discountCodes,
|
|
259
|
-
shopGid: shop.id,
|
|
260
|
-
extensionTarget: api.extension.target
|
|
261
|
-
}),
|
|
262
|
-
additionalPayload: {
|
|
263
|
-
orderId: order?.id,
|
|
264
|
-
orderName: order?.name,
|
|
265
|
-
target
|
|
266
|
-
},
|
|
267
|
-
isB2BPurchase: Boolean(purchasingCompany?.company),
|
|
268
|
-
children
|
|
269
|
-
});
|
|
270
|
-
};
|
|
271
|
-
const PAYLOAD_MANAGER_TARGET = {
|
|
272
|
-
GENERIC: "GENERIC",
|
|
273
|
-
ORDER_STATUS: "ORDER_STATUS",
|
|
274
|
-
THANK_YOU: "THANK_YOU"
|
|
275
|
-
};
|
|
276
|
-
const EXTENSION_TARGETS = {
|
|
277
|
-
"purchase.thank-you.block.render": PAYLOAD_MANAGER_TARGET.THANK_YOU,
|
|
278
|
-
"customer-account.order-status.block.render": PAYLOAD_MANAGER_TARGET.ORDER_STATUS
|
|
279
|
-
};
|
|
280
|
-
const getExtensionTarget = () => globalThis.shopify?.extension?.target;
|
|
281
|
-
const PayloadManager = ({ children }) => {
|
|
282
|
-
const extensionTarget = getExtensionTarget();
|
|
283
|
-
const target = extensionTarget && EXTENSION_TARGETS[extensionTarget];
|
|
284
|
-
if (target === PAYLOAD_MANAGER_TARGET.THANK_YOU) return /* @__PURE__ */ jsx(ThankYouPayloadManager, { children });
|
|
285
|
-
if (target === PAYLOAD_MANAGER_TARGET.ORDER_STATUS) return /* @__PURE__ */ jsx(OrderStatusPayloadManager, { children });
|
|
286
|
-
throw new Error(`[Disco]: Unsupported extension target ${extensionTarget ?? "(none)"}`);
|
|
287
|
-
};
|
|
288
|
-
//#endregion
|
|
289
|
-
//#region src/managers/UserManager.tsx
|
|
290
|
-
const UserManager = ({ children }) => {
|
|
291
|
-
const { buyerEmail, customerFirstName, customerLastName, customerFullName, derivedFirstName, extrapolatedFirstName } = usePayload();
|
|
292
|
-
const [user, setUser] = useState({
|
|
293
|
-
email: buyerEmail,
|
|
294
|
-
firstName: customerFirstName,
|
|
295
|
-
lastName: customerLastName,
|
|
296
|
-
fullName: customerFullName,
|
|
297
|
-
derivedFirstName,
|
|
298
|
-
extrapolatedFirstName
|
|
299
|
-
});
|
|
300
|
-
const hasIdentity = useMemo(() => !!user?.email, [user]);
|
|
301
|
-
return /* @__PURE__ */ jsx(UserContext.Provider, {
|
|
302
|
-
value: {
|
|
303
|
-
user,
|
|
304
|
-
setUser,
|
|
305
|
-
hasIdentity
|
|
306
|
-
},
|
|
307
|
-
children
|
|
308
|
-
});
|
|
309
|
-
};
|
|
310
|
-
//#endregion
|
|
311
|
-
//#region src/managers/index.ts
|
|
312
|
-
const RecommendationsDataContext = createContext(null);
|
|
313
|
-
const PayloadContext = createContext(null);
|
|
314
|
-
const UserContext = createContext(null);
|
|
315
|
-
//#endregion
|
|
316
|
-
//#region src/hooks/useRecommendationsData.tsx
|
|
317
|
-
function useRecommendationsData() {
|
|
318
|
-
const ctx = useContext(RecommendationsDataContext);
|
|
319
|
-
if (!ctx) throw new Error("useRecommendationsData must be used inside RecommendationsDataContext");
|
|
320
|
-
return ctx;
|
|
321
|
-
}
|
|
322
|
-
//#endregion
|
|
323
|
-
//#region src/hooks/useCounter.tsx
|
|
324
|
-
const useCounter = ({ start = 0, min = 0, max = Infinity, resetOnMax = false, disabled = false } = {}) => {
|
|
325
|
-
const [counter, setCounter] = useState(start);
|
|
326
|
-
const incrementCounter = useCallback((counter) => Math.min(max, counter + 1) % (resetOnMax ? max : Infinity), [max, resetOnMax]);
|
|
327
|
-
const increment = useCallback(() => disabled ? null : setCounter(incrementCounter), [incrementCounter, disabled]);
|
|
328
|
-
const decrementCounter = useCallback((counter) => Math.max(min, counter - 1), [min]);
|
|
329
|
-
const decrement = useCallback(() => disabled ? null : setCounter(decrementCounter), [decrementCounter, disabled]);
|
|
330
|
-
const nextCounter = useMemo(() => incrementCounter(counter), [incrementCounter, counter]);
|
|
331
|
-
const prevCounter = useMemo(() => decrementCounter(counter), [decrementCounter, counter]);
|
|
332
|
-
const isMin = useMemo(() => counter === min, [min, counter]);
|
|
333
|
-
const isMax = useMemo(() => counter === max, [max, counter]);
|
|
334
|
-
const procValue = useCallback((value) => Math.max(min, Math.min(max, value)), [max, min]);
|
|
335
|
-
return {
|
|
336
|
-
counter,
|
|
337
|
-
setCounter: useCallback((cb) => {
|
|
338
|
-
if (disabled) return;
|
|
339
|
-
setCounter((counter) => procValue(typeof cb === "function" ? cb(counter) : cb));
|
|
340
|
-
}, [procValue, disabled]),
|
|
341
|
-
increment,
|
|
342
|
-
decrement,
|
|
343
|
-
nextCounter,
|
|
344
|
-
prevCounter,
|
|
345
|
-
isMin,
|
|
346
|
-
isMax
|
|
347
|
-
};
|
|
348
|
-
};
|
|
349
|
-
//#endregion
|
|
350
|
-
//#region src/components/RecommendationsWidget/HeroOfferProvider.tsx
|
|
351
|
-
const HeroContext = createContext(null);
|
|
352
|
-
const HeroOfferProvider = ({ children, recommendationGroup, loop }) => {
|
|
353
|
-
const [claimedOffers, setClaimedOffers] = useState([]);
|
|
354
|
-
const { recommendations } = recommendationGroup;
|
|
355
|
-
const { counter: activeRecommendationIdx, increment: nextOffer, decrement: prevOffer, isMin: isFirstOffer, isMax: isLastOffer } = useCounter(loop ? {
|
|
356
|
-
start: 0,
|
|
357
|
-
min: 0,
|
|
358
|
-
max: recommendations.length,
|
|
359
|
-
resetOnMax: true
|
|
360
|
-
} : {
|
|
361
|
-
start: 0,
|
|
362
|
-
min: 0,
|
|
363
|
-
max: recommendations.length - 1
|
|
364
|
-
});
|
|
365
|
-
const activeRecommendation = recommendations[activeRecommendationIdx];
|
|
366
|
-
const handleOfferClaim = () => {
|
|
367
|
-
setClaimedOffers((claimedOffers) => [...claimedOffers, activeRecommendation.id]);
|
|
368
|
-
};
|
|
369
|
-
const value = {
|
|
370
|
-
activeRecommendation,
|
|
371
|
-
activeOfferIndex: activeRecommendationIdx,
|
|
372
|
-
nextOffer,
|
|
373
|
-
prevOffer,
|
|
374
|
-
isOfferClaimed: claimedOffers.includes(activeRecommendation.id),
|
|
375
|
-
handleOfferClaim,
|
|
376
|
-
TOTAL_NUM_OFFERS: recommendations.length,
|
|
377
|
-
isFirstOffer,
|
|
378
|
-
isLastOffer,
|
|
379
|
-
claimedOffers,
|
|
380
|
-
recommendations
|
|
381
|
-
};
|
|
382
|
-
return /* @__PURE__ */ jsx(HeroContext.Provider, {
|
|
383
|
-
value,
|
|
384
|
-
children
|
|
385
|
-
});
|
|
386
|
-
};
|
|
387
|
-
const useHeroOffer = () => {
|
|
388
|
-
const context = useContext(HeroContext);
|
|
389
|
-
if (!context) throw new Error("useHeroOffer must be used within a HeroOfferProvider");
|
|
390
|
-
return context;
|
|
391
|
-
};
|
|
392
|
-
//#endregion
|
|
393
|
-
//#region src/components/RecommendationsWidget/ScrollableSlotProvider.tsx
|
|
394
|
-
const ScrollableSlotContext = createContext(null);
|
|
395
|
-
const ScrollableSlotProvider = ({ children, scrollableRecommendationGroup }) => {
|
|
396
|
-
const value = { hasScrollableSlot: !!scrollableRecommendationGroup };
|
|
397
|
-
return /* @__PURE__ */ jsx(ScrollableSlotContext.Provider, {
|
|
398
|
-
value,
|
|
399
|
-
children
|
|
400
|
-
});
|
|
401
|
-
};
|
|
402
|
-
const useScrollableSlot = () => {
|
|
403
|
-
const context = useContext(ScrollableSlotContext);
|
|
404
|
-
if (!context) throw new Error("useScrollableSlot must be used within a ScrollableSlotProvider");
|
|
405
|
-
return context;
|
|
406
|
-
};
|
|
407
|
-
//#endregion
|
|
408
|
-
//#region src/hooks/useIdentity.tsx
|
|
409
|
-
const useIdentity = () => {
|
|
410
|
-
const data = useContext(UserContext);
|
|
411
|
-
if (!data) throw new Error("No wrapper User manager found");
|
|
412
|
-
return data;
|
|
413
|
-
};
|
|
414
|
-
//#endregion
|
|
415
|
-
//#region src/hooks/useCustomization.ts
|
|
416
|
-
const CUSTOMIZATION_TYPE = {
|
|
417
|
-
CHECKOUT: "checkout",
|
|
418
|
-
UPFRONT: "upfront"
|
|
419
|
-
};
|
|
420
|
-
//#endregion
|
|
421
|
-
//#region src/hooks/useRecommendationsCustomization.tsx
|
|
422
|
-
const useRecommendationsCustomization = ({ type = CUSTOMIZATION_TYPE.CHECKOUT } = {}) => {
|
|
423
|
-
const customization = useRecommendationsData()?.publisherCustomization?.[type] || null;
|
|
424
|
-
const hasCustomization = (detail) => {
|
|
425
|
-
if (!customization || typeof customization !== "object" || !detail) return false;
|
|
426
|
-
return !!customization[detail];
|
|
427
|
-
};
|
|
428
|
-
const getCustomization = (detail) => {
|
|
429
|
-
if (!hasCustomization(detail) || !customization) return null;
|
|
430
|
-
return customization[detail];
|
|
431
|
-
};
|
|
432
|
-
const applyCustomizationOrFallback = (detail, fallback = null) => {
|
|
433
|
-
if (!hasCustomization(detail)) return fallback;
|
|
434
|
-
return getCustomization(detail);
|
|
435
|
-
};
|
|
436
|
-
return { applyCustomizationOrFallback };
|
|
437
|
-
};
|
|
438
|
-
//#endregion
|
|
439
|
-
//#region src/components/RecommendationsWidget/useFirstOfferHeading.ts
|
|
440
|
-
const useFirstOfferHeading = () => {
|
|
441
|
-
const { user } = useIdentity();
|
|
442
|
-
const { applyCustomizationOrFallback } = useRecommendationsCustomization();
|
|
443
|
-
const firstName = user?.extrapolatedFirstName;
|
|
444
|
-
return applyCustomizationOrFallback("widget_heading", `${firstName ? `${firstName}, thank you` : "Thank you"} for your purchase:`);
|
|
445
|
-
};
|
|
446
|
-
//#endregion
|
|
447
|
-
//#region src/conf/env_conf.ts
|
|
448
|
-
const BUCKET_NAME = {
|
|
449
|
-
production: "coopcommerce",
|
|
450
|
-
staging: "coopcommerce-staging"
|
|
451
|
-
};
|
|
452
|
-
const IMAGE_HANDLING_CLOUDFRONT_DOMAIN = {
|
|
453
|
-
production: "https://d1t86rpuyqggut.cloudfront.net/",
|
|
454
|
-
staging: "https://dn9o42i1jy6mo.cloudfront.net/"
|
|
455
|
-
};
|
|
456
|
-
//#endregion
|
|
457
|
-
//#region src/utils/getImgUrl.ts
|
|
458
|
-
/**
|
|
459
|
-
* Parses a cloudfront image URL and extracts the key from its BASE64-encoded payload.
|
|
460
|
-
* Returns the key if the URL is a valid cloudfront URL, otherwise returns null.
|
|
461
|
-
*/
|
|
462
|
-
function parseKeyFromCloudfrontUrl(url, env) {
|
|
463
|
-
const domain = IMAGE_HANDLING_CLOUDFRONT_DOMAIN[env];
|
|
464
|
-
if (!url.startsWith(domain)) return null;
|
|
465
|
-
try {
|
|
466
|
-
const base64Path = url.slice(domain.length).split("?")[0];
|
|
467
|
-
if (!base64Path) return null;
|
|
468
|
-
const decodedPayload = atob(base64Path);
|
|
469
|
-
return JSON.parse(decodedPayload).key ?? null;
|
|
470
|
-
} catch {
|
|
471
|
-
return null;
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
const getCloudfrontImageSources = ({ env, key, edits, width, height }) => {
|
|
475
|
-
const imgPayload = JSON.stringify({
|
|
476
|
-
bucket: BUCKET_NAME[env],
|
|
477
|
-
key,
|
|
478
|
-
edits: {
|
|
479
|
-
...edits,
|
|
480
|
-
resize: {
|
|
481
|
-
fit: "fill",
|
|
482
|
-
withoutEnlargement: true
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
});
|
|
486
|
-
return getImageVariants(`${IMAGE_HANDLING_CLOUDFRONT_DOMAIN[env]}${btoa(imgPayload)}`, {
|
|
487
|
-
width: width || 350,
|
|
488
|
-
height: height || 350
|
|
489
|
-
});
|
|
490
|
-
};
|
|
491
|
-
/**
|
|
492
|
-
* Square image sources for `url`. A cloudfront image-handler URL is re-encoded
|
|
493
|
-
* at `size` with 1x-4x variants; any other URL is used as-is.
|
|
494
|
-
*/
|
|
495
|
-
function getImageSources(url, { env, size }) {
|
|
496
|
-
const key = parseKeyFromCloudfrontUrl(url, env);
|
|
497
|
-
return key ? getCloudfrontImageSources({
|
|
498
|
-
env,
|
|
499
|
-
key,
|
|
500
|
-
width: size,
|
|
501
|
-
height: size
|
|
502
|
-
}) : { src: url };
|
|
503
|
-
}
|
|
504
|
-
function getImageVariants(imgUrl, dimensions) {
|
|
505
|
-
const { width: cssWidth, height: cssHeight } = dimensions;
|
|
506
|
-
const getTransformedDimension = (resolution, dimension) => {
|
|
507
|
-
const STEP = 32;
|
|
508
|
-
return Math.ceil(dimension * resolution / STEP) * STEP;
|
|
509
|
-
};
|
|
510
|
-
const getTransformedImageUrl = (resolution) => {
|
|
511
|
-
return `${imgUrl}?width=${getTransformedDimension(resolution, cssWidth)}&height=${getTransformedDimension(resolution, cssHeight)}`;
|
|
512
|
-
};
|
|
513
|
-
const variants = [
|
|
514
|
-
1,
|
|
515
|
-
2,
|
|
516
|
-
3,
|
|
517
|
-
4
|
|
518
|
-
].map((resolution) => ({
|
|
519
|
-
resolution,
|
|
520
|
-
url: getTransformedImageUrl(resolution)
|
|
521
|
-
}));
|
|
522
|
-
return {
|
|
523
|
-
src: getTransformedImageUrl(1),
|
|
524
|
-
srcSet: variants.map(({ resolution, url }) => `${url} ${resolution}x`).join(", ")
|
|
525
|
-
};
|
|
526
|
-
}
|
|
527
|
-
//#endregion
|
|
528
|
-
//#region src/hooks/useDiscoEnv.ts
|
|
529
|
-
const useDiscoEnv = () => useDiscoClient().env;
|
|
530
|
-
//#endregion
|
|
531
|
-
//#region src/components/Essential/generation/LinkGenerator.tsx
|
|
532
|
-
function InternalLink({ targetScreenId, children }) {
|
|
533
|
-
const ctx = useRendererContext();
|
|
534
|
-
return /* @__PURE__ */ jsx("s-link", {
|
|
535
|
-
tone: "neutral",
|
|
536
|
-
onClick: () => ctx.setCurrentScreenId(targetScreenId),
|
|
537
|
-
children
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
const LinkGenerator = { link: ({ node, nodesToJSX }) => {
|
|
541
|
-
const children = nodesToJSX({ nodes: node.children });
|
|
542
|
-
if ("targetScreenId" in node.attributes) return /* @__PURE__ */ jsx(InternalLink, {
|
|
543
|
-
targetScreenId: node.attributes.targetScreenId,
|
|
544
|
-
children
|
|
545
|
-
});
|
|
546
|
-
const href = node.attributes.to;
|
|
547
|
-
const external = node.attributes.external;
|
|
548
|
-
return /* @__PURE__ */ jsx("s-link", {
|
|
549
|
-
tone: "neutral",
|
|
550
|
-
href,
|
|
551
|
-
target: external ? "_blank" : "auto",
|
|
552
|
-
children
|
|
553
|
-
});
|
|
554
|
-
} };
|
|
555
|
-
//#endregion
|
|
556
|
-
//#region src/components/Essential/generation/ParagraphGenerator.tsx
|
|
557
|
-
const ParagraphGenerator = { paragraph: ({ node, nodesToJSX }) => {
|
|
558
|
-
return /* @__PURE__ */ jsx("s-paragraph", {
|
|
559
|
-
color: "subdued",
|
|
560
|
-
children: /* @__PURE__ */ jsx("s-text", {
|
|
561
|
-
type: "strong",
|
|
562
|
-
children: nodesToJSX({ nodes: node.children })
|
|
563
|
-
})
|
|
564
|
-
});
|
|
565
|
-
} };
|
|
566
|
-
//#endregion
|
|
567
|
-
//#region src/components/Essential/generation/ScrollViewGenerator.tsx
|
|
568
|
-
const DEFAULT_MAX_BLOCK_SIZE = 300;
|
|
569
|
-
const ScrollViewGenerator = { scrollview: ({ node, nodesToJSX }) => {
|
|
570
|
-
const children = nodesToJSX({ nodes: node.children });
|
|
571
|
-
return /* @__PURE__ */ jsx("s-scroll-box", {
|
|
572
|
-
maxBlockSize: `${node.attributes?.maxBlockSize ?? DEFAULT_MAX_BLOCK_SIZE}px`,
|
|
573
|
-
children
|
|
574
|
-
});
|
|
575
|
-
} };
|
|
576
|
-
//#endregion
|
|
577
|
-
//#region src/components/Essential/EssentialOfferContent.tsx
|
|
578
|
-
const renderers = {
|
|
579
|
-
text: ({ node }) => {
|
|
580
|
-
return node.text;
|
|
581
|
-
},
|
|
582
|
-
...LinkGenerator,
|
|
583
|
-
...ParagraphGenerator,
|
|
584
|
-
...ScrollViewGenerator
|
|
585
|
-
};
|
|
586
|
-
const EssentialOfferContent = ({ heading: offerHeading, subheading: offerSubheading, jsonContent: incentiveJson }) => {
|
|
587
|
-
return /* @__PURE__ */ jsxs("s-stack", {
|
|
588
|
-
gap: "small-200",
|
|
589
|
-
children: [/* @__PURE__ */ jsx("s-heading", { children: offerHeading }), /* @__PURE__ */ jsx(ScreensRenderer, {
|
|
590
|
-
jsonContent: incentiveJson,
|
|
591
|
-
renderers,
|
|
592
|
-
fallback: /* @__PURE__ */ jsx("s-paragraph", {
|
|
593
|
-
color: "subdued",
|
|
594
|
-
children: /* @__PURE__ */ jsx("s-text", {
|
|
595
|
-
type: "strong",
|
|
596
|
-
children: offerSubheading || ""
|
|
597
|
-
})
|
|
598
|
-
})
|
|
599
|
-
})]
|
|
600
|
-
});
|
|
601
|
-
};
|
|
602
|
-
//#endregion
|
|
603
|
-
//#region src/components/RecommendationsWidget/Essential/EssentialLayoutType.tsx
|
|
604
|
-
const EssentialLayoutType = ({ onLastOffer, compact }) => {
|
|
605
|
-
const { isFirstOffer, activeRecommendation: recommendation } = useHeroOffer();
|
|
606
|
-
const renderBrandLogo = recommendation.offer.metadata.layoutType === "FEATURED_IMAGE";
|
|
607
|
-
return /* @__PURE__ */ jsx("s-query-container", { children: /* @__PURE__ */ jsx("s-box", {
|
|
608
|
-
padding: compact ? "none" : "base",
|
|
609
|
-
children: /* @__PURE__ */ jsxs("s-stack", {
|
|
610
|
-
gap: "small-400",
|
|
611
|
-
children: [
|
|
612
|
-
renderBrandLogo && /* @__PURE__ */ jsx("s-box", {
|
|
613
|
-
display: "@container (inline-size > 450px) none, auto",
|
|
614
|
-
children: /* @__PURE__ */ jsx("s-stack", {
|
|
615
|
-
alignItems: "center",
|
|
616
|
-
children: /* @__PURE__ */ jsx(AdvertiserLogo, { recommendation })
|
|
617
|
-
})
|
|
618
|
-
}),
|
|
619
|
-
isFirstOffer && !compact && /* @__PURE__ */ jsx(FirstOfferHeading, {}),
|
|
620
|
-
/* @__PURE__ */ jsxs("s-grid", {
|
|
621
|
-
gridTemplateColumns: renderBrandLogo ? "@container (inline-size > 450px) 1fr auto, 1fr" : "1fr",
|
|
622
|
-
gap: "base",
|
|
623
|
-
alignItems: "center",
|
|
624
|
-
children: [/* @__PURE__ */ jsxs("s-stack", {
|
|
625
|
-
gap: "base",
|
|
626
|
-
children: [/* @__PURE__ */ jsx(EssentialOfferContent, {
|
|
627
|
-
heading: recommendation.offer.heading || "",
|
|
628
|
-
subheading: recommendation.offer.subheading || "",
|
|
629
|
-
jsonContent: recommendation.offer.jsonContent
|
|
630
|
-
}), /* @__PURE__ */ jsxs("s-stack", {
|
|
631
|
-
direction: "@container (inline-size > 450px) inline, block",
|
|
632
|
-
gap: "base",
|
|
633
|
-
children: [/* @__PURE__ */ jsx("s-box", {
|
|
634
|
-
inlineSize: "@container (inline-size > 450px) auto, 100%",
|
|
635
|
-
children: /* @__PURE__ */ jsx(PrimaryButton, {})
|
|
636
|
-
}), /* @__PURE__ */ jsx("s-box", {
|
|
637
|
-
inlineSize: "@container (inline-size > 450px) auto, 100%",
|
|
638
|
-
children: /* @__PURE__ */ jsx(SecondaryButton, { onLastOffer })
|
|
639
|
-
})]
|
|
640
|
-
})]
|
|
641
|
-
}), renderBrandLogo && /* @__PURE__ */ jsx("s-box", {
|
|
642
|
-
display: "@container (inline-size > 450px) auto, none",
|
|
643
|
-
children: /* @__PURE__ */ jsx(AdvertiserLogo, { recommendation })
|
|
644
|
-
})]
|
|
645
|
-
})
|
|
646
|
-
]
|
|
647
|
-
})
|
|
648
|
-
}) });
|
|
649
|
-
};
|
|
650
|
-
function AdvertiserLogo({ recommendation }) {
|
|
651
|
-
const { advertiser } = recommendation;
|
|
652
|
-
const env = useDiscoEnv();
|
|
653
|
-
const imageSize = 140;
|
|
654
|
-
const image = getImageSources(advertiser.logoUrl, {
|
|
655
|
-
env,
|
|
656
|
-
size: imageSize
|
|
657
|
-
});
|
|
658
|
-
return /* @__PURE__ */ jsx("s-box", {
|
|
659
|
-
blockSize: `${imageSize}px`,
|
|
660
|
-
inlineSize: `${imageSize}px`,
|
|
661
|
-
children: /* @__PURE__ */ jsx("s-image", {
|
|
662
|
-
aspectRatio: "1",
|
|
663
|
-
src: image.src,
|
|
664
|
-
srcSet: image.srcSet,
|
|
665
|
-
alt: `${advertiser.name} Logo`,
|
|
666
|
-
inlineSize: "fill"
|
|
667
|
-
})
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
function PrimaryButton() {
|
|
671
|
-
const { track } = useEventTracker();
|
|
672
|
-
const { handleOfferClaim, isOfferClaimed, activeRecommendation: recommendation } = useHeroOffer();
|
|
673
|
-
const handleClick = () => {
|
|
674
|
-
track({
|
|
675
|
-
type: "BRAND_CLICK",
|
|
676
|
-
target: "INLINE_ACTION_BUTTON",
|
|
677
|
-
brand: {
|
|
678
|
-
offerId: recommendation.offer.id,
|
|
679
|
-
advertiserId: recommendation.advertiser.id,
|
|
680
|
-
insertionId: recommendation.insertionId
|
|
681
|
-
}
|
|
682
|
-
});
|
|
683
|
-
handleOfferClaim();
|
|
684
|
-
};
|
|
685
|
-
return /* @__PURE__ */ jsx("s-button", {
|
|
686
|
-
href: recommendation.offer.targetUrl,
|
|
687
|
-
target: "_blank",
|
|
688
|
-
inlineSize: "fill",
|
|
689
|
-
variant: isOfferClaimed ? "secondary" : "primary",
|
|
690
|
-
onClick: handleClick,
|
|
691
|
-
children: recommendation.offer.ctaDetails.acceptCopy
|
|
692
|
-
});
|
|
693
|
-
}
|
|
694
|
-
function SecondaryButton({ onLastOffer }) {
|
|
695
|
-
const { track } = useEventTracker();
|
|
696
|
-
const { hasScrollableSlot } = useScrollableSlot();
|
|
697
|
-
const { isOfferClaimed, nextOffer, isLastOffer, activeRecommendation: recommendation } = useHeroOffer();
|
|
698
|
-
const handleClick = () => {
|
|
699
|
-
track({
|
|
700
|
-
type: "ELEMENT_CLICK",
|
|
701
|
-
target: "INLINE_NAV_FORWARD",
|
|
702
|
-
brand: {
|
|
703
|
-
offerId: recommendation.offer.id,
|
|
704
|
-
advertiserId: recommendation.advertiser.id,
|
|
705
|
-
insertionId: recommendation.insertionId
|
|
706
|
-
}
|
|
707
|
-
});
|
|
708
|
-
if (isLastOffer) {
|
|
709
|
-
onLastOffer();
|
|
710
|
-
return;
|
|
711
|
-
}
|
|
712
|
-
nextOffer();
|
|
713
|
-
};
|
|
714
|
-
const buttonText = isOfferClaimed ? isLastOffer ? hasScrollableSlot ? "See more" : "Close" : "Next offer" : recommendation.offer.ctaDetails.declineCopy || "No thanks";
|
|
715
|
-
return /* @__PURE__ */ jsx("s-button", {
|
|
716
|
-
inlineSize: "fill",
|
|
717
|
-
variant: isOfferClaimed ? "primary" : "secondary",
|
|
718
|
-
onClick: handleClick,
|
|
719
|
-
children: buttonText
|
|
720
|
-
});
|
|
721
|
-
}
|
|
722
|
-
function FirstOfferHeading() {
|
|
723
|
-
return /* @__PURE__ */ jsx("s-text", {
|
|
724
|
-
tone: "info",
|
|
725
|
-
children: useFirstOfferHeading()
|
|
726
|
-
});
|
|
727
|
-
}
|
|
728
|
-
//#endregion
|
|
729
|
-
//#region src/components/RecommendationsWidget/DotIndicators.tsx
|
|
730
|
-
const DotIndicators = ({ totalCount, activeIndex }) => {
|
|
731
|
-
if (totalCount <= 1) return null;
|
|
732
|
-
return /* @__PURE__ */ jsx("s-stack", {
|
|
733
|
-
padding: "small-200 none",
|
|
734
|
-
alignItems: "center",
|
|
735
|
-
children: /* @__PURE__ */ jsx("s-stack", {
|
|
736
|
-
direction: "inline",
|
|
737
|
-
gap: "small-200",
|
|
738
|
-
children: Array.from({ length: totalCount }, (_, i) => /* @__PURE__ */ jsx("s-badge", {
|
|
739
|
-
size: "small",
|
|
740
|
-
color: i === activeIndex ? "base" : "subdued",
|
|
741
|
-
children: `${i + 1}`
|
|
742
|
-
}, i))
|
|
743
|
-
})
|
|
744
|
-
});
|
|
745
|
-
};
|
|
746
|
-
//#endregion
|
|
747
|
-
//#region src/conf/index.ts
|
|
748
|
-
const getLeadGenRegisterUrl = (env) => `${INTERNAL_BASE_URL[env]}/lead_gen/register_lead/`;
|
|
749
|
-
const PRIVACY_POLICY_URL = "https://www.disconetwork.com/privacy-policy";
|
|
750
|
-
//#endregion
|
|
751
|
-
//#region src/components/PrivacyLink.tsx
|
|
752
|
-
const PrivacyLink = ({ onPress }) => {
|
|
753
|
-
return /* @__PURE__ */ jsx("s-text", {
|
|
754
|
-
color: "subdued",
|
|
755
|
-
children: /* @__PURE__ */ jsx("s-link", {
|
|
756
|
-
href: PRIVACY_POLICY_URL,
|
|
757
|
-
target: "_blank",
|
|
758
|
-
tone: "neutral",
|
|
759
|
-
onClick: onPress,
|
|
760
|
-
children: "Privacy Policy"
|
|
761
|
-
})
|
|
762
|
-
});
|
|
763
|
-
};
|
|
764
|
-
//#endregion
|
|
765
|
-
//#region src/components/RecommendationsWidget/Footer.tsx
|
|
766
|
-
function Footer() {
|
|
767
|
-
const { track } = useEventTracker();
|
|
768
|
-
const handlePrivacyClick = () => {
|
|
769
|
-
track({
|
|
770
|
-
type: "ELEMENT_CLICK",
|
|
771
|
-
target: "INLINE_FOOTER_PRIVACY"
|
|
772
|
-
});
|
|
773
|
-
};
|
|
774
|
-
return /* @__PURE__ */ jsx("s-stack", {
|
|
775
|
-
padding: "small-200 base",
|
|
776
|
-
alignItems: "end",
|
|
777
|
-
children: /* @__PURE__ */ jsx(PrivacyLink, { onPress: handlePrivacyClick })
|
|
778
|
-
});
|
|
779
|
-
}
|
|
780
|
-
//#endregion
|
|
781
|
-
//#region src/components/RecommendationsWidget/Cover/index.tsx
|
|
782
|
-
const CoverRecommendationsWidget = ({ heroRecommendationGroup }) => {
|
|
783
|
-
const { track } = useEventTracker();
|
|
784
|
-
useEffect(() => {
|
|
785
|
-
track({ type: "WIDGET_LOAD" });
|
|
786
|
-
}, [track]);
|
|
787
|
-
return /* @__PURE__ */ jsx(HeroOfferProvider, {
|
|
788
|
-
recommendationGroup: heroRecommendationGroup,
|
|
789
|
-
loop: true,
|
|
790
|
-
children: /* @__PURE__ */ jsx(CoverRecommendationsWidgetContent, {})
|
|
791
|
-
});
|
|
792
|
-
};
|
|
793
|
-
const CoverRecommendationsWidgetContent = () => {
|
|
794
|
-
const { track } = useEventTracker();
|
|
795
|
-
const firstOfferHeading = useFirstOfferHeading();
|
|
796
|
-
const modalHeading = typeof firstOfferHeading === "string" ? firstOfferHeading : "Your rewards";
|
|
797
|
-
const { TOTAL_NUM_OFFERS, activeOfferIndex, nextOffer, activeRecommendation } = useHeroOffer();
|
|
798
|
-
const [modalOpen, setModalOpen] = useState(false);
|
|
799
|
-
const { insertionId, offer, advertiser } = activeRecommendation;
|
|
800
|
-
useEffect(() => {
|
|
801
|
-
if (!modalOpen) return;
|
|
802
|
-
track({
|
|
803
|
-
type: "BRAND_DISPLAY",
|
|
804
|
-
target: "INLINE_SLOT",
|
|
805
|
-
brand: {
|
|
806
|
-
offerId: offer.id,
|
|
807
|
-
advertiserId: advertiser.id,
|
|
808
|
-
insertionId
|
|
809
|
-
}
|
|
810
|
-
});
|
|
811
|
-
}, [
|
|
812
|
-
modalOpen,
|
|
813
|
-
track,
|
|
814
|
-
insertionId,
|
|
815
|
-
offer.id,
|
|
816
|
-
advertiser.id
|
|
817
|
-
]);
|
|
818
|
-
const subtitle = `You've unlocked ${TOTAL_NUM_OFFERS} exclusive offer${TOTAL_NUM_OFFERS !== 1 ? "s" : ""} with your purchase — don't let them go to waste!`;
|
|
819
|
-
return /* @__PURE__ */ jsx(CardContainer, {
|
|
820
|
-
background: "transparent",
|
|
821
|
-
children: /* @__PURE__ */ jsx("s-box", {
|
|
822
|
-
padding: "base",
|
|
823
|
-
children: /* @__PURE__ */ jsxs("s-stack", {
|
|
824
|
-
gap: "base",
|
|
825
|
-
children: [
|
|
826
|
-
/* @__PURE__ */ jsx("s-heading", { children: "Your purchase comes with rewards!" }),
|
|
827
|
-
/* @__PURE__ */ jsx("s-text", {
|
|
828
|
-
color: "subdued",
|
|
829
|
-
children: subtitle
|
|
830
|
-
}),
|
|
831
|
-
/* @__PURE__ */ jsx("s-button", {
|
|
832
|
-
variant: "primary",
|
|
833
|
-
command: "--show",
|
|
834
|
-
commandFor: "cover-modal",
|
|
835
|
-
onClick: () => track({
|
|
836
|
-
type: "ELEMENT_CLICK",
|
|
837
|
-
target: "OPEN_OVERLAY"
|
|
838
|
-
}),
|
|
839
|
-
children: "View my rewards"
|
|
840
|
-
}),
|
|
841
|
-
/* @__PURE__ */ jsxs("s-modal", {
|
|
842
|
-
id: "cover-modal",
|
|
843
|
-
padding: "base",
|
|
844
|
-
heading: modalHeading,
|
|
845
|
-
size: "large",
|
|
846
|
-
onShow: () => {
|
|
847
|
-
setModalOpen(true);
|
|
848
|
-
track({ type: "WIDGET_DISPLAY" });
|
|
849
|
-
},
|
|
850
|
-
onHide: () => {
|
|
851
|
-
setModalOpen(false);
|
|
852
|
-
track({
|
|
853
|
-
type: "ELEMENT_CLICK",
|
|
854
|
-
target: "CLOSE_BUTTON"
|
|
855
|
-
});
|
|
856
|
-
},
|
|
857
|
-
children: [
|
|
858
|
-
/* @__PURE__ */ jsx(ScrollableSlotProvider, { children: /* @__PURE__ */ jsx(EssentialLayoutType, {
|
|
859
|
-
onLastOffer: nextOffer,
|
|
860
|
-
compact: true
|
|
861
|
-
}) }),
|
|
862
|
-
/* @__PURE__ */ jsx(DotIndicators, {
|
|
863
|
-
totalCount: TOTAL_NUM_OFFERS,
|
|
864
|
-
activeIndex: activeOfferIndex
|
|
865
|
-
}),
|
|
866
|
-
/* @__PURE__ */ jsx("s-divider", {}),
|
|
867
|
-
/* @__PURE__ */ jsx(Footer, {})
|
|
868
|
-
]
|
|
869
|
-
})
|
|
870
|
-
]
|
|
871
|
-
})
|
|
872
|
-
})
|
|
873
|
-
});
|
|
874
|
-
};
|
|
875
|
-
//#endregion
|
|
876
|
-
//#region src/components/DiscoFeed/DiscoFeedProduct.tsx
|
|
877
|
-
function ProductTile({ targetUrl, trackClick, image, productName }) {
|
|
878
|
-
return /* @__PURE__ */ jsx("s-box", {
|
|
879
|
-
inlineSize: "100%",
|
|
880
|
-
children: /* @__PURE__ */ jsxs("s-stack", {
|
|
881
|
-
alignItems: "stretch",
|
|
882
|
-
gap: "none",
|
|
883
|
-
children: [/* @__PURE__ */ jsx("s-link", {
|
|
884
|
-
target: "_blank",
|
|
885
|
-
tone: "neutral",
|
|
886
|
-
href: targetUrl,
|
|
887
|
-
onClick: trackClick,
|
|
888
|
-
children: /* @__PURE__ */ jsx("s-box", {
|
|
889
|
-
inlineSize: "100%",
|
|
890
|
-
children: /* @__PURE__ */ jsx("s-image", {
|
|
891
|
-
aspectRatio: "1",
|
|
892
|
-
src: image.src,
|
|
893
|
-
srcSet: image.srcSet,
|
|
894
|
-
alt: productName,
|
|
895
|
-
inlineSize: "fill",
|
|
896
|
-
border: "base",
|
|
897
|
-
borderRadius: "small"
|
|
898
|
-
})
|
|
899
|
-
})
|
|
900
|
-
}), /* @__PURE__ */ jsx("s-stack", {
|
|
901
|
-
maxBlockSize: "50px",
|
|
902
|
-
maxInlineSize: "100%",
|
|
903
|
-
padding: "small-400 none none none",
|
|
904
|
-
overflow: "hidden",
|
|
905
|
-
children: /* @__PURE__ */ jsx("s-text", {
|
|
906
|
-
type: "strong",
|
|
907
|
-
color: "subdued",
|
|
908
|
-
children: /* @__PURE__ */ jsx("s-link", {
|
|
909
|
-
target: "_blank",
|
|
910
|
-
tone: "neutral",
|
|
911
|
-
href: targetUrl,
|
|
912
|
-
onClick: trackClick,
|
|
913
|
-
children: productName
|
|
914
|
-
})
|
|
915
|
-
})
|
|
916
|
-
})]
|
|
917
|
-
})
|
|
918
|
-
});
|
|
919
|
-
}
|
|
920
|
-
//#endregion
|
|
921
|
-
//#region src/components/RecommendationsWidget/RecommendationsOfferRow.tsx
|
|
922
|
-
const PAGE_SIZE = 4;
|
|
923
|
-
const PRODUCT_IMAGE_SOURCE_SIZE = 256;
|
|
924
|
-
const RecommendationsOfferRow = ({ recommendations, padding }) => {
|
|
925
|
-
return /* @__PURE__ */ jsx(RecommendationsPager, {
|
|
926
|
-
recommendations: recommendations.filter((recommendation) => recommendation.offer.assets.length > 0),
|
|
927
|
-
padding
|
|
928
|
-
});
|
|
929
|
-
};
|
|
930
|
-
function RecommendationsPager({ recommendations, padding }) {
|
|
931
|
-
const [page, setPage] = useState(0);
|
|
932
|
-
const pageCount = Math.ceil(recommendations.length / PAGE_SIZE);
|
|
933
|
-
const currentPage = Math.min(page, Math.max(pageCount - 1, 0));
|
|
934
|
-
const pageRecommendations = recommendations.slice(currentPage * PAGE_SIZE, (currentPage + 1) * PAGE_SIZE);
|
|
935
|
-
useEffect(() => {
|
|
936
|
-
if (page !== currentPage) setPage(currentPage);
|
|
937
|
-
}, [page, currentPage]);
|
|
938
|
-
if (pageRecommendations.length === 0) return null;
|
|
939
|
-
return /* @__PURE__ */ jsx("s-box", {
|
|
940
|
-
padding,
|
|
941
|
-
children: /* @__PURE__ */ jsxs("s-stack", {
|
|
942
|
-
gap: "base",
|
|
943
|
-
children: [/* @__PURE__ */ jsx("s-grid", {
|
|
944
|
-
gridTemplateColumns: "repeat(4, minmax(0, 1fr))",
|
|
945
|
-
gap: "small-200",
|
|
946
|
-
children: pageRecommendations.map((recommendation) => /* @__PURE__ */ jsx("s-box", {
|
|
947
|
-
inlineSize: "100%",
|
|
948
|
-
children: /* @__PURE__ */ jsx(RecommendationsOfferRowTile, { recommendation })
|
|
949
|
-
}, recommendation.id))
|
|
950
|
-
}), pageCount > 1 && /* @__PURE__ */ jsxs("s-stack", {
|
|
951
|
-
direction: "inline",
|
|
952
|
-
justifyContent: "center",
|
|
953
|
-
alignItems: "center",
|
|
954
|
-
gap: "small-200",
|
|
955
|
-
children: [
|
|
956
|
-
/* @__PURE__ */ jsx("s-clickable", {
|
|
957
|
-
accessibilityLabel: "Previous recommendations page",
|
|
958
|
-
disabled: currentPage === 0,
|
|
959
|
-
inlineSize: "32px",
|
|
960
|
-
blockSize: "32px",
|
|
961
|
-
border: "base",
|
|
962
|
-
borderRadius: "base",
|
|
963
|
-
onClick: () => setPage(currentPage - 1),
|
|
964
|
-
children: /* @__PURE__ */ jsx("s-stack", {
|
|
965
|
-
blockSize: "100%",
|
|
966
|
-
alignItems: "center",
|
|
967
|
-
justifyContent: "center",
|
|
968
|
-
children: /* @__PURE__ */ jsx("s-icon", {
|
|
969
|
-
type: "chevron-left",
|
|
970
|
-
size: "small",
|
|
971
|
-
tone: currentPage === 0 ? "neutral" : "auto"
|
|
972
|
-
})
|
|
973
|
-
})
|
|
974
|
-
}),
|
|
975
|
-
/* @__PURE__ */ jsxs("s-text", {
|
|
976
|
-
type: "small",
|
|
977
|
-
tone: "neutral",
|
|
978
|
-
color: "base",
|
|
979
|
-
children: [
|
|
980
|
-
currentPage + 1,
|
|
981
|
-
" / ",
|
|
982
|
-
pageCount
|
|
983
|
-
]
|
|
984
|
-
}),
|
|
985
|
-
/* @__PURE__ */ jsx("s-clickable", {
|
|
986
|
-
accessibilityLabel: "Next recommendations page",
|
|
987
|
-
disabled: currentPage === pageCount - 1,
|
|
988
|
-
inlineSize: "32px",
|
|
989
|
-
blockSize: "32px",
|
|
990
|
-
border: "base",
|
|
991
|
-
borderRadius: "base",
|
|
992
|
-
onClick: () => setPage(currentPage + 1),
|
|
993
|
-
children: /* @__PURE__ */ jsx("s-stack", {
|
|
994
|
-
blockSize: "100%",
|
|
995
|
-
alignItems: "center",
|
|
996
|
-
justifyContent: "center",
|
|
997
|
-
children: /* @__PURE__ */ jsx("s-icon", {
|
|
998
|
-
type: "chevron-right",
|
|
999
|
-
size: "small",
|
|
1000
|
-
tone: currentPage === pageCount - 1 ? "neutral" : "auto"
|
|
1001
|
-
})
|
|
1002
|
-
})
|
|
1003
|
-
})
|
|
1004
|
-
]
|
|
1005
|
-
})]
|
|
1006
|
-
})
|
|
1007
|
-
});
|
|
1008
|
-
}
|
|
1009
|
-
function RecommendationsOfferRowTile({ recommendation }) {
|
|
1010
|
-
const { track } = useEventTracker();
|
|
1011
|
-
const env = useDiscoEnv();
|
|
1012
|
-
const offerId = recommendation.offer.id;
|
|
1013
|
-
const advertiserId = recommendation.advertiser.id;
|
|
1014
|
-
const insertionId = recommendation.insertionId;
|
|
1015
|
-
useEffect(() => {
|
|
1016
|
-
track({
|
|
1017
|
-
type: "BRAND_DISPLAY",
|
|
1018
|
-
target: "SCROLLABLE_SLOT",
|
|
1019
|
-
brand: {
|
|
1020
|
-
offerId,
|
|
1021
|
-
advertiserId,
|
|
1022
|
-
insertionId
|
|
1023
|
-
}
|
|
1024
|
-
});
|
|
1025
|
-
}, [
|
|
1026
|
-
track,
|
|
1027
|
-
offerId,
|
|
1028
|
-
advertiserId,
|
|
1029
|
-
insertionId
|
|
1030
|
-
]);
|
|
1031
|
-
const trackClick = () => {
|
|
1032
|
-
track({
|
|
1033
|
-
type: "BRAND_CLICK",
|
|
1034
|
-
target: "SCROLLABLE_SLOT_TILE",
|
|
1035
|
-
brand: {
|
|
1036
|
-
offerId,
|
|
1037
|
-
advertiserId,
|
|
1038
|
-
insertionId
|
|
1039
|
-
}
|
|
1040
|
-
});
|
|
1041
|
-
};
|
|
1042
|
-
const targetUrl = recommendation.offer.targetUrl;
|
|
1043
|
-
const productName = `${recommendation.offer.heading} ${recommendation.offer.subheading}`;
|
|
1044
|
-
const offerImageAsset = recommendation.offer.assets[0];
|
|
1045
|
-
if (!offerImageAsset) return null;
|
|
1046
|
-
return /* @__PURE__ */ jsx(ProductTile, {
|
|
1047
|
-
targetUrl,
|
|
1048
|
-
trackClick,
|
|
1049
|
-
image: getImageSources(offerImageAsset.imageUrl, {
|
|
1050
|
-
env,
|
|
1051
|
-
size: PRODUCT_IMAGE_SOURCE_SIZE
|
|
1052
|
-
}),
|
|
1053
|
-
productName
|
|
1054
|
-
});
|
|
1055
|
-
}
|
|
1056
|
-
//#endregion
|
|
1057
|
-
//#region src/components/RecommendationsWidget/Essential/index.tsx
|
|
1058
|
-
const EssentialRecommendationsWidget = ({ heroRecommendationGroup, scrollableRecommendationGroup }) => {
|
|
1059
|
-
const [showOfferSlot, setShowOfferSlot] = useState(!!heroRecommendationGroup);
|
|
1060
|
-
const { track } = useEventTracker();
|
|
1061
|
-
const { applyCustomizationOrFallback } = useRecommendationsCustomization();
|
|
1062
|
-
useEffect(() => {
|
|
1063
|
-
track({ type: "WIDGET_LOAD" });
|
|
1064
|
-
track({ type: "WIDGET_DISPLAY" });
|
|
1065
|
-
}, [track]);
|
|
1066
|
-
const hideOfferSlot = () => setShowOfferSlot(false);
|
|
1067
|
-
const heading = applyCustomizationOrFallback("widget_bottom_slot_heading", "Trending brands we think you'll love");
|
|
1068
|
-
if (!showOfferSlot && !scrollableRecommendationGroup) return null;
|
|
1069
|
-
return /* @__PURE__ */ jsx(ScrollableSlotProvider, {
|
|
1070
|
-
scrollableRecommendationGroup,
|
|
1071
|
-
children: /* @__PURE__ */ jsxs(CardContainer, {
|
|
1072
|
-
background: "base",
|
|
1073
|
-
children: [
|
|
1074
|
-
showOfferSlot && heroRecommendationGroup ? /* @__PURE__ */ jsx("s-box", {
|
|
1075
|
-
border: "base",
|
|
1076
|
-
borderWidth: "none none base none",
|
|
1077
|
-
children: /* @__PURE__ */ jsx(HeroOfferProvider, {
|
|
1078
|
-
recommendationGroup: heroRecommendationGroup,
|
|
1079
|
-
children: /* @__PURE__ */ jsx(TrackedEssentialLayout, { onLastOffer: hideOfferSlot })
|
|
1080
|
-
})
|
|
1081
|
-
}) : /* @__PURE__ */ jsx("s-box", {
|
|
1082
|
-
padding: "base base none base",
|
|
1083
|
-
children: /* @__PURE__ */ jsx("s-heading", { children: heading })
|
|
1084
|
-
}),
|
|
1085
|
-
scrollableRecommendationGroup && /* @__PURE__ */ jsx("s-box", {
|
|
1086
|
-
padding: "base none",
|
|
1087
|
-
border: "base",
|
|
1088
|
-
borderWidth: "none none base none",
|
|
1089
|
-
children: /* @__PURE__ */ jsx(RecommendationsOfferRow, {
|
|
1090
|
-
recommendations: scrollableRecommendationGroup.recommendations,
|
|
1091
|
-
padding: "none base"
|
|
1092
|
-
})
|
|
1093
|
-
}),
|
|
1094
|
-
/* @__PURE__ */ jsx(Footer, {})
|
|
1095
|
-
]
|
|
1096
|
-
})
|
|
1097
|
-
});
|
|
1098
|
-
};
|
|
1099
|
-
const TrackedEssentialLayout = ({ onLastOffer }) => {
|
|
1100
|
-
const { track } = useEventTracker();
|
|
1101
|
-
const { activeRecommendation } = useHeroOffer();
|
|
1102
|
-
const { insertionId, offer, advertiser } = activeRecommendation;
|
|
1103
|
-
useEffect(() => {
|
|
1104
|
-
track({
|
|
1105
|
-
type: "BRAND_DISPLAY",
|
|
1106
|
-
target: "INLINE_SLOT",
|
|
1107
|
-
brand: {
|
|
1108
|
-
offerId: offer.id,
|
|
1109
|
-
advertiserId: advertiser.id,
|
|
1110
|
-
insertionId
|
|
1111
|
-
}
|
|
1112
|
-
});
|
|
1113
|
-
}, [
|
|
1114
|
-
track,
|
|
1115
|
-
insertionId,
|
|
1116
|
-
offer.id,
|
|
1117
|
-
advertiser.id
|
|
1118
|
-
]);
|
|
1119
|
-
return /* @__PURE__ */ jsx(EssentialLayoutType, { onLastOffer });
|
|
1120
|
-
};
|
|
1121
|
-
//#endregion
|
|
1122
|
-
//#region src/components/RecommendationsWidget/LeadGen/LeadGenHeader.tsx
|
|
1123
|
-
const LeadGenHeader = () => {
|
|
1124
|
-
const { claimedOffers } = useHeroOffer();
|
|
1125
|
-
const { applyCustomizationOrFallback } = useRecommendationsCustomization();
|
|
1126
|
-
const hasClaimedAnOffer = claimedOffers.length > 0;
|
|
1127
|
-
const heading = applyCustomizationOrFallback("widget_heading", !hasClaimedAnOffer ? `Special offers just for you` : `Your special offer is claimed!`);
|
|
1128
|
-
const subheading = applyCustomizationOrFallback("widget_subheading", !hasClaimedAnOffer ? `As a thank you for your recent purchase` : "Discover more deals to save on top brands");
|
|
1129
|
-
return /* @__PURE__ */ jsxs("s-stack", {
|
|
1130
|
-
gap: "none",
|
|
1131
|
-
padding: "large-200",
|
|
1132
|
-
children: [/* @__PURE__ */ jsx("s-heading", { children: heading }), /* @__PURE__ */ jsx("s-text", {
|
|
1133
|
-
color: "subdued",
|
|
1134
|
-
children: subheading
|
|
1135
|
-
})]
|
|
1136
|
-
});
|
|
1137
|
-
};
|
|
1138
|
-
//#endregion
|
|
1139
|
-
//#region src/components/RecommendationsWidget/LeadGen/LeadGenBrand.tsx
|
|
1140
|
-
const LeadGenAssetTile = ({ asset }) => {
|
|
1141
|
-
const env = useDiscoEnv();
|
|
1142
|
-
const image = getImageSources(asset.imageUrl, {
|
|
1143
|
-
env,
|
|
1144
|
-
size: 400
|
|
1145
|
-
});
|
|
1146
|
-
return /* @__PURE__ */ jsx("s-image", {
|
|
1147
|
-
aspectRatio: "1",
|
|
1148
|
-
src: image.src,
|
|
1149
|
-
srcSet: image.srcSet,
|
|
1150
|
-
alt: "Offer product",
|
|
1151
|
-
inlineSize: "fill",
|
|
1152
|
-
border: "base",
|
|
1153
|
-
borderRadius: "base",
|
|
1154
|
-
loading: "lazy"
|
|
1155
|
-
});
|
|
1156
|
-
};
|
|
1157
|
-
const LeadGenBrandProducts = () => {
|
|
1158
|
-
const { activeRecommendation } = useHeroOffer();
|
|
1159
|
-
const assets = activeRecommendation.offer.assets.slice(0, 4);
|
|
1160
|
-
if (assets.length === 0) return null;
|
|
1161
|
-
return /* @__PURE__ */ jsx("s-query-container", { children: /* @__PURE__ */ jsx("s-grid", {
|
|
1162
|
-
gridTemplateColumns: "@container (inline-size > 450px) repeat(4, 1fr), repeat(3, 1fr)",
|
|
1163
|
-
gap: "small-200",
|
|
1164
|
-
children: assets.map((asset) => /* @__PURE__ */ jsx(LeadGenAssetTile, { asset }, asset.id))
|
|
1165
|
-
}) });
|
|
1166
|
-
};
|
|
1167
|
-
const LeadGenBrand = () => {
|
|
1168
|
-
const { activeRecommendation } = useHeroOffer();
|
|
1169
|
-
const { advertiser } = activeRecommendation;
|
|
1170
|
-
const env = useDiscoEnv();
|
|
1171
|
-
const logoSize = 56;
|
|
1172
|
-
const logo = getImageSources(advertiser.logoUrl, {
|
|
1173
|
-
env,
|
|
1174
|
-
size: logoSize
|
|
1175
|
-
});
|
|
1176
|
-
return /* @__PURE__ */ jsxs("s-stack", {
|
|
1177
|
-
gap: "small-200",
|
|
1178
|
-
padding: "base large-200",
|
|
1179
|
-
children: [/* @__PURE__ */ jsxs("s-grid", {
|
|
1180
|
-
gridTemplateColumns: `1fr ${logoSize}px`,
|
|
1181
|
-
gap: "small-200",
|
|
1182
|
-
alignItems: "start",
|
|
1183
|
-
children: [/* @__PURE__ */ jsxs("s-stack", {
|
|
1184
|
-
gap: "none",
|
|
1185
|
-
children: [/* @__PURE__ */ jsx("s-text", {
|
|
1186
|
-
type: "strong",
|
|
1187
|
-
children: advertiser.name
|
|
1188
|
-
}), /* @__PURE__ */ jsx("s-paragraph", { children: advertiser.description })]
|
|
1189
|
-
}), /* @__PURE__ */ jsx("s-box", {
|
|
1190
|
-
inlineSize: `${logoSize}px`,
|
|
1191
|
-
blockSize: `${logoSize}px`,
|
|
1192
|
-
children: /* @__PURE__ */ jsx("s-image", {
|
|
1193
|
-
aspectRatio: "1",
|
|
1194
|
-
src: logo.src,
|
|
1195
|
-
srcSet: logo.srcSet,
|
|
1196
|
-
alt: `${advertiser.name} logo`,
|
|
1197
|
-
inlineSize: "fill",
|
|
1198
|
-
border: "base",
|
|
1199
|
-
borderRadius: "max"
|
|
1200
|
-
})
|
|
1201
|
-
})]
|
|
1202
|
-
}), /* @__PURE__ */ jsx(LeadGenBrandProducts, {})]
|
|
1203
|
-
});
|
|
1204
|
-
};
|
|
1205
|
-
//#endregion
|
|
1206
|
-
//#region src/hooks/useResource.tsx
|
|
1207
|
-
const initialResource = {
|
|
1208
|
-
loading: false,
|
|
1209
|
-
error: false,
|
|
1210
|
-
data: null,
|
|
1211
|
-
headers: null
|
|
1212
|
-
};
|
|
1213
|
-
const useResource = (options, autoLoad = true, debug = false) => {
|
|
1214
|
-
const [shouldLoad, setShouldLoad] = useState(autoLoad);
|
|
1215
|
-
const [resource, setResource] = useState(initialResource);
|
|
1216
|
-
const reset = useCallback(() => {
|
|
1217
|
-
setResource(initialResource);
|
|
1218
|
-
setShouldLoad(false);
|
|
1219
|
-
}, []);
|
|
1220
|
-
const log = useCallback((...msg) => {
|
|
1221
|
-
if (debug) console.log(...msg);
|
|
1222
|
-
}, [debug]);
|
|
1223
|
-
const mounted = useRef(true);
|
|
1224
|
-
useEffect(() => {
|
|
1225
|
-
mounted.current = true;
|
|
1226
|
-
return () => {
|
|
1227
|
-
mounted.current = false;
|
|
1228
|
-
};
|
|
1229
|
-
}, []);
|
|
1230
|
-
const startLoad = useCallback(() => setShouldLoad(true), []);
|
|
1231
|
-
const load = useCallback(async () => {
|
|
1232
|
-
log("[uR]: Load called ");
|
|
1233
|
-
if (resource.loading || !shouldLoad || !options?.url) {
|
|
1234
|
-
log("[uR]: Load stopped ");
|
|
1235
|
-
return;
|
|
1236
|
-
}
|
|
1237
|
-
log("[uR]: Load started ");
|
|
1238
|
-
setShouldLoad(false);
|
|
1239
|
-
let resp;
|
|
1240
|
-
setResource({
|
|
1241
|
-
loading: true,
|
|
1242
|
-
error: false,
|
|
1243
|
-
data: null,
|
|
1244
|
-
headers: null
|
|
1245
|
-
});
|
|
1246
|
-
try {
|
|
1247
|
-
let reqOptions = {
|
|
1248
|
-
headers: { "Content-Type": "application/json" },
|
|
1249
|
-
method: "GET",
|
|
1250
|
-
...options
|
|
1251
|
-
};
|
|
1252
|
-
if ((options?.method === "POST" || options?.method === "PUT") && options.data) reqOptions = {
|
|
1253
|
-
...reqOptions,
|
|
1254
|
-
body: JSON.stringify(options.data)
|
|
1255
|
-
};
|
|
1256
|
-
resp = await fetch(options.url, reqOptions);
|
|
1257
|
-
if (resp.status !== 200 && resp.status !== 201) throw new Error("RESP_ERR");
|
|
1258
|
-
try {
|
|
1259
|
-
resp = await resp.json();
|
|
1260
|
-
} catch {
|
|
1261
|
-
throw new Error("JSON_ERR");
|
|
1262
|
-
}
|
|
1263
|
-
} catch (e) {
|
|
1264
|
-
if (typeof e === "string") {
|
|
1265
|
-
log(`[uR]: Load error! String => ${e}`);
|
|
1266
|
-
return;
|
|
1267
|
-
} else if (!(e instanceof Error)) {
|
|
1268
|
-
log(`[uR]: Load error! Unknown error =>`, e);
|
|
1269
|
-
return;
|
|
1270
|
-
}
|
|
1271
|
-
const { message: errMessage } = e;
|
|
1272
|
-
log(`[uR]: Load error! ${errMessage}`);
|
|
1273
|
-
if (mounted.current) return setResource({
|
|
1274
|
-
loading: false,
|
|
1275
|
-
error: errMessage === "RESP_ERR" || errMessage === "JSON_ERR" ? "An unknown error occured" : "Could not connect to the server",
|
|
1276
|
-
data: null
|
|
1277
|
-
});
|
|
1278
|
-
else return log("[uR]: Load error but NOT MOUNTED ");
|
|
1279
|
-
}
|
|
1280
|
-
if (mounted.current) {
|
|
1281
|
-
log("[uR]: Load complete:", resp);
|
|
1282
|
-
setResource({
|
|
1283
|
-
loading: false,
|
|
1284
|
-
error: false,
|
|
1285
|
-
data: resp,
|
|
1286
|
-
headers: null
|
|
1287
|
-
});
|
|
1288
|
-
} else log("[uR]: Load complete but NOT MOUNTED ");
|
|
1289
|
-
}, [
|
|
1290
|
-
options,
|
|
1291
|
-
resource.loading,
|
|
1292
|
-
shouldLoad,
|
|
1293
|
-
log
|
|
1294
|
-
]);
|
|
1295
|
-
useEffect(() => {
|
|
1296
|
-
if (!resource.loading && shouldLoad) load();
|
|
1297
|
-
}, [
|
|
1298
|
-
resource.loading,
|
|
1299
|
-
shouldLoad,
|
|
1300
|
-
load
|
|
1301
|
-
]);
|
|
1302
|
-
return [
|
|
1303
|
-
resource,
|
|
1304
|
-
startLoad,
|
|
1305
|
-
reset
|
|
1306
|
-
];
|
|
1307
|
-
};
|
|
1308
|
-
//#endregion
|
|
1309
|
-
//#region src/hooks/useSendOfferEmail.ts
|
|
1310
|
-
const useSendOfferEmail = ({ shopGid, offerRemoteId, displayedOfferRemoteIds, sessionId }) => {
|
|
1311
|
-
const payload = usePayload();
|
|
1312
|
-
return useResource({
|
|
1313
|
-
url: getLeadGenRegisterUrl(useDiscoEnv()),
|
|
1314
|
-
method: "POST",
|
|
1315
|
-
data: {
|
|
1316
|
-
email: payload.buyerEmail,
|
|
1317
|
-
first_name: payload.billingFirstName || "",
|
|
1318
|
-
last_name: payload.billingLastName || "",
|
|
1319
|
-
shop_gid: shopGid,
|
|
1320
|
-
offer_id: offerRemoteId,
|
|
1321
|
-
displayed_offer_ids: displayedOfferRemoteIds,
|
|
1322
|
-
session_id: sessionId,
|
|
1323
|
-
shopify_order_id: shopifyOrderIdFormatter(payload.orderId || null)
|
|
1324
|
-
}
|
|
1325
|
-
}, false);
|
|
1326
|
-
};
|
|
1327
|
-
//#endregion
|
|
1328
|
-
//#region src/components/RecommendationsWidget/LeadGen/LeadGenActionButton.tsx
|
|
1329
|
-
function LeadGenActionButton() {
|
|
1330
|
-
const { activeRecommendation, isOfferClaimed, handleOfferClaim, recommendations } = useHeroOffer();
|
|
1331
|
-
const { track } = useEventTracker();
|
|
1332
|
-
const buttonText = useGetButtonText();
|
|
1333
|
-
const data = useRecommendationsData();
|
|
1334
|
-
const payload = usePayload();
|
|
1335
|
-
const [, sendOfferEmail] = useSendOfferEmail({
|
|
1336
|
-
shopGid: getShopIdentifier(payload.shopGid),
|
|
1337
|
-
displayedOfferRemoteIds: recommendations.map((recommendation) => recommendation.offer.id),
|
|
1338
|
-
offerRemoteId: activeRecommendation.offer.id,
|
|
1339
|
-
sessionId: data.sessionId
|
|
1340
|
-
});
|
|
1341
|
-
const handleClick = () => {
|
|
1342
|
-
track({
|
|
1343
|
-
type: "BRAND_CLICK",
|
|
1344
|
-
target: "INLINE_ACTION_BUTTON",
|
|
1345
|
-
brand: {
|
|
1346
|
-
offerId: activeRecommendation.offer.id,
|
|
1347
|
-
advertiserId: activeRecommendation.advertiser.id,
|
|
1348
|
-
insertionId: activeRecommendation.insertionId
|
|
1349
|
-
}
|
|
1350
|
-
});
|
|
1351
|
-
if (isOfferClaimed) return;
|
|
1352
|
-
if (payload.buyerEmail) sendOfferEmail();
|
|
1353
|
-
handleOfferClaim();
|
|
1354
|
-
};
|
|
1355
|
-
return /* @__PURE__ */ jsx("s-button", {
|
|
1356
|
-
href: activeRecommendation.offer.targetUrl,
|
|
1357
|
-
target: "_blank",
|
|
1358
|
-
inlineSize: "fill",
|
|
1359
|
-
variant: isOfferClaimed ? "secondary" : "primary",
|
|
1360
|
-
onClick: handleClick,
|
|
1361
|
-
children: buttonText
|
|
1362
|
-
}, "lead-action-button");
|
|
1363
|
-
}
|
|
1364
|
-
function useGetButtonText() {
|
|
1365
|
-
const { activeRecommendation, isOfferClaimed } = useHeroOffer();
|
|
1366
|
-
const { applyCustomizationOrFallback } = useRecommendationsCustomization();
|
|
1367
|
-
if (activeRecommendation.offer.metadata.type === "NO_PROMO_CODE") {
|
|
1368
|
-
if (isOfferClaimed) return applyCustomizationOrFallback("widget_claimed_no_promo_cta_text", "Redeem onsite");
|
|
1369
|
-
return applyCustomizationOrFallback("widget_unclaimed_no_promo_cta_text", "Redeem onsite");
|
|
1370
|
-
}
|
|
1371
|
-
if (isOfferClaimed) return applyCustomizationOrFallback("widget_claimed_promo_cta_text", "Visit shop");
|
|
1372
|
-
return applyCustomizationOrFallback("widget_unclaimed_promo_cta_text", "Claim offer");
|
|
1373
|
-
}
|
|
1374
|
-
//#endregion
|
|
1375
|
-
//#region src/components/RecommendationsWidget/LeadGen/LeadGenOfferRow.tsx
|
|
1376
|
-
const LeadGenOfferRow = ({ recommendations }) => {
|
|
1377
|
-
const { applyCustomizationOrFallback } = useRecommendationsCustomization();
|
|
1378
|
-
return /* @__PURE__ */ jsxs("s-stack", {
|
|
1379
|
-
gap: "small-200",
|
|
1380
|
-
padding: "base none",
|
|
1381
|
-
children: [/* @__PURE__ */ jsx("s-box", {
|
|
1382
|
-
padding: "none large-200",
|
|
1383
|
-
children: /* @__PURE__ */ jsx("s-text", {
|
|
1384
|
-
type: "strong",
|
|
1385
|
-
children: applyCustomizationOrFallback("widget_bottom_slot_heading", "Trending brands we think you'll love")
|
|
1386
|
-
})
|
|
1387
|
-
}), /* @__PURE__ */ jsx(RecommendationsOfferRow, {
|
|
1388
|
-
recommendations,
|
|
1389
|
-
padding: "small-400 large-200"
|
|
1390
|
-
})]
|
|
1391
|
-
});
|
|
1392
|
-
};
|
|
1393
|
-
//#endregion
|
|
1394
|
-
//#region src/components/RecommendationsWidget/LeadGen/index.tsx
|
|
1395
|
-
const LeadGen = ({ heroRecommendationGroup, scrollableRecommendationGroup }) => {
|
|
1396
|
-
const { track } = useEventTracker();
|
|
1397
|
-
useEffect(() => {
|
|
1398
|
-
track({ type: "WIDGET_LOAD" });
|
|
1399
|
-
track({ type: "WIDGET_DISPLAY" });
|
|
1400
|
-
}, [track]);
|
|
1401
|
-
return /* @__PURE__ */ jsxs(CardContainer, {
|
|
1402
|
-
background: "base",
|
|
1403
|
-
padding: "none none large-200 none",
|
|
1404
|
-
children: [
|
|
1405
|
-
heroRecommendationGroup && /* @__PURE__ */ jsxs(HeroOfferProvider, {
|
|
1406
|
-
recommendationGroup: heroRecommendationGroup,
|
|
1407
|
-
children: [
|
|
1408
|
-
/* @__PURE__ */ jsx(LeadGenHeader, {}),
|
|
1409
|
-
/* @__PURE__ */ jsx("s-divider", {}),
|
|
1410
|
-
/* @__PURE__ */ jsx("s-box", {
|
|
1411
|
-
minBlockSize: "230px",
|
|
1412
|
-
children: /* @__PURE__ */ jsx(LeadGenBrand, {})
|
|
1413
|
-
}),
|
|
1414
|
-
/* @__PURE__ */ jsxs("s-stack", {
|
|
1415
|
-
padding: "none large-200 large-200 large-200",
|
|
1416
|
-
gap: "base",
|
|
1417
|
-
children: [/* @__PURE__ */ jsx(LeadGenActionOffer, {}), /* @__PURE__ */ jsx(LeadGenActionNav, {})]
|
|
1418
|
-
}),
|
|
1419
|
-
/* @__PURE__ */ jsx("s-divider", {})
|
|
1420
|
-
]
|
|
1421
|
-
}),
|
|
1422
|
-
scrollableRecommendationGroup && /* @__PURE__ */ jsx(LeadGenOfferRow, { recommendations: scrollableRecommendationGroup.recommendations }),
|
|
1423
|
-
/* @__PURE__ */ jsx(Footer, {})
|
|
1424
|
-
]
|
|
1425
|
-
});
|
|
1426
|
-
};
|
|
1427
|
-
function LeadGenActionOffer() {
|
|
1428
|
-
const { activeRecommendation, isOfferClaimed } = useHeroOffer();
|
|
1429
|
-
const { heading, subheading, metadata } = activeRecommendation.offer;
|
|
1430
|
-
const primaryHeading = isOfferClaimed ? `You've got ${heading}` : heading;
|
|
1431
|
-
const secondaryHeading = isOfferClaimed && metadata.type === "PROMO_CODE" ? /* @__PURE__ */ jsxs(Fragment, { children: ["Use code: ", /* @__PURE__ */ jsx("s-text", {
|
|
1432
|
-
type: "strong",
|
|
1433
|
-
children: metadata.code
|
|
1434
|
-
})] }) : subheading || "On your next purchase";
|
|
1435
|
-
return /* @__PURE__ */ jsxs("s-stack", {
|
|
1436
|
-
padding: "base",
|
|
1437
|
-
background: "subdued",
|
|
1438
|
-
border: "base base dashed",
|
|
1439
|
-
borderRadius: "base",
|
|
1440
|
-
gap: "base",
|
|
1441
|
-
children: [/* @__PURE__ */ jsxs("s-stack", {
|
|
1442
|
-
gap: "none",
|
|
1443
|
-
children: [/* @__PURE__ */ jsx("s-heading", { children: primaryHeading }), /* @__PURE__ */ jsx("s-text", { children: secondaryHeading })]
|
|
1444
|
-
}), /* @__PURE__ */ jsx(LeadGenActionButton, {})]
|
|
1445
|
-
});
|
|
1446
|
-
}
|
|
1447
|
-
function LeadGenActionNav() {
|
|
1448
|
-
const { activeRecommendation, nextOffer, prevOffer, isFirstOffer, isLastOffer, isOfferClaimed, TOTAL_NUM_OFFERS } = useHeroOffer();
|
|
1449
|
-
const { track } = useEventTracker();
|
|
1450
|
-
const { applyCustomizationOrFallback } = useRecommendationsCustomization();
|
|
1451
|
-
if (TOTAL_NUM_OFFERS <= 1) return null;
|
|
1452
|
-
const showPrevious = !isFirstOffer;
|
|
1453
|
-
const showNext = !isLastOffer;
|
|
1454
|
-
const hasSingleButton = !showNext || !showPrevious;
|
|
1455
|
-
const trackNavigation = () => ({
|
|
1456
|
-
offerId: activeRecommendation.offer.id,
|
|
1457
|
-
advertiserId: activeRecommendation.advertiser.id,
|
|
1458
|
-
insertionId: activeRecommendation.insertionId
|
|
1459
|
-
});
|
|
1460
|
-
const handleNext = () => {
|
|
1461
|
-
track({
|
|
1462
|
-
type: "ELEMENT_CLICK",
|
|
1463
|
-
target: "INLINE_NAV_FORWARD",
|
|
1464
|
-
brand: trackNavigation()
|
|
1465
|
-
});
|
|
1466
|
-
nextOffer();
|
|
1467
|
-
};
|
|
1468
|
-
const handlePrevious = () => {
|
|
1469
|
-
track({
|
|
1470
|
-
type: "ELEMENT_CLICK",
|
|
1471
|
-
target: "INLINE_NAV_BACKWARD",
|
|
1472
|
-
brand: trackNavigation()
|
|
1473
|
-
});
|
|
1474
|
-
prevOffer();
|
|
1475
|
-
};
|
|
1476
|
-
return /* @__PURE__ */ jsxs("s-grid", {
|
|
1477
|
-
gridTemplateColumns: hasSingleButton ? "1fr" : "1fr 11px 1fr",
|
|
1478
|
-
gap: "base",
|
|
1479
|
-
children: [
|
|
1480
|
-
showPrevious && /* @__PURE__ */ jsx("s-button", {
|
|
1481
|
-
variant: !isOfferClaimed || showNext ? "secondary" : "primary",
|
|
1482
|
-
onClick: handlePrevious,
|
|
1483
|
-
children: applyCustomizationOrFallback("widget_nav_backward_cta_text", "Previous offer")
|
|
1484
|
-
}),
|
|
1485
|
-
!hasSingleButton && /* @__PURE__ */ jsx("s-box", {}),
|
|
1486
|
-
showNext && /* @__PURE__ */ jsx("s-button", {
|
|
1487
|
-
variant: isOfferClaimed ? "primary" : "secondary",
|
|
1488
|
-
onClick: handleNext,
|
|
1489
|
-
children: applyCustomizationOrFallback("widget_nav_forward_cta_text", showPrevious ? "Next offer" : "No thanks")
|
|
1490
|
-
})
|
|
1491
|
-
]
|
|
1492
|
-
});
|
|
1493
|
-
}
|
|
1494
|
-
//#endregion
|
|
1495
|
-
//#region src/components/RecommendationsWidget/index.tsx
|
|
1496
|
-
const ESSENTIAL_LAYOUT_IDS = ["SHOPIFY_NATIVE_ESSENTIAL", "SHOPIFY_NATIVE_ESSENTIAL_0.22"];
|
|
1497
|
-
const Widget = () => {
|
|
1498
|
-
const recommendationsData = useRecommendationsData();
|
|
1499
|
-
const heroRecommendationGroup = recommendationsData.recommendationGroups.find((group) => group.slotContext === "HERO");
|
|
1500
|
-
const scrollableRecommendationGroup = recommendationsData.recommendationGroups.find((group) => group.slotContext === "SCROLLABLE");
|
|
1501
|
-
if (!heroRecommendationGroup && !scrollableRecommendationGroup) return null;
|
|
1502
|
-
const layoutId = recommendationsData.layoutId;
|
|
1503
|
-
if (ESSENTIAL_LAYOUT_IDS.includes(layoutId)) return /* @__PURE__ */ jsx(EssentialRecommendationsWidget, {
|
|
1504
|
-
heroRecommendationGroup,
|
|
1505
|
-
scrollableRecommendationGroup
|
|
1506
|
-
});
|
|
1507
|
-
if (layoutId === "SHOPIFY_NATIVE_COVER") {
|
|
1508
|
-
if (!heroRecommendationGroup) return null;
|
|
1509
|
-
return /* @__PURE__ */ jsx(CoverRecommendationsWidget, { heroRecommendationGroup });
|
|
1510
|
-
}
|
|
1511
|
-
return /* @__PURE__ */ jsx(LeadGen, {
|
|
1512
|
-
heroRecommendationGroup,
|
|
1513
|
-
scrollableRecommendationGroup
|
|
1514
|
-
});
|
|
1515
|
-
};
|
|
1516
|
-
//#endregion
|
|
1517
|
-
//#region src/DiscoRecommendations.tsx
|
|
1518
|
-
/**
|
|
1519
|
-
* Disco post-purchase recommendations for a Shopify UI extension.
|
|
1520
|
-
*
|
|
1521
|
-
* Render it from a `purchase.thank-you.block.render` or
|
|
1522
|
-
* `customer-account.order-status.block.render` target; the order and buyer
|
|
1523
|
-
* details are read from that target's API.
|
|
1524
|
-
*/
|
|
1525
|
-
function DiscoRecommendations({ apiKey, env = "production" }) {
|
|
1526
|
-
return /* @__PURE__ */ jsx(PayloadManager, { children: /* @__PURE__ */ jsx(DataManager, {
|
|
1527
|
-
apiKey,
|
|
1528
|
-
env,
|
|
1529
|
-
children: /* @__PURE__ */ jsx(UserManager, { children: /* @__PURE__ */ jsx(Widget, {}) })
|
|
1530
|
-
}) });
|
|
1531
|
-
}
|
|
1532
|
-
//#endregion
|
|
1
|
+
import { t as DiscoRecommendations } from "./DiscoRecommendations-i3RGOqOq.js";
|
|
1533
2
|
export { DiscoRecommendations };
|
|
1534
|
-
|
|
1535
|
-
//# sourceMappingURL=index.js.map
|