@sentecacommerce-theme/lib 0.12.63 → 0.12.64

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.
@@ -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","split","el","collapseKey","selectVariantByCombination","attr","params","selectVariantOptions","definitionKey","optionKey","newSelectedVariant","filter","opt","mappedSelectedOptions","option","attributeRule","values","result","forEach","currentKey","found","getVariantById","getVariantByAttribute","getVariantByCombination","getCustomFieldValue","field","getCombinationsForAttributeRule","collapsedImages","state","functions","getProductVideos","useProductState","context","useContext","Error","useProductFunctions","useProduct","config","productsApi"],"mappings":";;;;;;;;;;;;AAAA;;AACA;;;;AASA;;AACA;;AAgBA;;AACA;;AA2LA,IAAMA,mBAAmB,gBAAGC,kBAAMC,aAAN,CAE1BC,SAF0B,CAA5B;;AAGA,IAAMC,oBAAoB,gBAAGH,kBAAMC,aAAN,CAE3BC,S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mI,UAAN,CAAiBpI,mBAAjB,CAAhB;;AACA,MAAImI,OAAO,KAAKhI,SAAhB,EAA2B;AACzB,UAAM,IAAIkI,KAAJ,CAAU,uDAAV,CAAN;AACD;;AACD,SAAOF,OAAP;AACD;;AACM,SAASG,mBAAT,GAA+B;AACpC,MAAMH,OAAO,GAAGlI,kBAAMmI,UAAN,CAAiBhI,oBAAjB,CAAhB;;AACA,MAAI+H,OAAO,KAAKhI,SAAhB,EAA2B;AACzB,UAAM,IAAIkI,KAAJ,CAAU,0DAAV,CAAN;AACD;;AACD,SAAOF,OAAP;AACD;;AAEM,SAASI,UAAT,CAAoBxG,IAApB,EAAkCyG,MAAlC,EAAmE;AACxE,SAAOC,yBAAYF,UAAZ,CAAuBxG,IAAvB,EAA6ByG,MAA7B,CAAP;AACD","sourcesContent":["import React from 'react'\nimport {\n ProductDTO,\n ProductVariantDTO,\n AttributeRuleDTO,\n ProductAttributeDraftDTO,\n SelectedOptionDTO,\n ReviewRatingStatisticsDTO,\n AssetSourceDTO,\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 createCollapseKeyImagesMap,\n} from './utils'\nimport { productsApi, getProductBySlugConfig } from '../../api/productsApi'\nimport { assetsFieldsToMap, AssetsMap } from '../../utils/assetsToMap'\n\nexport { AssetSourceDTO }\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 key: string\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 // Get by collapseKey for SD\n const split = key.split(':')\n if (split[0] === 'collapseKey') {\n const id = Object.keys(variants).find(\n (el) => variants[el].collapseKey === split[1]\n )\n return setSelectedVariant(variants[id as string])\n }\n const id = combinations[key]?.value\n setSelectedVariant(variants[id])\n }\n\n function selectVariantByCombination(key: string, value: string) {\n // Take collapseKey for SD\n const split = value.split(':')\n if (split[0] === 'collapseKey') {\n const id = Object.keys(variants).find(\n (el) =>\n variants[el].collapseKey === split[1] &&\n variants[el].attributes.find((attr) => attr.name === 'size')\n ?.value === key\n )\n return setSelectedVariant(variants[id as string])\n }\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 collapsedImages = createCollapseKeyImagesMap(product)\n\n const state = {\n metaData,\n seoData,\n variants,\n selectedVariant,\n attributeRules,\n collapsedImages,\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","split","el","collapseKey","selectVariantByCombination","attr","params","selectVariantOptions","definitionKey","optionKey","newSelectedVariant","filter","opt","mappedSelectedOptions","option","attributeRule","values","result","forEach","currentKey","found","getVariantById","getVariantByAttribute","getVariantByCombination","getCustomFieldValue","field","getCombinationsForAttributeRule","collapsedImages","state","functions","getProductVideos","useProductState","context","useContext","Error","useProductFunctions","useProduct","config","productsApi"],"mappings":";;;;;;;;;;;;AAAA;;AACA;;;;AASA;;AACA;;AAgBA;;AACA;;AA4LA,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,CAlBmB;AAAA,MAgBrBC,eAhBqB;AAAA,MAiBrBC,kBAjBqB;;AAoBvB,MAAMC,QAAQ,GAAGrB,kBAAMsB,OAAN,CAAc,YAAM;AAAA;;AACnC,QAAMC,YAAY,GAAGlB,OAAH,2CAAGA,OAAO,CAAEmB,UAAZ,qBAAG,oBAAsB,CAAtB,CAArB;AACA,QAAMC,cAAc,GAAGF,YAAH,oB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AAOhBsB,IAAAA,+BAA+B,EAA/BA,+BAPgB;AAQhBnB,IAAAA,oBAAoB,EAApBA,oBARgB;AAShBiB,IAAAA,mBAAmB,EAAnBA,mBATgB;AAUhBM,IAAAA,gBAAgB,EAAE;AAAA,aAAM,6BAAiB3G,QAAQ,CAACiB,MAA1B,CAAN;AAAA;AAVF,GAAlB;AAaA,sBACE,gCAAC,mBAAD,CAAqB,QAArB;AAA8B,IAAA,KAAK,EAAEwF;AAArC,kBACE,gCAAC,oBAAD,CAAsB,QAAtB;AAA+B,IAAA,KAAK,EAAEC;AAAtC,KACGzH,QADH,CADF,CADF;AAOD;;AAEM,SAAS2H,eAAT,GAA2B;AAChC,MAAMC,OAAO,GAAGlI,kBAAMmI,UAAN,CAAiBpI,mBAAjB,CAAhB;;AACA,MAAImI,OAAO,KAAKhI,SAAhB,EAA2B;AACzB,UAAM,IAAIkI,KAAJ,CAAU,uDAAV,CAAN;AACD;;AACD,SAAOF,OAAP;AACD;;AACM,SAASG,mBAAT,GAA+B;AACpC,MAAMH,OAAO,GAAGlI,kBAAMmI,UAAN,CAAiBhI,oBAAjB,CAAhB;;AACA,MAAI+H,OAAO,KAAKhI,SAAhB,EAA2B;AACzB,UAAM,IAAIkI,KAAJ,CAAU,0DAAV,CAAN;AACD;;AACD,SAAOF,OAAP;AACD;;AAEM,SAASI,UAAT,CAAoBxG,IAApB,EAAkCyG,MAAlC,EAAmE;AACxE,SAAOC,yBAAYF,UAAZ,CAAuBxG,IAAvB,EAA6ByG,MAA7B,CAAP;AACD","sourcesContent":["import React from 'react'\nimport {\n ProductDTO,\n ProductVariantDTO,\n AttributeRuleDTO,\n ProductAttributeDraftDTO,\n SelectedOptionDTO,\n ReviewRatingStatisticsDTO,\n AssetSourceDTO,\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 createCollapseKeyImagesMap,\n} from './utils'\nimport { productsApi, getProductBySlugConfig } from '../../api/productsApi'\nimport { assetsFieldsToMap, AssetsMap } from '../../utils/assetsToMap'\n\nexport { AssetSourceDTO }\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 key: string\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 collapsedImages?: object\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 // Get by collapseKey for SD\n const split = key.split(':')\n if (split[0] === 'collapseKey') {\n const id = Object.keys(variants).find(\n (el) => variants[el].collapseKey === split[1]\n )\n return setSelectedVariant(variants[id as string])\n }\n const id = combinations[key]?.value\n setSelectedVariant(variants[id])\n }\n\n function selectVariantByCombination(key: string, value: string) {\n // Take collapseKey for SD\n const split = value.split(':')\n if (split[0] === 'collapseKey') {\n const id = Object.keys(variants).find(\n (el) =>\n variants[el].collapseKey === split[1] &&\n variants[el].attributes.find((attr) => attr.name === 'size')\n ?.value === key\n )\n return setSelectedVariant(variants[id as string])\n }\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 collapsedImages = createCollapseKeyImagesMap(product)\n\n const state = {\n metaData,\n seoData,\n variants,\n selectedVariant,\n attributeRules,\n collapsedImages,\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 +1 @@
1
- {"version":3,"sources":["../../../../src/hooks/useProduct/index.tsx"],"names":["React","AssetSourceDTO","getTranslatableField","assignCombinationsToAttributeRules","createCombinationsMap","createCustomFieldsMap","createProductContent","createAttributeRulesMap","createMappedAttributes","processAvailabilityPerStore","getProductVideos","createMappedOptions","createSelectedOption2","formatCategories","createLabelsMap","createCollapseKeyImagesMap","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","split","el","collapseKey","selectVariantByCombination","attr","params","selectVariantOptions","definitionKey","optionKey","newSelectedVariant","filter","opt","mappedSelectedOptions","option","attributeRule","values","result","forEach","currentKey","found","getVariantById","getVariantByAttribute","getVariantByCombination","getCustomFieldValue","field","getCombinationsForAttributeRule","collapsedImages","state","functions","useProductState","context","useContext","Error","useProductFunctions","useProduct","config"],"mappings":";AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAOEC,cAPF,QAQO,sBARP;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,EAcEC,0BAdF,QAeO,SAfP;A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C,OAAO,GAAGlJ,KAAK,CAACmJ,UAAN,CAAiBjI,mBAAjB,CAAhB;;AACA,MAAIgI,OAAO,KAAK9H,SAAhB,EAA2B;AACzB,UAAM,IAAIgI,KAAJ,CAAU,uDAAV,CAAN;AACD;;AACD,SAAOF,OAAP;AACD;AACD,OAAO,SAASG,mBAAT,GAA+B;AACpC,MAAMH,OAAO,GAAGlJ,KAAK,CAACmJ,UAAN,CAAiB9H,oBAAjB,CAAhB;;AACA,MAAI6H,OAAO,KAAK9H,SAAhB,EAA2B;AACzB,UAAM,IAAIgI,KAAJ,CAAU,0DAAV,CAAN;AACD;;AACD,SAAOF,OAAP;AACD;AAED,OAAO,SAASI,UAAT,CAAoBtG,IAApB,EAAkCuG,MAAlC,EAAmE;AACxE,SAAOvI,WAAW,CAACsI,UAAZ,CAAuBtG,IAAvB,EAA6BuG,MAA7B,CAAP;AACD","sourcesContent":["import React from 'react'\nimport {\n ProductDTO,\n ProductVariantDTO,\n AttributeRuleDTO,\n ProductAttributeDraftDTO,\n SelectedOptionDTO,\n ReviewRatingStatisticsDTO,\n AssetSourceDTO,\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 createCollapseKeyImagesMap,\n} from './utils'\nimport { productsApi, getProductBySlugConfig } from '../../api/productsApi'\nimport { assetsFieldsToMap, AssetsMap } from '../../utils/assetsToMap'\n\nexport { AssetSourceDTO }\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 key: string\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 // Get by collapseKey for SD\n const split = key.split(':')\n if (split[0] === 'collapseKey') {\n const id = Object.keys(variants).find(\n (el) => variants[el].collapseKey === split[1]\n )\n return setSelectedVariant(variants[id as string])\n }\n const id = combinations[key]?.value\n setSelectedVariant(variants[id])\n }\n\n function selectVariantByCombination(key: string, value: string) {\n // Take collapseKey for SD\n const split = value.split(':')\n if (split[0] === 'collapseKey') {\n const id = Object.keys(variants).find(\n (el) =>\n variants[el].collapseKey === split[1] &&\n variants[el].attributes.find((attr) => attr.name === 'size')\n ?.value === key\n )\n return setSelectedVariant(variants[id as string])\n }\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 collapsedImages = createCollapseKeyImagesMap(product)\n\n const state = {\n metaData,\n seoData,\n variants,\n selectedVariant,\n attributeRules,\n collapsedImages,\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","AssetSourceDTO","getTranslatableField","assignCombinationsToAttributeRules","createCombinationsMap","createCustomFieldsMap","createProductContent","createAttributeRulesMap","createMappedAttributes","processAvailabilityPerStore","getProductVideos","createMappedOptions","createSelectedOption2","formatCategories","createLabelsMap","createCollapseKeyImagesMap","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","split","el","collapseKey","selectVariantByCombination","attr","params","selectVariantOptions","definitionKey","optionKey","newSelectedVariant","filter","opt","mappedSelectedOptions","option","attributeRule","values","result","forEach","currentKey","found","getVariantById","getVariantByAttribute","getVariantByCombination","getCustomFieldValue","field","getCombinationsForAttributeRule","collapsedImages","state","functions","useProductState","context","useContext","Error","useProductFunctions","useProduct","config"],"mappings":";AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAOEC,cAPF,QAQO,sBARP;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,EAcEC,0BAdF,QAeO,SAfP;AAgBA,SAASC,WAAT,QAAoD,uBAApD;AACA,SAASC,iBAAT,QAA6C,yBAA7C;AAEA,SAAShB,cAAT;AA0LA,IAAMiB,mBAAmB,gBAAGlB,KAAK,CAACmB,aAAN,CAE1BC,SAF0B,CAA5B;AAGA,IAAMC,oBAAoB,gBAAGrB,KAAK,CAACmB,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,IAAwB3B,KAAK,CAAC4B,QAAN,CAAe,KAA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,CAAoBtG,IAApB,EAAkCuG,MAAlC,EAAmE;AACxE,SAAOvI,WAAW,CAACsI,UAAZ,CAAuBtG,IAAvB,EAA6BuG,MAA7B,CAAP;AACD","sourcesContent":["import React from 'react'\nimport {\n ProductDTO,\n ProductVariantDTO,\n AttributeRuleDTO,\n ProductAttributeDraftDTO,\n SelectedOptionDTO,\n ReviewRatingStatisticsDTO,\n AssetSourceDTO,\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 createCollapseKeyImagesMap,\n} from './utils'\nimport { productsApi, getProductBySlugConfig } from '../../api/productsApi'\nimport { assetsFieldsToMap, AssetsMap } from '../../utils/assetsToMap'\n\nexport { AssetSourceDTO }\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 key: string\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 collapsedImages?: object\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 // Get by collapseKey for SD\n const split = key.split(':')\n if (split[0] === 'collapseKey') {\n const id = Object.keys(variants).find(\n (el) => variants[el].collapseKey === split[1]\n )\n return setSelectedVariant(variants[id as string])\n }\n const id = combinations[key]?.value\n setSelectedVariant(variants[id])\n }\n\n function selectVariantByCombination(key: string, value: string) {\n // Take collapseKey for SD\n const split = value.split(':')\n if (split[0] === 'collapseKey') {\n const id = Object.keys(variants).find(\n (el) =>\n variants[el].collapseKey === split[1] &&\n variants[el].attributes.find((attr) => attr.name === 'size')\n ?.value === key\n )\n return setSelectedVariant(variants[id as string])\n }\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 collapsedImages = createCollapseKeyImagesMap(product)\n\n const state = {\n metaData,\n seoData,\n variants,\n selectedVariant,\n attributeRules,\n collapsedImages,\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"}
@@ -136,6 +136,7 @@ declare type ProductStateContextType = {
136
136
  seoData: SeoInformationType;
137
137
  variants?: VariantMap;
138
138
  selectedVariant?: VariantType | null;
139
+ collapsedImages?: object;
139
140
  };
140
141
  export declare type VideoType = {
141
142
  type: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentecacommerce-theme/lib",
3
3
  "sideEffects": false,
4
- "version": "0.12.63",
4
+ "version": "0.12.64",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/types/index.d.ts",
@@ -28,9 +28,9 @@
28
28
  "build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types",
29
29
  "dev": "yarn build:esm --watch"
30
30
  },
31
- "gitHead": "23b0e6c849dede416af70244dcb41af8310e90f6",
31
+ "gitHead": "f178b41577e7384d5d7e2397f552ef5a44dba56d",
32
32
  "dependencies": {
33
- "@sentecacommerce-theme/base": "^0.12.63",
33
+ "@sentecacommerce-theme/base": "^0.12.64",
34
34
  "@sentecacommerce/sdk": "2.0.133",
35
35
  "body-scroll-lock": "^3.1.5",
36
36
  "copy-to-clipboard": "^3.3.1",