@rebuy/rebuy-hydrogen 3.0.0-beta.15 → 3.0.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +157 -0
- package/dist/constants/debug.d.ts +2 -1
- package/dist/constants/debug.d.ts.map +1 -1
- package/dist/index.css +42 -27
- package/dist/index.css.map +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +215 -25
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +228 -38
- package/dist/index.mjs.map +4 -4
- package/dist/smart-cart/components/SmartCartContainer/SmartCartContainer.d.ts.map +1 -1
- package/dist/types/common.d.ts +7 -0
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/rebuyCustom.d.ts +0 -1
- package/dist/types/rebuyCustom.d.ts.map +1 -1
- package/dist/widgetContainer/RebuyWidgetContainer.d.ts.map +1 -1
- package/dist/widgets/RebuyProductViewed/RebuyProductViewed.d.ts +3 -0
- package/dist/widgets/RebuyProductViewed/RebuyProductViewed.d.ts.map +1 -0
- package/dist/widgets/RebuyProductViewed/index.d.ts +2 -0
- package/dist/widgets/RebuyProductViewed/index.d.ts.map +1 -0
- package/dist/widgets/RebuyProductViewed/types.d.ts +8 -0
- package/dist/widgets/RebuyProductViewed/types.d.ts.map +1 -0
- package/dist/widgets/RebuyRecentlyViewedProducts/RebuyRecentlyViewedProducts.d.ts +3 -0
- package/dist/widgets/RebuyRecentlyViewedProducts/RebuyRecentlyViewedProducts.d.ts.map +1 -0
- package/dist/widgets/RebuyRecentlyViewedProducts/index.d.ts +2 -0
- package/dist/widgets/RebuyRecentlyViewedProducts/index.d.ts.map +1 -0
- package/dist/widgets/RebuyRecentlyViewedProducts/types.d.ts +11 -0
- package/dist/widgets/RebuyRecentlyViewedProducts/types.d.ts.map +1 -0
- package/dist/zustandStores/productViewed.d.ts +9 -0
- package/dist/zustandStores/productViewed.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -6,6 +6,8 @@ export * from './widgets/RebuyCompleteTheLook';
|
|
6
6
|
export * from './widgets/RebuyDynamicBundleProducts';
|
7
7
|
export * from './widgets/RebuyProductAddOns';
|
8
8
|
export * from './widgets/RebuyProductRecommendations';
|
9
|
+
export * from './widgets/RebuyProductViewed';
|
10
|
+
export * from './widgets/RebuyRecentlyViewedProducts';
|
9
11
|
export * from './widgets/RebuyWidget';
|
10
12
|
export { RebuyConfigProvider, useRebuyConfig } from './context/RebuyConfigContext';
|
11
13
|
export type { RebuyConfigContextType, RebuyConfigLoadingStatus, RebuyConfigProviderProps, } from './context/RebuyConfigContext';
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,0CAA0C,CAAC;AACzD,cAAc,+CAA+C,CAAC;AAG9D,cAAc,6BAA6B,CAAC;AAG5C,cAAc,wCAAwC,CAAC;AACvD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sCAAsC,CAAC;AACrD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uCAAuC,CAAC;AACtD,cAAc,uBAAuB,CAAC;AAGtC,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnF,YAAY,EACR,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,GAC3B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAGrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,0CAA0C,CAAC;AACzD,cAAc,+CAA+C,CAAC;AAG9D,cAAc,6BAA6B,CAAC;AAG5C,cAAc,wCAAwC,CAAC;AACvD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sCAAsC,CAAC;AACrD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uCAAuC,CAAC;AACtD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uCAAuC,CAAC;AACtD,cAAc,uBAAuB,CAAC;AAGtC,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnF,YAAY,EACR,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,GAC3B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAGrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
@@ -37,6 +37,8 @@ __export(index_exports, {
|
|
37
37
|
RebuyHydrogenReactContextProvider: () => RebuyHydrogenReactContextProvider,
|
38
38
|
RebuyProductAddOns: () => RebuyProductAddOns,
|
39
39
|
RebuyProductRecommendations: () => RebuyProductRecommendations,
|
40
|
+
RebuyProductViewed: () => RebuyProductViewed,
|
41
|
+
RebuyRecentlyViewedProducts: () => RebuyRecentlyViewedProducts,
|
40
42
|
RebuySmartCart: () => RebuySmartCart,
|
41
43
|
RebuyWidget: () => RebuyWidget,
|
42
44
|
RebuyWidgetContainer: () => RebuyWidgetContainer,
|
@@ -8707,10 +8709,25 @@ var SmartCartContainer_default = result22;
|
|
8707
8709
|
// src/smart-cart/components/SmartCartContainer/SmartCartContainer.tsx
|
8708
8710
|
var import_jsx_runtime40 = require("react/jsx-runtime");
|
8709
8711
|
var SmartCartContainer = ({ containerId }) => {
|
8710
|
-
const {
|
8712
|
+
const { config, getItemCount, hideCart, isVisible } = useSmartCart();
|
8713
|
+
const containerRef = (0, import_react32.useRef)(null);
|
8714
|
+
const previousFocusRef = (0, import_react32.useRef)(null);
|
8711
8715
|
const components = (0, import_react32.useMemo)(() => config && Array.isArray(config.components) ? config.components : [], [config]);
|
8712
|
-
const
|
8713
|
-
|
8716
|
+
const handleClose = (0, import_react32.useCallback)(() => {
|
8717
|
+
hideCart();
|
8718
|
+
if (previousFocusRef.current) {
|
8719
|
+
previousFocusRef.current.focus();
|
8720
|
+
}
|
8721
|
+
}, [hideCart]);
|
8722
|
+
(0, import_react32.useEffect)(() => {
|
8723
|
+
if (isVisible) {
|
8724
|
+
previousFocusRef.current = document.activeElement;
|
8725
|
+
const closeButton = containerRef.current?.querySelector("#rebuy-cart-close");
|
8726
|
+
if (closeButton instanceof HTMLElement) {
|
8727
|
+
closeButton.focus();
|
8728
|
+
}
|
8729
|
+
}
|
8730
|
+
}, [isVisible]);
|
8714
8731
|
const backgroundClassName = (0, import_clsx13.default)(SmartCartContainer_default["rebuy-smart-cart__overlay-background"], {
|
8715
8732
|
[SmartCartContainer_default["rebuy-smart-cart__overlay-background--visible"]]: isVisible
|
8716
8733
|
});
|
@@ -8736,17 +8753,18 @@ var SmartCartContainer = ({ containerId }) => {
|
|
8736
8753
|
const titleBarComponent = components.find((c) => c.type === "title_bar");
|
8737
8754
|
const ariaLabelledBy = titleBarComponent ? `rebuy-title-${titleBarComponent.component_id}` : defaultTitleId;
|
8738
8755
|
return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_react32.default.Fragment, { children: [
|
8739
|
-
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", {
|
8756
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: backgroundClassName, onClick: handleClose }),
|
8740
8757
|
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(
|
8741
8758
|
"div",
|
8742
8759
|
{
|
8743
|
-
"aria-hidden": !isVisible,
|
8744
8760
|
"aria-labelledby": ariaLabelledBy,
|
8745
8761
|
"aria-modal": "true",
|
8746
8762
|
className: flyoutContainerClasses,
|
8747
8763
|
"data-rebuy-cart-layout": config?.layout || "single",
|
8748
8764
|
id: containerId || "rebuy-cart-react",
|
8765
|
+
ref: containerRef,
|
8749
8766
|
role: "dialog",
|
8767
|
+
tabIndex: -1,
|
8750
8768
|
children: [
|
8751
8769
|
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("header", { className: SmartCartContainer_default["rebuy-smart-cart__header"], "data-rebuy-cart-anchor": "header", children: [
|
8752
8770
|
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: SmartCartContainer_default["rebuy-smart-cart__header-top-bar"], "data-rebuy-cart-header-top-bar": "", children: [
|
@@ -8793,19 +8811,8 @@ var Utilities5 = __toESM(require("@rebuy/rebuy/utilities"), 1);
|
|
8793
8811
|
var import_hydrogen7 = require("@shopify/hydrogen");
|
8794
8812
|
var import_react33 = __toESM(require("react"), 1);
|
8795
8813
|
var RebuyWidgetContainerBase = ({ children, ...props }) => {
|
8796
|
-
const {
|
8797
|
-
|
8798
|
-
collection,
|
8799
|
-
collectionId,
|
8800
|
-
dataSource,
|
8801
|
-
limit,
|
8802
|
-
options,
|
8803
|
-
product,
|
8804
|
-
productId,
|
8805
|
-
variant,
|
8806
|
-
variantId
|
8807
|
-
} = props;
|
8808
|
-
const { apiKey: apiKeyFromContext, loadingStatus: configLoadingStatus, rebuyConfig } = useRebuyConfig();
|
8814
|
+
const { collection, collectionId, dataSource, limit, options, product, productId, variant, variantId } = props;
|
8815
|
+
const { apiKey, loadingStatus: configLoadingStatus, rebuyConfig } = useRebuyConfig();
|
8809
8816
|
const rebuyContext = (0, import_react33.useContext)(RebuyContext);
|
8810
8817
|
const [rebuyApiClient, setRebuyApiClient] = (0, import_react33.useState)(null);
|
8811
8818
|
const [initialized, setInitialized] = (0, import_react33.useState)(false);
|
@@ -8814,10 +8821,9 @@ var RebuyWidgetContainerBase = ({ children, ...props }) => {
|
|
8814
8821
|
const shopifyCollectionId = collection?.id ?? collectionId ?? null;
|
8815
8822
|
const [products, setProducts] = (0, import_react33.useState)([]);
|
8816
8823
|
const [metadata, setMetadata] = (0, import_react33.useState)();
|
8817
|
-
const finalApiKey = apiKeyFromProps || apiKeyFromContext;
|
8818
8824
|
(0, import_react33.useEffect)(() => {
|
8819
|
-
if (!rebuyApiClient &&
|
8820
|
-
const client = new import_rebuy3.RebuyClient(
|
8825
|
+
if (!rebuyApiClient && apiKey && configLoadingStatus === "success") {
|
8826
|
+
const client = new import_rebuy3.RebuyClient(apiKey);
|
8821
8827
|
const currentEndpoint = dataSource || "/api/v1/products/recommended";
|
8822
8828
|
if (rebuyContext?.contextParameters) {
|
8823
8829
|
const filteredParams = filterContextForWidgetEndpoints(rebuyContext.contextParameters, currentEndpoint);
|
@@ -8829,7 +8835,7 @@ var RebuyWidgetContainerBase = ({ children, ...props }) => {
|
|
8829
8835
|
setRebuyApiClient(client);
|
8830
8836
|
setInitialized(true);
|
8831
8837
|
}
|
8832
|
-
}, [
|
8838
|
+
}, [apiKey, rebuyApiClient, configLoadingStatus, options, rebuyContext, dataSource]);
|
8833
8839
|
(0, import_react33.useEffect)(() => {
|
8834
8840
|
if (rebuyApiClient && rebuyContext?.contextParameters) {
|
8835
8841
|
const currentEndpoint = dataSource || "/api/v1/products/recommended";
|
@@ -8896,7 +8902,7 @@ var RebuyWidgetContainerBase = ({ children, ...props }) => {
|
|
8896
8902
|
);
|
8897
8903
|
const childProps = {
|
8898
8904
|
...props,
|
8899
|
-
apiKey
|
8905
|
+
apiKey,
|
8900
8906
|
cacheKey: rebuyConfig?.shop?.cache_key,
|
8901
8907
|
key: product?.id,
|
8902
8908
|
metadata,
|
@@ -9597,7 +9603,7 @@ var RebuyProductAddOns = (props) => {
|
|
9597
9603
|
};
|
9598
9604
|
|
9599
9605
|
// src/widgets/RebuyProductRecommendations/RebuyProductRecommendations.module.css
|
9600
|
-
var result26 = { "container": "RebuyProductRecommendations_container", "productGrid": "RebuyProductRecommendations_productGrid"
|
9606
|
+
var result26 = { "container": "RebuyProductRecommendations_container", "productGrid": "RebuyProductRecommendations_productGrid" };
|
9601
9607
|
var RebuyProductRecommendations_default = result26;
|
9602
9608
|
|
9603
9609
|
// src/widgets/RebuyProductRecommendations/RebuyProductRecommendations.tsx
|
@@ -9617,7 +9623,7 @@ var RebuyProductRecommendations = (props) => {
|
|
9617
9623
|
}
|
9618
9624
|
return /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)("section", { className: RebuyProductRecommendations_default.container, children: [
|
9619
9625
|
/* @__PURE__ */ (0, import_jsx_runtime50.jsx)(Title, { level: getTitleLevel(customTitleLevel), style: customTitleStyle, text: customTitle }),
|
9620
|
-
/* @__PURE__ */ (0, import_jsx_runtime50.jsx)("ul", { className: RebuyProductRecommendations_default.productGrid, children: products.map((product) => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("li", {
|
9626
|
+
/* @__PURE__ */ (0, import_jsx_runtime50.jsx)("ul", { className: RebuyProductRecommendations_default.productGrid, children: products.map((product) => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
|
9621
9627
|
ProductCard,
|
9622
9628
|
{
|
9623
9629
|
addToCartBtnText,
|
@@ -9630,6 +9636,190 @@ var RebuyProductRecommendations = (props) => {
|
|
9630
9636
|
] });
|
9631
9637
|
};
|
9632
9638
|
|
9639
|
+
// src/widgets/RebuyProductViewed/RebuyProductViewed.tsx
|
9640
|
+
var import_rebuy4 = require("@rebuy/rebuy");
|
9641
|
+
var Utilities6 = __toESM(require("@rebuy/rebuy/utilities"), 1);
|
9642
|
+
var import_react37 = require("react");
|
9643
|
+
|
9644
|
+
// src/zustandStores/productViewed.ts
|
9645
|
+
var import_zustand2 = require("zustand");
|
9646
|
+
var useProductViewedStore = (0, import_zustand2.create)((set) => ({
|
9647
|
+
customerId: null,
|
9648
|
+
setCustomerId: (customerId) => set({ customerId }),
|
9649
|
+
setUuid: (uuid) => set({ uuid }),
|
9650
|
+
uuid: null
|
9651
|
+
}));
|
9652
|
+
|
9653
|
+
// src/widgets/RebuyProductViewed/RebuyProductViewed.tsx
|
9654
|
+
var RebuyProductViewed = ({ ...props }) => {
|
9655
|
+
const { apiKey: apiKeyFromContext } = useRebuyConfig();
|
9656
|
+
const { customerId, product, productHandle, productId } = props;
|
9657
|
+
const [event, setEvent] = (0, import_react37.useState)(null);
|
9658
|
+
const [Rebuy, setRebuy] = (0, import_react37.useState)(null);
|
9659
|
+
const shopifyProductId = product?.id ?? productId ?? null;
|
9660
|
+
const [initialized, setInitialized] = (0, import_react37.useState)(false);
|
9661
|
+
const { setCustomerId, setUuid } = useProductViewedStore();
|
9662
|
+
const request = (0, import_react37.useMemo)(() => {
|
9663
|
+
const request2 = {
|
9664
|
+
parameters: {}
|
9665
|
+
};
|
9666
|
+
if (shopifyProductId) {
|
9667
|
+
const productNumericId = Utilities6.getIdFromGraphUrl(shopifyProductId, "Product");
|
9668
|
+
if (productNumericId !== null) {
|
9669
|
+
request2.parameters.shopify_product_id = productNumericId.toString();
|
9670
|
+
}
|
9671
|
+
} else if (productHandle) {
|
9672
|
+
request2.parameters.shopify_product_handle = productHandle;
|
9673
|
+
}
|
9674
|
+
return request2;
|
9675
|
+
}, [productHandle, shopifyProductId]);
|
9676
|
+
(0, import_react37.useEffect)(() => {
|
9677
|
+
const recordView = async () => {
|
9678
|
+
if (!Rebuy) {
|
9679
|
+
return;
|
9680
|
+
}
|
9681
|
+
try {
|
9682
|
+
const response = await Rebuy.trackProductViewed(request.parameters);
|
9683
|
+
setEvent(response.data);
|
9684
|
+
if (response.data === "Received" && request.parameters.uuid) {
|
9685
|
+
setUuid(request.parameters.uuid);
|
9686
|
+
if (customerId && customerId !== "") {
|
9687
|
+
setCustomerId(customerId);
|
9688
|
+
}
|
9689
|
+
}
|
9690
|
+
} catch (error) {
|
9691
|
+
console.error("Error tracking product view:", error);
|
9692
|
+
}
|
9693
|
+
};
|
9694
|
+
if (!initialized && apiKeyFromContext) {
|
9695
|
+
const client = new import_rebuy4.RebuyClient(apiKeyFromContext);
|
9696
|
+
setRebuy(client);
|
9697
|
+
setInitialized(true);
|
9698
|
+
return;
|
9699
|
+
}
|
9700
|
+
recordView();
|
9701
|
+
}, [request.parameters, initialized, apiKeyFromContext, Rebuy]);
|
9702
|
+
if (Object.keys(request.parameters).length === 0) {
|
9703
|
+
console.warn("No parameters!");
|
9704
|
+
return;
|
9705
|
+
}
|
9706
|
+
return null;
|
9707
|
+
};
|
9708
|
+
|
9709
|
+
// src/widgets/RebuyRecentlyViewedProducts/RebuyRecentlyViewedProducts.tsx
|
9710
|
+
var import_rebuy5 = require("@rebuy/rebuy");
|
9711
|
+
var import_hydrogen11 = require("@shopify/hydrogen");
|
9712
|
+
var import_react38 = require("react");
|
9713
|
+
|
9714
|
+
// src/widgets/RebuyRecentlyViewedProducts/RebuyRecentlyViewedProducts.module.css
|
9715
|
+
var result27 = { "rebuy-recently-viewed-products-container": "RebuyRecentlyViewedProducts_rebuy-recently-viewed-products-container", "product-grid": "RebuyRecentlyViewedProducts_product-grid" };
|
9716
|
+
var RebuyRecentlyViewedProducts_default = result27;
|
9717
|
+
|
9718
|
+
// src/widgets/RebuyRecentlyViewedProducts/RebuyRecentlyViewedProducts.tsx
|
9719
|
+
var import_jsx_runtime51 = require("react/jsx-runtime");
|
9720
|
+
var RebuyRecentlyViewedProducts = (props) => {
|
9721
|
+
const {
|
9722
|
+
addToCartBtnText = "Add to cart",
|
9723
|
+
addToCartCallback,
|
9724
|
+
customTitle = `Your recently viewed products`,
|
9725
|
+
customTitleLevel = "h2",
|
9726
|
+
customTitleStyle,
|
9727
|
+
limit,
|
9728
|
+
options,
|
9729
|
+
productId
|
9730
|
+
} = props;
|
9731
|
+
const { customerId, uuid } = useProductViewedStore();
|
9732
|
+
const { apiKey, loadingStatus: configLoadingStatus, rebuyConfig } = useRebuyConfig();
|
9733
|
+
const rebuyContext = (0, import_react38.useContext)(RebuyContext);
|
9734
|
+
const [rebuyApiClient, setRebuyApiClient] = (0, import_react38.useState)(null);
|
9735
|
+
const [initialized, setInitialized] = (0, import_react38.useState)(false);
|
9736
|
+
const [products, setProducts] = (0, import_react38.useState)([]);
|
9737
|
+
const [metadata, setMetadata] = (0, import_react38.useState)();
|
9738
|
+
const rebuyConfigKey = rebuyConfig?.shop?.cache_key;
|
9739
|
+
const endpoint = customerId && customerId !== "" ? `/api/v1/products/viewed?key=${rebuyConfigKey}&customer_id=${customerId}` : `/api/v1/products/viewed?key=${rebuyConfigKey}&uuid=${uuid}`;
|
9740
|
+
(0, import_react38.useEffect)(() => {
|
9741
|
+
if (!rebuyApiClient && apiKey && configLoadingStatus === "success") {
|
9742
|
+
const client = new import_rebuy5.RebuyClient(apiKey);
|
9743
|
+
if (rebuyContext?.contextParameters) {
|
9744
|
+
const filteredParams = filterContextForWidgetEndpoints(rebuyContext.contextParameters, endpoint);
|
9745
|
+
client.setContextParameters(filteredParams);
|
9746
|
+
}
|
9747
|
+
if (options) {
|
9748
|
+
client.setDefaultParameters(options);
|
9749
|
+
}
|
9750
|
+
setRebuyApiClient(client);
|
9751
|
+
setInitialized(true);
|
9752
|
+
}
|
9753
|
+
}, [apiKey, rebuyApiClient, configLoadingStatus, options, rebuyContext, uuid, endpoint]);
|
9754
|
+
(0, import_react38.useEffect)(() => {
|
9755
|
+
if (rebuyApiClient && rebuyContext?.contextParameters) {
|
9756
|
+
const filteredParams = filterContextForWidgetEndpoints(rebuyContext.contextParameters, endpoint);
|
9757
|
+
rebuyApiClient.setContextParameters(filteredParams);
|
9758
|
+
}
|
9759
|
+
}, [rebuyApiClient, rebuyContext, uuid, endpoint]);
|
9760
|
+
const request = (0, import_react38.useMemo)(() => {
|
9761
|
+
const req = {
|
9762
|
+
endpoint,
|
9763
|
+
params: {}
|
9764
|
+
// Keeping this object generic to allow for custom endpoints
|
9765
|
+
};
|
9766
|
+
if (limit) {
|
9767
|
+
req.params.limit = limit;
|
9768
|
+
}
|
9769
|
+
return req;
|
9770
|
+
}, [limit, uuid, endpoint]);
|
9771
|
+
(0, import_react38.useEffect)(() => {
|
9772
|
+
let isMounted = true;
|
9773
|
+
if (!rebuyApiClient || !initialized || configLoadingStatus !== "success") return;
|
9774
|
+
const fetchData = async () => {
|
9775
|
+
try {
|
9776
|
+
const { data, metadata: metadata2 } = await rebuyApiClient.getStorefrontData(
|
9777
|
+
request.endpoint,
|
9778
|
+
request.params
|
9779
|
+
);
|
9780
|
+
if (isMounted) {
|
9781
|
+
setProducts(
|
9782
|
+
Array.isArray(data) ? data.filter((p) => p.id !== productId).map((p) => ({
|
9783
|
+
...p,
|
9784
|
+
variants: {
|
9785
|
+
nodes: p.variants ? (0, import_hydrogen11.flattenConnection)(p.variants) : []
|
9786
|
+
}
|
9787
|
+
})) : []
|
9788
|
+
);
|
9789
|
+
setMetadata(metadata2);
|
9790
|
+
}
|
9791
|
+
} catch (error) {
|
9792
|
+
console.error("[RebuyWidgetContainer] Error fetching widget data:", error);
|
9793
|
+
if (isMounted) {
|
9794
|
+
setProducts([]);
|
9795
|
+
setMetadata(void 0);
|
9796
|
+
}
|
9797
|
+
}
|
9798
|
+
};
|
9799
|
+
fetchData();
|
9800
|
+
return () => {
|
9801
|
+
isMounted = false;
|
9802
|
+
};
|
9803
|
+
}, [rebuyApiClient, initialized, request, configLoadingStatus, productId]);
|
9804
|
+
if (products.length === 0) {
|
9805
|
+
rebuyDebugLog.log("widget-recently-viewed-products" /* WIDGET_RECENTLY_VIEWED_PRODUCTS */, "RebuyRecentlyViewedProducts: No products found");
|
9806
|
+
return null;
|
9807
|
+
}
|
9808
|
+
return /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: RebuyRecentlyViewedProducts_default["rebuy-recently-viewed-products-container"], children: [
|
9809
|
+
/* @__PURE__ */ (0, import_jsx_runtime51.jsx)(Title, { level: getTitleLevel(customTitleLevel), style: customTitleStyle, text: customTitle }),
|
9810
|
+
/* @__PURE__ */ (0, import_jsx_runtime51.jsx)("ul", { className: RebuyRecentlyViewedProducts_default["product-grid"], children: products?.map((product) => /* @__PURE__ */ (0, import_jsx_runtime51.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
|
9811
|
+
ProductCard,
|
9812
|
+
{
|
9813
|
+
addToCartBtnText,
|
9814
|
+
addToCartCallback,
|
9815
|
+
product,
|
9816
|
+
productCardTitleLevel: getTitleLevel("h2")
|
9817
|
+
},
|
9818
|
+
product.id
|
9819
|
+
) }, product.id)) })
|
9820
|
+
] });
|
9821
|
+
};
|
9822
|
+
|
9633
9823
|
// src/constants/api.ts
|
9634
9824
|
var REBUY_THEME_STYLES_BASE_URL = "https://rebuyengine.com/api/v1/theme-styles";
|
9635
9825
|
|