@sentecacommerce-theme/lib 0.11.68 → 0.11.72
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/cjs/analytics/Pixel/hooks/usePixelProductDetails.js +20 -9
- package/dist/cjs/analytics/Pixel/hooks/usePixelProductDetails.js.map +1 -1
- package/dist/cjs/analytics/Pixel/hooks/usePixelProductsImpression.js +18 -6
- package/dist/cjs/analytics/Pixel/hooks/usePixelProductsImpression.js.map +1 -1
- package/dist/cjs/analytics/Pixel/usePixel.js +11 -4
- package/dist/cjs/analytics/Pixel/usePixel.js.map +1 -1
- package/dist/cjs/hooks/useProduct/index.js.map +1 -1
- package/dist/cjs/hooks/useProduct/utils/index.js +24 -7
- package/dist/cjs/hooks/useProduct/utils/index.js.map +1 -1
- package/dist/esm/analytics/Pixel/hooks/usePixelProductDetails.js +18 -9
- package/dist/esm/analytics/Pixel/hooks/usePixelProductDetails.js.map +1 -1
- package/dist/esm/analytics/Pixel/hooks/usePixelProductsImpression.js +16 -6
- package/dist/esm/analytics/Pixel/hooks/usePixelProductsImpression.js.map +1 -1
- package/dist/esm/analytics/Pixel/usePixel.js +9 -3
- package/dist/esm/analytics/Pixel/usePixel.js.map +1 -1
- package/dist/esm/hooks/useProduct/index.js.map +1 -1
- package/dist/esm/hooks/useProduct/utils/index.js +14 -5
- package/dist/esm/hooks/useProduct/utils/index.js.map +1 -1
- package/dist/types/hooks/useProduct/index.d.ts +6 -5
- package/package.json +3 -3
@@ -26,15 +26,26 @@ var usePixelProductDetails = function usePixelProductDetails() {
|
|
26
26
|
|
27
27
|
var pixel = (_window = window) == null ? void 0 : _window.pixel;
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
}
|
36
|
-
|
37
|
-
|
29
|
+
var sendProductDetails = function sendProductDetails() {
|
30
|
+
if (!window.document.title || window.document.title === 'за') {
|
31
|
+
setTimeout(function () {
|
32
|
+
return sendProductDetails();
|
33
|
+
}, 20);
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
|
37
|
+
if (metaData._id && selectedVariant != null && selectedVariant.sku && !sentData) {
|
38
|
+
pixel == null ? void 0 : pixel.productDetails({
|
39
|
+
id: metaData._id,
|
40
|
+
sku: selectedVariant == null ? void 0 : selectedVariant.sku
|
41
|
+
}, {
|
42
|
+
merchantKey: defaultMerchant
|
43
|
+
});
|
44
|
+
setSentData.on();
|
45
|
+
}
|
46
|
+
};
|
47
|
+
|
48
|
+
sendProductDetails();
|
38
49
|
}, [metaData._id, selectedVariant == null ? void 0 : selectedVariant.sku]);
|
39
50
|
};
|
40
51
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../src/analytics/Pixel/hooks/usePixelProductDetails.tsx"],"names":["usePixelProductDetails","sentData","setSentData","defaultMerchant","metaData","selectedVariant","React","useEffect","pixel","window","_id","sku","productDetails","id","merchantKey","on"],"mappings":";;;;;;;AAAA;;AACA;;AAEO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAyB,GAAM;AAAA,oBACV,wBADU;AAAA,MACnCC,QADmC;AAAA,MACzBC,WADyB;;AAAA,wBAEd,4BAFc;AAAA,MAElCC,eAFkC,mBAElCA,eAFkC;;AAAA,yBAGJ,6BAHI;AAAA,MAGlCC,QAHkC,oBAGlCA,QAHkC;AAAA,MAGxBC,eAHwB,oBAGxBA,eAHwB;;AAK1CC,oBAAMC,SAAN,CAAgB,YAAM;AAAA;;AACpB,QAAMC,KAAK,cAAIC,MAAJ,qBAAG,QAAiBD,KAA/B;;AACA,
|
1
|
+
{"version":3,"sources":["../../../../../src/analytics/Pixel/hooks/usePixelProductDetails.tsx"],"names":["usePixelProductDetails","sentData","setSentData","defaultMerchant","metaData","selectedVariant","React","useEffect","pixel","window","sendProductDetails","document","title","setTimeout","_id","sku","productDetails","id","merchantKey","on"],"mappings":";;;;;;;AAAA;;AACA;;AAEO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAyB,GAAM;AAAA,oBACV,wBADU;AAAA,MACnCC,QADmC;AAAA,MACzBC,WADyB;;AAAA,wBAEd,4BAFc;AAAA,MAElCC,eAFkC,mBAElCA,eAFkC;;AAAA,yBAGJ,6BAHI;AAAA,MAGlCC,QAHkC,oBAGlCA,QAHkC;AAAA,MAGxBC,eAHwB,oBAGxBA,eAHwB;;AAK1CC,oBAAMC,SAAN,CAAgB,YAAM;AAAA;;AACpB,QAAMC,KAAK,cAAIC,MAAJ,qBAAG,QAAiBD,KAA/B;;AAEA,QAAME,kBAAkB,GAAG,SAArBA,kBAAqB,GAAM;AAC/B,UAAI,CAACD,MAAM,CAACE,QAAP,CAAgBC,KAAjB,IAA0BH,MAAM,CAACE,QAAP,CAAgBC,KAAhB,KAA0B,IAAxD,EAA8D;AAC5DC,QAAAA,UAAU,CAAC;AAAA,iBAAMH,kBAAkB,EAAxB;AAAA,SAAD,EAA6B,EAA7B,CAAV;AACA;AACD;;AACD,UAAIN,QAAQ,CAACU,GAAT,IAAgBT,eAAhB,YAAgBA,eAAe,CAAEU,GAAjC,IAAwC,CAACd,QAA7C,EAAuD;AACnDO,QAAAA,KAAK,QAAL,YAAAA,KAAK,CAAEQ,cAAP,CACE;AACEC,UAAAA,EAAE,EAAEb,QAAQ,CAACU,GADf;AAEEC,UAAAA,GAAG,EAAEV,eAAF,oBAAEA,eAAe,CAAEU;AAFxB,SADF,EAKE;AACEG,UAAAA,WAAW,EAAEf;AADf,SALF;AASFD,QAAAA,WAAW,CAACiB,EAAZ;AACD;AACF,KAjBD;;AAmBAT,IAAAA,kBAAkB;AACnB,GAvBD,EAuBG,CAACN,QAAQ,CAACU,GAAV,EAAeT,eAAf,oBAAeA,eAAe,CAAEU,GAAhC,CAvBH;AAwBD,CA7BM","sourcesContent":["import React from 'react'\nimport { useConfigState, useProductState, useBoolean } from '../../../index'\n\nexport const usePixelProductDetails = () => {\n const [sentData, setSentData] = useBoolean()\n const { defaultMerchant } = useConfigState()\n const { metaData, selectedVariant } = useProductState()\n\n React.useEffect(() => {\n const pixel = (window as any)?.pixel\n\n const sendProductDetails = () => {\n if (!window.document.title || window.document.title === 'за') {\n setTimeout(() => sendProductDetails(), 20)\n return\n }\n if (metaData._id && selectedVariant?.sku && !sentData) {\n pixel?.productDetails(\n {\n id: metaData._id as string,\n sku: selectedVariant?.sku as string,\n },\n {\n merchantKey: defaultMerchant,\n }\n )\n setSentData.on()\n }\n }\n\n sendProductDetails()\n }, [metaData._id, selectedVariant?.sku])\n}\n"],"file":"usePixelProductDetails.js"}
|
@@ -38,12 +38,24 @@ var usePixelProductsImpression = function usePixelProductsImpression(_ref) {
|
|
38
38
|
|
39
39
|
if (typeof window !== undefined && !((_productsData$product = productsData.products) != null && (_productsData$product2 = _productsData$product[0]) != null && _productsData$product2.isPlaceholder) && (productsData == null ? void 0 : productsData.length) > 0) {
|
40
40
|
var pixel = window.pixel;
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
|
42
|
+
var sendImpressions = function sendImpressions() {
|
43
|
+
if (!window.document.title || window.document.title === 'за') {
|
44
|
+
setTimeout(function () {
|
45
|
+
return sendImpressions();
|
46
|
+
}, 20);
|
47
|
+
return;
|
48
|
+
}
|
49
|
+
|
50
|
+
pixel == null ? void 0 : pixel.productsImpression(!isCarousel ? [{
|
51
|
+
listName: _Releva.PageTypeMap[router.route],
|
52
|
+
products: products
|
53
|
+
}] : productsData, {
|
54
|
+
merchantKey: defaultMerchant
|
55
|
+
});
|
56
|
+
};
|
57
|
+
|
58
|
+
sendImpressions();
|
47
59
|
setSentAlready.on();
|
48
60
|
}
|
49
61
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../src/analytics/Pixel/hooks/usePixelProductsImpression.tsx"],"names":["usePixelProductsImpression","productsData","isCarousel","sentAlready","setSentAlready","defaultMerchant","router","products","React","useEffect","events","on","window","undefined","isPlaceholder","length","pixel","productsImpression","listName","PageTypeMap","route","merchantKey"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AAEO,IAAMA,0BAA0B,GAAG,SAA7BA,0BAA6B,OAMpC;AAAA,MALJC,YAKI,QALJA,YAKI;AAAA,MAJJC,UAII,QAJJA,UAII;;AAAA,oBACkC,uBAAW,KAAX,CADlC;AAAA,MACGC,WADH;AAAA,MACgBC,cADhB;;AAAA,wBAEwB,4BAFxB;AAAA,MAEIC,eAFJ,mBAEIA,eAFJ;;AAGJ,MAAMC,MAAM,GAAG,wBAAf;AAEA,MAAIC,QAAuB,GAAG,EAA9B;;AAEA,MAAI,CAACL,UAAL,EAAiB;AACfK,IAAAA,QAAQ,GAAG,kCAAqBN,YAAY,CAACM,QAAlC,CAAX;AACD;;AAEDC,oBAAMC,SAAN,CAAgB,YAAM;AACpB,QAAIN,WAAJ,EAAiB;
|
1
|
+
{"version":3,"sources":["../../../../../src/analytics/Pixel/hooks/usePixelProductsImpression.tsx"],"names":["usePixelProductsImpression","productsData","isCarousel","sentAlready","setSentAlready","defaultMerchant","router","products","React","useEffect","events","on","window","undefined","isPlaceholder","length","pixel","sendImpressions","document","title","setTimeout","productsImpression","listName","PageTypeMap","route","merchantKey"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AAEO,IAAMA,0BAA0B,GAAG,SAA7BA,0BAA6B,OAMpC;AAAA,MALJC,YAKI,QALJA,YAKI;AAAA,MAJJC,UAII,QAJJA,UAII;;AAAA,oBACkC,uBAAW,KAAX,CADlC;AAAA,MACGC,WADH;AAAA,MACgBC,cADhB;;AAAA,wBAEwB,4BAFxB;AAAA,MAEIC,eAFJ,mBAEIA,eAFJ;;AAGJ,MAAMC,MAAM,GAAG,wBAAf;AAEA,MAAIC,QAAuB,GAAG,EAA9B;;AAEA,MAAI,CAACL,UAAL,EAAiB;AACfK,IAAAA,QAAQ,GAAG,kCAAqBN,YAAY,CAACM,QAAlC,CAAX;AACD;;AAEDC,oBAAMC,SAAN,CAAgB,YAAM;AACpB,QAAIN,WAAJ,EAAiB;AAEjBG,IAAAA,MAAM,CAACI,MAAP,CAAcC,EAAd,CAAiB,qBAAjB,EAAwC,YAAM;AAAA;;AAC5C,UACE,OAAOC,MAAP,KAAkBC,SAAlB,IACA,2BAACZ,YAAY,CAACM,QAAd,uCAAC,sBAAwB,CAAxB,CAAD,aAAC,uBAA4BO,aAA7B,CADA,IAEA,CAAAb,YAAY,QAAZ,YAAAA,YAAY,CAAEc,MAAd,IAAuB,CAHzB,EAIE;AACA,YAAMC,KAAK,GAAIJ,MAAD,CAAgBI,KAA9B;;AAEA,YAAMC,eAAe,GAAG,SAAlBA,eAAkB,GAAM;AAC5B,cAAI,CAACL,MAAM,CAACM,QAAP,CAAgBC,KAAjB,IAA0BP,MAAM,CAACM,QAAP,CAAgBC,KAAhB,KAA0B,IAAxD,EAA8D;AAC5DC,YAAAA,UAAU,CAAC;AAAA,qBAAMH,eAAe,EAArB;AAAA,aAAD,EAA0B,EAA1B,CAAV;AACA;AACD;;AACDD,UAAAA,KAAK,QAAL,YAAAA,KAAK,CAAEK,kBAAP,CACE,CAACnB,UAAD,GACI,CAAC;AAAEoB,YAAAA,QAAQ,EAAEC,oBAAYjB,MAAM,CAACkB,KAAnB,CAAZ;AAAuCjB,YAAAA,QAAQ,EAARA;AAAvC,WAAD,CADJ,GAEIN,YAHN,EAIE;AACEwB,YAAAA,WAAW,EAAEpB;AADf,WAJF;AAQD,SAbD;;AAcAY,QAAAA,eAAe;AACfb,QAAAA,cAAc,CAACO,EAAf;AACD;AACF,KAzBD;AA0BD,GA7BD,EA6BG,CAACL,MAAM,CAACkB,KAAR,CA7BH;AA8BD,CA/CM","sourcesContent":["import React from 'react'\nimport { useRouter } from 'next/router'\nimport { useConfigState, useBoolean } from '../../../index'\nimport { ProductType } from '../types'\nimport { createMappedProducts, PageTypeMap } from '../../Releva'\n\nexport const usePixelProductsImpression = ({\n productsData,\n isCarousel,\n}: {\n productsData: any\n isCarousel?: boolean\n}) => {\n const [sentAlready, setSentAlready] = useBoolean(false)\n const { defaultMerchant } = useConfigState()\n const router = useRouter()\n\n let products: ProductType[] = []\n\n if (!isCarousel) {\n products = createMappedProducts(productsData.products)\n }\n\n React.useEffect(() => {\n if (sentAlready) return\n\n router.events.on('routeChangeComplete', () => {\n if (\n typeof window !== undefined &&\n !productsData.products?.[0]?.isPlaceholder &&\n productsData?.length > 0\n ) {\n const pixel = (window as any).pixel\n\n const sendImpressions = () => {\n if (!window.document.title || window.document.title === 'за') {\n setTimeout(() => sendImpressions(), 20)\n return\n }\n pixel?.productsImpression(\n !isCarousel\n ? [{ listName: PageTypeMap[router.route], products }]\n : productsData,\n {\n merchantKey: defaultMerchant,\n }\n )\n }\n sendImpressions()\n setSentAlready.on()\n }\n })\n }, [router.route])\n}\n"],"file":"usePixelProductsImpression.js"}
|
@@ -11,14 +11,21 @@ var _index = require("../../index");
|
|
11
11
|
|
12
12
|
var _utils = require("../Releva/utils");
|
13
13
|
|
14
|
-
var _types = require("../Releva/types");
|
15
|
-
|
16
14
|
var pixelChangeRoute = function pixelChangeRoute() {
|
17
15
|
if (typeof window !== undefined) {
|
18
16
|
var pixel = window.pixel;
|
19
|
-
|
17
|
+
var title = window.document.title;
|
18
|
+
|
19
|
+
if (!title || title === 'за') {
|
20
|
+
setTimeout(function () {
|
21
|
+
return pixelChangeRoute();
|
22
|
+
}, 20);
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
|
26
|
+
return pixel == null ? void 0 : pixel.changeRoute({
|
20
27
|
path: _router["default"].router.asPath,
|
21
|
-
title:
|
28
|
+
title: title || 'Error',
|
22
29
|
location: window.location.href
|
23
30
|
});
|
24
31
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/analytics/Pixel/usePixel.tsx"],"names":["pixelChangeRoute","window","undefined","pixel","
|
1
|
+
{"version":3,"sources":["../../../../src/analytics/Pixel/usePixel.tsx"],"names":["pixelChangeRoute","window","undefined","pixel","title","document","setTimeout","changeRoute","path","Router","router","asPath","location","href","usePixel","defaultMerchant","orderId","pixelAddLineItem","product","currencyCode","addLineItem","merchantKey","pixelRemoveLineItem","removeLineItem","pixelCheckoutStep","stepNumber","checkoutStep","pixelCheckoutStepOption","option","checkoutStepOption","pixelPurchase","purchase"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AAGO,IAAMA,gBAAgB,GAAG,SAAnBA,gBAAmB,GAAY;AAC1C,MAAI,OAAOC,MAAP,KAAkBC,SAAtB,EAAiC;AAC/B,QAAMC,KAAK,GAAIF,MAAD,CAAgBE,KAA9B;AAEA,QAAMC,KAAK,GAAGH,MAAM,CAACI,QAAP,CAAgBD,KAA9B;;AAEA,QAAI,CAACA,KAAD,IAAUA,KAAK,KAAK,IAAxB,EAA8B;AAC5BE,MAAAA,UAAU,CAAC;AAAA,eAAMN,gBAAgB,EAAtB;AAAA,OAAD,EAA2B,EAA3B,CAAV;AACA;AACD;;AAED,WAAOG,KAAP,oBAAOA,KAAK,CAAEI,WAAP,CAAmB;AACxBC,MAAAA,IAAI,EAAEC,mBAAOC,MAAP,CAAeC,MADG;AAExBP,MAAAA,KAAK,EAAEA,KAAK,IAAI,OAFQ;AAGxBQ,MAAAA,QAAQ,EAAEX,MAAM,CAACW,QAAP,CAAgBC;AAHF,KAAnB,CAAP;AAKD;AACF,CAjBM;;;;AAmBA,IAAMC,QAAQ,GAAG,SAAXA,QAAW,GAAM;AAC5B,MAAMX,KAAK,GAAIF,MAAD,CAAgBE,KAA9B;;AAD4B,wBAEA,4BAFA;AAAA,MAEpBY,eAFoB,mBAEpBA,eAFoB;;AAG5B,MAAMC,OAAO,GAAG,yBAAhB;;AAEA,MAAMC,gBAAgB,GAAG,SAAnBA,gBAAmB,OAMnB;AAAA,QALJC,OAKI,QALJA,OAKI;AAAA,QAJJC,YAII,QAJJA,YAII;AACJhB,IAAAA,KAAK,QAAL,YAAAA,KAAK,CAAEiB,WAAP,CAAmBF,OAAnB,EAA4B;AAC1BC,MAAAA,YAAY,EAAZA,YAD0B;AAE1BE,MAAAA,WAAW,EAAEN;AAFa,KAA5B;AAID,GAXD;;AAaA,MAAMO,mBAAmB,GAAG,SAAtBA,mBAAsB,QAMtB;AAAA,QALJJ,OAKI,SALJA,OAKI;AAAA,QAJJC,YAII,SAJJA,YAII;AACJhB,IAAAA,KAAK,QAAL,YAAAA,KAAK,CAAEoB,cAAP,CAAsBL,OAAtB,EAA+B;AAC7BC,MAAAA,YAAY,EAAZA,YAD6B;AAE7BE,MAAAA,WAAW,EAAEN;AAFgB,KAA/B;AAID,GAXD;;AAaA,MAAMS,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,UAAD,EAAwB;AAChD,QAAItB,KAAJ,EAAWA,KAAK,QAAL,YAAAA,KAAK,CAAEuB,YAAP,CAAoBV,OAApB,EAA6BS,UAA7B;AACZ,GAFD;;AAIA,MAAME,uBAAuB,GAAG,SAA1BA,uBAA0B,CAACF,UAAD,EAAqBG,MAArB,EAAwC;AACtE,QAAIzB,KAAJ,EAAWA,KAAK,QAAL,YAAAA,KAAK,CAAE0B,kBAAP,CAA0Bb,OAA1B,EAAmCS,UAAnC,EAA+CG,MAA/C,EAD2D,CACJ;AACnE,GAFD;;AAIA,MAAME,aAAa,GAAG,SAAhBA,aAAgB,GAAM;AAC1B,QAAI3B,KAAJ,EAAWA,KAAK,QAAL,YAAAA,KAAK,CAAE4B,QAAP,CAAgBf,OAAhB;AACZ,GAFD;;AAIA,SAAO;AACLC,IAAAA,gBAAgB,EAAhBA,gBADK;AAELK,IAAAA,mBAAmB,EAAnBA,mBAFK;AAGLE,IAAAA,iBAAiB,EAAjBA,iBAHK;AAILG,IAAAA,uBAAuB,EAAvBA,uBAJK;AAKLG,IAAAA,aAAa,EAAbA;AALK,GAAP;AAOD,CAlDM","sourcesContent":["import React from 'react'\nimport Router from 'next/router'\nimport { useConfigState } from '../../index'\nimport { getBasketId } from '../Releva/utils'\nimport { ProductType } from './types'\n\nexport const pixelChangeRoute = (): void => {\n if (typeof window !== undefined) {\n const pixel = (window as any).pixel\n\n const title = window.document.title\n\n if (!title || title === 'за') {\n setTimeout(() => pixelChangeRoute(), 20)\n return\n }\n\n return pixel?.changeRoute({\n path: Router.router!.asPath,\n title: title || 'Error',\n location: window.location.href,\n })\n }\n}\n\nexport const usePixel = () => {\n const pixel = (window as any).pixel\n const { defaultMerchant } = useConfigState()\n const orderId = getBasketId()\n\n const pixelAddLineItem = ({\n product,\n currencyCode,\n }: {\n product: ProductType\n currencyCode: string\n }) => {\n pixel?.addLineItem(product, {\n currencyCode,\n merchantKey: defaultMerchant,\n })\n }\n\n const pixelRemoveLineItem = ({\n product,\n currencyCode,\n }: {\n product: ProductType\n currencyCode: string\n }) => {\n pixel?.removeLineItem(product, {\n currencyCode,\n merchantKey: defaultMerchant,\n })\n }\n\n const pixelCheckoutStep = (stepNumber: number) => {\n if (pixel) pixel?.checkoutStep(orderId, stepNumber)\n }\n\n const pixelCheckoutStepOption = (stepNumber: number, option: string) => {\n if (pixel) pixel?.checkoutStepOption(orderId, stepNumber, option) // order id, stepNumber and the selected shipping or payment option\n }\n\n const pixelPurchase = () => {\n if (pixel) pixel?.purchase(orderId)\n }\n\n return {\n pixelAddLineItem,\n pixelRemoveLineItem,\n pixelCheckoutStep,\n pixelCheckoutStepOption,\n pixelPurchase,\n }\n}\n"],"file":"usePixel.js"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/hooks/useProduct/index.tsx"],"names":["ProductStateContext","React","createContext","undefined","CountDispatchContext","ProductProvider","product","children","defaultVariantId","useState","mounted","setMounted","getCombinationsAndAttributeRules","combinations","attributeRules","setCombinationsAndAttributeRules","getVariantsWithInventory","variants","setVariants","getDefaultVariant","selectedVariant","setSelectedVariant","metaData","useMemo","rootCategory","categories","rootCategoryId","resourceId","metaObj","_id","name","slug","description","shortDescription","metaDescription","brand","brands","resource","logo","assets","sources","url","category","length","reviewRatingStatistics","content","Boolean","map","createProductContent","seoData","seoObj","title","metaTitle","keywords","metaKeywords","customFields","mappedFields","custom","useEffect","data","variantsWithInventory","reduce","_","index","arr","currentVariant","mappedAttributes","mappedOptions","availableOptions","isAvailable","inventorySnapshot","canOrder","updatedVariant","inventory","hasAvailableQuantity","availableQuantity","quantity","attributes","options","selectedOptions","labels","getAttribute","rule","getSelectedAttribute","getAttributeByKey","key","find","a","value","getAvailabilityByStore","availabilities","mappedAttributeRules","attributesWithId","Object","keys","variantId","combinationsMap","selectVariantById","id","selectVariantByAttribute","selectVariantByCombination","params","selectVariantOptions","definitionKey","optionKey","newSelectedVariant","filter","opt","mappedSelectedOptions","option","attributeRule","values","result","forEach","currentKey","found","getVariantById","getVariantByAttribute","getVariantByCombination","getCustomFieldValue","field","getCombinationsForAttributeRule","state","functions","getProductVideos","useProductState","context","useContext","Error","useProductFunctions","useProduct","config","productsApi"],"mappings":";;;;;;;;;;;;AAAA;;AAaA;;AACA;;AAeA;;AACA;;AAuLA,IAAMA,mBAAmB,gBAAGC,kBAAMC,aAAN,CAE1BC,SAF0B,CAA5B;;AAGA,IAAMC,oBAAoB,gBAAGH,kBAAMC,aAAN,CAE3BC,SAF2B,CAA7B;;AAIO,SAASE,eAAT,OAIkB;AAAA,MAHvBC,OAGuB,QAHvBA,OAGuB;AAAA,MAFvBC,QAEuB,QAFvBA,QAEuB;AAAA,MADvBC,gBACuB,QADvBA,gBACuB;;AAAA,wBACOP,kBAAMQ,QAAN,CAAe,KAAf,CADP;AAAA,MAChBC,OADgB;AAAA,MACPC,UADO;;AAAA,yBAMnBV,kBAAMQ,QAAN,CAGDG,gCAHC,CANmB;AAAA;AAAA,MAInBC,YAJmB,qBAInBA,YAJmB;AAAA,MAILC,cAJK,qBAILA,cAJK;AAAA,MAKrBC,gCALqB;;AAAA,yBAWSd,kBAAMQ,QAAN,CAC9BO,wBAD8B,CAXT;AAAA,MAWhBC,QAXgB;AAAA,MAWNC,WAXM;;AAAA,yBAkBnBjB,kBAAMQ,QAAN,CAAmCU,iBAAnC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AACD;;AAEM,SAASI,UAAT,CAAoBnG,IAApB,EAAkCoG,MAAlC,EAAmE;AACxE,SAAOC,yBAAYF,UAAZ,CAAuBnG,IAAvB,EAA6BoG,MAA7B,CAAP;AACD","sourcesContent":["import React from 'react'\nimport {\n ProductDTO,\n ProductVariantDTO,\n AttributeRuleDTO,\n ProductAttributeDraftDTO,\n CustomField,\n AssetSourceDTO,\n SelectedOptionDTO,\n ReviewRatingStatisticsDTO,\n CategoryDTO,\n ProductVariantLabelDTO,\n} from '@sentecacommerce/sdk'\nimport { getTranslatableField } from '../../'\nimport {\n assignCombinationsToAttributeRules,\n createCombinationsMap,\n createCustomFieldsMap,\n createProductContent,\n createAttributeRulesMap,\n createMappedAttributes,\n processAvailabilityPerStore,\n getProductVideos,\n createMappedOptions,\n createSelectedOption2,\n SelectedOptionType,\n formatCategories,\n createLabelsMap,\n} from './utils'\nimport { productsApi, getProductBySlugConfig } from '../../api/productsApi'\nimport { assetsFieldsToMap, AssetsMap } from '../../utils/assetsToMap'\n\nexport interface OptionsType {\n definitionKey: string\n label: string\n elements?: SubOptionType[]\n}\n\nexport interface SubOptionType {\n optionKey: string\n label: string\n imageIndex?: number\n}\n\nexport interface ContentType {\n name?: string\n content?: string\n}\n\nexport interface MetaInformationType {\n _id?: string\n name?: string\n slug?: string\n description?: string\n shortDescription?: string\n reviewRatingStatistics?: ReviewRatingStatisticsDTO\n brand: {\n _id?: string\n name?: string\n slug?: string\n logo?: string\n }\n category: {\n _id?: string\n name?: string\n slug?: string\n }\n rootCategory: {\n _id?: string\n name?: string\n slug?: string\n }\n categories?: {\n name: string\n id: string\n link: string\n }[]\n content?: ContentType[]\n assets?: AssetsMap\n}\n\ninterface SeoInformationType {\n title?: string\n description?: string\n keywords?: string\n}\n\ninterface AttributeRulesType extends AttributeRuleDTO {\n label: string\n values: {\n [id: string]: {\n label: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n }\n}\n\nexport interface VariantType\n extends Omit<\n ProductVariantDTO,\n 'attributes' | 'availableOptions' | 'selectedOptions' | 'labels'\n > {\n attributes: ProductAttributeDraftDTO[]\n options?: OptionsType[]\n selectedOptions: SelectedOptionDTO[]\n mappedSelectedOptions?: SelectedOptionType[]\n isAvailable: boolean\n quantity?: number\n inventory: {\n hasAvailableQuantity?: boolean\n availableQuantity?: number\n }\n labels?: string[]\n getAttribute: (\n rule: string\n ) => {\n id: string\n label: string\n name: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n getAttributeByKey: (key: string) => undefined | any\n getAvailabilityByStore: () => InventoryAvailabilityType[] | undefined\n}\ninterface VariantMap {\n [productId: string]: VariantType\n}\n\nexport interface BooleanKVP {\n [sku: string]: boolean | undefined\n}\n\nexport interface AttributeRulesMap {\n [name: string]: AttributeRulesType\n}\n\nexport interface CombinationsMap {\n [id: string]: {\n value: string\n params: {\n [id: string]: string\n }\n }\n}\n\nexport interface InventoryAvailabilityType {\n storeName: string\n availableQuantity: number\n acceptsBackorders: boolean\n restockableInDays: number\n}\n\ntype ProductProviderProps = {\n children: React.ReactNode\n product?: ProductDTO\n defaultVariantId?: string\n query?: {\n storeKey?: string\n currencyCode?: string\n languageCode?: string\n priceListKey?: string\n time?: number\n merchantKey?: string\n expand?: string\n project?: string\n }\n}\n\ntype ProductStateContextType = {\n attributeRules: AttributeRulesMap\n metaData: MetaInformationType\n seoData: SeoInformationType\n variants?: VariantMap\n selectedVariant?: VariantType | null\n}\n\nexport type VideoType = {\n type: string\n source: string\n iframe: JSX.Element\n thumb: {\n url: string\n }\n}\n\ntype CountFunctionsContextType = {\n selectVariantById: (id: string) => void\n selectVariantByAttribute: (key: string) => void\n selectVariantByCombination: (key: string, value: string) => void\n selectVariantOptions: (optionId: string, elementId: string) => void\n getVariantById: (id: string) => VariantType\n getVariantByAttribute: (key: string) => VariantType\n getVariantByCombination: (key: string, value: string) => VariantType\n getCustomFieldValue: (field: string) => boolean | undefined\n getCombinationsForAttributeRule: (\n key: string,\n id: string\n ) => {\n label: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n getProductVideos: () => VideoType[]\n}\n\nconst ProductStateContext = React.createContext<\n ProductStateContextType | undefined\n>(undefined)\nconst CountDispatchContext = React.createContext<\n CountFunctionsContextType | undefined\n>(undefined)\n\nexport function ProductProvider({\n product,\n children,\n defaultVariantId,\n}: ProductProviderProps) {\n const [mounted, setMounted] = React.useState(false)\n\n const [\n { combinations, attributeRules },\n setCombinationsAndAttributeRules,\n ] = React.useState<{\n combinations: CombinationsMap\n attributeRules: AttributeRulesMap\n }>(getCombinationsAndAttributeRules)\n\n const [variants, setVariants] = React.useState<VariantMap>(\n getVariantsWithInventory\n )\n\n const [\n selectedVariant,\n setSelectedVariant,\n ] = React.useState<VariantType | null>(getDefaultVariant)\n\n const metaData = React.useMemo(() => {\n const rootCategory = product?.categories?.[0]\n const rootCategoryId = rootCategory?.resourceId\n\n const metaObj: MetaInformationType = {\n _id: product?._id,\n name:\n getTranslatableField(selectedVariant?.name) ||\n getTranslatableField(product?.name),\n slug: getTranslatableField(product?.slug),\n description:\n getTranslatableField(selectedVariant?.description) ||\n getTranslatableField(product?.description),\n shortDescription:\n getTranslatableField(selectedVariant?.metaDescription) ||\n getTranslatableField(product?.metaDescription),\n brand: {\n _id: product?.brands?.[0]?.resourceId,\n name: getTranslatableField(product?.brands?.[0]?.resource?.name),\n slug: getTranslatableField(product?.brands?.[0]?.resource?.slug),\n logo: product?.brands?.[0]?.resource?.assets?.[0]?.sources?.[0]?.url,\n },\n category: {\n _id: product?.categories?.[product?.categories?.length - 1]?.resourceId,\n name: getTranslatableField(\n product?.categories?.[product?.categories?.length - 1]?.resource?.name\n ),\n slug: getTranslatableField(\n product?.categories?.[product?.categories?.length - 1]?.resource?.slug\n ),\n },\n rootCategory: {\n _id: rootCategoryId,\n name: getTranslatableField(rootCategory?.resource?.name),\n slug: getTranslatableField(rootCategory?.resource?.slug),\n },\n categories: formatCategories(product?.categories, rootCategoryId),\n reviewRatingStatistics: product?.reviewRatingStatistics,\n content: Boolean(\n selectedVariant?.content?.map(createProductContent).length\n )\n ? selectedVariant?.content?.map(createProductContent)\n : product?.content?.map(createProductContent),\n assets: assetsFieldsToMap(product?.assets),\n }\n return metaObj\n }, [\n product?._id,\n product?.brands,\n product?.content,\n product?.description,\n product?.metaDescription,\n product?.name,\n product?.slug,\n product?.assets,\n selectedVariant,\n ])\n\n const seoData = React.useMemo(() => {\n const seoObj: SeoInformationType = {\n title:\n getTranslatableField(selectedVariant?.metaTitle) ||\n getTranslatableField(product?.metaTitle),\n description:\n getTranslatableField(selectedVariant?.metaDescription) ||\n getTranslatableField(product?.metaDescription),\n keywords:\n getTranslatableField(selectedVariant?.metaKeywords) ||\n getTranslatableField(product?.metaKeywords),\n }\n return seoObj\n }, [\n product?.metaDescription,\n product?.metaKeywords,\n product?.metaTitle,\n selectedVariant,\n ])\n\n const customFields = React.useMemo(() => {\n const mappedFields = createCustomFieldsMap(product?.custom) as BooleanKVP\n return mappedFields\n }, [product?.custom])\n\n React.useEffect(() => {\n // prevent unnecessary calculations\n if (mounted) {\n setVariants(getVariantsWithInventory())\n }\n }, [product])\n\n React.useMemo(() => {\n // prevent unnecessary calculations\n if (!mounted) {\n return setMounted(true)\n }\n\n const data = getCombinationsAndAttributeRules()\n\n setCombinationsAndAttributeRules(data)\n }, [variants])\n\n function getVariantsWithInventory() {\n const variantsWithInventory = product?.variants?.reduce(\n (map: any, _, index, arr) => {\n const currentVariant = arr[index] as ProductVariantDTO\n\n const mappedAttributes = createMappedAttributes(currentVariant)\n\n const mappedOptions =\n createMappedOptions(currentVariant?.availableOptions) || []\n\n const isAvailable = currentVariant?.inventorySnapshot?.canOrder\n\n const updatedVariant: VariantType = {\n ...currentVariant,\n inventory: {\n hasAvailableQuantity: currentVariant.inventorySnapshot?.canOrder,\n availableQuantity:\n currentVariant.inventorySnapshot?.availableQuantity,\n },\n isAvailable: isAvailable ? true : false,\n quantity: isAvailable\n ? currentVariant?.inventorySnapshot?.availableQuantity\n : 0,\n attributes: mappedAttributes,\n options: mappedOptions,\n selectedOptions: [],\n labels: createLabelsMap(currentVariant.labels),\n getAttribute: (rule: string) =>\n getSelectedAttribute(rule, mappedAttributes),\n getAttributeByKey: (key: string) =>\n mappedAttributes.find((a) => a.name === key)?.value,\n getAvailabilityByStore: () =>\n processAvailabilityPerStore(\n currentVariant?.inventorySnapshot?.availabilities\n ),\n }\n\n map[currentVariant._id] = updatedVariant\n\n return map\n },\n {}\n )\n\n return variantsWithInventory || {}\n }\n\n function getCombinationsAndAttributeRules() {\n const mappedAttributeRules: AttributeRulesMap = createAttributeRulesMap(\n product\n )\n\n const attributesWithId = Object.keys(variants || {}).map((key) => {\n return {\n variantId: variants?.[key]._id,\n attributes: variants?.[key].attributes,\n }\n })\n\n const combinationsMap = createCombinationsMap(\n Object.keys(mappedAttributeRules),\n attributesWithId\n )\n\n assignCombinationsToAttributeRules(mappedAttributeRules, combinationsMap)\n\n return {\n combinations: combinationsMap,\n attributeRules: mappedAttributeRules,\n }\n }\n\n function getDefaultVariant() {\n if (!defaultVariantId) return null\n\n return variants[defaultVariantId]\n }\n\n function selectVariantById(id: string) {\n setSelectedVariant(variants[id])\n }\n\n function selectVariantByAttribute(key: string) {\n const id = combinations[key]?.value\n setSelectedVariant(variants[id])\n }\n\n function selectVariantByCombination(key: string, value: string) {\n const id = combinations[key].params[value]\n setSelectedVariant(variants[id])\n }\n\n function selectVariantOptions(definitionKey: string, optionKey: string) {\n if (selectedVariant) {\n const newSelectedVariant = { ...selectedVariant }\n\n newSelectedVariant.selectedOptions = newSelectedVariant.selectedOptions.filter(\n (opt) => opt.definitionKey !== definitionKey\n )\n\n newSelectedVariant.selectedOptions = [\n ...newSelectedVariant.selectedOptions,\n {\n definitionKey,\n optionKey,\n },\n ]\n\n newSelectedVariant.mappedSelectedOptions = newSelectedVariant.selectedOptions.map(\n (option) => createSelectedOption2(newSelectedVariant.options, option)\n )\n\n setSelectedVariant(newSelectedVariant)\n }\n }\n\n function getSelectedAttribute(rule: string, attributes: any[]) {\n const attributeRule = attributeRules[rule]?.values\n let result\n\n attributes.forEach((currentKey) => {\n const found = attributeRule?.[currentKey.value]\n if (found) result = { id: currentKey.value, name: rule, ...found }\n })\n\n return (result as unknown) as {\n id: string\n name: string\n label: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n }\n\n function getVariantById(id: string) {\n return variants?.[id]\n }\n\n function getVariantByAttribute(key: string) {\n const id = combinations[key]?.value\n return variants?.[id]\n }\n\n function getVariantByCombination(key: string, value: string) {\n const id = combinations[key]?.params[value]\n return variants?.[id]\n }\n\n function getCustomFieldValue(field: string) {\n return customFields?.[field]\n }\n\n function getCombinationsForAttributeRule(key: string, id: string) {\n const result = attributeRules?.[key]?.values?.[id]\n return result\n }\n\n const state = {\n metaData,\n seoData,\n variants,\n selectedVariant,\n attributeRules,\n }\n\n const functions = {\n getVariantById,\n getVariantByAttribute,\n getVariantByCombination,\n selectVariantById,\n selectVariantByAttribute,\n selectVariantByCombination,\n getCombinationsForAttributeRule,\n selectVariantOptions,\n getCustomFieldValue,\n getProductVideos: () => getProductVideos(metaData.assets),\n }\n\n return (\n <ProductStateContext.Provider value={state}>\n <CountDispatchContext.Provider value={functions}>\n {children}\n </CountDispatchContext.Provider>\n </ProductStateContext.Provider>\n )\n}\n\nexport function useProductState() {\n const context = React.useContext(ProductStateContext)\n if (context === undefined) {\n throw new Error('useProductState must be used within a ProductProvider')\n }\n return context\n}\nexport function useProductFunctions() {\n const context = React.useContext(CountDispatchContext)\n if (context === undefined) {\n throw new Error('useProductDispatch must be used within a ProductProvider')\n }\n return context\n}\n\nexport function useProduct(slug: string, config?: getProductBySlugConfig) {\n return productsApi.useProduct(slug, config)\n}\n"],"file":"index.js"}
|
1
|
+
{"version":3,"sources":["../../../../src/hooks/useProduct/index.tsx"],"names":["ProductStateContext","React","createContext","undefined","CountDispatchContext","ProductProvider","product","children","defaultVariantId","useState","mounted","setMounted","getCombinationsAndAttributeRules","combinations","attributeRules","setCombinationsAndAttributeRules","getVariantsWithInventory","variants","setVariants","getDefaultVariant","selectedVariant","setSelectedVariant","metaData","useMemo","rootCategory","categories","rootCategoryId","resourceId","metaObj","_id","name","slug","description","shortDescription","metaDescription","brand","brands","resource","logo","assets","sources","url","category","length","reviewRatingStatistics","content","Boolean","map","createProductContent","seoData","seoObj","title","metaTitle","keywords","metaKeywords","customFields","mappedFields","custom","useEffect","data","variantsWithInventory","reduce","_","index","arr","currentVariant","mappedAttributes","mappedOptions","availableOptions","isAvailable","inventorySnapshot","canOrder","updatedVariant","inventory","hasAvailableQuantity","availableQuantity","quantity","attributes","options","selectedOptions","labels","getAttribute","rule","getSelectedAttribute","getAttributeByKey","key","find","a","value","getAvailabilityByStore","availabilities","mappedAttributeRules","attributesWithId","Object","keys","variantId","combinationsMap","selectVariantById","id","selectVariantByAttribute","selectVariantByCombination","params","selectVariantOptions","definitionKey","optionKey","newSelectedVariant","filter","opt","mappedSelectedOptions","option","attributeRule","values","result","forEach","currentKey","found","getVariantById","getVariantByAttribute","getVariantByCombination","getCustomFieldValue","field","getCombinationsForAttributeRule","state","functions","getProductVideos","useProductState","context","useContext","Error","useProductFunctions","useProduct","config","productsApi"],"mappings":";;;;;;;;;;;;AAAA;;AASA;;AACA;;AAeA;;AACA;;AAyLA,IAAMA,mBAAmB,gBAAGC,kBAAMC,aAAN,CAE1BC,SAF0B,CAA5B;;AAGA,IAAMC,oBAAoB,gBAAGH,kBAAMC,aAAN,CAE3BC,SAF2B,CAA7B;;AAIO,SAASE,eAAT,OAIkB;AAAA,MAHvBC,OAGuB,QAHvBA,OAGuB;AAAA,MAFvBC,QAEuB,QAFvBA,QAEuB;AAAA,MADvBC,gBACuB,QADvBA,gBACuB;;AAAA,wBACOP,kBAAMQ,QAAN,CAAe,KAAf,CADP;AAAA,MAChBC,OADgB;AAAA,MACPC,UADO;;AAAA,yBAMnBV,kBAAMQ,QAAN,CAGDG,gCAHC,CANmB;AAAA;AAAA,MAInBC,YAJmB,qBAInBA,Y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,SAASG,mBAAT,GAA+B;AACpC,MAAMH,OAAO,GAAG7H,kBAAM8H,UAAN,CAAiB3H,oBAAjB,CAAhB;;AACA,MAAI0H,OAAO,KAAK3H,SAAhB,EAA2B;AACzB,UAAM,IAAI6H,KAAJ,CAAU,0DAAV,CAAN;AACD;;AACD,SAAOF,OAAP;AACD;;AAEM,SAASI,UAAT,CAAoBnG,IAApB,EAAkCoG,MAAlC,EAAmE;AACxE,SAAOC,yBAAYF,UAAZ,CAAuBnG,IAAvB,EAA6BoG,MAA7B,CAAP;AACD","sourcesContent":["import React from 'react'\nimport {\n ProductDTO,\n ProductVariantDTO,\n AttributeRuleDTO,\n ProductAttributeDraftDTO,\n SelectedOptionDTO,\n ReviewRatingStatisticsDTO,\n} from '@sentecacommerce/sdk'\nimport { getTranslatableField } from '../../'\nimport {\n assignCombinationsToAttributeRules,\n createCombinationsMap,\n createCustomFieldsMap,\n createProductContent,\n createAttributeRulesMap,\n createMappedAttributes,\n processAvailabilityPerStore,\n getProductVideos,\n createMappedOptions,\n createSelectedOption2,\n SelectedOptionType,\n formatCategories,\n createLabelsMap,\n} from './utils'\nimport { productsApi, getProductBySlugConfig } from '../../api/productsApi'\nimport { assetsFieldsToMap, AssetsMap } from '../../utils/assetsToMap'\n\nexport interface OptionsType {\n definitionKey: string\n label: string\n elements?: SubOptionType[]\n}\n\nexport interface SubOptionType {\n optionKey: string\n label: string\n imageIndex?: number\n}\n\nexport interface ContentType {\n name?: string\n content?: string\n}\n\nexport interface MetaInfoCategoryType {\n name: string\n id: string\n link: string\n}\n\nexport interface MetaInformationType {\n _id?: string\n name?: string\n slug?: string\n description?: string\n shortDescription?: string\n reviewRatingStatistics?: ReviewRatingStatisticsDTO\n brand: {\n _id?: string\n name?: string\n slug?: string\n logo?: string\n }\n category: {\n _id?: string\n name?: string\n slug?: string\n }\n rootCategory: {\n _id?: string\n name?: string\n slug?: string\n }\n categories?: MetaInfoCategoryType[]\n content?: ContentType[]\n assets?: AssetsMap\n}\n\ninterface SeoInformationType {\n title?: string\n description?: string\n keywords?: string\n}\n\ninterface AttributeRulesType extends AttributeRuleDTO {\n label: string\n values: {\n [id: string]: {\n label: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n }\n}\n\nexport interface VariantType\n extends Omit<\n ProductVariantDTO,\n 'attributes' | 'availableOptions' | 'selectedOptions' | 'labels'\n > {\n attributes: ProductAttributeDraftDTO[]\n options?: OptionsType[]\n selectedOptions: SelectedOptionDTO[]\n mappedSelectedOptions?: SelectedOptionType[]\n isAvailable: boolean\n quantity?: number\n inventory: {\n hasAvailableQuantity?: boolean\n availableQuantity?: number\n }\n labels?: string[]\n getAttribute: (\n rule: string\n ) => {\n id: string\n label: string\n name: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n getAttributeByKey: (key: string) => undefined | any\n getAvailabilityByStore: () => InventoryAvailabilityType[] | undefined\n}\ninterface VariantMap {\n [productId: string]: VariantType\n}\n\nexport interface BooleanKVP {\n [sku: string]: boolean | undefined\n}\n\nexport interface AttributeRulesMap {\n [name: string]: AttributeRulesType\n}\n\nexport interface CombinationsMap {\n [id: string]: {\n value: string\n params: {\n [id: string]: string\n }\n }\n}\n\nexport interface InventoryAvailabilityType {\n storeName: string\n availableQuantity: number\n acceptsBackorders: boolean\n restockableInDays: number\n}\n\ntype ProductProviderProps = {\n children: React.ReactNode\n product?: ProductDTO\n defaultVariantId?: string\n query?: {\n storeKey?: string\n currencyCode?: string\n languageCode?: string\n priceListKey?: string\n time?: number\n merchantKey?: string\n expand?: string\n project?: string\n }\n}\n\ntype ProductStateContextType = {\n attributeRules: AttributeRulesMap\n metaData: MetaInformationType\n seoData: SeoInformationType\n variants?: VariantMap\n selectedVariant?: VariantType | null\n}\n\nexport type VideoType = {\n type: string\n source: string\n iframe: JSX.Element\n thumb: {\n url: string\n }\n}\n\ntype CountFunctionsContextType = {\n selectVariantById: (id: string) => void\n selectVariantByAttribute: (key: string) => void\n selectVariantByCombination: (key: string, value: string) => void\n selectVariantOptions: (optionId: string, elementId: string) => void\n getVariantById: (id: string) => VariantType\n getVariantByAttribute: (key: string) => VariantType\n getVariantByCombination: (key: string, value: string) => VariantType\n getCustomFieldValue: (field: string) => boolean | undefined\n getCombinationsForAttributeRule: (\n key: string,\n id: string\n ) => {\n label: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n getProductVideos: () => VideoType[]\n}\n\nconst ProductStateContext = React.createContext<\n ProductStateContextType | undefined\n>(undefined)\nconst CountDispatchContext = React.createContext<\n CountFunctionsContextType | undefined\n>(undefined)\n\nexport function ProductProvider({\n product,\n children,\n defaultVariantId,\n}: ProductProviderProps) {\n const [mounted, setMounted] = React.useState(false)\n\n const [\n { combinations, attributeRules },\n setCombinationsAndAttributeRules,\n ] = React.useState<{\n combinations: CombinationsMap\n attributeRules: AttributeRulesMap\n }>(getCombinationsAndAttributeRules)\n\n const [variants, setVariants] = React.useState<VariantMap>(\n getVariantsWithInventory\n )\n\n const [\n selectedVariant,\n setSelectedVariant,\n ] = React.useState<VariantType | null>(getDefaultVariant)\n\n const metaData = React.useMemo(() => {\n const rootCategory = product?.categories?.[0]\n const rootCategoryId = rootCategory?.resourceId\n\n const metaObj: MetaInformationType = {\n _id: product?._id,\n name:\n getTranslatableField(selectedVariant?.name) ||\n getTranslatableField(product?.name),\n slug: getTranslatableField(product?.slug),\n description:\n getTranslatableField(selectedVariant?.description) ||\n getTranslatableField(product?.description),\n shortDescription:\n getTranslatableField(selectedVariant?.metaDescription) ||\n getTranslatableField(product?.metaDescription),\n brand: {\n _id: product?.brands?.[0]?.resourceId,\n name: getTranslatableField(product?.brands?.[0]?.resource?.name),\n slug: getTranslatableField(product?.brands?.[0]?.resource?.slug),\n logo: product?.brands?.[0]?.resource?.assets?.[0]?.sources?.[0]?.url,\n },\n category: {\n _id: product?.categories?.[product?.categories?.length - 1]?.resourceId,\n name: getTranslatableField(\n product?.categories?.[product?.categories?.length - 1]?.resource?.name\n ),\n slug: getTranslatableField(\n product?.categories?.[product?.categories?.length - 1]?.resource?.slug\n ),\n },\n rootCategory: {\n _id: rootCategoryId,\n name: getTranslatableField(rootCategory?.resource?.name),\n slug: getTranslatableField(rootCategory?.resource?.slug),\n },\n categories: formatCategories(product?.categories, rootCategoryId),\n reviewRatingStatistics: product?.reviewRatingStatistics,\n content: Boolean(\n selectedVariant?.content?.map(createProductContent).length\n )\n ? selectedVariant?.content?.map(createProductContent)\n : product?.content?.map(createProductContent),\n assets: assetsFieldsToMap(product?.assets),\n }\n return metaObj\n }, [\n product?._id,\n product?.brands,\n product?.content,\n product?.description,\n product?.metaDescription,\n product?.name,\n product?.slug,\n product?.assets,\n selectedVariant,\n ])\n\n const seoData = React.useMemo(() => {\n const seoObj: SeoInformationType = {\n title:\n getTranslatableField(selectedVariant?.metaTitle) ||\n getTranslatableField(product?.metaTitle),\n description:\n getTranslatableField(selectedVariant?.metaDescription) ||\n getTranslatableField(product?.metaDescription),\n keywords:\n getTranslatableField(selectedVariant?.metaKeywords) ||\n getTranslatableField(product?.metaKeywords),\n }\n return seoObj\n }, [\n product?.metaDescription,\n product?.metaKeywords,\n product?.metaTitle,\n selectedVariant,\n ])\n\n const customFields = React.useMemo(() => {\n const mappedFields = createCustomFieldsMap(product?.custom) as BooleanKVP\n return mappedFields\n }, [product?.custom])\n\n React.useEffect(() => {\n // prevent unnecessary calculations\n if (mounted) {\n setVariants(getVariantsWithInventory())\n }\n }, [product])\n\n React.useMemo(() => {\n // prevent unnecessary calculations\n if (!mounted) {\n return setMounted(true)\n }\n\n const data = getCombinationsAndAttributeRules()\n\n setCombinationsAndAttributeRules(data)\n }, [variants])\n\n function getVariantsWithInventory() {\n const variantsWithInventory = product?.variants?.reduce(\n (map: any, _, index, arr) => {\n const currentVariant = arr[index] as ProductVariantDTO\n\n const mappedAttributes = createMappedAttributes(currentVariant)\n\n const mappedOptions =\n createMappedOptions(currentVariant?.availableOptions) || []\n\n const isAvailable = currentVariant?.inventorySnapshot?.canOrder\n\n const updatedVariant: VariantType = {\n ...currentVariant,\n inventory: {\n hasAvailableQuantity: currentVariant.inventorySnapshot?.canOrder,\n availableQuantity:\n currentVariant.inventorySnapshot?.availableQuantity,\n },\n isAvailable: isAvailable ? true : false,\n quantity: isAvailable\n ? currentVariant?.inventorySnapshot?.availableQuantity\n : 0,\n attributes: mappedAttributes,\n options: mappedOptions,\n selectedOptions: [],\n labels: createLabelsMap(currentVariant.labels),\n getAttribute: (rule: string) =>\n getSelectedAttribute(rule, mappedAttributes),\n getAttributeByKey: (key: string) =>\n mappedAttributes.find((a) => a.name === key)?.value,\n getAvailabilityByStore: () =>\n processAvailabilityPerStore(\n currentVariant?.inventorySnapshot?.availabilities\n ),\n }\n\n map[currentVariant._id] = updatedVariant\n\n return map\n },\n {}\n )\n\n return variantsWithInventory || {}\n }\n\n function getCombinationsAndAttributeRules() {\n const mappedAttributeRules: AttributeRulesMap = createAttributeRulesMap(\n product\n )\n\n const attributesWithId = Object.keys(variants || {}).map((key) => {\n return {\n variantId: variants?.[key]._id,\n attributes: variants?.[key].attributes,\n }\n })\n\n const combinationsMap = createCombinationsMap(\n Object.keys(mappedAttributeRules),\n attributesWithId\n )\n\n assignCombinationsToAttributeRules(mappedAttributeRules, combinationsMap)\n\n return {\n combinations: combinationsMap,\n attributeRules: mappedAttributeRules,\n }\n }\n\n function getDefaultVariant() {\n if (!defaultVariantId) return null\n\n return variants[defaultVariantId]\n }\n\n function selectVariantById(id: string) {\n setSelectedVariant(variants[id])\n }\n\n function selectVariantByAttribute(key: string) {\n const id = combinations[key]?.value\n setSelectedVariant(variants[id])\n }\n\n function selectVariantByCombination(key: string, value: string) {\n const id = combinations[key].params[value]\n setSelectedVariant(variants[id])\n }\n\n function selectVariantOptions(definitionKey: string, optionKey: string) {\n if (selectedVariant) {\n const newSelectedVariant = { ...selectedVariant }\n\n newSelectedVariant.selectedOptions = newSelectedVariant.selectedOptions.filter(\n (opt) => opt.definitionKey !== definitionKey\n )\n\n newSelectedVariant.selectedOptions = [\n ...newSelectedVariant.selectedOptions,\n {\n definitionKey,\n optionKey,\n },\n ]\n\n newSelectedVariant.mappedSelectedOptions = newSelectedVariant.selectedOptions.map(\n (option) => createSelectedOption2(newSelectedVariant.options, option)\n )\n\n setSelectedVariant(newSelectedVariant)\n }\n }\n\n function getSelectedAttribute(rule: string, attributes: any[]) {\n const attributeRule = attributeRules[rule]?.values\n let result\n\n attributes.forEach((currentKey) => {\n const found = attributeRule?.[currentKey.value]\n if (found) result = { id: currentKey.value, name: rule, ...found }\n })\n\n return (result as unknown) as {\n id: string\n name: string\n label: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n }\n\n function getVariantById(id: string) {\n return variants?.[id]\n }\n\n function getVariantByAttribute(key: string) {\n const id = combinations[key]?.value\n return variants?.[id]\n }\n\n function getVariantByCombination(key: string, value: string) {\n const id = combinations[key]?.params[value]\n return variants?.[id]\n }\n\n function getCustomFieldValue(field: string) {\n return customFields?.[field]\n }\n\n function getCombinationsForAttributeRule(key: string, id: string) {\n const result = attributeRules?.[key]?.values?.[id]\n return result\n }\n\n const state = {\n metaData,\n seoData,\n variants,\n selectedVariant,\n attributeRules,\n }\n\n const functions = {\n getVariantById,\n getVariantByAttribute,\n getVariantByCombination,\n selectVariantById,\n selectVariantByAttribute,\n selectVariantByCombination,\n getCombinationsForAttributeRule,\n selectVariantOptions,\n getCustomFieldValue,\n getProductVideos: () => getProductVideos(metaData.assets),\n }\n\n return (\n <ProductStateContext.Provider value={state}>\n <CountDispatchContext.Provider value={functions}>\n {children}\n </CountDispatchContext.Provider>\n </ProductStateContext.Provider>\n )\n}\n\nexport function useProductState() {\n const context = React.useContext(ProductStateContext)\n if (context === undefined) {\n throw new Error('useProductState must be used within a ProductProvider')\n }\n return context\n}\nexport function useProductFunctions() {\n const context = React.useContext(CountDispatchContext)\n if (context === undefined) {\n throw new Error('useProductDispatch must be used within a ProductProvider')\n }\n return context\n}\n\nexport function useProduct(slug: string, config?: getProductBySlugConfig) {\n return productsApi.useProduct(slug, config)\n}\n"],"file":"index.js"}
|
@@ -259,14 +259,31 @@ var getProductVideos = function getProductVideos(assets) {
|
|
259
259
|
exports.getProductVideos = getProductVideos;
|
260
260
|
|
261
261
|
var formatCategories = function formatCategories(categories, rootCategoryId) {
|
262
|
-
var
|
263
|
-
var _cat$resource, _cat$resource$ancesto;
|
262
|
+
var _results;
|
264
263
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
264
|
+
var results;
|
265
|
+
|
266
|
+
if (categories != null && categories.some(function (cat) {
|
267
|
+
return cat.resource.custom.some(function (customField) {
|
268
|
+
return customField.field === 'isTemporary';
|
269
|
+
});
|
270
|
+
})) {
|
271
|
+
results = categories == null ? void 0 : categories.filter(function (cat) {
|
272
|
+
return cat.resource.custom.some(function (customField) {
|
273
|
+
return customField.field === 'isTemporary' ? !customField.value : true;
|
274
|
+
});
|
275
|
+
});
|
276
|
+
} else {
|
277
|
+
results = categories == null ? void 0 : categories.filter(function (cat) {
|
278
|
+
var _cat$resource, _cat$resource$ancesto;
|
279
|
+
|
280
|
+
return (cat == null ? void 0 : cat.resourceId) === rootCategoryId || (cat == null ? void 0 : (_cat$resource = cat.resource) == null ? void 0 : (_cat$resource$ancesto = _cat$resource.ancestors) == null ? void 0 : _cat$resource$ancesto.some(function (ancestor) {
|
281
|
+
return ancestor.resource === rootCategoryId;
|
282
|
+
}));
|
283
|
+
});
|
284
|
+
}
|
285
|
+
|
286
|
+
var formattedResults = (_results = results) == null ? void 0 : _results.map(function (category) {
|
270
287
|
if (category.resource) {
|
271
288
|
var resource = category.resource;
|
272
289
|
return {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../src/hooks/useProduct/utils/index.ts"],"names":["createCustomFieldsMap","customFields","reduce","map","currentObj","field","value","createCombinationsMap","mappedAttributeRulesKeys","attributesArray","combinationsMap","forEach","key","p","currentKey","attributes","find","x","name","filtered","filter","currentCombination","params","variantId","attribute","assignCombinationsToAttributeRules","mappedAttributeRules","Object","keys","current","values","combinations","createProductContent","data","label","content","createAttributeRulesMap","product","uniqueRules","attributeRules","constraint","AttributeRuleDTOConstraintEnum","CombinationUnique","reduceVariantsToAttributeRuleValues","found","attributeName","valueData","extra","variants","v","flat","createMappedOptions","options","mappedOptions","currentOption","definitionKey","elements","subOption","optionKey","imageIndex","createSelectedOption2","selectedOption","availableOption","element","createSelectedOption","optionValue","createMappedAttributes","currentVariant","mappedAttributes","attributeArray","push","processAvailabilityPerStore","availabilities","isPhysical","acceptsBackorders","stockLocationName","restockableInDays","availableQuantity","storeName","getProductVideos","assets","youtube","videos","sources","a","embeded","type","source","url","iframe","thumb","thumbnail","formatCategories","categories","rootCategoryId","results","cat","resourceId","resource","ancestors","some","ancestor","formattedResults","category","id","link","slug","_id","createLabelsMap","now","Date","getTime","currentLabels","el","validFrom","validTo"],"mappings":";;;;;;;;;AAAA;;AAuBA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEO,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,YAAD,EAAkC;AACrE,SAAOA,YAAP,oBAAOA,YAAY,CAAEC,MAAd,CAAqB,UAACC,GAAD,EAAkBC,UAAlB,EAAiC;AAC3DD,IAAAA,GAAG,CAACC,UAAU,CAACC,KAAZ,CAAH,GAAwBD,UAAU,CAACE,KAAnC;AACA,WAAOH,GAAP;AACD,GAHM,EAGJ,EAHI,CAAP;AAID,CALM;;;;AAOA,IAAMI,qBAAqB,GAAG,SAAxBA,qBAAwB,CACnCC,wBADmC,EAEnCC,eAFmC,EAMhC;AACH,MAAMC,eAAgC,GAAG,EAAzC;AACAF,EAAAA,wBAAwB,CAACG,OAAzB,CAAiC,UAACC,GAAD,EAAS;AACxCH,IAAAA,eAAe,CAACE,OAAhB,CAAwB,UAACE,CAAD,EAAO;AAC7B,UAAMC,UAAU,GAAGD,CAAC,CAACE,UAAF,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AP,oBAAOA,aAAa,CAAE7G,GAAf,CAAmB,UAAC8G,EAAD;AAAA,WAAQA,EAAE,CAACrG,GAAX;AAAA,GAAnB,CAAP;AACD,CAbM","sourcesContent":["import {\n ProductAttributeDTO,\n CustomField,\n AttributeRuleDTOConstraintEnum,\n ProductDTO,\n ProductVariantDTO,\n InventoryAvailability,\n OptionDefinitionDTO,\n SelectedOptionDTO,\n IdReferenceDTO,\n CategoryDTO,\n ProductVariantLabelDTO,\n} from '@sentecacommerce/sdk'\n\nimport {\n AttributeRulesMap,\n CombinationsMap,\n BooleanKVP,\n InventoryAvailabilityType,\n MetaInformationType,\n OptionsType,\n} from '../index'\n\nimport { createEmbededVideo } from './createEmbededVideo'\n\nimport { getTranslatableField } from '../../../utils'\n\n// export const createMappedInventory = (\n// currentVariant: ProductVariantDraftDTO,\n// inventory?: SkuReservationResponseDTO\n// ) => {\n// const currentInventory = inventory?.find(\n// (x) => x.sku === currentVariant.sku\n// )\n\n// const mappedInventory = {\n// ...currentInventory,\n// status:\n// currentInventory?.status === SkuReservationDTOStatusEnum.Available\n// ? true\n// : false,\n// inventoryId: currentInventory?.inventoryReservations?.[0].inventoryId,\n// quantity: currentInventory?.inventoryReservations?.[0].quantity,\n// }\n\n// return mappedInventory\n// }\n\nexport const createCustomFieldsMap = (customFields?: CustomField[]) => {\n return customFields?.reduce((map: BooleanKVP, currentObj) => {\n map[currentObj.field] = currentObj.value\n return map\n }, {})\n}\n\nexport const createCombinationsMap = (\n mappedAttributeRulesKeys: string[],\n attributesArray: {\n variantId: string\n attributes: ProductAttributeDTO[]\n }[]\n) => {\n const combinationsMap: CombinationsMap = {}\n mappedAttributeRulesKeys.forEach((key) => {\n attributesArray.forEach((p) => {\n const currentKey = p.attributes.find((x) => x.name === key)\n const filtered = p.attributes.filter((x) => x.name !== key)\n\n let currentCombination = combinationsMap[currentKey?.value]\n\n if (!currentCombination) {\n currentCombination = {\n params: {},\n value: '',\n }\n }\n\n currentCombination.value = p.variantId\n\n filtered.forEach((attribute) => {\n currentCombination.params = {\n ...currentCombination.params,\n [attribute.value]: p.variantId,\n }\n })\n\n combinationsMap[currentKey?.value] = currentCombination\n })\n })\n\n return combinationsMap\n}\n\nexport const assignCombinationsToAttributeRules = (\n mappedAttributeRules: AttributeRulesMap,\n combinationsMap: CombinationsMap\n) => {\n Object.keys(mappedAttributeRules).forEach((key) => {\n const current = mappedAttributeRules[key].values\n Object.keys(current).forEach((currentKey) => {\n mappedAttributeRules[key].values[currentKey].combinations =\n combinationsMap[currentKey]?.params\n })\n })\n}\n\nexport const createProductContent = (\n data: any\n): { key: string; name: string; content: string } => {\n return {\n key: data.key,\n name: getTranslatableField(data.label),\n content: getTranslatableField(data.content),\n }\n}\n\nexport const createAttributeRulesMap = (product?: ProductDTO) => {\n const uniqueRules = product?.attributeRules?.filter(\n (x) => x.constraint === AttributeRuleDTOConstraintEnum.CombinationUnique\n )\n const reduceVariantsToAttributeRuleValues = (map: any, attribute: any) => {\n const found = uniqueRules?.find((x) => x.attributeName === attribute.name)\n if (found) {\n if (!map[attribute.name]) {\n map[attribute.name] = {\n ...found,\n label: getTranslatableField(attribute.data.label),\n values: {},\n }\n }\n\n map[attribute.name] = {\n ...map[attribute.name],\n values: {\n ...map[attribute.name].values,\n [attribute.value]: {\n label: getTranslatableField(attribute.valueData.label),\n extra: attribute.valueData.extra,\n },\n },\n }\n }\n\n return map\n }\n\n const mappedAttributeRules = product?.variants\n ?.map((v) => v.attributes)\n .flat()\n .reduce(reduceVariantsToAttributeRuleValues, {})\n\n return mappedAttributeRules\n}\n\nexport const createMappedOptions = (\n options?: OptionDefinitionDTO[]\n): OptionsType[] => {\n const mappedOptions =\n options?.map((currentOption) => {\n return {\n definitionKey: currentOption.key,\n label: getTranslatableField(currentOption?.label),\n elements: currentOption.options?.map((subOption) => {\n return {\n optionKey: subOption.key,\n label: getTranslatableField(subOption?.label),\n imageIndex: subOption?.imageIndex,\n }\n }),\n }\n }) || []\n\n return mappedOptions\n}\n\nexport type SelectedOptionType = {\n label?: string\n value?: { key?: string; label?: string; imageIndex?: number }\n}\n\nexport const createSelectedOption2 = (\n options?: OptionsType[],\n selectedOption?: SelectedOptionDTO\n): SelectedOptionType => {\n const currentOption = options?.find(\n (availableOption) =>\n availableOption.definitionKey === selectedOption?.definitionKey\n )\n\n const value = currentOption?.elements?.find(\n (element) => element.optionKey === selectedOption?.optionKey\n )\n\n return {\n label: currentOption?.label,\n value: {\n key: value?.optionKey,\n imageIndex: value?.imageIndex,\n label: value?.label,\n },\n }\n}\n\nexport const createSelectedOption = (\n options?: OptionDefinitionDTO[],\n selectedOption?: SelectedOptionDTO\n): SelectedOptionType => {\n const currentOption = options?.find(\n (availableOption) => availableOption.key === selectedOption?.definitionKey\n )\n\n const value = currentOption?.options?.find(\n (optionValue) => optionValue.key === selectedOption?.optionKey\n )\n\n return {\n label: getTranslatableField(currentOption?.label),\n value: {\n key: value?.key,\n imageIndex: value?.imageIndex,\n label: getTranslatableField(value?.label),\n },\n }\n}\n\nexport const createMappedAttributes = (currentVariant: ProductVariantDTO) => {\n const mappedAttributes =\n currentVariant.attributes?.reduce(\n (attributeArray: ProductAttributeDTO[], attribute) => {\n attributeArray.push({\n name: attribute.name,\n value: attribute.value,\n valueData: attribute.valueData,\n })\n return attributeArray\n },\n []\n ) || []\n\n return mappedAttributes\n}\n\nexport const processAvailabilityPerStore = (\n availabilities?: InventoryAvailability[]\n): InventoryAvailabilityType[] | undefined => {\n return availabilities\n ?.filter((x) => !x.isPhysical)\n ?.map(\n ({\n acceptsBackorders,\n stockLocationName,\n restockableInDays,\n availableQuantity,\n }) => {\n return {\n storeName: getTranslatableField(stockLocationName),\n availableQuantity,\n acceptsBackorders,\n restockableInDays: restockableInDays,\n }\n }\n )\n}\n\nexport const getProductVideos = (assets: MetaInformationType['assets']) => {\n if (assets?.youtube) {\n const videos = assets.youtube.sources.map((a) => {\n const embeded = createEmbededVideo(a)\n return {\n type: 'video',\n source: a.url,\n iframe: embeded.iframe,\n thumb: { url: embeded.thumbnail },\n }\n })\n\n return videos\n }\n return []\n}\n\nexport const formatCategories = (\n categories?: IdReferenceDTO[],\n rootCategoryId?: string\n) => {\n const results = categories?.filter(\n (cat) =>\n cat?.resourceId === rootCategoryId ||\n cat?.resource?.ancestors?.some(\n (ancestor: any) => ancestor.resource === rootCategoryId\n )\n )\n\n const formattedResults = results?.map((category) => {\n if (category.resource) {\n const resource = category.resource as CategoryDTO\n\n return {\n name: getTranslatableField(resource.name),\n id: category.resourceId || '',\n link: `/${getTranslatableField(resource.slug)}/c`,\n }\n }\n\n const cat = (category as unknown) as CategoryDTO\n\n return {\n name: getTranslatableField(cat.name),\n id: cat._id || '',\n link: `/${getTranslatableField(cat.slug)}/c`,\n }\n })\n\n return formattedResults || []\n}\n\nexport const createLabelsMap = (data?: ProductVariantLabelDTO[]) => {\n // Filter only labels that are currently active\n const now = new Date().getTime()\n\n const currentLabels = data?.filter((el) => {\n if (!el.validFrom || !el.validTo) {\n return el\n } else {\n return el.validFrom < now && el.validTo > now\n }\n })\n\n return currentLabels?.map((el) => el.key)\n}\n"],"file":"index.js"}
|
1
|
+
{"version":3,"sources":["../../../../../src/hooks/useProduct/utils/index.ts"],"names":["createCustomFieldsMap","customFields","reduce","map","currentObj","field","value","createCombinationsMap","mappedAttributeRulesKeys","attributesArray","combinationsMap","forEach","key","p","currentKey","attributes","find","x","name","filtered","filter","currentCombination","params","variantId","attribute","assignCombinationsToAttributeRules","mappedAttributeRules","Object","keys","current","values","combinations","createProductContent","data","label","content","createAttributeRulesMap","product","uniqueRules","attributeRules","constraint","AttributeRuleDTOConstraintEnum","CombinationUnique","reduceVariantsToAttributeRuleValues","found","attributeName","valueData","extra","variants","v","flat","createMappedOptions","options","mappedOptions","currentOption","definitionKey","elements","subOption","optionKey","imageIndex","createSelectedOption2","selectedOption","availableOption","element","createSelectedOption","optionValue","createMappedAttributes","currentVariant","mappedAttributes","attributeArray","push","processAvailabilityPerStore","availabilities","isPhysical","acceptsBackorders","stockLocationName","restockableInDays","availableQuantity","storeName","getProductVideos","assets","youtube","videos","sources","a","embeded","type","source","url","iframe","thumb","thumbnail","formatCategories","categories","rootCategoryId","results","some","cat","resource","custom","customField","resourceId","ancestors","ancestor","formattedResults","category","id","link","slug","_id","createLabelsMap","now","Date","getTime","currentLabels","el","validFrom","validTo"],"mappings":";;;;;;;;;AAAA;;AAuBA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEO,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,YAAD,EAAkC;AACrE,SAAOA,YAAP,oBAAOA,YAAY,CAAEC,MAAd,CAAqB,UAACC,GAAD,EAAkBC,UAAlB,EAAiC;AAC3DD,IAAAA,GAAG,CAACC,UAAU,CAACC,KAAZ,CAAH,GAAwBD,UAAU,CAACE,KAAnC;AACA,WAAOH,GAAP;AACD,GAHM,EAGJ,EAHI,CAAP;AAID,CALM;;;;AAOA,IAAMI,qBAAqB,GAAG,SAAxBA,qBAAwB,CACnCC,wBADmC,EAEnCC,eAFmC,EAMhC;AACH,MAAMC,eAAgC,GAAG,EAAzC;AACAF,EAAAA,wBAAwB,CAACG,OAAzB,CAAiC,UAACC,GAAD,EAAS;AACxCH,IAAAA,eAAe,CAACE,OAAhB,CAAwB,UAACE,CAAD,EAAO;AAC7B,UAAMC,UAAU,GAAGD,CAAC,CAACE,UAAF,CAAaC,IAAb,CAAkB,UAACC,CAAD;AAAA,eAAOA,CAAC,CAACC,IAAF,KAAWN,GAAlB;AAAA,OAAlB,CAAnB;AACA,UAAMO,QAAQ,GAAGN,CAAC,CAACE,UAAF,CAAaK,MAAb,CAAoB,UAACH,CAAD;AAAA,eAAOA,CAAC,CAACC,IAAF,KAAWN,GAAlB;AAAA,OAApB,CAAjB;AAEA,UAAIS,kBAAkB,GAAGX,eAAe,CAACI,UAAD,oBAACA,UAAU,CAAER,KAAb,CAAxC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a,UAAC+F,EAAD,EAAQ;AACzC,QAAI,CAACA,EAAE,CAACC,SAAJ,IAAiB,CAACD,EAAE,CAACE,OAAzB,EAAkC;AAChC,aAAOF,EAAP;AACD,KAFD,MAEO;AACL,aAAOA,EAAE,CAACC,SAAH,GAAeL,GAAf,IAAsBI,EAAE,CAACE,OAAH,GAAaN,GAA1C;AACD;AACF,GANqB,CAAtB;AAQA,SAAOG,aAAP,oBAAOA,aAAa,CAAE/G,GAAf,CAAmB,UAACgH,EAAD;AAAA,WAAQA,EAAE,CAACvG,GAAX;AAAA,GAAnB,CAAP;AACD,CAbM","sourcesContent":["import {\n ProductAttributeDTO,\n CustomField,\n AttributeRuleDTOConstraintEnum,\n ProductDTO,\n ProductVariantDTO,\n InventoryAvailability,\n OptionDefinitionDTO,\n SelectedOptionDTO,\n IdReferenceDTO,\n CategoryDTO,\n ProductVariantLabelDTO,\n} from '@sentecacommerce/sdk'\n\nimport {\n AttributeRulesMap,\n CombinationsMap,\n BooleanKVP,\n InventoryAvailabilityType,\n MetaInformationType,\n OptionsType,\n} from '../index'\n\nimport { createEmbededVideo } from './createEmbededVideo'\n\nimport { getTranslatableField } from '../../../utils'\n\n// export const createMappedInventory = (\n// currentVariant: ProductVariantDraftDTO,\n// inventory?: SkuReservationResponseDTO\n// ) => {\n// const currentInventory = inventory?.find(\n// (x) => x.sku === currentVariant.sku\n// )\n\n// const mappedInventory = {\n// ...currentInventory,\n// status:\n// currentInventory?.status === SkuReservationDTOStatusEnum.Available\n// ? true\n// : false,\n// inventoryId: currentInventory?.inventoryReservations?.[0].inventoryId,\n// quantity: currentInventory?.inventoryReservations?.[0].quantity,\n// }\n\n// return mappedInventory\n// }\n\nexport const createCustomFieldsMap = (customFields?: CustomField[]) => {\n return customFields?.reduce((map: BooleanKVP, currentObj) => {\n map[currentObj.field] = currentObj.value\n return map\n }, {})\n}\n\nexport const createCombinationsMap = (\n mappedAttributeRulesKeys: string[],\n attributesArray: {\n variantId: string\n attributes: ProductAttributeDTO[]\n }[]\n) => {\n const combinationsMap: CombinationsMap = {}\n mappedAttributeRulesKeys.forEach((key) => {\n attributesArray.forEach((p) => {\n const currentKey = p.attributes.find((x) => x.name === key)\n const filtered = p.attributes.filter((x) => x.name !== key)\n\n let currentCombination = combinationsMap[currentKey?.value]\n\n if (!currentCombination) {\n currentCombination = {\n params: {},\n value: '',\n }\n }\n\n currentCombination.value = p.variantId\n\n filtered.forEach((attribute) => {\n currentCombination.params = {\n ...currentCombination.params,\n [attribute.value]: p.variantId,\n }\n })\n\n combinationsMap[currentKey?.value] = currentCombination\n })\n })\n\n return combinationsMap\n}\n\nexport const assignCombinationsToAttributeRules = (\n mappedAttributeRules: AttributeRulesMap,\n combinationsMap: CombinationsMap\n) => {\n Object.keys(mappedAttributeRules).forEach((key) => {\n const current = mappedAttributeRules[key].values\n Object.keys(current).forEach((currentKey) => {\n mappedAttributeRules[key].values[currentKey].combinations =\n combinationsMap[currentKey]?.params\n })\n })\n}\n\nexport const createProductContent = (\n data: any\n): { key: string; name: string; content: string } => {\n return {\n key: data.key,\n name: getTranslatableField(data.label),\n content: getTranslatableField(data.content),\n }\n}\n\nexport const createAttributeRulesMap = (product?: ProductDTO) => {\n const uniqueRules = product?.attributeRules?.filter(\n (x) => x.constraint === AttributeRuleDTOConstraintEnum.CombinationUnique\n )\n const reduceVariantsToAttributeRuleValues = (map: any, attribute: any) => {\n const found = uniqueRules?.find((x) => x.attributeName === attribute.name)\n if (found) {\n if (!map[attribute.name]) {\n map[attribute.name] = {\n ...found,\n label: getTranslatableField(attribute.data.label),\n values: {},\n }\n }\n\n map[attribute.name] = {\n ...map[attribute.name],\n values: {\n ...map[attribute.name].values,\n [attribute.value]: {\n label: getTranslatableField(attribute.valueData.label),\n extra: attribute.valueData.extra,\n },\n },\n }\n }\n\n return map\n }\n\n const mappedAttributeRules = product?.variants\n ?.map((v) => v.attributes)\n .flat()\n .reduce(reduceVariantsToAttributeRuleValues, {})\n\n return mappedAttributeRules\n}\n\nexport const createMappedOptions = (\n options?: OptionDefinitionDTO[]\n): OptionsType[] => {\n const mappedOptions =\n options?.map((currentOption) => {\n return {\n definitionKey: currentOption.key,\n label: getTranslatableField(currentOption?.label),\n elements: currentOption.options?.map((subOption) => {\n return {\n optionKey: subOption.key,\n label: getTranslatableField(subOption?.label),\n imageIndex: subOption?.imageIndex,\n }\n }),\n }\n }) || []\n\n return mappedOptions\n}\n\nexport type SelectedOptionType = {\n label?: string\n value?: { key?: string; label?: string; imageIndex?: number }\n}\n\nexport const createSelectedOption2 = (\n options?: OptionsType[],\n selectedOption?: SelectedOptionDTO\n): SelectedOptionType => {\n const currentOption = options?.find(\n (availableOption) =>\n availableOption.definitionKey === selectedOption?.definitionKey\n )\n\n const value = currentOption?.elements?.find(\n (element) => element.optionKey === selectedOption?.optionKey\n )\n\n return {\n label: currentOption?.label,\n value: {\n key: value?.optionKey,\n imageIndex: value?.imageIndex,\n label: value?.label,\n },\n }\n}\n\nexport const createSelectedOption = (\n options?: OptionDefinitionDTO[],\n selectedOption?: SelectedOptionDTO\n): SelectedOptionType => {\n const currentOption = options?.find(\n (availableOption) => availableOption.key === selectedOption?.definitionKey\n )\n\n const value = currentOption?.options?.find(\n (optionValue) => optionValue.key === selectedOption?.optionKey\n )\n\n return {\n label: getTranslatableField(currentOption?.label),\n value: {\n key: value?.key,\n imageIndex: value?.imageIndex,\n label: getTranslatableField(value?.label),\n },\n }\n}\n\nexport const createMappedAttributes = (currentVariant: ProductVariantDTO) => {\n const mappedAttributes =\n currentVariant.attributes?.reduce(\n (attributeArray: ProductAttributeDTO[], attribute) => {\n attributeArray.push({\n name: attribute.name,\n value: attribute.value,\n valueData: attribute.valueData,\n })\n return attributeArray\n },\n []\n ) || []\n\n return mappedAttributes\n}\n\nexport const processAvailabilityPerStore = (\n availabilities?: InventoryAvailability[]\n): InventoryAvailabilityType[] | undefined => {\n return availabilities\n ?.filter((x) => !x.isPhysical)\n ?.map(\n ({\n acceptsBackorders,\n stockLocationName,\n restockableInDays,\n availableQuantity,\n }) => {\n return {\n storeName: getTranslatableField(stockLocationName),\n availableQuantity,\n acceptsBackorders,\n restockableInDays: restockableInDays,\n }\n }\n )\n}\n\nexport const getProductVideos = (assets: MetaInformationType['assets']) => {\n if (assets?.youtube) {\n const videos = assets.youtube.sources.map((a) => {\n const embeded = createEmbededVideo(a)\n return {\n type: 'video',\n source: a.url,\n iframe: embeded.iframe,\n thumb: { url: embeded.thumbnail },\n }\n })\n\n return videos\n }\n return []\n}\n\nexport const formatCategories = (\n categories?: IdReferenceDTO[],\n rootCategoryId?: string\n) => {\n let results\n\n if (\n categories?.some((cat) =>\n cat.resource.custom.some(\n (customField: any) => customField.field === 'isTemporary'\n )\n )\n ) {\n results = categories?.filter((cat) =>\n cat.resource.custom.some((customField: any) =>\n customField.field === 'isTemporary' ? !customField.value : true\n )\n )\n } else {\n results = categories?.filter(\n (cat) =>\n cat?.resourceId === rootCategoryId ||\n cat?.resource?.ancestors?.some(\n (ancestor: any) => ancestor.resource === rootCategoryId\n )\n )\n }\n\n const formattedResults = results?.map((category) => {\n if (category.resource) {\n const resource = category.resource as CategoryDTO\n\n return {\n name: getTranslatableField(resource.name),\n id: category.resourceId || '',\n link: `/${getTranslatableField(resource.slug)}/c`,\n }\n }\n\n const cat = (category as unknown) as CategoryDTO\n\n return {\n name: getTranslatableField(cat.name),\n id: cat._id || '',\n link: `/${getTranslatableField(cat.slug)}/c`,\n }\n })\n\n return formattedResults || []\n}\n\nexport const createLabelsMap = (data?: ProductVariantLabelDTO[]) => {\n // Filter only labels that are currently active\n const now = new Date().getTime()\n\n const currentLabels = data?.filter((el) => {\n if (!el.validFrom || !el.validTo) {\n return el\n } else {\n return el.validFrom < now && el.validTo > now\n }\n })\n\n return currentLabels?.map((el) => el.key)\n}\n"],"file":"index.js"}
|
@@ -14,15 +14,24 @@ export var usePixelProductDetails = () => {
|
|
14
14
|
|
15
15
|
var pixel = (_window = window) == null ? void 0 : _window.pixel;
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
var sendProductDetails = () => {
|
18
|
+
if (!window.document.title || window.document.title === 'за') {
|
19
|
+
setTimeout(() => sendProductDetails(), 20);
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
|
23
|
+
if (metaData._id && selectedVariant != null && selectedVariant.sku && !sentData) {
|
24
|
+
pixel == null ? void 0 : pixel.productDetails({
|
25
|
+
id: metaData._id,
|
26
|
+
sku: selectedVariant == null ? void 0 : selectedVariant.sku
|
27
|
+
}, {
|
28
|
+
merchantKey: defaultMerchant
|
29
|
+
});
|
30
|
+
setSentData.on();
|
31
|
+
}
|
32
|
+
};
|
33
|
+
|
34
|
+
sendProductDetails();
|
26
35
|
}, [metaData._id, selectedVariant == null ? void 0 : selectedVariant.sku]);
|
27
36
|
};
|
28
37
|
//# sourceMappingURL=usePixelProductDetails.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../src/analytics/Pixel/hooks/usePixelProductDetails.tsx"],"names":["React","useConfigState","useProductState","useBoolean","usePixelProductDetails","sentData","setSentData","defaultMerchant","metaData","selectedVariant","useEffect","pixel","window","_id","sku","productDetails","id","merchantKey","on"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,cAAT,EAAyBC,eAAzB,EAA0CC,UAA1C,QAA4D,gBAA5D;AAEA,OAAO,IAAMC,sBAAsB,GAAG,MAAM;AAC1C,MAAM,CAACC,QAAD,EAAWC,WAAX,IAA0BH,UAAU,EAA1C;AACA,MAAM;AAAEI,IAAAA;AAAF,MAAsBN,cAAc,EAA1C;AACA,MAAM;AAAEO,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAAgCP,eAAe,EAArD;AAEAF,EAAAA,KAAK,CAACU,SAAN,CAAgB,MAAM;AAAA;;AACpB,QAAMC,KAAK,cAAIC,MAAJ,qBAAG,QAAiBD,KAA/B;;AACA,
|
1
|
+
{"version":3,"sources":["../../../../../src/analytics/Pixel/hooks/usePixelProductDetails.tsx"],"names":["React","useConfigState","useProductState","useBoolean","usePixelProductDetails","sentData","setSentData","defaultMerchant","metaData","selectedVariant","useEffect","pixel","window","sendProductDetails","document","title","setTimeout","_id","sku","productDetails","id","merchantKey","on"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,cAAT,EAAyBC,eAAzB,EAA0CC,UAA1C,QAA4D,gBAA5D;AAEA,OAAO,IAAMC,sBAAsB,GAAG,MAAM;AAC1C,MAAM,CAACC,QAAD,EAAWC,WAAX,IAA0BH,UAAU,EAA1C;AACA,MAAM;AAAEI,IAAAA;AAAF,MAAsBN,cAAc,EAA1C;AACA,MAAM;AAAEO,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAAgCP,eAAe,EAArD;AAEAF,EAAAA,KAAK,CAACU,SAAN,CAAgB,MAAM;AAAA;;AACpB,QAAMC,KAAK,cAAIC,MAAJ,qBAAG,QAAiBD,KAA/B;;AAEA,QAAME,kBAAkB,GAAG,MAAM;AAC/B,UAAI,CAACD,MAAM,CAACE,QAAP,CAAgBC,KAAjB,IAA0BH,MAAM,CAACE,QAAP,CAAgBC,KAAhB,KAA0B,IAAxD,EAA8D;AAC5DC,QAAAA,UAAU,CAAC,MAAMH,kBAAkB,EAAzB,EAA6B,EAA7B,CAAV;AACA;AACD;;AACD,UAAIL,QAAQ,CAACS,GAAT,IAAgBR,eAAhB,YAAgBA,eAAe,CAAES,GAAjC,IAAwC,CAACb,QAA7C,EAAuD;AACnDM,QAAAA,KAAK,QAAL,YAAAA,KAAK,CAAEQ,cAAP,CACE;AACEC,UAAAA,EAAE,EAAEZ,QAAQ,CAACS,GADf;AAEEC,UAAAA,GAAG,EAAET,eAAF,oBAAEA,eAAe,CAAES;AAFxB,SADF,EAKE;AACEG,UAAAA,WAAW,EAAEd;AADf,SALF;AASFD,QAAAA,WAAW,CAACgB,EAAZ;AACD;AACF,KAjBD;;AAmBAT,IAAAA,kBAAkB;AACnB,GAvBD,EAuBG,CAACL,QAAQ,CAACS,GAAV,EAAeR,eAAf,oBAAeA,eAAe,CAAES,GAAhC,CAvBH;AAwBD,CA7BM","sourcesContent":["import React from 'react'\nimport { useConfigState, useProductState, useBoolean } from '../../../index'\n\nexport const usePixelProductDetails = () => {\n const [sentData, setSentData] = useBoolean()\n const { defaultMerchant } = useConfigState()\n const { metaData, selectedVariant } = useProductState()\n\n React.useEffect(() => {\n const pixel = (window as any)?.pixel\n\n const sendProductDetails = () => {\n if (!window.document.title || window.document.title === 'за') {\n setTimeout(() => sendProductDetails(), 20)\n return\n }\n if (metaData._id && selectedVariant?.sku && !sentData) {\n pixel?.productDetails(\n {\n id: metaData._id as string,\n sku: selectedVariant?.sku as string,\n },\n {\n merchantKey: defaultMerchant,\n }\n )\n setSentData.on()\n }\n }\n\n sendProductDetails()\n }, [metaData._id, selectedVariant?.sku])\n}\n"],"file":"usePixelProductDetails.js"}
|
@@ -25,12 +25,22 @@ export var usePixelProductsImpression = (_ref) => {
|
|
25
25
|
|
26
26
|
if (typeof window !== undefined && !((_productsData$product = productsData.products) != null && (_productsData$product2 = _productsData$product[0]) != null && _productsData$product2.isPlaceholder) && (productsData == null ? void 0 : productsData.length) > 0) {
|
27
27
|
var pixel = window.pixel;
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
|
29
|
+
var sendImpressions = () => {
|
30
|
+
if (!window.document.title || window.document.title === 'за') {
|
31
|
+
setTimeout(() => sendImpressions(), 20);
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
|
35
|
+
pixel == null ? void 0 : pixel.productsImpression(!isCarousel ? [{
|
36
|
+
listName: PageTypeMap[router.route],
|
37
|
+
products
|
38
|
+
}] : productsData, {
|
39
|
+
merchantKey: defaultMerchant
|
40
|
+
});
|
41
|
+
};
|
42
|
+
|
43
|
+
sendImpressions();
|
34
44
|
setSentAlready.on();
|
35
45
|
}
|
36
46
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../src/analytics/Pixel/hooks/usePixelProductsImpression.tsx"],"names":["React","useRouter","useConfigState","useBoolean","createMappedProducts","PageTypeMap","usePixelProductsImpression","productsData","isCarousel","sentAlready","setSentAlready","defaultMerchant","router","products","useEffect","events","on","window","undefined","isPlaceholder","length","pixel","productsImpression","listName","route","merchantKey"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,SAAT,QAA0B,aAA1B;AACA,SAASC,cAAT,EAAyBC,UAAzB,QAA2C,gBAA3C;AAEA,SAASC,oBAAT,EAA+BC,WAA/B,QAAkD,cAAlD;AAEA,OAAO,IAAMC,0BAA0B,GAAG,UAMpC;AAAA,MANqC;AACzCC,IAAAA,YADyC;AAEzCC,IAAAA;AAFyC,GAMrC;AACJ,MAAM,CAACC,WAAD,EAAcC,cAAd,IAAgCP,UAAU,CAAC,KAAD,CAAhD;AACA,MAAM;AAAEQ,IAAAA;AAAF,MAAsBT,cAAc,EAA1C;AACA,MAAMU,MAAM,GAAGX,SAAS,EAAxB;AAEA,MAAIY,QAAuB,GAAG,EAA9B;;AAEA,MAAI,CAACL,UAAL,EAAiB;AACfK,IAAAA,QAAQ,GAAGT,oBAAoB,CAACG,YAAY,CAACM,QAAd,CAA/B;AACD;;AAEDb,EAAAA,KAAK,CAACc,SAAN,CAAgB,MAAM;AACpB,QAAIL,WAAJ,EAAiB;
|
1
|
+
{"version":3,"sources":["../../../../../src/analytics/Pixel/hooks/usePixelProductsImpression.tsx"],"names":["React","useRouter","useConfigState","useBoolean","createMappedProducts","PageTypeMap","usePixelProductsImpression","productsData","isCarousel","sentAlready","setSentAlready","defaultMerchant","router","products","useEffect","events","on","window","undefined","isPlaceholder","length","pixel","sendImpressions","document","title","setTimeout","productsImpression","listName","route","merchantKey"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,SAAT,QAA0B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AEmB,YAAAA,QAAQ,EAAEtB,WAAW,CAACO,MAAM,CAACgB,KAAR,CAAvB;AAAuCf,YAAAA;AAAvC,WAAD,CADJ,GAEIN,YAHN,EAIE;AACEsB,YAAAA,WAAW,EAAElB;AADf,WAJF;AAQD,SAbD;;AAcAW,QAAAA,eAAe;AACfZ,QAAAA,cAAc,CAACM,EAAf;AACD;AACF,KAzBD;AA0BD,GA7BD,EA6BG,CAACJ,MAAM,CAACgB,KAAR,CA7BH;AA8BD,CA/CM","sourcesContent":["import React from 'react'\nimport { useRouter } from 'next/router'\nimport { useConfigState, useBoolean } from '../../../index'\nimport { ProductType } from '../types'\nimport { createMappedProducts, PageTypeMap } from '../../Releva'\n\nexport const usePixelProductsImpression = ({\n productsData,\n isCarousel,\n}: {\n productsData: any\n isCarousel?: boolean\n}) => {\n const [sentAlready, setSentAlready] = useBoolean(false)\n const { defaultMerchant } = useConfigState()\n const router = useRouter()\n\n let products: ProductType[] = []\n\n if (!isCarousel) {\n products = createMappedProducts(productsData.products)\n }\n\n React.useEffect(() => {\n if (sentAlready) return\n\n router.events.on('routeChangeComplete', () => {\n if (\n typeof window !== undefined &&\n !productsData.products?.[0]?.isPlaceholder &&\n productsData?.length > 0\n ) {\n const pixel = (window as any).pixel\n\n const sendImpressions = () => {\n if (!window.document.title || window.document.title === 'за') {\n setTimeout(() => sendImpressions(), 20)\n return\n }\n pixel?.productsImpression(\n !isCarousel\n ? [{ listName: PageTypeMap[router.route], products }]\n : productsData,\n {\n merchantKey: defaultMerchant,\n }\n )\n }\n sendImpressions()\n setSentAlready.on()\n }\n })\n }, [router.route])\n}\n"],"file":"usePixelProductsImpression.js"}
|
@@ -1,13 +1,19 @@
|
|
1
1
|
import Router from 'next/router';
|
2
2
|
import { useConfigState } from '../../index';
|
3
3
|
import { getBasketId } from '../Releva/utils';
|
4
|
-
import { PageTypeMap } from '../Releva/types';
|
5
4
|
export var pixelChangeRoute = () => {
|
6
5
|
if (typeof window !== undefined) {
|
7
6
|
var pixel = window.pixel;
|
8
|
-
|
7
|
+
var title = window.document.title;
|
8
|
+
|
9
|
+
if (!title || title === 'за') {
|
10
|
+
setTimeout(() => pixelChangeRoute(), 20);
|
11
|
+
return;
|
12
|
+
}
|
13
|
+
|
14
|
+
return pixel == null ? void 0 : pixel.changeRoute({
|
9
15
|
path: Router.router.asPath,
|
10
|
-
title:
|
16
|
+
title: title || 'Error',
|
11
17
|
location: window.location.href
|
12
18
|
});
|
13
19
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/analytics/Pixel/usePixel.tsx"],"names":["Router","useConfigState","getBasketId","
|
1
|
+
{"version":3,"sources":["../../../../src/analytics/Pixel/usePixel.tsx"],"names":["Router","useConfigState","getBasketId","pixelChangeRoute","window","undefined","pixel","title","document","setTimeout","changeRoute","path","router","asPath","location","href","usePixel","defaultMerchant","orderId","pixelAddLineItem","product","currencyCode","addLineItem","merchantKey","pixelRemoveLineItem","removeLineItem","pixelCheckoutStep","stepNumber","checkoutStep","pixelCheckoutStepOption","option","checkoutStepOption","pixelPurchase","purchase"],"mappings":"AACA,OAAOA,MAAP,MAAmB,aAAnB;AACA,SAASC,cAAT,QAA+B,aAA/B;AACA,SAASC,WAAT,QAA4B,iBAA5B;AAGA,OAAO,IAAMC,gBAAgB,GAAG,MAAY;AAC1C,MAAI,OAAOC,MAAP,KAAkBC,SAAtB,EAAiC;AAC/B,QAAMC,KAAK,GAAIF,MAAD,CAAgBE,KAA9B;AAEA,QAAMC,KAAK,GAAGH,MAAM,CAACI,QAAP,CAAgBD,KAA9B;;AAEA,QAAI,CAACA,KAAD,IAAUA,KAAK,KAAK,IAAxB,EAA8B;AAC5BE,MAAAA,UAAU,CAAC,MAAMN,gBAAgB,EAAvB,EAA2B,EAA3B,CAAV;AACA;AACD;;AAED,WAAOG,KAAP,oBAAOA,KAAK,CAAEI,WAAP,CAAmB;AACxBC,MAAAA,IAAI,EAAEX,MAAM,CAACY,MAAP,CAAeC,MADG;A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B,KAAJ,EAAWA,KAAK,QAAL,YAAAA,KAAK,CAAE2B,QAAP,CAAgBf,OAAhB;AACZ,GAFD;;AAIA,SAAO;AACLC,IAAAA,gBADK;AAELK,IAAAA,mBAFK;AAGLE,IAAAA,iBAHK;AAILG,IAAAA,uBAJK;AAKLG,IAAAA;AALK,GAAP;AAOD,CAlDM","sourcesContent":["import React from 'react'\nimport Router from 'next/router'\nimport { useConfigState } from '../../index'\nimport { getBasketId } from '../Releva/utils'\nimport { ProductType } from './types'\n\nexport const pixelChangeRoute = (): void => {\n if (typeof window !== undefined) {\n const pixel = (window as any).pixel\n\n const title = window.document.title\n\n if (!title || title === 'за') {\n setTimeout(() => pixelChangeRoute(), 20)\n return\n }\n\n return pixel?.changeRoute({\n path: Router.router!.asPath,\n title: title || 'Error',\n location: window.location.href,\n })\n }\n}\n\nexport const usePixel = () => {\n const pixel = (window as any).pixel\n const { defaultMerchant } = useConfigState()\n const orderId = getBasketId()\n\n const pixelAddLineItem = ({\n product,\n currencyCode,\n }: {\n product: ProductType\n currencyCode: string\n }) => {\n pixel?.addLineItem(product, {\n currencyCode,\n merchantKey: defaultMerchant,\n })\n }\n\n const pixelRemoveLineItem = ({\n product,\n currencyCode,\n }: {\n product: ProductType\n currencyCode: string\n }) => {\n pixel?.removeLineItem(product, {\n currencyCode,\n merchantKey: defaultMerchant,\n })\n }\n\n const pixelCheckoutStep = (stepNumber: number) => {\n if (pixel) pixel?.checkoutStep(orderId, stepNumber)\n }\n\n const pixelCheckoutStepOption = (stepNumber: number, option: string) => {\n if (pixel) pixel?.checkoutStepOption(orderId, stepNumber, option) // order id, stepNumber and the selected shipping or payment option\n }\n\n const pixelPurchase = () => {\n if (pixel) pixel?.purchase(orderId)\n }\n\n return {\n pixelAddLineItem,\n pixelRemoveLineItem,\n pixelCheckoutStep,\n pixelCheckoutStepOption,\n pixelPurchase,\n }\n}\n"],"file":"usePixel.js"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/hooks/useProduct/index.tsx"],"names":["React","getTranslatableField","assignCombinationsToAttributeRules","createCombinationsMap","createCustomFieldsMap","createProductContent","createAttributeRulesMap","createMappedAttributes","processAvailabilityPerStore","getProductVideos","createMappedOptions","createSelectedOption2","formatCategories","createLabelsMap","productsApi","assetsFieldsToMap","ProductStateContext","createContext","undefined","CountDispatchContext","ProductProvider","product","children","defaultVariantId","mounted","setMounted","useState","combinations","attributeRules","setCombinationsAndAttributeRules","getCombinationsAndAttributeRules","variants","setVariants","getVariantsWithInventory","selectedVariant","setSelectedVariant","getDefaultVariant","metaData","useMemo","rootCategory","categories","rootCategoryId","resourceId","metaObj","_id","name","slug","description","shortDescription","metaDescription","brand","brands","resource","logo","assets","sources","url","category","length","reviewRatingStatistics","content","Boolean","map","seoData","seoObj","title","metaTitle","keywords","metaKeywords","customFields","mappedFields","custom","useEffect","data","variantsWithInventory","reduce","_","index","arr","currentVariant","mappedAttributes","mappedOptions","availableOptions","isAvailable","inventorySnapshot","canOrder","updatedVariant","inventory","hasAvailableQuantity","availableQuantity","quantity","attributes","options","selectedOptions","labels","getAttribute","rule","getSelectedAttribute","getAttributeByKey","key","find","a","value","getAvailabilityByStore","availabilities","mappedAttributeRules","attributesWithId","Object","keys","variantId","combinationsMap","selectVariantById","id","selectVariantByAttribute","selectVariantByCombination","params","selectVariantOptions","definitionKey","optionKey","newSelectedVariant","filter","opt","mappedSelectedOptions","option","attributeRule","values","result","forEach","currentKey","found","getVariantById","getVariantByAttribute","getVariantByCombination","getCustomFieldValue","field","getCombinationsForAttributeRule","state","functions","useProductState","context","useContext","Error","useProductFunctions","useProduct","config"],"mappings":";AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAaA,SAASC,oBAAT,QAAqC,QAArC;AACA,SACEC,kCADF,EAEEC,qBAFF,EAGEC,qBAHF,EAIEC,oBAJF,EAKEC,uBALF,EAMEC,sBANF,EAOEC,2BAPF,EAQEC,gBAAgB,IAAhBA,iBARF,EASEC,mBATF,EAUEC,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C4B,QAAQ,CAACiB,MAAV;AAVxB,GAAlB;AAaA,sBACE,oBAAC,mBAAD,CAAqB,QAArB;AAA8B,IAAA,KAAK,EAAEkF;AAArC,kBACE,oBAAC,oBAAD,CAAsB,QAAtB;AAA+B,IAAA,KAAK,EAAEC;AAAtC,KACGnH,QADH,CADF,CADF;AAOD;AAED,OAAO,SAASoH,eAAT,GAA2B;AAChC,MAAMC,OAAO,GAAG3I,KAAK,CAAC4I,UAAN,CAAiB5H,mBAAjB,CAAhB;;AACA,MAAI2H,OAAO,KAAKzH,SAAhB,EAA2B;AACzB,UAAM,IAAI2H,KAAJ,CAAU,uDAAV,CAAN;AACD;;AACD,SAAOF,OAAP;AACD;AACD,OAAO,SAASG,mBAAT,GAA+B;AACpC,MAAMH,OAAO,GAAG3I,KAAK,CAAC4I,UAAN,CAAiBzH,oBAAjB,CAAhB;;AACA,MAAIwH,OAAO,KAAKzH,SAAhB,EAA2B;AACzB,UAAM,IAAI2H,KAAJ,CAAU,0DAAV,CAAN;AACD;;AACD,SAAOF,OAAP;AACD;AAED,OAAO,SAASI,UAAT,CAAoBjG,IAApB,EAAkCkG,MAAlC,EAAmE;AACxE,SAAOlI,WAAW,CAACiI,UAAZ,CAAuBjG,IAAvB,EAA6BkG,MAA7B,CAAP;AACD","sourcesContent":["import React from 'react'\nimport {\n ProductDTO,\n ProductVariantDTO,\n AttributeRuleDTO,\n ProductAttributeDraftDTO,\n CustomField,\n AssetSourceDTO,\n SelectedOptionDTO,\n ReviewRatingStatisticsDTO,\n CategoryDTO,\n ProductVariantLabelDTO,\n} from '@sentecacommerce/sdk'\nimport { getTranslatableField } from '../../'\nimport {\n assignCombinationsToAttributeRules,\n createCombinationsMap,\n createCustomFieldsMap,\n createProductContent,\n createAttributeRulesMap,\n createMappedAttributes,\n processAvailabilityPerStore,\n getProductVideos,\n createMappedOptions,\n createSelectedOption2,\n SelectedOptionType,\n formatCategories,\n createLabelsMap,\n} from './utils'\nimport { productsApi, getProductBySlugConfig } from '../../api/productsApi'\nimport { assetsFieldsToMap, AssetsMap } from '../../utils/assetsToMap'\n\nexport interface OptionsType {\n definitionKey: string\n label: string\n elements?: SubOptionType[]\n}\n\nexport interface SubOptionType {\n optionKey: string\n label: string\n imageIndex?: number\n}\n\nexport interface ContentType {\n name?: string\n content?: string\n}\n\nexport interface MetaInformationType {\n _id?: string\n name?: string\n slug?: string\n description?: string\n shortDescription?: string\n reviewRatingStatistics?: ReviewRatingStatisticsDTO\n brand: {\n _id?: string\n name?: string\n slug?: string\n logo?: string\n }\n category: {\n _id?: string\n name?: string\n slug?: string\n }\n rootCategory: {\n _id?: string\n name?: string\n slug?: string\n }\n categories?: {\n name: string\n id: string\n link: string\n }[]\n content?: ContentType[]\n assets?: AssetsMap\n}\n\ninterface SeoInformationType {\n title?: string\n description?: string\n keywords?: string\n}\n\ninterface AttributeRulesType extends AttributeRuleDTO {\n label: string\n values: {\n [id: string]: {\n label: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n }\n}\n\nexport interface VariantType\n extends Omit<\n ProductVariantDTO,\n 'attributes' | 'availableOptions' | 'selectedOptions' | 'labels'\n > {\n attributes: ProductAttributeDraftDTO[]\n options?: OptionsType[]\n selectedOptions: SelectedOptionDTO[]\n mappedSelectedOptions?: SelectedOptionType[]\n isAvailable: boolean\n quantity?: number\n inventory: {\n hasAvailableQuantity?: boolean\n availableQuantity?: number\n }\n labels?: string[]\n getAttribute: (\n rule: string\n ) => {\n id: string\n label: string\n name: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n getAttributeByKey: (key: string) => undefined | any\n getAvailabilityByStore: () => InventoryAvailabilityType[] | undefined\n}\ninterface VariantMap {\n [productId: string]: VariantType\n}\n\nexport interface BooleanKVP {\n [sku: string]: boolean | undefined\n}\n\nexport interface AttributeRulesMap {\n [name: string]: AttributeRulesType\n}\n\nexport interface CombinationsMap {\n [id: string]: {\n value: string\n params: {\n [id: string]: string\n }\n }\n}\n\nexport interface InventoryAvailabilityType {\n storeName: string\n availableQuantity: number\n acceptsBackorders: boolean\n restockableInDays: number\n}\n\ntype ProductProviderProps = {\n children: React.ReactNode\n product?: ProductDTO\n defaultVariantId?: string\n query?: {\n storeKey?: string\n currencyCode?: string\n languageCode?: string\n priceListKey?: string\n time?: number\n merchantKey?: string\n expand?: string\n project?: string\n }\n}\n\ntype ProductStateContextType = {\n attributeRules: AttributeRulesMap\n metaData: MetaInformationType\n seoData: SeoInformationType\n variants?: VariantMap\n selectedVariant?: VariantType | null\n}\n\nexport type VideoType = {\n type: string\n source: string\n iframe: JSX.Element\n thumb: {\n url: string\n }\n}\n\ntype CountFunctionsContextType = {\n selectVariantById: (id: string) => void\n selectVariantByAttribute: (key: string) => void\n selectVariantByCombination: (key: string, value: string) => void\n selectVariantOptions: (optionId: string, elementId: string) => void\n getVariantById: (id: string) => VariantType\n getVariantByAttribute: (key: string) => VariantType\n getVariantByCombination: (key: string, value: string) => VariantType\n getCustomFieldValue: (field: string) => boolean | undefined\n getCombinationsForAttributeRule: (\n key: string,\n id: string\n ) => {\n label: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n getProductVideos: () => VideoType[]\n}\n\nconst ProductStateContext = React.createContext<\n ProductStateContextType | undefined\n>(undefined)\nconst CountDispatchContext = React.createContext<\n CountFunctionsContextType | undefined\n>(undefined)\n\nexport function ProductProvider({\n product,\n children,\n defaultVariantId,\n}: ProductProviderProps) {\n const [mounted, setMounted] = React.useState(false)\n\n const [\n { combinations, attributeRules },\n setCombinationsAndAttributeRules,\n ] = React.useState<{\n combinations: CombinationsMap\n attributeRules: AttributeRulesMap\n }>(getCombinationsAndAttributeRules)\n\n const [variants, setVariants] = React.useState<VariantMap>(\n getVariantsWithInventory\n )\n\n const [\n selectedVariant,\n setSelectedVariant,\n ] = React.useState<VariantType | null>(getDefaultVariant)\n\n const metaData = React.useMemo(() => {\n const rootCategory = product?.categories?.[0]\n const rootCategoryId = rootCategory?.resourceId\n\n const metaObj: MetaInformationType = {\n _id: product?._id,\n name:\n getTranslatableField(selectedVariant?.name) ||\n getTranslatableField(product?.name),\n slug: getTranslatableField(product?.slug),\n description:\n getTranslatableField(selectedVariant?.description) ||\n getTranslatableField(product?.description),\n shortDescription:\n getTranslatableField(selectedVariant?.metaDescription) ||\n getTranslatableField(product?.metaDescription),\n brand: {\n _id: product?.brands?.[0]?.resourceId,\n name: getTranslatableField(product?.brands?.[0]?.resource?.name),\n slug: getTranslatableField(product?.brands?.[0]?.resource?.slug),\n logo: product?.brands?.[0]?.resource?.assets?.[0]?.sources?.[0]?.url,\n },\n category: {\n _id: product?.categories?.[product?.categories?.length - 1]?.resourceId,\n name: getTranslatableField(\n product?.categories?.[product?.categories?.length - 1]?.resource?.name\n ),\n slug: getTranslatableField(\n product?.categories?.[product?.categories?.length - 1]?.resource?.slug\n ),\n },\n rootCategory: {\n _id: rootCategoryId,\n name: getTranslatableField(rootCategory?.resource?.name),\n slug: getTranslatableField(rootCategory?.resource?.slug),\n },\n categories: formatCategories(product?.categories, rootCategoryId),\n reviewRatingStatistics: product?.reviewRatingStatistics,\n content: Boolean(\n selectedVariant?.content?.map(createProductContent).length\n )\n ? selectedVariant?.content?.map(createProductContent)\n : product?.content?.map(createProductContent),\n assets: assetsFieldsToMap(product?.assets),\n }\n return metaObj\n }, [\n product?._id,\n product?.brands,\n product?.content,\n product?.description,\n product?.metaDescription,\n product?.name,\n product?.slug,\n product?.assets,\n selectedVariant,\n ])\n\n const seoData = React.useMemo(() => {\n const seoObj: SeoInformationType = {\n title:\n getTranslatableField(selectedVariant?.metaTitle) ||\n getTranslatableField(product?.metaTitle),\n description:\n getTranslatableField(selectedVariant?.metaDescription) ||\n getTranslatableField(product?.metaDescription),\n keywords:\n getTranslatableField(selectedVariant?.metaKeywords) ||\n getTranslatableField(product?.metaKeywords),\n }\n return seoObj\n }, [\n product?.metaDescription,\n product?.metaKeywords,\n product?.metaTitle,\n selectedVariant,\n ])\n\n const customFields = React.useMemo(() => {\n const mappedFields = createCustomFieldsMap(product?.custom) as BooleanKVP\n return mappedFields\n }, [product?.custom])\n\n React.useEffect(() => {\n // prevent unnecessary calculations\n if (mounted) {\n setVariants(getVariantsWithInventory())\n }\n }, [product])\n\n React.useMemo(() => {\n // prevent unnecessary calculations\n if (!mounted) {\n return setMounted(true)\n }\n\n const data = getCombinationsAndAttributeRules()\n\n setCombinationsAndAttributeRules(data)\n }, [variants])\n\n function getVariantsWithInventory() {\n const variantsWithInventory = product?.variants?.reduce(\n (map: any, _, index, arr) => {\n const currentVariant = arr[index] as ProductVariantDTO\n\n const mappedAttributes = createMappedAttributes(currentVariant)\n\n const mappedOptions =\n createMappedOptions(currentVariant?.availableOptions) || []\n\n const isAvailable = currentVariant?.inventorySnapshot?.canOrder\n\n const updatedVariant: VariantType = {\n ...currentVariant,\n inventory: {\n hasAvailableQuantity: currentVariant.inventorySnapshot?.canOrder,\n availableQuantity:\n currentVariant.inventorySnapshot?.availableQuantity,\n },\n isAvailable: isAvailable ? true : false,\n quantity: isAvailable\n ? currentVariant?.inventorySnapshot?.availableQuantity\n : 0,\n attributes: mappedAttributes,\n options: mappedOptions,\n selectedOptions: [],\n labels: createLabelsMap(currentVariant.labels),\n getAttribute: (rule: string) =>\n getSelectedAttribute(rule, mappedAttributes),\n getAttributeByKey: (key: string) =>\n mappedAttributes.find((a) => a.name === key)?.value,\n getAvailabilityByStore: () =>\n processAvailabilityPerStore(\n currentVariant?.inventorySnapshot?.availabilities\n ),\n }\n\n map[currentVariant._id] = updatedVariant\n\n return map\n },\n {}\n )\n\n return variantsWithInventory || {}\n }\n\n function getCombinationsAndAttributeRules() {\n const mappedAttributeRules: AttributeRulesMap = createAttributeRulesMap(\n product\n )\n\n const attributesWithId = Object.keys(variants || {}).map((key) => {\n return {\n variantId: variants?.[key]._id,\n attributes: variants?.[key].attributes,\n }\n })\n\n const combinationsMap = createCombinationsMap(\n Object.keys(mappedAttributeRules),\n attributesWithId\n )\n\n assignCombinationsToAttributeRules(mappedAttributeRules, combinationsMap)\n\n return {\n combinations: combinationsMap,\n attributeRules: mappedAttributeRules,\n }\n }\n\n function getDefaultVariant() {\n if (!defaultVariantId) return null\n\n return variants[defaultVariantId]\n }\n\n function selectVariantById(id: string) {\n setSelectedVariant(variants[id])\n }\n\n function selectVariantByAttribute(key: string) {\n const id = combinations[key]?.value\n setSelectedVariant(variants[id])\n }\n\n function selectVariantByCombination(key: string, value: string) {\n const id = combinations[key].params[value]\n setSelectedVariant(variants[id])\n }\n\n function selectVariantOptions(definitionKey: string, optionKey: string) {\n if (selectedVariant) {\n const newSelectedVariant = { ...selectedVariant }\n\n newSelectedVariant.selectedOptions = newSelectedVariant.selectedOptions.filter(\n (opt) => opt.definitionKey !== definitionKey\n )\n\n newSelectedVariant.selectedOptions = [\n ...newSelectedVariant.selectedOptions,\n {\n definitionKey,\n optionKey,\n },\n ]\n\n newSelectedVariant.mappedSelectedOptions = newSelectedVariant.selectedOptions.map(\n (option) => createSelectedOption2(newSelectedVariant.options, option)\n )\n\n setSelectedVariant(newSelectedVariant)\n }\n }\n\n function getSelectedAttribute(rule: string, attributes: any[]) {\n const attributeRule = attributeRules[rule]?.values\n let result\n\n attributes.forEach((currentKey) => {\n const found = attributeRule?.[currentKey.value]\n if (found) result = { id: currentKey.value, name: rule, ...found }\n })\n\n return (result as unknown) as {\n id: string\n name: string\n label: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n }\n\n function getVariantById(id: string) {\n return variants?.[id]\n }\n\n function getVariantByAttribute(key: string) {\n const id = combinations[key]?.value\n return variants?.[id]\n }\n\n function getVariantByCombination(key: string, value: string) {\n const id = combinations[key]?.params[value]\n return variants?.[id]\n }\n\n function getCustomFieldValue(field: string) {\n return customFields?.[field]\n }\n\n function getCombinationsForAttributeRule(key: string, id: string) {\n const result = attributeRules?.[key]?.values?.[id]\n return result\n }\n\n const state = {\n metaData,\n seoData,\n variants,\n selectedVariant,\n attributeRules,\n }\n\n const functions = {\n getVariantById,\n getVariantByAttribute,\n getVariantByCombination,\n selectVariantById,\n selectVariantByAttribute,\n selectVariantByCombination,\n getCombinationsForAttributeRule,\n selectVariantOptions,\n getCustomFieldValue,\n getProductVideos: () => getProductVideos(metaData.assets),\n }\n\n return (\n <ProductStateContext.Provider value={state}>\n <CountDispatchContext.Provider value={functions}>\n {children}\n </CountDispatchContext.Provider>\n </ProductStateContext.Provider>\n )\n}\n\nexport function useProductState() {\n const context = React.useContext(ProductStateContext)\n if (context === undefined) {\n throw new Error('useProductState must be used within a ProductProvider')\n }\n return context\n}\nexport function useProductFunctions() {\n const context = React.useContext(CountDispatchContext)\n if (context === undefined) {\n throw new Error('useProductDispatch must be used within a ProductProvider')\n }\n return context\n}\n\nexport function useProduct(slug: string, config?: getProductBySlugConfig) {\n return productsApi.useProduct(slug, config)\n}\n"],"file":"index.js"}
|
1
|
+
{"version":3,"sources":["../../../../src/hooks/useProduct/index.tsx"],"names":["React","getTranslatableField","assignCombinationsToAttributeRules","createCombinationsMap","createCustomFieldsMap","createProductContent","createAttributeRulesMap","createMappedAttributes","processAvailabilityPerStore","getProductVideos","createMappedOptions","createSelectedOption2","formatCategories","createLabelsMap","productsApi","assetsFieldsToMap","ProductStateContext","createContext","undefined","CountDispatchContext","ProductProvider","product","children","defaultVariantId","mounted","setMounted","useState","combinations","attributeRules","setCombinationsAndAttributeRules","getCombinationsAndAttributeRules","variants","setVariants","getVariantsWithInventory","selectedVariant","setSelectedVariant","getDefaultVariant","metaData","useMemo","rootCategory","categories","rootCategoryId","resourceId","metaObj","_id","name","slug","description","shortDescription","metaDescription","brand","brands","resource","logo","assets","sources","url","category","length","reviewRatingStatistics","content","Boolean","map","seoData","seoObj","title","metaTitle","keywords","metaKeywords","customFields","mappedFields","custom","useEffect","data","variantsWithInventory","reduce","_","index","arr","currentVariant","mappedAttributes","mappedOptions","availableOptions","isAvailable","inventorySnapshot","canOrder","updatedVariant","inventory","hasAvailableQuantity","availableQuantity","quantity","attributes","options","selectedOptions","labels","getAttribute","rule","getSelectedAttribute","getAttributeByKey","key","find","a","value","getAvailabilityByStore","availabilities","mappedAttributeRules","attributesWithId","Object","keys","variantId","combinationsMap","selectVariantById","id","selectVariantByAttribute","selectVariantByCombination","params","selectVariantOptions","definitionKey","optionKey","newSelectedVariant","filter","opt","mappedSelectedOptions","option","attributeRule","values","result","forEach","currentKey","found","getVariantById","getVariantByAttribute","getVariantByCombination","getCustomFieldValue","field","getCombinationsForAttributeRule","state","functions","useProductState","context","useContext","Error","useProductFunctions","useProduct","config"],"mappings":";AAAA,OAAOA,KAAP,MAAkB,OAAlB;AASA,SAASC,oBAAT,QAAqC,QAArC;AACA,SACEC,kCADF,EAEEC,qBAFF,EAGEC,qBAHF,EAIEC,oBAJF,EAKEC,uBALF,EAMEC,sBANF,EAOEC,2BAPF,EAQEC,gBAAgB,IAAhBA,iBARF,EASEC,mBATF,EAUEC,qBAVF,EAYEC,gBAZF,EAaEC,eAbF,QAcO,SAdP;AAeA,SAASC,WAAT,QAAoD,uBAApD;AACA,SAASC,iBAAT,QAA6C,yBAA7C;AAyLA,IAAMC,mBAAmB,gBAAGhB,KAAK,CAACiB,aAAN,CAE1BC,SAF0B,CAA5B;AAGA,IAAMC,oBAAoB,gBAAGnB,KAAK,CAACiB,aAAN,CAE3BC,SAF2B,CAA7B;AAIA,OAAO,SAASE,eAAT,OAIkB;AAAA,MAJO;AAC9BC,IAAAA,OAD8B;AAE9BC,IAAAA,QAF8B;AAG9BC,IAAAA;AAH8B,GAIP;AACvB,MAAM,CAACC,OAAD,EAAUC,UAAV,IAAwBzB,KAAK,CAAC0B,QAAN,CAAe,KAAf,CAA9B;AAEA,MAAM,CACJ;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,GADI,EAEJC,gCAFI,IAGF7B,KAAK,CAAC0B,QAAN,CAGDI,gCAHC,CAHJ;AAQA,MAAM,CAACC,QAAD,EAAWC,WAAX,IAA0BhC,KAAK,CAAC0B,QAAN,CAC9BO,wBAD8B,CAAhC;AAIA,MAAM,CACJC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MAAlC,EAAmE;AACxE,SAAOlI,WAAW,CAACiI,UAAZ,CAAuBjG,IAAvB,EAA6BkG,MAA7B,CAAP;AACD","sourcesContent":["import React from 'react'\nimport {\n ProductDTO,\n ProductVariantDTO,\n AttributeRuleDTO,\n ProductAttributeDraftDTO,\n SelectedOptionDTO,\n ReviewRatingStatisticsDTO,\n} from '@sentecacommerce/sdk'\nimport { getTranslatableField } from '../../'\nimport {\n assignCombinationsToAttributeRules,\n createCombinationsMap,\n createCustomFieldsMap,\n createProductContent,\n createAttributeRulesMap,\n createMappedAttributes,\n processAvailabilityPerStore,\n getProductVideos,\n createMappedOptions,\n createSelectedOption2,\n SelectedOptionType,\n formatCategories,\n createLabelsMap,\n} from './utils'\nimport { productsApi, getProductBySlugConfig } from '../../api/productsApi'\nimport { assetsFieldsToMap, AssetsMap } from '../../utils/assetsToMap'\n\nexport interface OptionsType {\n definitionKey: string\n label: string\n elements?: SubOptionType[]\n}\n\nexport interface SubOptionType {\n optionKey: string\n label: string\n imageIndex?: number\n}\n\nexport interface ContentType {\n name?: string\n content?: string\n}\n\nexport interface MetaInfoCategoryType {\n name: string\n id: string\n link: string\n}\n\nexport interface MetaInformationType {\n _id?: string\n name?: string\n slug?: string\n description?: string\n shortDescription?: string\n reviewRatingStatistics?: ReviewRatingStatisticsDTO\n brand: {\n _id?: string\n name?: string\n slug?: string\n logo?: string\n }\n category: {\n _id?: string\n name?: string\n slug?: string\n }\n rootCategory: {\n _id?: string\n name?: string\n slug?: string\n }\n categories?: MetaInfoCategoryType[]\n content?: ContentType[]\n assets?: AssetsMap\n}\n\ninterface SeoInformationType {\n title?: string\n description?: string\n keywords?: string\n}\n\ninterface AttributeRulesType extends AttributeRuleDTO {\n label: string\n values: {\n [id: string]: {\n label: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n }\n}\n\nexport interface VariantType\n extends Omit<\n ProductVariantDTO,\n 'attributes' | 'availableOptions' | 'selectedOptions' | 'labels'\n > {\n attributes: ProductAttributeDraftDTO[]\n options?: OptionsType[]\n selectedOptions: SelectedOptionDTO[]\n mappedSelectedOptions?: SelectedOptionType[]\n isAvailable: boolean\n quantity?: number\n inventory: {\n hasAvailableQuantity?: boolean\n availableQuantity?: number\n }\n labels?: string[]\n getAttribute: (\n rule: string\n ) => {\n id: string\n label: string\n name: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n getAttributeByKey: (key: string) => undefined | any\n getAvailabilityByStore: () => InventoryAvailabilityType[] | undefined\n}\ninterface VariantMap {\n [productId: string]: VariantType\n}\n\nexport interface BooleanKVP {\n [sku: string]: boolean | undefined\n}\n\nexport interface AttributeRulesMap {\n [name: string]: AttributeRulesType\n}\n\nexport interface CombinationsMap {\n [id: string]: {\n value: string\n params: {\n [id: string]: string\n }\n }\n}\n\nexport interface InventoryAvailabilityType {\n storeName: string\n availableQuantity: number\n acceptsBackorders: boolean\n restockableInDays: number\n}\n\ntype ProductProviderProps = {\n children: React.ReactNode\n product?: ProductDTO\n defaultVariantId?: string\n query?: {\n storeKey?: string\n currencyCode?: string\n languageCode?: string\n priceListKey?: string\n time?: number\n merchantKey?: string\n expand?: string\n project?: string\n }\n}\n\ntype ProductStateContextType = {\n attributeRules: AttributeRulesMap\n metaData: MetaInformationType\n seoData: SeoInformationType\n variants?: VariantMap\n selectedVariant?: VariantType | null\n}\n\nexport type VideoType = {\n type: string\n source: string\n iframe: JSX.Element\n thumb: {\n url: string\n }\n}\n\ntype CountFunctionsContextType = {\n selectVariantById: (id: string) => void\n selectVariantByAttribute: (key: string) => void\n selectVariantByCombination: (key: string, value: string) => void\n selectVariantOptions: (optionId: string, elementId: string) => void\n getVariantById: (id: string) => VariantType\n getVariantByAttribute: (key: string) => VariantType\n getVariantByCombination: (key: string, value: string) => VariantType\n getCustomFieldValue: (field: string) => boolean | undefined\n getCombinationsForAttributeRule: (\n key: string,\n id: string\n ) => {\n label: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n getProductVideos: () => VideoType[]\n}\n\nconst ProductStateContext = React.createContext<\n ProductStateContextType | undefined\n>(undefined)\nconst CountDispatchContext = React.createContext<\n CountFunctionsContextType | undefined\n>(undefined)\n\nexport function ProductProvider({\n product,\n children,\n defaultVariantId,\n}: ProductProviderProps) {\n const [mounted, setMounted] = React.useState(false)\n\n const [\n { combinations, attributeRules },\n setCombinationsAndAttributeRules,\n ] = React.useState<{\n combinations: CombinationsMap\n attributeRules: AttributeRulesMap\n }>(getCombinationsAndAttributeRules)\n\n const [variants, setVariants] = React.useState<VariantMap>(\n getVariantsWithInventory\n )\n\n const [\n selectedVariant,\n setSelectedVariant,\n ] = React.useState<VariantType | null>(getDefaultVariant)\n\n const metaData = React.useMemo(() => {\n const rootCategory = product?.categories?.[0]\n const rootCategoryId = rootCategory?.resourceId\n\n const metaObj: MetaInformationType = {\n _id: product?._id,\n name:\n getTranslatableField(selectedVariant?.name) ||\n getTranslatableField(product?.name),\n slug: getTranslatableField(product?.slug),\n description:\n getTranslatableField(selectedVariant?.description) ||\n getTranslatableField(product?.description),\n shortDescription:\n getTranslatableField(selectedVariant?.metaDescription) ||\n getTranslatableField(product?.metaDescription),\n brand: {\n _id: product?.brands?.[0]?.resourceId,\n name: getTranslatableField(product?.brands?.[0]?.resource?.name),\n slug: getTranslatableField(product?.brands?.[0]?.resource?.slug),\n logo: product?.brands?.[0]?.resource?.assets?.[0]?.sources?.[0]?.url,\n },\n category: {\n _id: product?.categories?.[product?.categories?.length - 1]?.resourceId,\n name: getTranslatableField(\n product?.categories?.[product?.categories?.length - 1]?.resource?.name\n ),\n slug: getTranslatableField(\n product?.categories?.[product?.categories?.length - 1]?.resource?.slug\n ),\n },\n rootCategory: {\n _id: rootCategoryId,\n name: getTranslatableField(rootCategory?.resource?.name),\n slug: getTranslatableField(rootCategory?.resource?.slug),\n },\n categories: formatCategories(product?.categories, rootCategoryId),\n reviewRatingStatistics: product?.reviewRatingStatistics,\n content: Boolean(\n selectedVariant?.content?.map(createProductContent).length\n )\n ? selectedVariant?.content?.map(createProductContent)\n : product?.content?.map(createProductContent),\n assets: assetsFieldsToMap(product?.assets),\n }\n return metaObj\n }, [\n product?._id,\n product?.brands,\n product?.content,\n product?.description,\n product?.metaDescription,\n product?.name,\n product?.slug,\n product?.assets,\n selectedVariant,\n ])\n\n const seoData = React.useMemo(() => {\n const seoObj: SeoInformationType = {\n title:\n getTranslatableField(selectedVariant?.metaTitle) ||\n getTranslatableField(product?.metaTitle),\n description:\n getTranslatableField(selectedVariant?.metaDescription) ||\n getTranslatableField(product?.metaDescription),\n keywords:\n getTranslatableField(selectedVariant?.metaKeywords) ||\n getTranslatableField(product?.metaKeywords),\n }\n return seoObj\n }, [\n product?.metaDescription,\n product?.metaKeywords,\n product?.metaTitle,\n selectedVariant,\n ])\n\n const customFields = React.useMemo(() => {\n const mappedFields = createCustomFieldsMap(product?.custom) as BooleanKVP\n return mappedFields\n }, [product?.custom])\n\n React.useEffect(() => {\n // prevent unnecessary calculations\n if (mounted) {\n setVariants(getVariantsWithInventory())\n }\n }, [product])\n\n React.useMemo(() => {\n // prevent unnecessary calculations\n if (!mounted) {\n return setMounted(true)\n }\n\n const data = getCombinationsAndAttributeRules()\n\n setCombinationsAndAttributeRules(data)\n }, [variants])\n\n function getVariantsWithInventory() {\n const variantsWithInventory = product?.variants?.reduce(\n (map: any, _, index, arr) => {\n const currentVariant = arr[index] as ProductVariantDTO\n\n const mappedAttributes = createMappedAttributes(currentVariant)\n\n const mappedOptions =\n createMappedOptions(currentVariant?.availableOptions) || []\n\n const isAvailable = currentVariant?.inventorySnapshot?.canOrder\n\n const updatedVariant: VariantType = {\n ...currentVariant,\n inventory: {\n hasAvailableQuantity: currentVariant.inventorySnapshot?.canOrder,\n availableQuantity:\n currentVariant.inventorySnapshot?.availableQuantity,\n },\n isAvailable: isAvailable ? true : false,\n quantity: isAvailable\n ? currentVariant?.inventorySnapshot?.availableQuantity\n : 0,\n attributes: mappedAttributes,\n options: mappedOptions,\n selectedOptions: [],\n labels: createLabelsMap(currentVariant.labels),\n getAttribute: (rule: string) =>\n getSelectedAttribute(rule, mappedAttributes),\n getAttributeByKey: (key: string) =>\n mappedAttributes.find((a) => a.name === key)?.value,\n getAvailabilityByStore: () =>\n processAvailabilityPerStore(\n currentVariant?.inventorySnapshot?.availabilities\n ),\n }\n\n map[currentVariant._id] = updatedVariant\n\n return map\n },\n {}\n )\n\n return variantsWithInventory || {}\n }\n\n function getCombinationsAndAttributeRules() {\n const mappedAttributeRules: AttributeRulesMap = createAttributeRulesMap(\n product\n )\n\n const attributesWithId = Object.keys(variants || {}).map((key) => {\n return {\n variantId: variants?.[key]._id,\n attributes: variants?.[key].attributes,\n }\n })\n\n const combinationsMap = createCombinationsMap(\n Object.keys(mappedAttributeRules),\n attributesWithId\n )\n\n assignCombinationsToAttributeRules(mappedAttributeRules, combinationsMap)\n\n return {\n combinations: combinationsMap,\n attributeRules: mappedAttributeRules,\n }\n }\n\n function getDefaultVariant() {\n if (!defaultVariantId) return null\n\n return variants[defaultVariantId]\n }\n\n function selectVariantById(id: string) {\n setSelectedVariant(variants[id])\n }\n\n function selectVariantByAttribute(key: string) {\n const id = combinations[key]?.value\n setSelectedVariant(variants[id])\n }\n\n function selectVariantByCombination(key: string, value: string) {\n const id = combinations[key].params[value]\n setSelectedVariant(variants[id])\n }\n\n function selectVariantOptions(definitionKey: string, optionKey: string) {\n if (selectedVariant) {\n const newSelectedVariant = { ...selectedVariant }\n\n newSelectedVariant.selectedOptions = newSelectedVariant.selectedOptions.filter(\n (opt) => opt.definitionKey !== definitionKey\n )\n\n newSelectedVariant.selectedOptions = [\n ...newSelectedVariant.selectedOptions,\n {\n definitionKey,\n optionKey,\n },\n ]\n\n newSelectedVariant.mappedSelectedOptions = newSelectedVariant.selectedOptions.map(\n (option) => createSelectedOption2(newSelectedVariant.options, option)\n )\n\n setSelectedVariant(newSelectedVariant)\n }\n }\n\n function getSelectedAttribute(rule: string, attributes: any[]) {\n const attributeRule = attributeRules[rule]?.values\n let result\n\n attributes.forEach((currentKey) => {\n const found = attributeRule?.[currentKey.value]\n if (found) result = { id: currentKey.value, name: rule, ...found }\n })\n\n return (result as unknown) as {\n id: string\n name: string\n label: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n }\n\n function getVariantById(id: string) {\n return variants?.[id]\n }\n\n function getVariantByAttribute(key: string) {\n const id = combinations[key]?.value\n return variants?.[id]\n }\n\n function getVariantByCombination(key: string, value: string) {\n const id = combinations[key]?.params[value]\n return variants?.[id]\n }\n\n function getCustomFieldValue(field: string) {\n return customFields?.[field]\n }\n\n function getCombinationsForAttributeRule(key: string, id: string) {\n const result = attributeRules?.[key]?.values?.[id]\n return result\n }\n\n const state = {\n metaData,\n seoData,\n variants,\n selectedVariant,\n attributeRules,\n }\n\n const functions = {\n getVariantById,\n getVariantByAttribute,\n getVariantByCombination,\n selectVariantById,\n selectVariantByAttribute,\n selectVariantByCombination,\n getCombinationsForAttributeRule,\n selectVariantOptions,\n getCustomFieldValue,\n getProductVideos: () => getProductVideos(metaData.assets),\n }\n\n return (\n <ProductStateContext.Provider value={state}>\n <CountDispatchContext.Provider value={functions}>\n {children}\n </CountDispatchContext.Provider>\n </ProductStateContext.Provider>\n )\n}\n\nexport function useProductState() {\n const context = React.useContext(ProductStateContext)\n if (context === undefined) {\n throw new Error('useProductState must be used within a ProductProvider')\n }\n return context\n}\nexport function useProductFunctions() {\n const context = React.useContext(CountDispatchContext)\n if (context === undefined) {\n throw new Error('useProductDispatch must be used within a ProductProvider')\n }\n return context\n}\n\nexport function useProduct(slug: string, config?: getProductBySlugConfig) {\n return productsApi.useProduct(slug, config)\n}\n"],"file":"index.js"}
|
@@ -197,12 +197,21 @@ export var getProductVideos = assets => {
|
|
197
197
|
return [];
|
198
198
|
};
|
199
199
|
export var formatCategories = (categories, rootCategoryId) => {
|
200
|
-
var
|
201
|
-
var _cat$resource, _cat$resource$ancesto;
|
200
|
+
var _results;
|
202
201
|
|
203
|
-
|
204
|
-
|
205
|
-
|
202
|
+
var results;
|
203
|
+
|
204
|
+
if (categories != null && categories.some(cat => cat.resource.custom.some(customField => customField.field === 'isTemporary'))) {
|
205
|
+
results = categories == null ? void 0 : categories.filter(cat => cat.resource.custom.some(customField => customField.field === 'isTemporary' ? !customField.value : true));
|
206
|
+
} else {
|
207
|
+
results = categories == null ? void 0 : categories.filter(cat => {
|
208
|
+
var _cat$resource, _cat$resource$ancesto;
|
209
|
+
|
210
|
+
return (cat == null ? void 0 : cat.resourceId) === rootCategoryId || (cat == null ? void 0 : (_cat$resource = cat.resource) == null ? void 0 : (_cat$resource$ancesto = _cat$resource.ancestors) == null ? void 0 : _cat$resource$ancesto.some(ancestor => ancestor.resource === rootCategoryId));
|
211
|
+
});
|
212
|
+
}
|
213
|
+
|
214
|
+
var formattedResults = (_results = results) == null ? void 0 : _results.map(category => {
|
206
215
|
if (category.resource) {
|
207
216
|
var resource = category.resource;
|
208
217
|
return {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../src/hooks/useProduct/utils/index.ts"],"names":["AttributeRuleDTOConstraintEnum","createEmbededVideo","getTranslatableField","createCustomFieldsMap","customFields","reduce","map","currentObj","field","value","createCombinationsMap","mappedAttributeRulesKeys","attributesArray","combinationsMap","forEach","key","p","currentKey","attributes","find","x","name","filtered","filter","currentCombination","params","variantId","attribute","assignCombinationsToAttributeRules","mappedAttributeRules","Object","keys","current","values","combinations","createProductContent","data","label","content","createAttributeRulesMap","product","uniqueRules","attributeRules","constraint","CombinationUnique","reduceVariantsToAttributeRuleValues","found","attributeName","valueData","extra","variants","v","flat","createMappedOptions","options","mappedOptions","currentOption","definitionKey","elements","subOption","optionKey","imageIndex","createSelectedOption2","selectedOption","availableOption","element","createSelectedOption","optionValue","createMappedAttributes","currentVariant","mappedAttributes","attributeArray","push","processAvailabilityPerStore","availabilities","isPhysical","acceptsBackorders","stockLocationName","restockableInDays","availableQuantity","storeName","getProductVideos","assets","youtube","videos","sources","a","embeded","type","source","url","iframe","thumb","thumbnail","formatCategories","categories","rootCategoryId","results","cat","resourceId","resource","ancestors","some","ancestor","formattedResults","category","id","link","slug","_id","createLabelsMap","now","Date","getTime","currentLabels","el","validFrom","validTo"],"mappings":";AAAA,SAGEA,8BAHF,QAYO,sBAZP;AAuBA,SAASC,kBAAT,QAAmC,sBAAnC;AAEA,SAASC,oBAAT,QAAqC,gBAArC,C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;;AAEA,OAAO,IAAMC,qBAAqB,GAAIC,YAAD,IAAkC;AACrE,SAAOA,YAAP,oBAAOA,YAAY,CAAEC,MAAd,CAAqB,CAACC,GAAD,EAAkBC,UAAlB,KAAiC;AAC3DD,IAAAA,GAAG,CAACC,UAAU,CAACC,KAAZ,CAAH,GAAwBD,UAAU,CAACE,KAAnC;AACA,WAAOH,GAAP;AACD,GAHM,EAGJ,EAHI,CAAP;AAID,CALM;AAOP,OAAO,IAAMI,qBAAqB,GAAG,CACnCC,wBADmC,EAEnCC,eAFmC,KAMhC;AACH,MAAMC,eAAgC,GAAG,EAAzC;AACAF,EAAAA,wBAAwB,CAACG,OAAzB,CAAkCC,GAAD,IAAS;AACxCH,IAAAA,eAAe,CAACE,OAAhB,CAAyBE,CAAD,IAAO;AAC7B,UAAMC,UAAU,GAAGD,CAAC,CAACE,UAAF,CAAaC,IAAb,CAAmBC,CAAD,IAAOA,CAAC,CAACC,IAAF,KAAWN,GAApC,CAAnB;AACA,UAAMO,QAAQ,GAAGN,CAAC,CAACE,UAAF,CAAaK,MAAb,CAAqBH,CAAD,IAAOA,CAAC,CAACC,IAAF,KAAWN,GAAtC,CAAjB;AAEA,UAAIS,kBAAkB,GAAGX,eAAe,CAACI,UAAD,oBAACA,UAAU,CAAER,KAAb,CAAxC;;AAEA,UAAI,CAACe,kBAAL,EAAyB;AACvBA,QAAAA,kBAAkB,GAAG;AACnBC,UAAAA,MAAM,EAAE,EADW;AAEnBhB,UAAAA,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2E,GAAG,GAAG,IAAIC,IAAJ,GAAWC,OAAX,EAAZ;AAEA,MAAMC,aAAa,GAAG9E,IAAH,oBAAGA,IAAI,CAAEb,MAAN,CAAc4F,EAAD,IAAQ;AACzC,QAAI,CAACA,EAAE,CAACC,SAAJ,IAAiB,CAACD,EAAE,CAACE,OAAzB,EAAkC;AAChC,aAAOF,EAAP;AACD,KAFD,MAEO;AACL,aAAOA,EAAE,CAACC,SAAH,GAAeL,GAAf,IAAsBI,EAAE,CAACE,OAAH,GAAaN,GAA1C;AACD;AACF,GANqB,CAAtB;AAQA,SAAOG,aAAP,oBAAOA,aAAa,CAAE5G,GAAf,CAAoB6G,EAAD,IAAQA,EAAE,CAACpG,GAA9B,CAAP;AACD,CAbM","sourcesContent":["import {\n ProductAttributeDTO,\n CustomField,\n AttributeRuleDTOConstraintEnum,\n ProductDTO,\n ProductVariantDTO,\n InventoryAvailability,\n OptionDefinitionDTO,\n SelectedOptionDTO,\n IdReferenceDTO,\n CategoryDTO,\n ProductVariantLabelDTO,\n} from '@sentecacommerce/sdk'\n\nimport {\n AttributeRulesMap,\n CombinationsMap,\n BooleanKVP,\n InventoryAvailabilityType,\n MetaInformationType,\n OptionsType,\n} from '../index'\n\nimport { createEmbededVideo } from './createEmbededVideo'\n\nimport { getTranslatableField } from '../../../utils'\n\n// export const createMappedInventory = (\n// currentVariant: ProductVariantDraftDTO,\n// inventory?: SkuReservationResponseDTO\n// ) => {\n// const currentInventory = inventory?.find(\n// (x) => x.sku === currentVariant.sku\n// )\n\n// const mappedInventory = {\n// ...currentInventory,\n// status:\n// currentInventory?.status === SkuReservationDTOStatusEnum.Available\n// ? true\n// : false,\n// inventoryId: currentInventory?.inventoryReservations?.[0].inventoryId,\n// quantity: currentInventory?.inventoryReservations?.[0].quantity,\n// }\n\n// return mappedInventory\n// }\n\nexport const createCustomFieldsMap = (customFields?: CustomField[]) => {\n return customFields?.reduce((map: BooleanKVP, currentObj) => {\n map[currentObj.field] = currentObj.value\n return map\n }, {})\n}\n\nexport const createCombinationsMap = (\n mappedAttributeRulesKeys: string[],\n attributesArray: {\n variantId: string\n attributes: ProductAttributeDTO[]\n }[]\n) => {\n const combinationsMap: CombinationsMap = {}\n mappedAttributeRulesKeys.forEach((key) => {\n attributesArray.forEach((p) => {\n const currentKey = p.attributes.find((x) => x.name === key)\n const filtered = p.attributes.filter((x) => x.name !== key)\n\n let currentCombination = combinationsMap[currentKey?.value]\n\n if (!currentCombination) {\n currentCombination = {\n params: {},\n value: '',\n }\n }\n\n currentCombination.value = p.variantId\n\n filtered.forEach((attribute) => {\n currentCombination.params = {\n ...currentCombination.params,\n [attribute.value]: p.variantId,\n }\n })\n\n combinationsMap[currentKey?.value] = currentCombination\n })\n })\n\n return combinationsMap\n}\n\nexport const assignCombinationsToAttributeRules = (\n mappedAttributeRules: AttributeRulesMap,\n combinationsMap: CombinationsMap\n) => {\n Object.keys(mappedAttributeRules).forEach((key) => {\n const current = mappedAttributeRules[key].values\n Object.keys(current).forEach((currentKey) => {\n mappedAttributeRules[key].values[currentKey].combinations =\n combinationsMap[currentKey]?.params\n })\n })\n}\n\nexport const createProductContent = (\n data: any\n): { key: string; name: string; content: string } => {\n return {\n key: data.key,\n name: getTranslatableField(data.label),\n content: getTranslatableField(data.content),\n }\n}\n\nexport const createAttributeRulesMap = (product?: ProductDTO) => {\n const uniqueRules = product?.attributeRules?.filter(\n (x) => x.constraint === AttributeRuleDTOConstraintEnum.CombinationUnique\n )\n const reduceVariantsToAttributeRuleValues = (map: any, attribute: any) => {\n const found = uniqueRules?.find((x) => x.attributeName === attribute.name)\n if (found) {\n if (!map[attribute.name]) {\n map[attribute.name] = {\n ...found,\n label: getTranslatableField(attribute.data.label),\n values: {},\n }\n }\n\n map[attribute.name] = {\n ...map[attribute.name],\n values: {\n ...map[attribute.name].values,\n [attribute.value]: {\n label: getTranslatableField(attribute.valueData.label),\n extra: attribute.valueData.extra,\n },\n },\n }\n }\n\n return map\n }\n\n const mappedAttributeRules = product?.variants\n ?.map((v) => v.attributes)\n .flat()\n .reduce(reduceVariantsToAttributeRuleValues, {})\n\n return mappedAttributeRules\n}\n\nexport const createMappedOptions = (\n options?: OptionDefinitionDTO[]\n): OptionsType[] => {\n const mappedOptions =\n options?.map((currentOption) => {\n return {\n definitionKey: currentOption.key,\n label: getTranslatableField(currentOption?.label),\n elements: currentOption.options?.map((subOption) => {\n return {\n optionKey: subOption.key,\n label: getTranslatableField(subOption?.label),\n imageIndex: subOption?.imageIndex,\n }\n }),\n }\n }) || []\n\n return mappedOptions\n}\n\nexport type SelectedOptionType = {\n label?: string\n value?: { key?: string; label?: string; imageIndex?: number }\n}\n\nexport const createSelectedOption2 = (\n options?: OptionsType[],\n selectedOption?: SelectedOptionDTO\n): SelectedOptionType => {\n const currentOption = options?.find(\n (availableOption) =>\n availableOption.definitionKey === selectedOption?.definitionKey\n )\n\n const value = currentOption?.elements?.find(\n (element) => element.optionKey === selectedOption?.optionKey\n )\n\n return {\n label: currentOption?.label,\n value: {\n key: value?.optionKey,\n imageIndex: value?.imageIndex,\n label: value?.label,\n },\n }\n}\n\nexport const createSelectedOption = (\n options?: OptionDefinitionDTO[],\n selectedOption?: SelectedOptionDTO\n): SelectedOptionType => {\n const currentOption = options?.find(\n (availableOption) => availableOption.key === selectedOption?.definitionKey\n )\n\n const value = currentOption?.options?.find(\n (optionValue) => optionValue.key === selectedOption?.optionKey\n )\n\n return {\n label: getTranslatableField(currentOption?.label),\n value: {\n key: value?.key,\n imageIndex: value?.imageIndex,\n label: getTranslatableField(value?.label),\n },\n }\n}\n\nexport const createMappedAttributes = (currentVariant: ProductVariantDTO) => {\n const mappedAttributes =\n currentVariant.attributes?.reduce(\n (attributeArray: ProductAttributeDTO[], attribute) => {\n attributeArray.push({\n name: attribute.name,\n value: attribute.value,\n valueData: attribute.valueData,\n })\n return attributeArray\n },\n []\n ) || []\n\n return mappedAttributes\n}\n\nexport const processAvailabilityPerStore = (\n availabilities?: InventoryAvailability[]\n): InventoryAvailabilityType[] | undefined => {\n return availabilities\n ?.filter((x) => !x.isPhysical)\n ?.map(\n ({\n acceptsBackorders,\n stockLocationName,\n restockableInDays,\n availableQuantity,\n }) => {\n return {\n storeName: getTranslatableField(stockLocationName),\n availableQuantity,\n acceptsBackorders,\n restockableInDays: restockableInDays,\n }\n }\n )\n}\n\nexport const getProductVideos = (assets: MetaInformationType['assets']) => {\n if (assets?.youtube) {\n const videos = assets.youtube.sources.map((a) => {\n const embeded = createEmbededVideo(a)\n return {\n type: 'video',\n source: a.url,\n iframe: embeded.iframe,\n thumb: { url: embeded.thumbnail },\n }\n })\n\n return videos\n }\n return []\n}\n\nexport const formatCategories = (\n categories?: IdReferenceDTO[],\n rootCategoryId?: string\n) => {\n const results = categories?.filter(\n (cat) =>\n cat?.resourceId === rootCategoryId ||\n cat?.resource?.ancestors?.some(\n (ancestor: any) => ancestor.resource === rootCategoryId\n )\n )\n\n const formattedResults = results?.map((category) => {\n if (category.resource) {\n const resource = category.resource as CategoryDTO\n\n return {\n name: getTranslatableField(resource.name),\n id: category.resourceId || '',\n link: `/${getTranslatableField(resource.slug)}/c`,\n }\n }\n\n const cat = (category as unknown) as CategoryDTO\n\n return {\n name: getTranslatableField(cat.name),\n id: cat._id || '',\n link: `/${getTranslatableField(cat.slug)}/c`,\n }\n })\n\n return formattedResults || []\n}\n\nexport const createLabelsMap = (data?: ProductVariantLabelDTO[]) => {\n // Filter only labels that are currently active\n const now = new Date().getTime()\n\n const currentLabels = data?.filter((el) => {\n if (!el.validFrom || !el.validTo) {\n return el\n } else {\n return el.validFrom < now && el.validTo > now\n }\n })\n\n return currentLabels?.map((el) => el.key)\n}\n"],"file":"index.js"}
|
1
|
+
{"version":3,"sources":["../../../../../src/hooks/useProduct/utils/index.ts"],"names":["AttributeRuleDTOConstraintEnum","createEmbededVideo","getTranslatableField","createCustomFieldsMap","customFields","reduce","map","currentObj","field","value","createCombinationsMap","mappedAttributeRulesKeys","attributesArray","combinationsMap","forEach","key","p","currentKey","attributes","find","x","name","filtered","filter","currentCombination","params","variantId","attribute","assignCombinationsToAttributeRules","mappedAttributeRules","Object","keys","current","values","combinations","createProductContent","data","label","content","createAttributeRulesMap","product","uniqueRules","attributeRules","constraint","CombinationUnique","reduceVariantsToAttributeRuleValues","found","attributeName","valueData","extra","variants","v","flat","createMappedOptions","options","mappedOptions","currentOption","definitionKey","elements","subOption","optionKey","imageIndex","createSelectedOption2","selectedOption","availableOption","element","createSelectedOption","optionValue","createMappedAttributes","currentVariant","mappedAttributes","attributeArray","push","processAvailabilityPerStore","availabilities","isPhysical","acceptsBackorders","stockLocationName","restockableInDays","availableQuantity","storeName","getProductVideos","assets","youtube","videos","sources","a","embeded","type","source","url","iframe","thumb","thumbnail","formatCategories","categories","rootCategoryId","results","some","cat","resource","custom","customField","resourceId","ancestors","ancestor","formattedResults","category","id","link","slug","_id","createLabelsMap","now","Date","getTime","currentLabels","el","validFrom","validTo"],"mappings":";AAAA,SAGEA,8BAHF,QAYO,sBAZP;AAuBA,SAASC,kBAAT,QAAmC,sBAAnC;AAEA,SAASC,oBAAT,QAAqC,gBAArC,C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;;AAEA,OAAO,IAAMC,qBAAqB,GAAIC,YAAD,IAAkC;AACrE,SAAOA,YAAP,oBAAOA,YAAY,CAAEC,MAAd,CAAqB,CAACC,GAAD,EAAkBC,UAAlB,KAAiC;AAC3DD,IAAAA,GAAG,CAACC,UAAU,CAACC,KAAZ,CAAH,GAAwBD,UAAU,CAACE,KAAnC;AACA,WAAOH,GAAP;AACD,GAHM,EAGJ,EAHI,CAAP;AAID,CALM;AAOP,OAAO,IAAMI,qBAAqB,GAAG,CACnCC,wBADmC,EAEnCC,eAFmC,KAMhC;AACH,MAAMC,eAAgC,GAAG,EAAzC;AACAF,EAAAA,wBAAwB,CAACG,OAAzB,CAAkCC,GAAD,IAAS;AACxCH,IAAAA,eAA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AAf,IAAsBI,EAAE,CAACE,OAAH,GAAaN,GAA1C;AACD;AACF,GANqB,CAAtB;AAQA,SAAOG,aAAP,oBAAOA,aAAa,CAAE9G,GAAf,CAAoB+G,EAAD,IAAQA,EAAE,CAACtG,GAA9B,CAAP;AACD,CAbM","sourcesContent":["import {\n ProductAttributeDTO,\n CustomField,\n AttributeRuleDTOConstraintEnum,\n ProductDTO,\n ProductVariantDTO,\n InventoryAvailability,\n OptionDefinitionDTO,\n SelectedOptionDTO,\n IdReferenceDTO,\n CategoryDTO,\n ProductVariantLabelDTO,\n} from '@sentecacommerce/sdk'\n\nimport {\n AttributeRulesMap,\n CombinationsMap,\n BooleanKVP,\n InventoryAvailabilityType,\n MetaInformationType,\n OptionsType,\n} from '../index'\n\nimport { createEmbededVideo } from './createEmbededVideo'\n\nimport { getTranslatableField } from '../../../utils'\n\n// export const createMappedInventory = (\n// currentVariant: ProductVariantDraftDTO,\n// inventory?: SkuReservationResponseDTO\n// ) => {\n// const currentInventory = inventory?.find(\n// (x) => x.sku === currentVariant.sku\n// )\n\n// const mappedInventory = {\n// ...currentInventory,\n// status:\n// currentInventory?.status === SkuReservationDTOStatusEnum.Available\n// ? true\n// : false,\n// inventoryId: currentInventory?.inventoryReservations?.[0].inventoryId,\n// quantity: currentInventory?.inventoryReservations?.[0].quantity,\n// }\n\n// return mappedInventory\n// }\n\nexport const createCustomFieldsMap = (customFields?: CustomField[]) => {\n return customFields?.reduce((map: BooleanKVP, currentObj) => {\n map[currentObj.field] = currentObj.value\n return map\n }, {})\n}\n\nexport const createCombinationsMap = (\n mappedAttributeRulesKeys: string[],\n attributesArray: {\n variantId: string\n attributes: ProductAttributeDTO[]\n }[]\n) => {\n const combinationsMap: CombinationsMap = {}\n mappedAttributeRulesKeys.forEach((key) => {\n attributesArray.forEach((p) => {\n const currentKey = p.attributes.find((x) => x.name === key)\n const filtered = p.attributes.filter((x) => x.name !== key)\n\n let currentCombination = combinationsMap[currentKey?.value]\n\n if (!currentCombination) {\n currentCombination = {\n params: {},\n value: '',\n }\n }\n\n currentCombination.value = p.variantId\n\n filtered.forEach((attribute) => {\n currentCombination.params = {\n ...currentCombination.params,\n [attribute.value]: p.variantId,\n }\n })\n\n combinationsMap[currentKey?.value] = currentCombination\n })\n })\n\n return combinationsMap\n}\n\nexport const assignCombinationsToAttributeRules = (\n mappedAttributeRules: AttributeRulesMap,\n combinationsMap: CombinationsMap\n) => {\n Object.keys(mappedAttributeRules).forEach((key) => {\n const current = mappedAttributeRules[key].values\n Object.keys(current).forEach((currentKey) => {\n mappedAttributeRules[key].values[currentKey].combinations =\n combinationsMap[currentKey]?.params\n })\n })\n}\n\nexport const createProductContent = (\n data: any\n): { key: string; name: string; content: string } => {\n return {\n key: data.key,\n name: getTranslatableField(data.label),\n content: getTranslatableField(data.content),\n }\n}\n\nexport const createAttributeRulesMap = (product?: ProductDTO) => {\n const uniqueRules = product?.attributeRules?.filter(\n (x) => x.constraint === AttributeRuleDTOConstraintEnum.CombinationUnique\n )\n const reduceVariantsToAttributeRuleValues = (map: any, attribute: any) => {\n const found = uniqueRules?.find((x) => x.attributeName === attribute.name)\n if (found) {\n if (!map[attribute.name]) {\n map[attribute.name] = {\n ...found,\n label: getTranslatableField(attribute.data.label),\n values: {},\n }\n }\n\n map[attribute.name] = {\n ...map[attribute.name],\n values: {\n ...map[attribute.name].values,\n [attribute.value]: {\n label: getTranslatableField(attribute.valueData.label),\n extra: attribute.valueData.extra,\n },\n },\n }\n }\n\n return map\n }\n\n const mappedAttributeRules = product?.variants\n ?.map((v) => v.attributes)\n .flat()\n .reduce(reduceVariantsToAttributeRuleValues, {})\n\n return mappedAttributeRules\n}\n\nexport const createMappedOptions = (\n options?: OptionDefinitionDTO[]\n): OptionsType[] => {\n const mappedOptions =\n options?.map((currentOption) => {\n return {\n definitionKey: currentOption.key,\n label: getTranslatableField(currentOption?.label),\n elements: currentOption.options?.map((subOption) => {\n return {\n optionKey: subOption.key,\n label: getTranslatableField(subOption?.label),\n imageIndex: subOption?.imageIndex,\n }\n }),\n }\n }) || []\n\n return mappedOptions\n}\n\nexport type SelectedOptionType = {\n label?: string\n value?: { key?: string; label?: string; imageIndex?: number }\n}\n\nexport const createSelectedOption2 = (\n options?: OptionsType[],\n selectedOption?: SelectedOptionDTO\n): SelectedOptionType => {\n const currentOption = options?.find(\n (availableOption) =>\n availableOption.definitionKey === selectedOption?.definitionKey\n )\n\n const value = currentOption?.elements?.find(\n (element) => element.optionKey === selectedOption?.optionKey\n )\n\n return {\n label: currentOption?.label,\n value: {\n key: value?.optionKey,\n imageIndex: value?.imageIndex,\n label: value?.label,\n },\n }\n}\n\nexport const createSelectedOption = (\n options?: OptionDefinitionDTO[],\n selectedOption?: SelectedOptionDTO\n): SelectedOptionType => {\n const currentOption = options?.find(\n (availableOption) => availableOption.key === selectedOption?.definitionKey\n )\n\n const value = currentOption?.options?.find(\n (optionValue) => optionValue.key === selectedOption?.optionKey\n )\n\n return {\n label: getTranslatableField(currentOption?.label),\n value: {\n key: value?.key,\n imageIndex: value?.imageIndex,\n label: getTranslatableField(value?.label),\n },\n }\n}\n\nexport const createMappedAttributes = (currentVariant: ProductVariantDTO) => {\n const mappedAttributes =\n currentVariant.attributes?.reduce(\n (attributeArray: ProductAttributeDTO[], attribute) => {\n attributeArray.push({\n name: attribute.name,\n value: attribute.value,\n valueData: attribute.valueData,\n })\n return attributeArray\n },\n []\n ) || []\n\n return mappedAttributes\n}\n\nexport const processAvailabilityPerStore = (\n availabilities?: InventoryAvailability[]\n): InventoryAvailabilityType[] | undefined => {\n return availabilities\n ?.filter((x) => !x.isPhysical)\n ?.map(\n ({\n acceptsBackorders,\n stockLocationName,\n restockableInDays,\n availableQuantity,\n }) => {\n return {\n storeName: getTranslatableField(stockLocationName),\n availableQuantity,\n acceptsBackorders,\n restockableInDays: restockableInDays,\n }\n }\n )\n}\n\nexport const getProductVideos = (assets: MetaInformationType['assets']) => {\n if (assets?.youtube) {\n const videos = assets.youtube.sources.map((a) => {\n const embeded = createEmbededVideo(a)\n return {\n type: 'video',\n source: a.url,\n iframe: embeded.iframe,\n thumb: { url: embeded.thumbnail },\n }\n })\n\n return videos\n }\n return []\n}\n\nexport const formatCategories = (\n categories?: IdReferenceDTO[],\n rootCategoryId?: string\n) => {\n let results\n\n if (\n categories?.some((cat) =>\n cat.resource.custom.some(\n (customField: any) => customField.field === 'isTemporary'\n )\n )\n ) {\n results = categories?.filter((cat) =>\n cat.resource.custom.some((customField: any) =>\n customField.field === 'isTemporary' ? !customField.value : true\n )\n )\n } else {\n results = categories?.filter(\n (cat) =>\n cat?.resourceId === rootCategoryId ||\n cat?.resource?.ancestors?.some(\n (ancestor: any) => ancestor.resource === rootCategoryId\n )\n )\n }\n\n const formattedResults = results?.map((category) => {\n if (category.resource) {\n const resource = category.resource as CategoryDTO\n\n return {\n name: getTranslatableField(resource.name),\n id: category.resourceId || '',\n link: `/${getTranslatableField(resource.slug)}/c`,\n }\n }\n\n const cat = (category as unknown) as CategoryDTO\n\n return {\n name: getTranslatableField(cat.name),\n id: cat._id || '',\n link: `/${getTranslatableField(cat.slug)}/c`,\n }\n })\n\n return formattedResults || []\n}\n\nexport const createLabelsMap = (data?: ProductVariantLabelDTO[]) => {\n // Filter only labels that are currently active\n const now = new Date().getTime()\n\n const currentLabels = data?.filter((el) => {\n if (!el.validFrom || !el.validTo) {\n return el\n } else {\n return el.validFrom < now && el.validTo > now\n }\n })\n\n return currentLabels?.map((el) => el.key)\n}\n"],"file":"index.js"}
|
@@ -17,6 +17,11 @@ export interface ContentType {
|
|
17
17
|
name?: string;
|
18
18
|
content?: string;
|
19
19
|
}
|
20
|
+
export interface MetaInfoCategoryType {
|
21
|
+
name: string;
|
22
|
+
id: string;
|
23
|
+
link: string;
|
24
|
+
}
|
20
25
|
export interface MetaInformationType {
|
21
26
|
_id?: string;
|
22
27
|
name?: string;
|
@@ -40,11 +45,7 @@ export interface MetaInformationType {
|
|
40
45
|
name?: string;
|
41
46
|
slug?: string;
|
42
47
|
};
|
43
|
-
categories?:
|
44
|
-
name: string;
|
45
|
-
id: string;
|
46
|
-
link: string;
|
47
|
-
}[];
|
48
|
+
categories?: MetaInfoCategoryType[];
|
48
49
|
content?: ContentType[];
|
49
50
|
assets?: AssetsMap;
|
50
51
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentecacommerce-theme/lib",
|
3
3
|
"sideEffects": false,
|
4
|
-
"version": "0.11.
|
4
|
+
"version": "0.11.72",
|
5
5
|
"main": "dist/cjs/index.js",
|
6
6
|
"module": "dist/esm/index.js",
|
7
7
|
"types": "dist/types/index.d.ts",
|
@@ -27,9 +27,9 @@
|
|
27
27
|
"build:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts,.tsx -d dist/cjs --source-maps",
|
28
28
|
"build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types"
|
29
29
|
},
|
30
|
-
"gitHead": "
|
30
|
+
"gitHead": "6ec87ddeeadbb1f0359c303ee5543463adb186f9",
|
31
31
|
"dependencies": {
|
32
|
-
"@sentecacommerce-theme/base": "^0.11.
|
32
|
+
"@sentecacommerce-theme/base": "^0.11.72",
|
33
33
|
"@sentecacommerce/sdk": "^2.0.89",
|
34
34
|
"body-scroll-lock": "^3.1.5",
|
35
35
|
"copy-to-clipboard": "^3.3.1",
|