@sentecacommerce-theme/lib 0.12.63 → 0.12.67
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/hooks/order-hooks/useReferralOrders/index.js.map +1 -1
- package/dist/cjs/hooks/useLineItem/index.js +4 -0
- package/dist/cjs/hooks/useLineItem/index.js.map +1 -1
- package/dist/cjs/hooks/useProduct/index.js.map +1 -1
- package/dist/esm/hooks/order-hooks/useReferralOrders/index.js.map +1 -1
- package/dist/esm/hooks/useLineItem/index.js +2 -0
- package/dist/esm/hooks/useLineItem/index.js.map +1 -1
- package/dist/esm/hooks/useProduct/index.js.map +1 -1
- package/dist/types/hooks/basket-hooks/useBasketItemList/index.d.ts +1 -0
- package/dist/types/hooks/order-hooks/api/queries/useOrderGetPaymentMethodQuery.d.ts +1 -16
- package/dist/types/hooks/order-hooks/useReferralOrders/index.d.ts +1 -0
- package/dist/types/hooks/useLineItem/index.d.ts +2 -2
- package/dist/types/hooks/useProduct/index.d.ts +1 -0
- package/package.json +4 -4
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../src/hooks/order-hooks/useReferralOrders/index.ts"],"names":["useReferralOrders","query","filter"],"mappings":";;;;;;;;;;;AACA;;AACA;;AAEO,IAAMA,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,KAAD,
|
1
|
+
{"version":3,"sources":["../../../../../src/hooks/order-hooks/useReferralOrders/index.ts"],"names":["useReferralOrders","query","filter"],"mappings":";;;;;;;;;;;AACA;;AACA;;AAEO,IAAMA,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,KAAD,EAM3B;AACJ,SAAO,kCACL,CAACA,KAAD,oBAACA,KAAK,CAAEC,MAAR,EAAgB,gBAAhB,CADK,6FAEL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB,sCAA4BD,KAA5B,CAAlB;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAFK,GAAP;AAID,CAXM","sourcesContent":["import React from 'react'\nimport { useInfiniteQuery } from 'react-query'\nimport { MyOrdersGetMyReferralOrders } from '@sentecacommerce/sdk'\n\nexport const useReferralOrders = (query?: {\n limit?: number\n offset?: number\n filter?: string\n project?: string\n sort?: string\n}) => {\n return useInfiniteQuery(\n [query?.filter, 'referralOrders'],\n async () => await MyOrdersGetMyReferralOrders(query)\n )\n}\n"],"file":"index.js"}
|
@@ -9,6 +9,10 @@ var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
9
9
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
11
11
|
|
12
|
+
var _sdk = require("@sentecacommerce/sdk");
|
13
|
+
|
14
|
+
exports.OfferDTOStatusEnum = _sdk.OfferDTOStatusEnum;
|
15
|
+
|
12
16
|
var _utils = require("../../utils");
|
13
17
|
|
14
18
|
var _usePrefetchProduct2 = require("../usePrefetchProduct");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/hooks/useLineItem/index.tsx"],"names":["useLineItem","props","slug","onMouseEnter","onMouseLeave","onMouseDown","data","React","useMemo","mappedAttributes","Object","keys","attributes","reduce","map","key","current","count","length","elements","attribute","_id","value","label","extra","customFields","custom","Boolean","field","name","brand","brands","collapseKey","variantId","offerId","offer","sku","images","ratings","reviewRatingStatistics","price","originalPrice","discountedPrice","variantOptions","variantsCount","categories","category","inventory","hasAvailableQuantity","inventorySnapshot","canOrder","availableQuantity","maxQuantity","labels","mapLabelData","getCustomFieldByKey","getAttributeByKey","callback","now","Date","getTime","currentLabels","filter","el","validFrom","validTo"],"mappings":";;;;;;;;;AAAA;;AAUA;;AACA;;
|
1
|
+
{"version":3,"sources":["../../../../src/hooks/useLineItem/index.tsx"],"names":["useLineItem","props","slug","onMouseEnter","onMouseLeave","onMouseDown","data","React","useMemo","mappedAttributes","Object","keys","attributes","reduce","map","key","current","count","length","elements","attribute","_id","value","label","extra","customFields","custom","Boolean","field","name","brand","brands","collapseKey","variantId","offerId","offer","sku","images","ratings","reviewRatingStatistics","price","originalPrice","discountedPrice","variantOptions","variantsCount","categories","category","inventory","hasAvailableQuantity","inventorySnapshot","canOrder","availableQuantity","maxQuantity","labels","mapLabelData","getCustomFieldByKey","getAttributeByKey","callback","now","Date","getTime","currentLabels","filter","el","validFrom","validTo"],"mappings":";;;;;;;;;AAAA;;AACA;;;;AAUA;;AACA;;AAuDO,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAACC,KAAD,EAA4B;AAAA,4BACD,6CAClD,iCAAqBA,KAArB,oBAAqBA,KAAK,CAAEC,IAA5B,CADkD,CADC;AAAA,MAC7CC,aAD6C,uBAC7CA,YAD6C;AAAA,MAC/BC,aAD+B,uBAC/BA,YAD+B;AAAA,MACjBC,YADiB,uBACjBA,WADiB;;AAKrD,MAAMC,IAAkB,GAAGC,kBAAMC,OAAN,CAAc,YAAM;AAAA;;AAC7C,QAAMC,gBAAgB,mBAAGC,MAAM,CAACC,IAAP,CAAYV,KAAZ,oBAAYA,KAAK,CAAEW,UAAnB,CAAH,qBAAG,aAAgCC,MAAhC,CACvB,UAACC,GAAD,EAAMC,GAAN,EAAc;AAAA;;AACZ,UAAMC,OAAO,GAAGf,KAAH,oBAAGA,KAAK,CAAEW,UAAP,CAAkBG,GAAlB,CAAhB;AACAD,MAAAA,GAAG,CAACC,GAAD,CAAH,GAAW;AACTE,QAAAA,KAAK,qBAAED,OAAF,oBAAEA,OAAO,CAAEE,MAAX,8BAAqB,CADjB;AAETC,QAAAA,QAAQ,EAAEH,OAAF,oBAAEA,OAAO,CAAEF,GAAT,CAAa,UAACM,SAAD,EAAoB;AACzC,iBAAO;AACLC,YAAAA,GAAG,EAAED,SAAF,oBAAEA,SAAS,CAAEE,KADX;AAELC,YAAAA,KAAK,EAAE,iCAAqBH,SAArB,oBAAqBA,SAAS,CAAEG,KAAhC,CAFF;AAGLC,YAAAA,KAAK,EAAEJ,SAAF,oBAAEA,SAAS,CAAEI;AAHb,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D;AAAA,WAAQA,EAAE,CAAChD,GAAX;AAAA,GAAnB,CAAP;AACD,CAZD","sourcesContent":["import React from 'react'\nimport {\n SearchResultDTO,\n ImageDTO,\n MoneyDTO,\n ReviewRatingStatisticsDTO,\n OfferDTO,\n OfferDTOStatusEnum,\n ProductVariantLabelDTO,\n} from '@sentecacommerce/sdk'\n\nimport { getTranslatableField } from '../../utils'\nimport { usePrefetchProduct } from '../usePrefetchProduct'\n\nexport { OfferDTOStatusEnum }\n\nexport interface BaseProductType {\n name: string\n slug: string\n variantId: string\n offerId?: string\n offer?: OfferDTO\n collapseKey?: string\n sku: string\n images?: ImageDTO[]\n inventory: {\n hasAvailableQuantity: boolean\n availableQuantity: number\n maxQuantity?: number\n }\n onMouseEnter: (callback: () => void) => void\n onMouseLeave: () => void\n onMouseDown: (callback: () => void) => void\n}\n\nexport interface AttributeType {\n _id: string\n label: string\n extra?: any\n}\n\nexport interface AttributesType {\n count: number\n elements: AttributeType[]\n}\n\ninterface LineItemType extends BaseProductType {\n name: string\n brand?: {\n name: string\n slug: string\n }\n _id: string\n labels?: string[]\n price?: MoneyDTO\n discountedPrice?: MoneyDTO\n variantOptions: number\n variantsCount: number\n categories: {\n name: string\n slug: string\n }[]\n ratings: ReviewRatingStatisticsDTO\n getAttributeByKey: (key: string) => AttributesType\n getCustomFieldByKey: (key: string) => any\n}\n\nexport const useLineItem = (props: SearchResultDTO) => {\n const { onMouseEnter, onMouseLeave, onMouseDown } = usePrefetchProduct(\n getTranslatableField(props?.slug)\n )\n\n const data: LineItemType = React.useMemo(() => {\n const mappedAttributes = Object.keys(props?.attributes)?.reduce(\n (map, key) => {\n const current = props?.attributes[key]\n map[key] = {\n count: current?.length ?? 0,\n elements: current?.map((attribute: any) => {\n return {\n _id: attribute?.value,\n label: getTranslatableField(attribute?.label),\n extra: attribute?.extra,\n }\n }),\n }\n return map\n },\n {}\n )\n\n const customFields = props?.custom?.reduce(\n (map: { [key: string]: any }, current) => {\n if (Boolean(current.value) && current.value !== '0') {\n return { ...map, [current.field]: current.value }\n }\n return map\n },\n {}\n )\n\n return {\n _id: props?._id,\n name: getTranslatableField(props?.name),\n brand: {\n name: getTranslatableField(props?.brands?.[0]?.name),\n slug: getTranslatableField(props?.brands?.[0]?.slug),\n },\n slug: getTranslatableField(props?.slug),\n collapseKey: props?.collapseKey,\n variantId: props?.variantId,\n offerId: props?.offer?._id,\n offer: props?.offer,\n sku: props?.sku,\n images: props?.images || {},\n ratings: props?.reviewRatingStatistics,\n price: props?.offer?.originalPrice,\n discountedPrice: props?.offer?.discountedPrice,\n variantOptions: props?.variantOptions ?? 0,\n variantsCount: props?.variantsCount ?? 0,\n categories: props?.categories.map((category) => ({\n name: getTranslatableField(category.name),\n slug: getTranslatableField(category.slug),\n })),\n inventory: {\n hasAvailableQuantity: props?.inventorySnapshot?.canOrder ? true : false,\n availableQuantity: props?.inventorySnapshot?.canOrder\n ? props?.inventorySnapshot?.availableQuantity ?? 0\n : 0,\n maxQuantity: props?.offer?.maxQuantity,\n },\n labels: mapLabelData(props?.labels),\n getCustomFieldByKey: (key: string) => customFields?.[key],\n getAttributeByKey: (key: string) => mappedAttributes?.[key],\n onMouseEnter: (callback) => onMouseEnter(callback),\n onMouseLeave: () => onMouseLeave(),\n onMouseDown: (callback) => () => onMouseDown(callback),\n }\n }, [props])\n\n return data\n}\n\nconst mapLabelData = (data?: ProductVariantLabelDTO[]) => {\n // Filter only labels that are currently active\n const now = new Date().getTime()\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 +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,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,MA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AM,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;;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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/order-hooks/useReferralOrders/index.ts"],"names":["useInfiniteQuery","MyOrdersGetMyReferralOrders","useReferralOrders","query","filter"],"mappings":";AACA,SAASA,gBAAT,QAAiC,aAAjC;AACA,SAASC,2BAAT,QAA4C,sBAA5C;AAEA,OAAO,IAAMC,iBAAiB,GAAIC,KAAD,
|
1
|
+
{"version":3,"sources":["../../../../../src/hooks/order-hooks/useReferralOrders/index.ts"],"names":["useInfiniteQuery","MyOrdersGetMyReferralOrders","useReferralOrders","query","filter"],"mappings":";AACA,SAASA,gBAAT,QAAiC,aAAjC;AACA,SAASC,2BAAT,QAA4C,sBAA5C;AAEA,OAAO,IAAMC,iBAAiB,GAAIC,KAAD,IAM3B;AACJ,SAAOH,gBAAgB,CACrB,CAACG,KAAD,oBAACA,KAAK,CAAEC,MAAR,EAAgB,gBAAhB,CADqB,iCAErB;AAAA,iBAAkBH,2BAA2B,CAACE,KAAD,CAA7C;AAAA,GAFqB,EAAvB;AAID,CAXM","sourcesContent":["import React from 'react'\nimport { useInfiniteQuery } from 'react-query'\nimport { MyOrdersGetMyReferralOrders } from '@sentecacommerce/sdk'\n\nexport const useReferralOrders = (query?: {\n limit?: number\n offset?: number\n filter?: string\n project?: string\n sort?: string\n}) => {\n return useInfiniteQuery(\n [query?.filter, 'referralOrders'],\n async () => await MyOrdersGetMyReferralOrders(query)\n )\n}\n"],"file":"index.js"}
|
@@ -1,7 +1,9 @@
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
2
2
|
import React from 'react';
|
3
|
+
import { OfferDTOStatusEnum } from '@sentecacommerce/sdk';
|
3
4
|
import { getTranslatableField } from '../../utils';
|
4
5
|
import { usePrefetchProduct } from '../usePrefetchProduct';
|
6
|
+
export { OfferDTOStatusEnum };
|
5
7
|
export var useLineItem = props => {
|
6
8
|
var {
|
7
9
|
onMouseEnter: _onMouseEnter,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/hooks/useLineItem/index.tsx"],"names":["React","getTranslatableField","usePrefetchProduct","useLineItem","props","onMouseEnter","onMouseLeave","onMouseDown","slug","data","useMemo","mappedAttributes","Object","keys","attributes","reduce","map","key","current","count","length","elements","attribute","_id","value","label","extra","customFields","custom","Boolean","field","name","brand","brands","collapseKey","variantId","offerId","offer","sku","images","ratings","reviewRatingStatistics","price","originalPrice","discountedPrice","variantOptions","variantsCount","categories","category","inventory","hasAvailableQuantity","inventorySnapshot","canOrder","availableQuantity","maxQuantity","labels","mapLabelData","getCustomFieldByKey","getAttributeByKey","callback","now","Date","getTime","currentLabels","filter","el","validFrom","validTo"],"mappings":";AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAUA,SAASC,oBAAT,QAAqC,aAArC;AACA,SAASC,kBAAT,QAAmC,uBAAnC;AAqDA,OAAO,
|
1
|
+
{"version":3,"sources":["../../../../src/hooks/useLineItem/index.tsx"],"names":["React","OfferDTOStatusEnum","getTranslatableField","usePrefetchProduct","useLineItem","props","onMouseEnter","onMouseLeave","onMouseDown","slug","data","useMemo","mappedAttributes","Object","keys","attributes","reduce","map","key","current","count","length","elements","attribute","_id","value","label","extra","customFields","custom","Boolean","field","name","brand","brands","collapseKey","variantId","offerId","offer","sku","images","ratings","reviewRatingStatistics","price","originalPrice","discountedPrice","variantOptions","variantsCount","categories","category","inventory","hasAvailableQuantity","inventorySnapshot","canOrder","availableQuantity","maxQuantity","labels","mapLabelData","getCustomFieldByKey","getAttributeByKey","callback","now","Date","getTime","currentLabels","filter","el","validFrom","validTo"],"mappings":";AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAMEC,kBANF,QAQO,sBARP;AAUA,SAASC,oBAAT,QAAqC,aAArC;AACA,SAASC,kBAAT,QAAmC,uBAAnC;AAEA,SAASF,kBAAT;AAqDA,OAAO,IAAMG,WAAW,GAAIC,KAAD,IAA4B;AACrD,MAAM;AAAEC,IAAAA,YAAY,EAAZA,aAAF;AAAgBC,IAAAA,YAAY,EAAZA,aAAhB;AAA8BC,IAAAA,WAAW,EAAXA;AAA9B,MAA8CL,kBAAkB,CACpED,oBAAoB,CAACG,KAAD,oBAACA,KAAK,CAAEI,IAAR,CADgD,CAAtE;AAIA,MAAMC,IAAkB,GAAGV,KAAK,CAACW,OAAN,CAAc,MAAM;AAAA;;AAC7C,QAAMC,gBAAgB,mBAAGC,MAAM,CAACC,IAAP,CAAYT,KAAZ,oBAAYA,KAAK,CAAEU,UAAnB,CAAH,qBAAG,aAAgCC,MAAhC,CACvB,CAACC,GAAD,EAAMC,GAAN,KAAc;AAAA;;AACZ,UAAMC,OAAO,GAAGd,KAAH,oBAAGA,KAAK,CAAEU,UAAP,CAAkBG,GAAlB,CAAhB;AACAD,MAAAA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AACD,EAAE,CAACE,OAAzB,EAAkC;AAChC,aAAOF,EAAP;AACD,KAFD,MAEO;AACL,aAAOA,EAAE,CAACC,SAAH,GAAeN,GAAf,IAAsBK,EAAE,CAACE,OAAH,GAAaP,GAA1C;AACD;AACF,GANqB,CAAtB;AAQA,SAAOG,aAAP,oBAAOA,aAAa,CAAE/C,GAAf,CAAoBiD,EAAD,IAAQA,EAAE,CAAChD,GAA9B,CAAP;AACD,CAZD","sourcesContent":["import React from 'react'\nimport {\n SearchResultDTO,\n ImageDTO,\n MoneyDTO,\n ReviewRatingStatisticsDTO,\n OfferDTO,\n OfferDTOStatusEnum,\n ProductVariantLabelDTO,\n} from '@sentecacommerce/sdk'\n\nimport { getTranslatableField } from '../../utils'\nimport { usePrefetchProduct } from '../usePrefetchProduct'\n\nexport { OfferDTOStatusEnum }\n\nexport interface BaseProductType {\n name: string\n slug: string\n variantId: string\n offerId?: string\n offer?: OfferDTO\n collapseKey?: string\n sku: string\n images?: ImageDTO[]\n inventory: {\n hasAvailableQuantity: boolean\n availableQuantity: number\n maxQuantity?: number\n }\n onMouseEnter: (callback: () => void) => void\n onMouseLeave: () => void\n onMouseDown: (callback: () => void) => void\n}\n\nexport interface AttributeType {\n _id: string\n label: string\n extra?: any\n}\n\nexport interface AttributesType {\n count: number\n elements: AttributeType[]\n}\n\ninterface LineItemType extends BaseProductType {\n name: string\n brand?: {\n name: string\n slug: string\n }\n _id: string\n labels?: string[]\n price?: MoneyDTO\n discountedPrice?: MoneyDTO\n variantOptions: number\n variantsCount: number\n categories: {\n name: string\n slug: string\n }[]\n ratings: ReviewRatingStatisticsDTO\n getAttributeByKey: (key: string) => AttributesType\n getCustomFieldByKey: (key: string) => any\n}\n\nexport const useLineItem = (props: SearchResultDTO) => {\n const { onMouseEnter, onMouseLeave, onMouseDown } = usePrefetchProduct(\n getTranslatableField(props?.slug)\n )\n\n const data: LineItemType = React.useMemo(() => {\n const mappedAttributes = Object.keys(props?.attributes)?.reduce(\n (map, key) => {\n const current = props?.attributes[key]\n map[key] = {\n count: current?.length ?? 0,\n elements: current?.map((attribute: any) => {\n return {\n _id: attribute?.value,\n label: getTranslatableField(attribute?.label),\n extra: attribute?.extra,\n }\n }),\n }\n return map\n },\n {}\n )\n\n const customFields = props?.custom?.reduce(\n (map: { [key: string]: any }, current) => {\n if (Boolean(current.value) && current.value !== '0') {\n return { ...map, [current.field]: current.value }\n }\n return map\n },\n {}\n )\n\n return {\n _id: props?._id,\n name: getTranslatableField(props?.name),\n brand: {\n name: getTranslatableField(props?.brands?.[0]?.name),\n slug: getTranslatableField(props?.brands?.[0]?.slug),\n },\n slug: getTranslatableField(props?.slug),\n collapseKey: props?.collapseKey,\n variantId: props?.variantId,\n offerId: props?.offer?._id,\n offer: props?.offer,\n sku: props?.sku,\n images: props?.images || {},\n ratings: props?.reviewRatingStatistics,\n price: props?.offer?.originalPrice,\n discountedPrice: props?.offer?.discountedPrice,\n variantOptions: props?.variantOptions ?? 0,\n variantsCount: props?.variantsCount ?? 0,\n categories: props?.categories.map((category) => ({\n name: getTranslatableField(category.name),\n slug: getTranslatableField(category.slug),\n })),\n inventory: {\n hasAvailableQuantity: props?.inventorySnapshot?.canOrder ? true : false,\n availableQuantity: props?.inventorySnapshot?.canOrder\n ? props?.inventorySnapshot?.availableQuantity ?? 0\n : 0,\n maxQuantity: props?.offer?.maxQuantity,\n },\n labels: mapLabelData(props?.labels),\n getCustomFieldByKey: (key: string) => customFields?.[key],\n getAttributeByKey: (key: string) => mappedAttributes?.[key],\n onMouseEnter: (callback) => onMouseEnter(callback),\n onMouseLeave: () => onMouseLeave(),\n onMouseDown: (callback) => () => onMouseDown(callback),\n }\n }, [props])\n\n return data\n}\n\nconst mapLabelData = (data?: ProductVariantLabelDTO[]) => {\n // Filter only labels that are currently active\n const now = new Date().getTime()\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 +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,QA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AlB;AAaA,sBACE,oBAAC,mBAAD,CAAqB,QAArB;AAA8B,IAAA,KAAK,EAAEuF;AAArC,kBACE,oBAAC,oBAAD,CAAsB,QAAtB;AAA+B,IAAA,KAAK,EAAEC;AAAtC,KACGxH,QADH,CADF,CADF;AAOD;AAED,OAAO,SAASyH,eAAT,GAA2B;AAChC,MAAMC,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,aA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AA+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 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,16 +1 @@
|
|
1
|
-
export declare const useOrderGetPaymentMethodQuery: (orderId: string) => import("react-query").QueryResult<
|
2
|
-
name: string;
|
3
|
-
description: string;
|
4
|
-
_id: string;
|
5
|
-
createdAt: number;
|
6
|
-
updatedAt: number;
|
7
|
-
version?: number | undefined;
|
8
|
-
key: string;
|
9
|
-
type: import("@sentecacommerce/sdk").PaymentMethodDTOTypeEnum;
|
10
|
-
moduleKey?: string | undefined;
|
11
|
-
authority: import("@sentecacommerce/sdk").PaymentMethodDTOAuthorityEnum;
|
12
|
-
merchantKey?: string | undefined;
|
13
|
-
countryCode: string;
|
14
|
-
currencyCode: string;
|
15
|
-
config: any;
|
16
|
-
}, unknown>;
|
1
|
+
export declare const useOrderGetPaymentMethodQuery: (orderId: string) => import("react-query").QueryResult<any, unknown>;
|
@@ -3,4 +3,5 @@ export declare const useReferralOrders: (query?: {
|
|
3
3
|
offset?: number | undefined;
|
4
4
|
filter?: string | undefined;
|
5
5
|
project?: string | undefined;
|
6
|
+
sort?: string | undefined;
|
6
7
|
} | undefined) => import("react-query").InfiniteQueryResult<import("@sentecacommerce/sdk").OrderFilterResultDTO, unknown>;
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import { SearchResultDTO, ImageDTO, MoneyDTO, ReviewRatingStatisticsDTO, OfferDTO } from '@sentecacommerce/sdk';
|
1
|
+
import { SearchResultDTO, ImageDTO, MoneyDTO, ReviewRatingStatisticsDTO, OfferDTO, OfferDTOStatusEnum } from '@sentecacommerce/sdk';
|
2
|
+
export { OfferDTOStatusEnum };
|
2
3
|
export interface BaseProductType {
|
3
4
|
name: string;
|
4
5
|
slug: string;
|
@@ -47,4 +48,3 @@ interface LineItemType extends BaseProductType {
|
|
47
48
|
getCustomFieldByKey: (key: string) => any;
|
48
49
|
}
|
49
50
|
export declare const useLineItem: (props: SearchResultDTO) => LineItemType;
|
50
|
-
export {};
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentecacommerce-theme/lib",
|
3
3
|
"sideEffects": false,
|
4
|
-
"version": "0.12.
|
4
|
+
"version": "0.12.67",
|
5
5
|
"main": "dist/cjs/index.js",
|
6
6
|
"module": "dist/esm/index.js",
|
7
7
|
"types": "dist/types/index.d.ts",
|
@@ -28,10 +28,10 @@
|
|
28
28
|
"build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types",
|
29
29
|
"dev": "yarn build:esm --watch"
|
30
30
|
},
|
31
|
-
"gitHead": "
|
31
|
+
"gitHead": "94c712f1b69e10e75c058eb6a5efdb8cf8462c4b",
|
32
32
|
"dependencies": {
|
33
|
-
"@sentecacommerce-theme/base": "^0.12.
|
34
|
-
"@sentecacommerce/sdk": "2.0.
|
33
|
+
"@sentecacommerce-theme/base": "^0.12.67",
|
34
|
+
"@sentecacommerce/sdk": "2.0.142",
|
35
35
|
"body-scroll-lock": "^3.1.5",
|
36
36
|
"copy-to-clipboard": "^3.3.1",
|
37
37
|
"embla-carousel": "^4.5.1",
|