@sentecacommerce-theme/lib 0.12.61 → 0.12.65

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.
Files changed (63) hide show
  1. package/dist/cjs/contexts/CheckoutForm/index.js +1 -1
  2. package/dist/cjs/contexts/CheckoutForm/index.js.map +1 -1
  3. package/dist/cjs/hooks/useProduct/index.js +29 -1
  4. package/dist/cjs/hooks/useProduct/index.js.map +1 -1
  5. package/dist/cjs/hooks/useProduct/utils/index.js +21 -4
  6. package/dist/cjs/hooks/useProduct/utils/index.js.map +1 -1
  7. package/dist/cjs/order/api/mutations/index.js +8 -0
  8. package/dist/cjs/order/api/mutations/index.js.map +1 -1
  9. package/dist/cjs/order/api/mutations/useUpdateCustomLineItemMutation.js.map +1 -1
  10. package/dist/cjs/order/api/mutations/useUpdateOrderCustomFieldMutation.js +20 -0
  11. package/dist/cjs/order/api/mutations/useUpdateOrderCustomFieldMutation.js.map +1 -0
  12. package/dist/cjs/order/hooks/index.js +8 -0
  13. package/dist/cjs/order/hooks/index.js.map +1 -1
  14. package/dist/cjs/order/hooks/useUpdateCustomLineItem.js.map +1 -1
  15. package/dist/cjs/order/hooks/useUpdateOrderCustomField.js +13 -0
  16. package/dist/cjs/order/hooks/useUpdateOrderCustomField.js.map +1 -0
  17. package/dist/cjs/user/api/queries/index.js +8 -0
  18. package/dist/cjs/user/api/queries/index.js.map +1 -1
  19. package/dist/cjs/user/api/queries/useGetMyLoyaltyCardQuery.js +24 -0
  20. package/dist/cjs/user/api/queries/useGetMyLoyaltyCardQuery.js.map +1 -0
  21. package/dist/cjs/user/hooks/index.js +8 -0
  22. package/dist/cjs/user/hooks/index.js.map +1 -1
  23. package/dist/cjs/user/hooks/useGetMyLoyaltyCard.js +13 -0
  24. package/dist/cjs/user/hooks/useGetMyLoyaltyCard.js.map +1 -0
  25. package/dist/esm/contexts/CheckoutForm/index.js +1 -1
  26. package/dist/esm/contexts/CheckoutForm/index.js.map +1 -1
  27. package/dist/esm/hooks/useProduct/index.js +26 -2
  28. package/dist/esm/hooks/useProduct/index.js.map +1 -1
  29. package/dist/esm/hooks/useProduct/utils/index.js +16 -2
  30. package/dist/esm/hooks/useProduct/utils/index.js.map +1 -1
  31. package/dist/esm/order/api/mutations/index.js +1 -0
  32. package/dist/esm/order/api/mutations/index.js.map +1 -1
  33. package/dist/esm/order/api/mutations/useUpdateCustomLineItemMutation.js.map +1 -1
  34. package/dist/esm/order/api/mutations/useUpdateOrderCustomFieldMutation.js +9 -0
  35. package/dist/esm/order/api/mutations/useUpdateOrderCustomFieldMutation.js.map +1 -0
  36. package/dist/esm/order/hooks/index.js +1 -0
  37. package/dist/esm/order/hooks/index.js.map +1 -1
  38. package/dist/esm/order/hooks/useUpdateCustomLineItem.js.map +1 -1
  39. package/dist/esm/order/hooks/useUpdateOrderCustomField.js +5 -0
  40. package/dist/esm/order/hooks/useUpdateOrderCustomField.js.map +1 -0
  41. package/dist/esm/user/api/queries/index.js +1 -0
  42. package/dist/esm/user/api/queries/index.js.map +1 -1
  43. package/dist/esm/user/api/queries/useGetMyLoyaltyCardQuery.js +11 -0
  44. package/dist/esm/user/api/queries/useGetMyLoyaltyCardQuery.js.map +1 -0
  45. package/dist/esm/user/hooks/index.js +1 -0
  46. package/dist/esm/user/hooks/index.js.map +1 -1
  47. package/dist/esm/user/hooks/useGetMyLoyaltyCard.js +5 -0
  48. package/dist/esm/user/hooks/useGetMyLoyaltyCard.js.map +1 -0
  49. package/dist/types/hooks/basket-hooks/useBasketItemList/index.d.ts +1 -0
  50. package/dist/types/hooks/order-hooks/api/queries/useOrderGetPaymentMethodQuery.d.ts +1 -16
  51. package/dist/types/hooks/useProduct/index.d.ts +1 -0
  52. package/dist/types/hooks/useProduct/utils/index.d.ts +1 -0
  53. package/dist/types/order/api/mutations/index.d.ts +1 -0
  54. package/dist/types/order/api/mutations/useUpdateCustomLineItemMutation.d.ts +2 -5
  55. package/dist/types/order/api/mutations/useUpdateOrderCustomFieldMutation.d.ts +9 -0
  56. package/dist/types/order/hooks/index.d.ts +1 -0
  57. package/dist/types/order/hooks/useUpdateCustomLineItem.d.ts +2 -2
  58. package/dist/types/order/hooks/useUpdateOrderCustomField.d.ts +2 -0
  59. package/dist/types/user/api/queries/index.d.ts +1 -0
  60. package/dist/types/user/api/queries/useGetMyLoyaltyCardQuery.d.ts +5 -0
  61. package/dist/types/user/hooks/index.d.ts +1 -0
  62. package/dist/types/user/hooks/useGetMyLoyaltyCard.d.ts +2 -0
  63. package/package.json +4 -4
@@ -72,7 +72,7 @@ function CheckoutFormContextProvider(_ref) {
72
72
  _ref$requiredFieldsOn = _ref.requiredFieldsOnShippingStep,
73
73
  requiredFieldsOnShippingStep = _ref$requiredFieldsOn === void 0 ? ['firstName', 'lastName', 'email', 'phoneNumber'] : _ref$requiredFieldsOn,
74
74
  _ref$requiredFieldsOn2 = _ref.requiredFieldsOnBillingAddressStep,
75
- requiredFieldsOnBillingAddressStep = _ref$requiredFieldsOn2 === void 0 ? ['city', 'postalCode', 'streetName'] : _ref$requiredFieldsOn2,
75
+ requiredFieldsOnBillingAddressStep = _ref$requiredFieldsOn2 === void 0 ? ['vatId', 'companyId', 'companyPerson', 'companyName'] : _ref$requiredFieldsOn2,
76
76
  _ref$enableNoShipping = _ref.enableNoShippingMethodMode,
77
77
  enableNoShippingMethodMode = _ref$enableNoShipping === void 0 ? false : _ref$enableNoShipping,
78
78
  _ref$disablePaymentRe = _ref.disablePaymentRedirects,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/contexts/CheckoutForm/index.tsx"],"names":["CheckoutFormContext","CheckoutFormContextProvider","children","defaultStep","errorLabels","enableSavedAddressList","withPersistBeforePageLeave","shippingValidations","defaultShippingValidations","validateBillingAddress","genericBillingAddressValidation","enableSaveBillingAddress","enableSavedBillingAddressList","countryCode","enableSaveAddress","autofillShippingPersonalData","onSubmit","paymentEnabledOnStep","getPaymentMethodsWhenShippingMethodIsSelected","shippingEnabledOnStep","billingEnabledOnStep","customState","initialCustomState","redirectTimeout","onBeforeRedirect","onSuccess","onError","isBoricaInDevMode","withPixelMeta","requiredFieldsOnShippingStep","requiredFieldsOnBillingAddressStep","enableNoShippingMethodMode","disablePaymentRedirects","orderQuery","myCartApi","useGet","boricaData","setBoricaData","step","setStep","isRedirecting","setIsRedirecting","fieldsWithError","serverErrors","setServerErrors","collectFieldsWithError","error","push","handleStepChange","newStep","window","scrollTo","updateServerErrors","errors","formattedErrors","reduce","data","code","response","internalError","isAuthenticated","isShippingEnabled","userQuery","usersApi","enabled","shippingState","Boolean","validations","requiredFields","mod","getIsPaymentMethodsEnabled","moduleKey","moduleData","methodKey","paymentState","billingState","withSavedBillingAddressList","requiredFieldsOnShipping","onBeforeBoricaRedirect","setTimeout","onBeforePaypalRedirect","location","replace","redirectUrl","withMeta","handleCheckoutSubmit","scrollToFirstError","interval","setInterval","errorElement","top","clearInterval","handleSubmit","e","preventDefault","Promise","all","persistShippingAddress","persistBillingAddress","isShippingValid","isValid","setIsShippingSubmitting","updateIsSubmitting","isBillingValid","setIsBillingSubmitting","isPaymentValid","setIsPaymentSubmitting","updateStep","saveOrder","shippingAddress","state","errorRef","errorFields","CheckoutFormStepsEnum","useCheckoutFormStep","context","Error","currentStep","useCheckoutFormOrder","useCheckoutFormErrorLabels","useCheckoutFormServerErrors","useCheckoutFormBillingState","useCheckoutFormShippingState","useCheckoutErrorFields","useCheckoutFormPaymentState"],"mappings":";;;;;;;;;;;;;;;;AAAA;;AAcA;;AACA;;AAQA;;AACA;;AAEA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AAEO,IAAMA,mBAAmB,gBAAG,0BACjC,EADiC,CAA5B;;;AAMA,SAASC,2BAAT,OAoCG;AAAA,MAnCRC,QAmCQ,QAnCRA,QAmCQ;AAAA,MAlCRC,WAkCQ,QAlCRA,WAkCQ;AAAA,MAjCRC,WAiCQ,QAjCRA,WAiCQ;AAAA,MAhCRC,sBAgCQ,QAhCRA,sBAgCQ;AAA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C,KAAJ,CACJ,0EADI,CAAN;AAGD;;AAED,SAAO;AACLJ,IAAAA,WAAW,EAAEG,OAAO,CAACH,WADhB;AAELD,IAAAA,QAAQ,EAAEI,OAAO,CAACJ;AAFb,GAAP;AAID,CAbM;;;;AAeA,IAAMa,2BAA2B,GAAG,SAA9BA,2BAA8B,GAAM;AAC/C,MAAMT,OAAO,GAAG,uBAAWnH,mBAAX,CAAhB;;AAEA,MAAI,CAACmH,OAAL,EAAc;AACZ,UAAM,IAAIC,KAAJ,CACJ,+EADI,CAAN;AAGD;;AAED,SAAOD,OAAO,CAACzC,YAAf;AACD,CAVM","sourcesContent":["import React, {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useState,\n} from 'react'\nimport {\n BoricaGeneratePaymentDataResponse,\n OrderDTO,\n AddressDTO,\n PaypalGeneratePaymentUrlResponseDTO,\n} from '@sentecacommerce/sdk'\nimport { MutateFunction, QueryResult } from 'react-query'\nimport { myCartApi } from '../../api/myCartApi'\nimport {\n useBilling,\n UseBillingResultType,\n usePayment,\n UsePaymentResultType,\n useShipping,\n UseShippingResultType,\n} from './hooks'\nimport { useIsAuthenticated } from '../../user/hooks'\nimport { useCheckoutSubmit } from '../../hooks/useCheckoutSubmit'\n\nimport {\n ShippingValidationsType,\n defaultShippingValidations,\n genericBillingAddressValidation,\n BillingAddressValidationType,\n} from './utils'\nimport { usersApi } from '../../api/usersApi'\nimport { useCheckoutShippingModule } from '../../hooks/useCheckoutShippingModule'\nimport { CheckoutFormCustomStateProvider, BoricaRedirect } from './Components'\nimport { useScrollTo } from '../../hooks/ui-hooks'\nimport { getElementOffset } from '../../utils/getElementOffset'\n\nexport const CheckoutFormContext = createContext<CheckoutFormContextType>(\n {} as any\n)\n\nexport type CheckoutCustomState = {}\n\nexport function CheckoutFormContextProvider({\n children,\n defaultStep,\n errorLabels,\n enableSavedAddressList,\n withPersistBeforePageLeave,\n shippingValidations = defaultShippingValidations,\n validateBillingAddress = genericBillingAddressValidation,\n enableSaveBillingAddress,\n enableSavedBillingAddressList,\n countryCode,\n enableSaveAddress,\n autofillShippingPersonalData,\n onSubmit,\n\n paymentEnabledOnStep,\n getPaymentMethodsWhenShippingMethodIsSelected,\n shippingEnabledOnStep,\n billingEnabledOnStep,\n\n customState: initialCustomState = {},\n redirectTimeout = 420,\n onBeforeRedirect,\n onSuccess,\n onError,\n isBoricaInDevMode,\n withPixelMeta = false,\n requiredFieldsOnShippingStep = [\n 'firstName',\n 'lastName',\n 'email',\n 'phoneNumber',\n ],\n requiredFieldsOnBillingAddressStep = ['city', 'postalCode', 'streetName'],\n enableNoShippingMethodMode = false,\n disablePaymentRedirects = false,\n}: Props) {\n const orderQuery = myCartApi.useGet()\n const [\n boricaData,\n setBoricaData,\n ] = useState<BoricaGeneratePaymentDataResponse | null>(null)\n const [step, setStep] = useState<CheckoutFormStepsEnum>(defaultStep)\n const [isRedirecting, setIsRedirecting] = useState(false)\n\n const fieldsWithError: HTMLElement[] = []\n\n const [serverErrors, setServerErrors] = useState<ServerErrors>(null)\n\n const collectFieldsWithError = (error: HTMLElement) => {\n fieldsWithError.push(error)\n }\n\n const handleStepChange = useCallback((newStep: CheckoutFormStepsEnum) => {\n window.scrollTo(0, 0)\n\n setStep(newStep)\n }, [])\n\n const updateServerErrors = useCallback((errors: any[]) => {\n // Example Error\n // [{\n // code: \"OutOfStock\"\n // message: \"Some of the ordered line items are out of stock at the time of placing the order.\"\n // responses: {\n // availableQuantity: 1\n // sku: \"200000095849\"\n // status: \"unavailable\"\n // }\n // }]\n const formattedErrors = errors?.reduce?.(\n (data: ServerErrors, error: any) => {\n return {\n ...data,\n [error?.code || 'internal']: error?.response,\n }\n },\n {}\n )\n setServerErrors(formattedErrors || { internalError: errors })\n }, [])\n\n const { isAuthenticated } = useIsAuthenticated()\n\n const isShippingEnabled = shippingEnabledOnStep === step\n\n const userQuery = usersApi.useGet(\n {},\n { enabled: isShippingEnabled && autofillShippingPersonalData }\n )\n\n const shippingState = useShipping({\n errorLabels,\n orderQuery,\n enableSavedAddressList: Boolean(isAuthenticated && enableSavedAddressList),\n enableSaveAddress: Boolean(isAuthenticated && enableSaveAddress),\n withPersistBeforePageLeave: !isRedirecting && withPersistBeforePageLeave,\n validations: shippingValidations,\n autofillShippingPersonalData: Boolean(\n isAuthenticated && autofillShippingPersonalData\n ),\n userQuery,\n enabled: isShippingEnabled,\n countryCode,\n requiredFields: requiredFieldsOnShippingStep,\n enableNoShippingMethodMode,\n })\n const mod = useCheckoutShippingModule(orderQuery, !enableNoShippingMethodMode)\n\n const getIsPaymentMethodsEnabled = () => {\n if (paymentEnabledOnStep) {\n return paymentEnabledOnStep === step\n }\n\n if (\n !enableNoShippingMethodMode &&\n getPaymentMethodsWhenShippingMethodIsSelected\n ) {\n return Boolean(mod?.moduleKey && mod?.moduleData.methodKey)\n }\n\n return false\n }\n\n const paymentState = usePayment({\n errorLabels,\n orderQuery,\n enabled: getIsPaymentMethodsEnabled(),\n })\n\n const billingState = useBilling({\n errorLabels,\n orderQuery,\n validateBillingAddress,\n enableSaveBillingAddress: Boolean(\n isAuthenticated && enableSaveBillingAddress\n ),\n withSavedBillingAddressList: Boolean(\n isAuthenticated && enableSavedBillingAddressList\n ),\n withPersistBeforePageLeave: !isRedirecting && withPersistBeforePageLeave,\n countryCode,\n enabled: billingEnabledOnStep === step,\n requiredFields: requiredFieldsOnBillingAddressStep,\n requiredFieldsOnShipping: requiredFieldsOnShippingStep,\n })\n\n const onBeforeBoricaRedirect = (data: BoricaGeneratePaymentDataResponse) => {\n if (disablePaymentRedirects) return\n\n onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n setBoricaData(data)\n }, redirectTimeout)\n }\n\n const onBeforePaypalRedirect = (\n data: PaypalGeneratePaymentUrlResponseDTO\n ) => {\n if (disablePaymentRedirects) return\n\n onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n window.location.replace(data.redirectUrl)\n }, redirectTimeout)\n }\n const { handleCheckoutSubmit } = useCheckoutSubmit({\n onBeforeBoricaRedirect,\n onBeforePaypalRedirect,\n onSuccess,\n onError: (errors: any) => {\n updateServerErrors(errors)\n onError(errors)\n },\n withMeta: withPixelMeta,\n disablePaymentRedirects,\n })\n\n const { scrollTo } = useScrollTo(fieldsWithError[0], 0)\n\n const scrollToFirstError = () => {\n const interval = setInterval(() => {\n const errorElement = fieldsWithError[0]\n if (!errorElement) return\n\n scrollTo(getElementOffset(errorElement).top - 100)\n clearInterval(interval)\n }, 50)\n\n setTimeout(() => {\n clearInterval(interval)\n }, 1000)\n }\n\n const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n\n await Promise.all([\n shippingState.persistShippingAddress(),\n billingState.persistBillingAddress(),\n ]).catch(() => {})\n\n onSubmit({\n isShippingValid: shippingState.isValid,\n setIsShippingSubmitting: shippingState.updateIsSubmitting,\n isBillingValid: billingState.isValid,\n setIsBillingSubmitting: billingState.updateIsSubmitting,\n isPaymentValid: paymentState.isValid,\n setIsPaymentSubmitting: paymentState.updateIsSubmitting,\n step,\n updateStep: setStep,\n saveOrder: handleCheckoutSubmit,\n updateServerErrors,\n scrollToFirstError,\n shippingState,\n shippingAddress: shippingState.data,\n })\n }\n\n const state = {\n setStep: handleStepChange,\n step,\n orderQuery,\n serverErrors,\n updateServerErrors,\n errorLabels,\n shippingState,\n paymentState,\n billingState,\n errorRef: collectFieldsWithError,\n errorFields: fieldsWithError,\n }\n\n return (\n <CheckoutFormContext.Provider value={state}>\n <CheckoutFormCustomStateProvider initialCustomState={initialCustomState}>\n <>\n <form noValidate onSubmit={handleSubmit}>\n {children}\n </form>\n {!!boricaData && (\n <BoricaRedirect\n isInDevMode={isBoricaInDevMode}\n formData={boricaData}\n />\n )}\n </>\n </CheckoutFormCustomStateProvider>\n </CheckoutFormContext.Provider>\n )\n}\n\nexport type CheckoutFormOnSubmitData = {\n isShippingValid: boolean\n setIsShippingSubmitting: (value: boolean) => void\n isBillingValid: boolean\n setIsBillingSubmitting: (value: boolean) => void\n isPaymentValid: boolean\n setIsPaymentSubmitting: (value: boolean) => void\n step: CheckoutFormStepsEnum\n updateStep: (step: CheckoutFormStepsEnum) => void\n saveOrder: MutateFunction<OrderDTO, unknown, any, unknown>\n\n updateServerErrors: (errors: any) => void\n scrollToFirstError: () => void\n shippingState: UseShippingResultType\n shippingAddress?: AddressDTO\n}\n\ntype Props = {\n children: any\n defaultStep: CheckoutFormStepsEnum\n errorLabels: CheckoutFormErrorLabelsType\n withPersistBeforePageLeave: boolean\n countryCode: string\n onSubmit: (data: CheckoutFormOnSubmitData) => void\n onError: (error: any) => void\n onSuccess: (order: OrderDTO) => void\n\n redirectTimeout?: number\n onBeforeRedirect?: () => void\n\n customState?: CheckoutCustomState\n\n enableSavedAddressList: boolean\n shippingValidations?: ShippingValidationsType\n enableSaveAddress: boolean\n autofillShippingPersonalData: boolean\n autoSelectDefaultShippingAddress: boolean\n\n enableSaveBillingAddress: boolean\n validateBillingAddress?: BillingAddressValidationType\n enableSavedBillingAddressList: boolean\n autoSelectDefaultBillingAddress: boolean\n\n paymentEnabledOnStep?: CheckoutFormStepsEnum\n getPaymentMethodsWhenShippingMethodIsSelected?: boolean\n\n shippingEnabledOnStep: CheckoutFormStepsEnum\n\n billingEnabledOnStep: CheckoutFormStepsEnum\n\n isBoricaInDevMode?: boolean\n\n withPixelMeta?: boolean\n requiredFieldsOnShippingStep?: string[]\n requiredFieldsOnBillingAddressStep?: string[]\n enableNoShippingMethodMode?: boolean\n disablePaymentRedirects?: boolean\n}\n\ntype ServerErrors = { [key: string]: any } | null\n\nexport enum CheckoutFormStepsEnum {\n Basket = 'Basket',\n Shipping = 'Shipping',\n BillingAddress = 'BillingAddress',\n Payment = 'Payment',\n Preview = 'Preview',\n All = 'All',\n}\n\nexport type CheckoutFormErrorsResultType =\n | {\n [key: string]: string\n }\n | null\n | undefined\n\nexport type ShippingFormErrorLabels = {\n fieldIsRequired: string\n fillStreetNumberBuildingEntranceOrApartment: string\n streetIsRequired: string\n invalidPhoneNumber?: string\n quarterIsRequired: string\n cantFindStreetOrQuarterMessage: string\n cityIsRequired: string\n emailIsRequired: string\n officeIsRequired: string\n selectCourier: string\n noStoreSelected: string\n}\n\nexport type CheckoutFormErrorLabelsType = ShippingFormErrorLabels & {\n selectPaymentMethod: string\n}\n\nexport type CheckoutFormContextType = {\n setStep: (step: CheckoutFormStepsEnum) => void\n step: CheckoutFormStepsEnum\n serverErrors: ServerErrors\n updateServerErrors: (errors: any) => void\n errorRef: (error: HTMLElement) => void\n errorFields: HTMLElement[]\n errorLabels: CheckoutFormErrorLabelsType\n orderQuery: QueryResult<OrderDTO, unknown>\n shippingState: UseShippingResultType\n paymentState: UsePaymentResultType\n billingState: UseBillingResultType\n}\n\nexport const useCheckoutFormStep = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormStep must be used within a CheckoutFormContextProvider'\n )\n }\n\n return useMemo(() => {\n return {\n currentStep: context.step,\n updateStep: context.setStep,\n }\n }, [context])\n}\n\nexport const useCheckoutFormOrder = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormOrder must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.orderQuery\n}\n\nexport const useCheckoutFormErrorLabels = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormErrorLabels must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.errorLabels\n}\n\nexport const useCheckoutFormServerErrors = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormServerErrors must be used within a CheckoutFormContextProvider'\n )\n }\n\n return useMemo(() => {\n return {\n serverErrors: context.serverErrors,\n updateServerErrors: context.updateServerErrors,\n }\n }, [context])\n}\n\nexport const useCheckoutFormBillingState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormBillingState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.billingState\n}\n\nexport const useCheckoutFormShippingState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormShippingState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.shippingState\n}\n\nexport const useCheckoutErrorFields = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutErrorFields must be used within a CheckoutFormContextProvider'\n )\n }\n\n return {\n errorFields: context.errorFields,\n errorRef: context.errorRef,\n }\n}\n\nexport const useCheckoutFormPaymentState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormPaymentState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.paymentState\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/contexts/CheckoutForm/index.tsx"],"names":["CheckoutFormContext","CheckoutFormContextProvider","children","defaultStep","errorLabels","enableSavedAddressList","withPersistBeforePageLeave","shippingValidations","defaultShippingValidations","validateBillingAddress","genericBillingAddressValidation","enableSaveBillingAddress","enableSavedBillingAddressList","countryCode","enableSaveAddress","autofillShippingPersonalData","onSubmit","paymentEnabledOnStep","getPaymentMethodsWhenShippingMethodIsSelected","shippingEnabledOnStep","billingEnabledOnStep","customState","initialCustomState","redirectTimeout","onBeforeRedirect","onSuccess","onError","isBoricaInDevMode","withPixelMeta","requiredFieldsOnShippingStep","requiredFieldsOnBillingAddressStep","enableNoShippingMethodMode","disablePaymentRedirects","orderQuery","myCartApi","useGet","boricaData","setBoricaData","step","setStep","isRedirecting","setIsRedirecting","fieldsWithError","serverErrors","setServerErrors","collectFieldsWithError","error","push","handleStepChange","newStep","window","scrollTo","updateServerErrors","errors","formattedErrors","reduce","data","code","response","internalError","isAuthenticated","isShippingEnabled","userQuery","usersApi","enabled","shippingState","Boolean","validations","requiredFields","mod","getIsPaymentMethodsEnabled","moduleKey","moduleData","methodKey","paymentState","billingState","withSavedBillingAddressList","requiredFieldsOnShipping","onBeforeBoricaRedirect","setTimeout","onBeforePaypalRedirect","location","replace","redirectUrl","withMeta","handleCheckoutSubmit","scrollToFirstError","interval","setInterval","errorElement","top","clearInterval","handleSubmit","e","preventDefault","Promise","all","persistShippingAddress","persistBillingAddress","isShippingValid","isValid","setIsShippingSubmitting","updateIsSubmitting","isBillingValid","setIsBillingSubmitting","isPaymentValid","setIsPaymentSubmitting","updateStep","saveOrder","shippingAddress","state","errorRef","errorFields","CheckoutFormStepsEnum","useCheckoutFormStep","context","Error","currentStep","useCheckoutFormOrder","useCheckoutFormErrorLabels","useCheckoutFormServerErrors","useCheckoutFormBillingState","useCheckoutFormShippingState","useCheckoutErrorFields","useCheckoutFormPaymentState"],"mappings":";;;;;;;;;;;;;;;;AAAA;;AAcA;;AACA;;AAQA;;AACA;;AAEA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AAEO,IAAMA,mBAAmB,gBAAG,0BACjC,EADiC,CAA5B;;;AAMA,SAASC,2BAAT,OAyCG;AAAA,MAxCRC,QAwCQ,QAxCRA,QAwCQ;AAAA,MAvCRC,WAuCQ,QAvCRA,WAuCQ;AAAA,MAtCRC,WAsCQ,QAtCRA,WAsCQ;AAAA,MArCRC,sBAqCQ,QArCRA,sBAqCQ;AAAA,MApCRC,0BAoCQ,QApCRA,0BAoCQ;AAAA,mCAnCRC,mBAmCQ;AAAA,MAnCRA,mBAmCQ,sCAnCcC,iCAmCd;AAAA,mCAlCRC,sBAkCQ;AAAA,MAlCRA,sBAkCQ,sCAlCiBC,sCAkCjB;AAAA,MAjCRC,wBAiCQ,QAjCRA,wBAiCQ;AAAA,MAhCRC,6BAgCQ,QAhCRA,6BAgCQ;AAAA,MA/BRC,WA+BQ,QA/BRA,WA+BQ;AAAA,MA9BRC,iBA8BQ,QA9BRA,iBA8BQ;AAAA,MA7BRC,4BA6BQ,QA7BRA,4BA6BQ;AAAA,MA5BRC,QA4BQ,QA5BRA,QA4BQ;AAAA,MA1BRC,oBA0BQ,QA1BR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useCallback,\n useContext,\n useMemo,\n useState,\n} from 'react'\nimport {\n BoricaGeneratePaymentDataResponse,\n OrderDTO,\n AddressDTO,\n PaypalGeneratePaymentUrlResponseDTO,\n} from '@sentecacommerce/sdk'\nimport { MutateFunction, QueryResult } from 'react-query'\nimport { myCartApi } from '../../api/myCartApi'\nimport {\n useBilling,\n UseBillingResultType,\n usePayment,\n UsePaymentResultType,\n useShipping,\n UseShippingResultType,\n} from './hooks'\nimport { useIsAuthenticated } from '../../user/hooks'\nimport { useCheckoutSubmit } from '../../hooks/useCheckoutSubmit'\n\nimport {\n ShippingValidationsType,\n defaultShippingValidations,\n genericBillingAddressValidation,\n BillingAddressValidationType,\n} from './utils'\nimport { usersApi } from '../../api/usersApi'\nimport { useCheckoutShippingModule } from '../../hooks/useCheckoutShippingModule'\nimport { CheckoutFormCustomStateProvider, BoricaRedirect } from './Components'\nimport { useScrollTo } from '../../hooks/ui-hooks'\nimport { getElementOffset } from '../../utils/getElementOffset'\n\nexport const CheckoutFormContext = createContext<CheckoutFormContextType>(\n {} as any\n)\n\nexport type CheckoutCustomState = {}\n\nexport function CheckoutFormContextProvider({\n children,\n defaultStep,\n errorLabels,\n enableSavedAddressList,\n withPersistBeforePageLeave,\n shippingValidations = defaultShippingValidations,\n validateBillingAddress = genericBillingAddressValidation,\n enableSaveBillingAddress,\n enableSavedBillingAddressList,\n countryCode,\n enableSaveAddress,\n autofillShippingPersonalData,\n onSubmit,\n\n paymentEnabledOnStep,\n getPaymentMethodsWhenShippingMethodIsSelected,\n shippingEnabledOnStep,\n billingEnabledOnStep,\n\n customState: initialCustomState = {},\n redirectTimeout = 420,\n onBeforeRedirect,\n onSuccess,\n onError,\n isBoricaInDevMode,\n withPixelMeta = false,\n requiredFieldsOnShippingStep = [\n 'firstName',\n 'lastName',\n 'email',\n 'phoneNumber',\n ],\n requiredFieldsOnBillingAddressStep = [\n 'vatId',\n 'companyId',\n 'companyPerson',\n 'companyName',\n ],\n enableNoShippingMethodMode = false,\n disablePaymentRedirects = false,\n}: Props) {\n const orderQuery = myCartApi.useGet()\n const [\n boricaData,\n setBoricaData,\n ] = useState<BoricaGeneratePaymentDataResponse | null>(null)\n const [step, setStep] = useState<CheckoutFormStepsEnum>(defaultStep)\n const [isRedirecting, setIsRedirecting] = useState(false)\n\n const fieldsWithError: HTMLElement[] = []\n\n const [serverErrors, setServerErrors] = useState<ServerErrors>(null)\n\n const collectFieldsWithError = (error: HTMLElement) => {\n fieldsWithError.push(error)\n }\n\n const handleStepChange = useCallback((newStep: CheckoutFormStepsEnum) => {\n window.scrollTo(0, 0)\n\n setStep(newStep)\n }, [])\n\n const updateServerErrors = useCallback((errors: any[]) => {\n // Example Error\n // [{\n // code: \"OutOfStock\"\n // message: \"Some of the ordered line items are out of stock at the time of placing the order.\"\n // responses: {\n // availableQuantity: 1\n // sku: \"200000095849\"\n // status: \"unavailable\"\n // }\n // }]\n const formattedErrors = errors?.reduce?.(\n (data: ServerErrors, error: any) => {\n return {\n ...data,\n [error?.code || 'internal']: error?.response,\n }\n },\n {}\n )\n setServerErrors(formattedErrors || { internalError: errors })\n }, [])\n\n const { isAuthenticated } = useIsAuthenticated()\n\n const isShippingEnabled = shippingEnabledOnStep === step\n\n const userQuery = usersApi.useGet(\n {},\n { enabled: isShippingEnabled && autofillShippingPersonalData }\n )\n\n const shippingState = useShipping({\n errorLabels,\n orderQuery,\n enableSavedAddressList: Boolean(isAuthenticated && enableSavedAddressList),\n enableSaveAddress: Boolean(isAuthenticated && enableSaveAddress),\n withPersistBeforePageLeave: !isRedirecting && withPersistBeforePageLeave,\n validations: shippingValidations,\n autofillShippingPersonalData: Boolean(\n isAuthenticated && autofillShippingPersonalData\n ),\n userQuery,\n enabled: isShippingEnabled,\n countryCode,\n requiredFields: requiredFieldsOnShippingStep,\n enableNoShippingMethodMode,\n })\n const mod = useCheckoutShippingModule(orderQuery, !enableNoShippingMethodMode)\n\n const getIsPaymentMethodsEnabled = () => {\n if (paymentEnabledOnStep) {\n return paymentEnabledOnStep === step\n }\n\n if (\n !enableNoShippingMethodMode &&\n getPaymentMethodsWhenShippingMethodIsSelected\n ) {\n return Boolean(mod?.moduleKey && mod?.moduleData.methodKey)\n }\n\n return false\n }\n\n const paymentState = usePayment({\n errorLabels,\n orderQuery,\n enabled: getIsPaymentMethodsEnabled(),\n })\n\n const billingState = useBilling({\n errorLabels,\n orderQuery,\n validateBillingAddress,\n enableSaveBillingAddress: Boolean(\n isAuthenticated && enableSaveBillingAddress\n ),\n withSavedBillingAddressList: Boolean(\n isAuthenticated && enableSavedBillingAddressList\n ),\n withPersistBeforePageLeave: !isRedirecting && withPersistBeforePageLeave,\n countryCode,\n enabled: billingEnabledOnStep === step,\n requiredFields: requiredFieldsOnBillingAddressStep,\n requiredFieldsOnShipping: requiredFieldsOnShippingStep,\n })\n\n const onBeforeBoricaRedirect = (data: BoricaGeneratePaymentDataResponse) => {\n if (disablePaymentRedirects) return\n\n onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n setBoricaData(data)\n }, redirectTimeout)\n }\n\n const onBeforePaypalRedirect = (\n data: PaypalGeneratePaymentUrlResponseDTO\n ) => {\n if (disablePaymentRedirects) return\n\n onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n window.location.replace(data.redirectUrl)\n }, redirectTimeout)\n }\n const { handleCheckoutSubmit } = useCheckoutSubmit({\n onBeforeBoricaRedirect,\n onBeforePaypalRedirect,\n onSuccess,\n onError: (errors: any) => {\n updateServerErrors(errors)\n onError(errors)\n },\n withMeta: withPixelMeta,\n disablePaymentRedirects,\n })\n\n const { scrollTo } = useScrollTo(fieldsWithError[0], 0)\n\n const scrollToFirstError = () => {\n const interval = setInterval(() => {\n const errorElement = fieldsWithError[0]\n if (!errorElement) return\n\n scrollTo(getElementOffset(errorElement).top - 100)\n clearInterval(interval)\n }, 50)\n\n setTimeout(() => {\n clearInterval(interval)\n }, 1000)\n }\n\n const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n\n await Promise.all([\n shippingState.persistShippingAddress(),\n billingState.persistBillingAddress(),\n ]).catch(() => {})\n\n onSubmit({\n isShippingValid: shippingState.isValid,\n setIsShippingSubmitting: shippingState.updateIsSubmitting,\n isBillingValid: billingState.isValid,\n setIsBillingSubmitting: billingState.updateIsSubmitting,\n isPaymentValid: paymentState.isValid,\n setIsPaymentSubmitting: paymentState.updateIsSubmitting,\n step,\n updateStep: setStep,\n saveOrder: handleCheckoutSubmit,\n updateServerErrors,\n scrollToFirstError,\n shippingState,\n shippingAddress: shippingState.data,\n })\n }\n\n const state = {\n setStep: handleStepChange,\n step,\n orderQuery,\n serverErrors,\n updateServerErrors,\n errorLabels,\n shippingState,\n paymentState,\n billingState,\n errorRef: collectFieldsWithError,\n errorFields: fieldsWithError,\n }\n\n return (\n <CheckoutFormContext.Provider value={state}>\n <CheckoutFormCustomStateProvider initialCustomState={initialCustomState}>\n <>\n <form noValidate onSubmit={handleSubmit}>\n {children}\n </form>\n {!!boricaData && (\n <BoricaRedirect\n isInDevMode={isBoricaInDevMode}\n formData={boricaData}\n />\n )}\n </>\n </CheckoutFormCustomStateProvider>\n </CheckoutFormContext.Provider>\n )\n}\n\nexport type CheckoutFormOnSubmitData = {\n isShippingValid: boolean\n setIsShippingSubmitting: (value: boolean) => void\n isBillingValid: boolean\n setIsBillingSubmitting: (value: boolean) => void\n isPaymentValid: boolean\n setIsPaymentSubmitting: (value: boolean) => void\n step: CheckoutFormStepsEnum\n updateStep: (step: CheckoutFormStepsEnum) => void\n saveOrder: MutateFunction<OrderDTO, unknown, any, unknown>\n\n updateServerErrors: (errors: any) => void\n scrollToFirstError: () => void\n shippingState: UseShippingResultType\n shippingAddress?: AddressDTO\n}\n\ntype Props = {\n children: any\n defaultStep: CheckoutFormStepsEnum\n errorLabels: CheckoutFormErrorLabelsType\n withPersistBeforePageLeave: boolean\n countryCode: string\n onSubmit: (data: CheckoutFormOnSubmitData) => void\n onError: (error: any) => void\n onSuccess: (order: OrderDTO) => void\n\n redirectTimeout?: number\n onBeforeRedirect?: () => void\n\n customState?: CheckoutCustomState\n\n enableSavedAddressList: boolean\n shippingValidations?: ShippingValidationsType\n enableSaveAddress: boolean\n autofillShippingPersonalData: boolean\n autoSelectDefaultShippingAddress: boolean\n\n enableSaveBillingAddress: boolean\n validateBillingAddress?: BillingAddressValidationType\n enableSavedBillingAddressList: boolean\n autoSelectDefaultBillingAddress: boolean\n\n paymentEnabledOnStep?: CheckoutFormStepsEnum\n getPaymentMethodsWhenShippingMethodIsSelected?: boolean\n\n shippingEnabledOnStep: CheckoutFormStepsEnum\n\n billingEnabledOnStep: CheckoutFormStepsEnum\n\n isBoricaInDevMode?: boolean\n\n withPixelMeta?: boolean\n requiredFieldsOnShippingStep?: string[]\n requiredFieldsOnBillingAddressStep?: string[]\n enableNoShippingMethodMode?: boolean\n disablePaymentRedirects?: boolean\n}\n\ntype ServerErrors = { [key: string]: any } | null\n\nexport enum CheckoutFormStepsEnum {\n Basket = 'Basket',\n Shipping = 'Shipping',\n BillingAddress = 'BillingAddress',\n Payment = 'Payment',\n Preview = 'Preview',\n All = 'All',\n}\n\nexport type CheckoutFormErrorsResultType =\n | {\n [key: string]: string\n }\n | null\n | undefined\n\nexport type ShippingFormErrorLabels = {\n fieldIsRequired: string\n fillStreetNumberBuildingEntranceOrApartment: string\n streetIsRequired: string\n invalidPhoneNumber?: string\n quarterIsRequired: string\n cantFindStreetOrQuarterMessage: string\n cityIsRequired: string\n emailIsRequired: string\n officeIsRequired: string\n selectCourier: string\n noStoreSelected: string\n}\n\nexport type CheckoutFormErrorLabelsType = ShippingFormErrorLabels & {\n selectPaymentMethod: string\n}\n\nexport type CheckoutFormContextType = {\n setStep: (step: CheckoutFormStepsEnum) => void\n step: CheckoutFormStepsEnum\n serverErrors: ServerErrors\n updateServerErrors: (errors: any) => void\n errorRef: (error: HTMLElement) => void\n errorFields: HTMLElement[]\n errorLabels: CheckoutFormErrorLabelsType\n orderQuery: QueryResult<OrderDTO, unknown>\n shippingState: UseShippingResultType\n paymentState: UsePaymentResultType\n billingState: UseBillingResultType\n}\n\nexport const useCheckoutFormStep = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormStep must be used within a CheckoutFormContextProvider'\n )\n }\n\n return useMemo(() => {\n return {\n currentStep: context.step,\n updateStep: context.setStep,\n }\n }, [context])\n}\n\nexport const useCheckoutFormOrder = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormOrder must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.orderQuery\n}\n\nexport const useCheckoutFormErrorLabels = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormErrorLabels must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.errorLabels\n}\n\nexport const useCheckoutFormServerErrors = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormServerErrors must be used within a CheckoutFormContextProvider'\n )\n }\n\n return useMemo(() => {\n return {\n serverErrors: context.serverErrors,\n updateServerErrors: context.updateServerErrors,\n }\n }, [context])\n}\n\nexport const useCheckoutFormBillingState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormBillingState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.billingState\n}\n\nexport const useCheckoutFormShippingState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormShippingState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.shippingState\n}\n\nexport const useCheckoutErrorFields = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutErrorFields must be used within a CheckoutFormContextProvider'\n )\n }\n\n return {\n errorFields: context.errorFields,\n errorRef: context.errorRef,\n }\n}\n\nexport const useCheckoutFormPaymentState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormPaymentState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.paymentState\n}\n"],"file":"index.js"}
@@ -188,11 +188,37 @@ function ProductProvider(_ref) {
188
188
  function selectVariantByAttribute(key) {
189
189
  var _combinations$key;
190
190
 
191
+ // Get by collapseKey for SD
192
+ var split = key.split(':');
193
+
194
+ if (split[0] === 'collapseKey') {
195
+ var _id = Object.keys(variants).find(function (el) {
196
+ return variants[el].collapseKey === split[1];
197
+ });
198
+
199
+ return setSelectedVariant(variants[_id]);
200
+ }
201
+
191
202
  var id = (_combinations$key = combinations[key]) == null ? void 0 : _combinations$key.value;
192
203
  setSelectedVariant(variants[id]);
193
204
  }
194
205
 
195
206
  function selectVariantByCombination(key, value) {
207
+ // Take collapseKey for SD
208
+ var split = value.split(':');
209
+
210
+ if (split[0] === 'collapseKey') {
211
+ var _id2 = Object.keys(variants).find(function (el) {
212
+ var _variants$el$attribut;
213
+
214
+ return variants[el].collapseKey === split[1] && ((_variants$el$attribut = variants[el].attributes.find(function (attr) {
215
+ return attr.name === 'size';
216
+ })) == null ? void 0 : _variants$el$attribut.value) === key;
217
+ });
218
+
219
+ return setSelectedVariant(variants[_id2]);
220
+ }
221
+
196
222
  var id = combinations[key].params[value];
197
223
  setSelectedVariant(variants[id]);
198
224
  }
@@ -258,12 +284,14 @@ function ProductProvider(_ref) {
258
284
  return result;
259
285
  }
260
286
 
287
+ var collapsedImages = (0, _utils.createCollapseKeyImagesMap)(product);
261
288
  var state = {
262
289
  metaData: metaData,
263
290
  seoData: seoData,
264
291
  variants: variants,
265
292
  selectedVariant: selectedVariant,
266
- attributeRules: attributeRules
293
+ attributeRules: attributeRules,
294
+ collapsedImages: collapsedImages
267
295
  };
268
296
  var functions = {
269
297
  getVariantById: getVariantById,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/hooks/useProduct/index.tsx"],"names":["ProductStateContext","React","createContext","undefined","CountDispatchContext","ProductProvider","product","children","defaultVariantId","useState","mounted","setMounted","getCombinationsAndAttributeRules","combinations","attributeRules","setCombinationsAndAttributeRules","getVariantsWithInventory","variants","setVariants","getDefaultVariant","selectedVariant","setSelectedVariant","metaData","useMemo","rootCategory","categories","rootCategoryId","resourceId","metaObj","_id","name","slug","description","shortDescription","metaDescription","brand","brands","resource","logo","assets","sources","url","category","length","reviewRatingStatistics","content","Boolean","map","createProductContent","seoData","seoObj","title","metaTitle","keywords","metaKeywords","customFields","mappedFields","custom","useEffect","data","variantsWithInventory","reduce","_","index","arr","currentVariant","mappedAttributes","mappedOptions","availableOptions","isAvailable","inventorySnapshot","canOrder","updatedVariant","inventory","hasAvailableQuantity","availableQuantity","quantity","attributes","options","selectedOptions","labels","getAttribute","rule","getSelectedAttribute","getAttributeByKey","key","find","a","value","getAvailabilityByStore","availabilities","mappedAttributeRules","attributesWithId","Object","keys","variantId","combinationsMap","selectVariantById","id","selectVariantByAttribute","selectVariantByCombination","params","selectVariantOptions","definitionKey","optionKey","newSelectedVariant","filter","opt","mappedSelectedOptions","option","attributeRule","values","result","forEach","currentKey","found","getVariantById","getVariantByAttribute","getVariantByCombination","getCustomFieldValue","field","getCombinationsForAttributeRule","state","functions","getProductVideos","useProductState","context","useContext","Error","useProductFunctions","useProduct","config","productsApi"],"mappings":";;;;;;;;;;;;AAAA;;AACA;;;;AASA;;AACA;;AAeA;;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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I6H,KAAJ,CAAU,uDAAV,CAAN;AACD;;AACD,SAAOF,OAAP;AACD;;AACM,SAASG,mBAAT,GAA+B;AACpC,MAAMH,OAAO,GAAG7H,kBAAM8H,UAAN,CAAiB3H,oBAAjB,CAAhB;;AACA,MAAI0H,OAAO,KAAK3H,SAAhB,EAA2B;AACzB,UAAM,IAAI6H,KAAJ,CAAU,0DAAV,CAAN;AACD;;AACD,SAAOF,OAAP;AACD;;AAEM,SAASI,UAAT,CAAoBnG,IAApB,EAAkCoG,MAAlC,EAAmE;AACxE,SAAOC,yBAAYF,UAAZ,CAAuBnG,IAAvB,EAA6BoG,MAA7B,CAAP;AACD","sourcesContent":["import React from 'react'\nimport {\n ProductDTO,\n ProductVariantDTO,\n AttributeRuleDTO,\n ProductAttributeDraftDTO,\n SelectedOptionDTO,\n ReviewRatingStatisticsDTO,\n 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} 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 const id = combinations[key]?.value\n setSelectedVariant(variants[id])\n }\n\n function selectVariantByCombination(key: string, value: string) {\n const id = combinations[key].params[value]\n setSelectedVariant(variants[id])\n }\n\n function selectVariantOptions(definitionKey: string, optionKey: string) {\n if (selectedVariant) {\n const newSelectedVariant = { ...selectedVariant }\n\n newSelectedVariant.selectedOptions = newSelectedVariant.selectedOptions.filter(\n (opt) => opt.definitionKey !== definitionKey\n )\n\n newSelectedVariant.selectedOptions = [\n ...newSelectedVariant.selectedOptions,\n {\n definitionKey,\n optionKey,\n },\n ]\n\n newSelectedVariant.mappedSelectedOptions = newSelectedVariant.selectedOptions.map(\n (option) => createSelectedOption2(newSelectedVariant.options, option)\n )\n\n setSelectedVariant(newSelectedVariant)\n }\n }\n\n function getSelectedAttribute(rule: string, attributes: any[]) {\n const attributeRule = attributeRules[rule]?.values\n let result\n\n attributes.forEach((currentKey) => {\n const found = attributeRule?.[currentKey.value]\n if (found) result = { id: currentKey.value, name: rule, ...found }\n })\n\n return (result as unknown) as {\n id: string\n name: string\n label: string\n extra: any\n combinations: {\n [id: string]: string\n }\n }\n }\n\n function getVariantById(id: string) {\n return variants?.[id]\n }\n\n function getVariantByAttribute(key: string) {\n const id = combinations[key]?.value\n return variants?.[id]\n }\n\n function getVariantByCombination(key: string, value: string) {\n const id = combinations[key]?.params[value]\n return variants?.[id]\n }\n\n function getCustomFieldValue(field: string) {\n return customFields?.[field]\n }\n\n function getCombinationsForAttributeRule(key: string, id: string) {\n const result = attributeRules?.[key]?.values?.[id]\n return result\n }\n\n const state = {\n metaData,\n seoData,\n variants,\n selectedVariant,\n attributeRules,\n }\n\n const functions = {\n getVariantById,\n getVariantByAttribute,\n getVariantByCombination,\n selectVariantById,\n selectVariantByAttribute,\n selectVariantByCombination,\n getCombinationsForAttributeRule,\n selectVariantOptions,\n getCustomFieldValue,\n getProductVideos: () => getProductVideos(metaData.assets),\n }\n\n return (\n <ProductStateContext.Provider value={state}>\n <CountDispatchContext.Provider value={functions}>\n {children}\n </CountDispatchContext.Provider>\n </ProductStateContext.Provider>\n )\n}\n\nexport function useProductState() {\n const context = React.useContext(ProductStateContext)\n if (context === undefined) {\n throw new Error('useProductState must be used within a ProductProvider')\n }\n return context\n}\nexport function useProductFunctions() {\n const context = React.useContext(CountDispatchContext)\n if (context === undefined) {\n throw new Error('useProductDispatch must be used within a ProductProvider')\n }\n return context\n}\n\nexport function useProduct(slug: string, config?: getProductBySlugConfig) {\n return productsApi.useProduct(slug, config)\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/hooks/useProduct/index.tsx"],"names":["ProductStateContext","React","createContext","undefined","CountDispatchContext","ProductProvider","product","children","defaultVariantId","useState","mounted","setMounted","getCombinationsAndAttributeRules","combinations","attributeRules","setCombinationsAndAttributeRules","getVariantsWithInventory","variants","setVariants","getDefaultVariant","selectedVariant","setSelectedVariant","metaData","useMemo","rootCategory","categories","rootCategoryId","resourceId","metaObj","_id","name","slug","description","shortDescription","metaDescription","brand","brands","resource","logo","assets","sources","url","category","length","reviewRatingStatistics","content","Boolean","map","createProductContent","seoData","seoObj","title","metaTitle","keywords","metaKeywords","customFields","mappedFields","custom","useEffect","data","variantsWithInventory","reduce","_","index","arr","currentVariant","mappedAttributes","mappedOptions","availableOptions","isAvailable","inventorySnapshot","canOrder","updatedVariant","inventory","hasAvailableQuantity","availableQuantity","quantity","attributes","options","selectedOptions","labels","getAttribute","rule","getSelectedAttribute","getAttributeByKey","key","find","a","value","getAvailabilityByStore","availabilities","mappedAttributeRules","attributesWithId","Object","keys","variantId","combinationsMap","selectVariantById","id","selectVariantByAttribute","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,SA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I,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"}
@@ -3,7 +3,7 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
5
  exports.__esModule = true;
6
- exports.createLabelsMap = exports.formatCategories = exports.getProductVideos = exports.processAvailabilityPerStore = exports.createMappedAttributes = exports.createSelectedOption = exports.createSelectedOption2 = exports.createMappedOptions = exports.createAttributeRulesMap = exports.createProductContent = exports.assignCombinationsToAttributeRules = exports.createCombinationsMap = exports.createCustomFieldsMap = void 0;
6
+ exports.createLabelsMap = exports.formatCategories = exports.getProductVideos = exports.processAvailabilityPerStore = exports.createMappedAttributes = exports.createSelectedOption = exports.createSelectedOption2 = exports.createMappedOptions = exports.createAttributeRulesMap = exports.createCollapseKeyImagesMap = exports.createProductContent = exports.assignCombinationsToAttributeRules = exports.createCombinationsMap = exports.createCustomFieldsMap = void 0;
7
7
 
8
8
  var _extends4 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
 
@@ -92,12 +92,29 @@ var createProductContent = function createProductContent(data) {
92
92
  name: (0, _utils.getTranslatableField)(data.label),
93
93
  content: (0, _utils.getTranslatableField)(data.content)
94
94
  };
95
- };
95
+ }; // Add grouped images for SD color variants
96
+
96
97
 
97
98
  exports.createProductContent = createProductContent;
98
99
 
100
+ var createCollapseKeyImagesMap = function createCollapseKeyImagesMap(product) {
101
+ var _product$variants;
102
+
103
+ var mappedKeys = product == null ? void 0 : (_product$variants = product.variants) == null ? void 0 : _product$variants.reduce(function (res, cur) {
104
+ if (!res[cur.collapseKey]) {
105
+ res[cur.collapseKey] = [];
106
+ }
107
+
108
+ res[cur.collapseKey].push(cur);
109
+ return res;
110
+ }, {});
111
+ return mappedKeys;
112
+ };
113
+
114
+ exports.createCollapseKeyImagesMap = createCollapseKeyImagesMap;
115
+
99
116
  var createAttributeRulesMap = function createAttributeRulesMap(product) {
100
- var _product$attributeRul, _product$variants;
117
+ var _product$attributeRul, _product$variants2;
101
118
 
102
119
  var uniqueRules = product == null ? void 0 : (_product$attributeRul = product.attributeRules) == null ? void 0 : _product$attributeRul.filter(function (x) {
103
120
  return x.constraint === _sdk.AttributeRuleDTOConstraintEnum.CombinationUnique;
@@ -129,7 +146,7 @@ var createAttributeRulesMap = function createAttributeRulesMap(product) {
129
146
  return map;
130
147
  };
131
148
 
132
- var mappedAttributeRules = product == null ? void 0 : (_product$variants = product.variants) == null ? void 0 : _product$variants.map(function (v) {
149
+ var mappedAttributeRules = product == null ? void 0 : (_product$variants2 = product.variants) == null ? void 0 : _product$variants2.map(function (v) {
133
150
  return v.attributes;
134
151
  }).flat().reduce(reduceVariantsToAttributeRuleValues, {});
135
152
  return mappedAttributeRules;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/hooks/useProduct/utils/index.ts"],"names":["createCustomFieldsMap","customFields","reduce","map","currentObj","field","value","createCombinationsMap","mappedAttributeRulesKeys","attributesArray","combinationsMap","forEach","key","p","currentKey","attributes","find","x","name","filtered","filter","currentCombination","params","variantId","attribute","assignCombinationsToAttributeRules","mappedAttributeRules","Object","keys","current","values","combinations","createProductContent","data","label","content","createAttributeRulesMap","product","uniqueRules","attributeRules","constraint","AttributeRuleDTOConstraintEnum","CombinationUnique","reduceVariantsToAttributeRuleValues","found","attributeName","valueData","extra","variants","v","flat","createMappedOptions","options","mappedOptions","currentOption","definitionKey","elements","subOption","optionKey","imageIndex","createSelectedOption2","selectedOption","availableOption","element","createSelectedOption","optionValue","createMappedAttributes","currentVariant","mappedAttributes","attributeArray","push","processAvailabilityPerStore","availabilities","isPhysical","acceptsBackorders","stockLocationName","restockableInDays","availableQuantity","storeName","getProductVideos","assets","youtube","videos","sources","a","embeded","type","source","url","iframe","thumb","thumbnail","formatCategories","categories","rootCategoryId","results","some","cat","resource","custom","customField","cats","result","category","resourceId","hasChildCategories","paths","parents","ancestors","parent","_id","Boolean","mainPaths","path","ancestor","formattedResults","id","link","slug","createLabelsMap","now","Date","getTime","currentLabels","el","validFrom","validTo"],"mappings":";;;;;;;;;AAAA;;AAuBA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEO,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,YAAD,EAAkC;AACrE,SAAOA,YAAP,oBAAOA,YAAY,CAAEC,MAAd,CAAqB,UAACC,GAAD,EAAkBC,UAAlB,EAAiC;AAC3DD,IAAAA,GAAG,CAACC,UAAU,CAACC,KAAZ,CAAH,GAAwBD,UAAU,CAACE,KAAnC;AACA,WAAOH,GAAP;AACD,GAHM,EAGJ,EAHI,CAAP;AAID,CALM;;;;AAOA,IAAMI,qBAAqB,GAAG,SAAxBA,qBAAwB,CACnCC,wBADmC,EAEnCC,eAFmC,EAMhC;AACH,MAAMC,eAAgC,GAAG,EAAzC;AACAF,EAAAA,wBAAwB,CAACG,OAAzB,CAAiC,UAACC,GAAD,EAAS;AACxCH,IAAAA,eAAe,CAACE,OAAhB,CAAwB,UAACE,CAAD,EAAO;AAC7B,UAA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,IAAuB,EAFtB;AAGLa,QAAAA,IAAI,QAAM,iCAAqBnB,QAAQ,CAACoB,IAA9B,CAAN;AAHC,OAAP;AAKD;;AAED,QAAMrB,GAAG,GAAIM,QAAb;AAEA,WAAO;AACLrF,MAAAA,IAAI,EAAE,iCAAqB+E,GAAG,CAAC/E,IAAzB,CADD;AAELkG,MAAAA,EAAE,EAAEnB,GAAG,CAACa,GAAJ,IAAW,EAFV;AAGLO,MAAAA,IAAI,QAAM,iCAAqBpB,GAAG,CAACqB,IAAzB,CAAN;AAHC,KAAP;AAKD,GAlBwB,CAAzB;AAoBA,SAAOH,gBAAgB,IAAI,EAA3B;AACD,CA1FM;;;;AA4FA,IAAMI,eAAe,GAAG,SAAlBA,eAAkB,CAACtF,IAAD,EAAqC;AAClE;AACA,MAAMuF,GAAG,GAAG,IAAIC,IAAJ,GAAWC,OAAX,EAAZ;AAEA,MAAMC,aAAa,GAAG1F,IAAH,oBAAGA,IAAI,CAAEb,MAAN,CAAa,UAACwG,EAAD,EAAQ;AACzC,QAAI,CAACA,EAAE,CAACC,SAAJ,IAAiB,CAACD,EAAE,CAACE,OAAzB,EAAkC;AAChC,aAAOF,EAAP;AACD,KAFD,MAEO;AACL,aAAOA,EAAE,CAACC,SAAH,GAAeL,GAAf,IAAsBI,EAAE,CAACE,OAAH,GAAaN,GAA1C;AACD;AACF,GANqB,CAAtB;AAQA,SAAOG,aAAP,oBAAOA,aAAa,CAAExH,GAAf,CAAmB,UAACyH,EAAD;AAAA,WAAQA,EAAE,CAAChH,GAAX;AAAA,GAAnB,CAAP;AACD,CAbM","sourcesContent":["import {\n ProductAttributeDTO,\n CustomField,\n AttributeRuleDTOConstraintEnum,\n ProductDTO,\n ProductVariantDTO,\n InventoryAvailability,\n OptionDefinitionDTO,\n SelectedOptionDTO,\n IdReferenceDTO,\n CategoryDTO,\n ProductVariantLabelDTO,\n} from '@sentecacommerce/sdk'\n\nimport {\n AttributeRulesMap,\n CombinationsMap,\n BooleanKVP,\n InventoryAvailabilityType,\n MetaInformationType,\n OptionsType,\n} from '../index'\n\nimport { createEmbededVideo } from './createEmbededVideo'\n\nimport { getTranslatableField } from '../../../utils'\n\n// export const createMappedInventory = (\n// currentVariant: ProductVariantDraftDTO,\n// inventory?: SkuReservationResponseDTO\n// ) => {\n// const currentInventory = inventory?.find(\n// (x) => x.sku === currentVariant.sku\n// )\n\n// const mappedInventory = {\n// ...currentInventory,\n// status:\n// currentInventory?.status === SkuReservationDTOStatusEnum.Available\n// ? true\n// : false,\n// inventoryId: currentInventory?.inventoryReservations?.[0].inventoryId,\n// quantity: currentInventory?.inventoryReservations?.[0].quantity,\n// }\n\n// return mappedInventory\n// }\n\nexport const createCustomFieldsMap = (customFields?: CustomField[]) => {\n return customFields?.reduce((map: BooleanKVP, currentObj) => {\n map[currentObj.field] = currentObj.value\n return map\n }, {})\n}\n\nexport const createCombinationsMap = (\n mappedAttributeRulesKeys: string[],\n attributesArray: {\n variantId: string\n attributes: ProductAttributeDTO[]\n }[]\n) => {\n const combinationsMap: CombinationsMap = {}\n mappedAttributeRulesKeys.forEach((key) => {\n attributesArray.forEach((p) => {\n const currentKey = p.attributes.find((x) => x.name === key)\n const filtered = p.attributes.filter((x) => x.name !== key)\n\n let currentCombination = combinationsMap[currentKey?.value]\n\n if (!currentCombination) {\n currentCombination = {\n params: {},\n value: '',\n }\n }\n\n currentCombination.value = p.variantId\n\n filtered.forEach((attribute) => {\n currentCombination.params = {\n ...currentCombination.params,\n [attribute.value]: p.variantId,\n }\n })\n\n combinationsMap[currentKey?.value] = currentCombination\n })\n })\n\n return combinationsMap\n}\n\nexport const assignCombinationsToAttributeRules = (\n mappedAttributeRules: AttributeRulesMap,\n combinationsMap: CombinationsMap\n) => {\n Object.keys(mappedAttributeRules).forEach((key) => {\n const current = mappedAttributeRules[key].values\n Object.keys(current).forEach((currentKey) => {\n mappedAttributeRules[key].values[currentKey].combinations =\n combinationsMap[currentKey]?.params\n })\n })\n}\n\nexport const createProductContent = (\n data: any\n): { key: string; name: string; content: string } => {\n return {\n key: data.key,\n name: getTranslatableField(data.label),\n content: getTranslatableField(data.content),\n }\n}\n\nexport const createAttributeRulesMap = (product?: ProductDTO) => {\n const uniqueRules = product?.attributeRules?.filter(\n (x) => x.constraint === AttributeRuleDTOConstraintEnum.CombinationUnique\n )\n const reduceVariantsToAttributeRuleValues = (map: any, attribute: any) => {\n const found = uniqueRules?.find((x) => x.attributeName === attribute.name)\n if (found) {\n if (!map[attribute.name]) {\n map[attribute.name] = {\n ...found,\n label: getTranslatableField(attribute.data.label),\n values: {},\n }\n }\n\n map[attribute.name] = {\n ...map[attribute.name],\n values: {\n ...map[attribute.name].values,\n [attribute.value]: {\n label: getTranslatableField(attribute.valueData.label),\n extra: attribute.valueData.extra,\n },\n },\n }\n }\n\n return map\n }\n\n const mappedAttributeRules = product?.variants\n ?.map((v) => v.attributes)\n .flat()\n .reduce(reduceVariantsToAttributeRuleValues, {})\n\n return mappedAttributeRules\n}\n\nexport const createMappedOptions = (\n options?: OptionDefinitionDTO[]\n): OptionsType[] => {\n const mappedOptions =\n options?.map((currentOption) => {\n return {\n definitionKey: currentOption.key,\n label: getTranslatableField(currentOption?.label),\n elements: currentOption.options?.map((subOption) => {\n return {\n optionKey: subOption.key,\n label: getTranslatableField(subOption?.label),\n imageIndex: subOption?.imageIndex,\n }\n }),\n }\n }) || []\n\n return mappedOptions\n}\n\nexport type SelectedOptionType = {\n label?: string\n value?: { key?: string; label?: string; imageIndex?: number }\n}\n\nexport const createSelectedOption2 = (\n options?: OptionsType[],\n selectedOption?: SelectedOptionDTO\n): SelectedOptionType => {\n const currentOption = options?.find(\n (availableOption) =>\n availableOption.definitionKey === selectedOption?.definitionKey\n )\n\n const value = currentOption?.elements?.find(\n (element) => element.optionKey === selectedOption?.optionKey\n )\n\n return {\n label: currentOption?.label,\n value: {\n key: value?.optionKey,\n imageIndex: value?.imageIndex,\n label: value?.label,\n },\n }\n}\n\nexport const createSelectedOption = (\n options?: OptionDefinitionDTO[],\n selectedOption?: SelectedOptionDTO\n): SelectedOptionType => {\n const currentOption = options?.find(\n (availableOption) => availableOption.key === selectedOption?.definitionKey\n )\n\n const value = currentOption?.options?.find(\n (optionValue) => optionValue.key === selectedOption?.optionKey\n )\n\n return {\n label: getTranslatableField(currentOption?.label),\n value: {\n key: value?.key,\n imageIndex: value?.imageIndex,\n label: getTranslatableField(value?.label),\n },\n }\n}\n\nexport const createMappedAttributes = (currentVariant: ProductVariantDTO) => {\n const mappedAttributes =\n currentVariant.attributes?.reduce(\n (attributeArray: ProductAttributeDTO[], attribute) => {\n attributeArray.push({\n name: attribute.name,\n value: attribute.value,\n valueData: attribute.valueData,\n })\n return attributeArray\n },\n []\n ) || []\n\n return mappedAttributes\n}\n\nexport const processAvailabilityPerStore = (\n availabilities?: InventoryAvailability[]\n): InventoryAvailabilityType[] | undefined => {\n return availabilities\n ?.filter((x) => !x.isPhysical)\n ?.map(\n ({\n acceptsBackorders,\n stockLocationName,\n restockableInDays,\n availableQuantity,\n }) => {\n return {\n storeName: getTranslatableField(stockLocationName),\n availableQuantity,\n acceptsBackorders,\n restockableInDays: restockableInDays,\n }\n }\n )\n}\n\nexport const getProductVideos = (assets: MetaInformationType['assets']) => {\n if (assets?.youtube) {\n const videos = assets.youtube.sources.map((a) => {\n const embeded = createEmbededVideo(a)\n return {\n type: 'video',\n source: a.url,\n iframe: embeded.iframe,\n thumb: { url: embeded.thumbnail },\n }\n })\n\n return videos\n }\n return []\n}\n\nexport const formatCategories = (\n categories?: IdReferenceDTO[],\n rootCategoryId?: string\n) => {\n let results\n\n if (\n categories?.some((cat) =>\n cat.resource?.custom?.some(\n (customField: any) => customField.field === 'isTemporary'\n )\n )\n ) {\n type PathType = {\n [key: string]: string\n }\n type CategoryType = CategoryDTO & { hasChildCategories: boolean }\n\n const cats = categories.reduce((result, category) => {\n result[category.resourceId] = {\n ...category.resource,\n hasChildCategories: false,\n }\n\n return result\n }, {} as CategoryDTO[])\n\n const paths = Object.values(cats).reduce((result, category) => {\n const parents = (category?.ancestors as IdReferenceDTO[])\n .map((parent: any) => {\n return (cats?.[parent?.resourceId] as any)?._id\n })\n .filter(Boolean)\n\n parents.forEach((parent: any) => {\n ;(cats as CategoryType[])[parent].hasChildCategories = true\n })\n\n result[category._id as string] = [...parents, category._id]\n\n return result\n }, {} as PathType[])\n\n const mainPaths = Object.values(cats as CategoryType[] & IdReferenceDTO[])\n .filter((category: CategoryType) => category.hasChildCategories === false)\n .map((category) => paths?.[category._id as string])\n .map((paths) => paths.map((path: string) => cats?.[path]))\n .filter(\n (paths) =>\n !paths.some(\n (path: { custom: any }) =>\n path?.custom?.find(\n (custom: any) => custom.field === 'isTemporary'\n )?.value ?? false\n )\n )?.[0]\n .flat()\n\n results = mainPaths\n } else {\n results = categories?.filter(\n (cat) =>\n cat?.resourceId === rootCategoryId ||\n cat?.resource?.ancestors?.some(\n (ancestor: any) => ancestor.resource === rootCategoryId\n )\n )\n }\n\n const formattedResults = (results as IdReferenceDTO[])?.map((category) => {\n if (category.resource) {\n const resource = category.resource as CategoryDTO\n\n return {\n name: getTranslatableField(resource.name),\n id: category.resourceId || '',\n link: `/${getTranslatableField(resource.slug)}/c`,\n }\n }\n\n const cat = (category as unknown) as CategoryDTO\n\n return {\n name: getTranslatableField(cat.name),\n id: cat._id || '',\n link: `/${getTranslatableField(cat.slug)}/c`,\n }\n })\n\n return formattedResults || []\n}\n\nexport const createLabelsMap = (data?: ProductVariantLabelDTO[]) => {\n // Filter only labels that are currently active\n const now = new Date().getTime()\n\n const currentLabels = data?.filter((el) => {\n if (!el.validFrom || !el.validTo) {\n return el\n } else {\n return el.validFrom < now && el.validTo > now\n }\n })\n\n return currentLabels?.map((el) => el.key)\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../../src/hooks/useProduct/utils/index.ts"],"names":["createCustomFieldsMap","customFields","reduce","map","currentObj","field","value","createCombinationsMap","mappedAttributeRulesKeys","attributesArray","combinationsMap","forEach","key","p","currentKey","attributes","find","x","name","filtered","filter","currentCombination","params","variantId","attribute","assignCombinationsToAttributeRules","mappedAttributeRules","Object","keys","current","values","combinations","createProductContent","data","label","content","createCollapseKeyImagesMap","product","mappedKeys","variants","res","cur","collapseKey","push","createAttributeRulesMap","uniqueRules","attributeRules","constraint","AttributeRuleDTOConstraintEnum","CombinationUnique","reduceVariantsToAttributeRuleValues","found","attributeName","valueData","extra","v","flat","createMappedOptions","options","mappedOptions","currentOption","definitionKey","elements","subOption","optionKey","imageIndex","createSelectedOption2","selectedOption","availableOption","element","createSelectedOption","optionValue","createMappedAttributes","currentVariant","mappedAttributes","attributeArray","processAvailabilityPerStore","availabilities","isPhysical","acceptsBackorders","stockLocationName","restockableInDays","availableQuantity","storeName","getProductVideos","assets","youtube","videos","sources","a","embeded","type","source","url","iframe","thumb","thumbnail","formatCategories","categories","rootCategoryId","results","some","cat","resource","custom","customField","cats","result","category","resourceId","hasChildCategories","paths","parents","ancestors","parent","_id","Boolean","mainPaths","path","ancestor","formattedResults","id","link","slug","createLabelsMap","now","Date","getTime","currentLabels","el","validFrom","validTo"],"mappings":";;;;;;;;;AAAA;;AAuBA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEO,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,YAAD,EAAkC;AACrE,SAAOA,YAAP,oBAAOA,YAAY,CAAEC,MAAd,CAAqB,UAACC,GAAD,EAAkBC,UAAlB,EAAiC;AAC3DD,IAAAA,GAAG,CAACC,UAAU,CAACC,KAAZ,CAAH,GAAwBD,UAAU,CAACE,KAAnC;AACA,WAAOH,GAAP;AACD,GAHM,EAGJ,EAHI,CAAP;AAID,CALM;;;;AAOA,IAAMI,qBAAqB,GAAG,SAAxBA,qBAAwB,CACnCC,wBADmC,EAEnCC,eAFmC,EAMhC;AACH,MAAMC,eAAgC,GAAG,EAAzC;AACAF,EAAAA,w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UAAC6G,EAAD,EAAQ;AACzC,QAAI,CAACA,EAAE,CAACC,SAAJ,IAAiB,CAACD,EAAE,CAACE,OAAzB,EAAkC;AAChC,aAAOF,EAAP;AACD,KAFD,MAEO;AACL,aAAOA,EAAE,CAACC,SAAH,GAAeL,GAAf,IAAsBI,EAAE,CAACE,OAAH,GAAaN,GAA1C;AACD;AACF,GANqB,CAAtB;AAQA,SAAOG,aAAP,oBAAOA,aAAa,CAAE7H,GAAf,CAAmB,UAAC8H,EAAD;AAAA,WAAQA,EAAE,CAACrH,GAAX;AAAA,GAAnB,CAAP;AACD,CAbM","sourcesContent":["import {\n ProductAttributeDTO,\n CustomField,\n AttributeRuleDTOConstraintEnum,\n ProductDTO,\n ProductVariantDTO,\n InventoryAvailability,\n OptionDefinitionDTO,\n SelectedOptionDTO,\n IdReferenceDTO,\n CategoryDTO,\n ProductVariantLabelDTO,\n} from '@sentecacommerce/sdk'\n\nimport {\n AttributeRulesMap,\n CombinationsMap,\n BooleanKVP,\n InventoryAvailabilityType,\n MetaInformationType,\n OptionsType,\n} from '../index'\n\nimport { createEmbededVideo } from './createEmbededVideo'\n\nimport { getTranslatableField } from '../../../utils'\n\n// export const createMappedInventory = (\n// currentVariant: ProductVariantDraftDTO,\n// inventory?: SkuReservationResponseDTO\n// ) => {\n// const currentInventory = inventory?.find(\n// (x) => x.sku === currentVariant.sku\n// )\n\n// const mappedInventory = {\n// ...currentInventory,\n// status:\n// currentInventory?.status === SkuReservationDTOStatusEnum.Available\n// ? true\n// : false,\n// inventoryId: currentInventory?.inventoryReservations?.[0].inventoryId,\n// quantity: currentInventory?.inventoryReservations?.[0].quantity,\n// }\n\n// return mappedInventory\n// }\n\nexport const createCustomFieldsMap = (customFields?: CustomField[]) => {\n return customFields?.reduce((map: BooleanKVP, currentObj) => {\n map[currentObj.field] = currentObj.value\n return map\n }, {})\n}\n\nexport const createCombinationsMap = (\n mappedAttributeRulesKeys: string[],\n attributesArray: {\n variantId: string\n attributes: ProductAttributeDTO[]\n }[]\n) => {\n const combinationsMap: CombinationsMap = {}\n mappedAttributeRulesKeys.forEach((key) => {\n attributesArray.forEach((p) => {\n const currentKey = p.attributes.find((x) => x.name === key)\n const filtered = p.attributes.filter((x) => x.name !== key)\n\n let currentCombination = combinationsMap[currentKey?.value]\n\n if (!currentCombination) {\n currentCombination = {\n params: {},\n value: '',\n }\n }\n\n currentCombination.value = p.variantId\n\n filtered.forEach((attribute) => {\n currentCombination.params = {\n ...currentCombination.params,\n [attribute.value]: p.variantId,\n }\n })\n\n combinationsMap[currentKey?.value] = currentCombination\n })\n })\n\n return combinationsMap\n}\n\nexport const assignCombinationsToAttributeRules = (\n mappedAttributeRules: AttributeRulesMap,\n combinationsMap: CombinationsMap\n) => {\n Object.keys(mappedAttributeRules).forEach((key) => {\n const current = mappedAttributeRules[key].values\n Object.keys(current).forEach((currentKey) => {\n mappedAttributeRules[key].values[currentKey].combinations =\n combinationsMap[currentKey]?.params\n })\n })\n}\n\nexport const createProductContent = (\n data: any\n): { key: string; name: string; content: string } => {\n return {\n key: data.key,\n name: getTranslatableField(data.label),\n content: getTranslatableField(data.content),\n }\n}\n\n// Add grouped images for SD color variants\nexport const createCollapseKeyImagesMap = (product?: ProductDTO) => {\n const mappedKeys = product?.variants?.reduce((res, cur) => {\n if (!res[cur.collapseKey as string]) {\n res[cur.collapseKey as string] = []\n }\n res[cur.collapseKey as string].push(cur)\n return res\n }, {})\n\n return mappedKeys\n}\n\nexport const createAttributeRulesMap = (product?: ProductDTO) => {\n const uniqueRules = product?.attributeRules?.filter(\n (x) => x.constraint === AttributeRuleDTOConstraintEnum.CombinationUnique\n )\n const reduceVariantsToAttributeRuleValues = (map: any, attribute: any) => {\n const found = uniqueRules?.find((x) => x.attributeName === attribute.name)\n if (found) {\n if (!map[attribute.name]) {\n map[attribute.name] = {\n ...found,\n label: getTranslatableField(attribute.data.label),\n values: {},\n }\n }\n\n map[attribute.name] = {\n ...map[attribute.name],\n values: {\n ...map[attribute.name].values,\n [attribute.value]: {\n label: getTranslatableField(attribute.valueData.label),\n extra: attribute.valueData.extra,\n },\n },\n }\n }\n\n return map\n }\n\n const mappedAttributeRules = product?.variants\n ?.map((v) => v.attributes)\n .flat()\n .reduce(reduceVariantsToAttributeRuleValues, {})\n\n return mappedAttributeRules\n}\n\nexport const createMappedOptions = (\n options?: OptionDefinitionDTO[]\n): OptionsType[] => {\n const mappedOptions =\n options?.map((currentOption) => {\n return {\n definitionKey: currentOption.key,\n label: getTranslatableField(currentOption?.label),\n elements: currentOption.options?.map((subOption) => {\n return {\n optionKey: subOption.key,\n label: getTranslatableField(subOption?.label),\n imageIndex: subOption?.imageIndex,\n }\n }),\n }\n }) || []\n\n return mappedOptions\n}\n\nexport type SelectedOptionType = {\n label?: string\n value?: { key?: string; label?: string; imageIndex?: number }\n}\n\nexport const createSelectedOption2 = (\n options?: OptionsType[],\n selectedOption?: SelectedOptionDTO\n): SelectedOptionType => {\n const currentOption = options?.find(\n (availableOption) =>\n availableOption.definitionKey === selectedOption?.definitionKey\n )\n\n const value = currentOption?.elements?.find(\n (element) => element.optionKey === selectedOption?.optionKey\n )\n\n return {\n label: currentOption?.label,\n value: {\n key: value?.optionKey,\n imageIndex: value?.imageIndex,\n label: value?.label,\n },\n }\n}\n\nexport const createSelectedOption = (\n options?: OptionDefinitionDTO[],\n selectedOption?: SelectedOptionDTO\n): SelectedOptionType => {\n const currentOption = options?.find(\n (availableOption) => availableOption.key === selectedOption?.definitionKey\n )\n\n const value = currentOption?.options?.find(\n (optionValue) => optionValue.key === selectedOption?.optionKey\n )\n\n return {\n label: getTranslatableField(currentOption?.label),\n value: {\n key: value?.key,\n imageIndex: value?.imageIndex,\n label: getTranslatableField(value?.label),\n },\n }\n}\n\nexport const createMappedAttributes = (currentVariant: ProductVariantDTO) => {\n const mappedAttributes =\n currentVariant.attributes?.reduce(\n (attributeArray: ProductAttributeDTO[], attribute) => {\n attributeArray.push({\n name: attribute.name,\n value: attribute.value,\n valueData: attribute.valueData,\n })\n return attributeArray\n },\n []\n ) || []\n\n return mappedAttributes\n}\n\nexport const processAvailabilityPerStore = (\n availabilities?: InventoryAvailability[]\n): InventoryAvailabilityType[] | undefined => {\n return availabilities\n ?.filter((x) => !x.isPhysical)\n ?.map(\n ({\n acceptsBackorders,\n stockLocationName,\n restockableInDays,\n availableQuantity,\n }) => {\n return {\n storeName: getTranslatableField(stockLocationName),\n availableQuantity,\n acceptsBackorders,\n restockableInDays: restockableInDays,\n }\n }\n )\n}\n\nexport const getProductVideos = (assets: MetaInformationType['assets']) => {\n if (assets?.youtube) {\n const videos = assets.youtube.sources.map((a) => {\n const embeded = createEmbededVideo(a)\n return {\n type: 'video',\n source: a.url,\n iframe: embeded.iframe,\n thumb: { url: embeded.thumbnail },\n }\n })\n\n return videos\n }\n return []\n}\n\nexport const formatCategories = (\n categories?: IdReferenceDTO[],\n rootCategoryId?: string\n) => {\n let results\n\n if (\n categories?.some((cat) =>\n cat.resource?.custom?.some(\n (customField: any) => customField.field === 'isTemporary'\n )\n )\n ) {\n type PathType = {\n [key: string]: string\n }\n type CategoryType = CategoryDTO & { hasChildCategories: boolean }\n\n const cats = categories.reduce((result, category) => {\n result[category.resourceId] = {\n ...category.resource,\n hasChildCategories: false,\n }\n\n return result\n }, {} as CategoryDTO[])\n\n const paths = Object.values(cats).reduce((result, category) => {\n const parents = (category?.ancestors as IdReferenceDTO[])\n .map((parent: any) => {\n return (cats?.[parent?.resourceId] as any)?._id\n })\n .filter(Boolean)\n\n parents.forEach((parent: any) => {\n ;(cats as CategoryType[])[parent].hasChildCategories = true\n })\n\n result[category._id as string] = [...parents, category._id]\n\n return result\n }, {} as PathType[])\n\n const mainPaths = Object.values(cats as CategoryType[] & IdReferenceDTO[])\n .filter((category: CategoryType) => category.hasChildCategories === false)\n .map((category) => paths?.[category._id as string])\n .map((paths) => paths.map((path: string) => cats?.[path]))\n .filter(\n (paths) =>\n !paths.some(\n (path: { custom: any }) =>\n path?.custom?.find(\n (custom: any) => custom.field === 'isTemporary'\n )?.value ?? false\n )\n )?.[0]\n .flat()\n\n results = mainPaths\n } else {\n results = categories?.filter(\n (cat) =>\n cat?.resourceId === rootCategoryId ||\n cat?.resource?.ancestors?.some(\n (ancestor: any) => ancestor.resource === rootCategoryId\n )\n )\n }\n\n const formattedResults = (results as IdReferenceDTO[])?.map((category) => {\n if (category.resource) {\n const resource = category.resource as CategoryDTO\n\n return {\n name: getTranslatableField(resource.name),\n id: category.resourceId || '',\n link: `/${getTranslatableField(resource.slug)}/c`,\n }\n }\n\n const cat = (category as unknown) as CategoryDTO\n\n return {\n name: getTranslatableField(cat.name),\n id: cat._id || '',\n link: `/${getTranslatableField(cat.slug)}/c`,\n }\n })\n\n return formattedResults || []\n}\n\nexport const createLabelsMap = (data?: ProductVariantLabelDTO[]) => {\n // Filter only labels that are currently active\n const now = new Date().getTime()\n\n const currentLabels = data?.filter((el) => {\n if (!el.validFrom || !el.validTo) {\n return el\n } else {\n return el.validFrom < now && el.validTo > now\n }\n })\n\n return currentLabels?.map((el) => el.key)\n}\n"],"file":"index.js"}
@@ -9,4 +9,12 @@ Object.keys(_useUpdateCustomLineItemMutation).forEach(function (key) {
9
9
  if (key in exports && exports[key] === _useUpdateCustomLineItemMutation[key]) return;
10
10
  exports[key] = _useUpdateCustomLineItemMutation[key];
11
11
  });
12
+
13
+ var _useUpdateOrderCustomFieldMutation = require("./useUpdateOrderCustomFieldMutation");
14
+
15
+ Object.keys(_useUpdateOrderCustomFieldMutation).forEach(function (key) {
16
+ if (key === "default" || key === "__esModule") return;
17
+ if (key in exports && exports[key] === _useUpdateOrderCustomFieldMutation[key]) return;
18
+ exports[key] = _useUpdateOrderCustomFieldMutation[key];
19
+ });
12
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/order/api/mutations/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './useUpdateCustomLineItemMutation'\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../../src/order/api/mutations/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './useUpdateCustomLineItemMutation'\nexport * from './useUpdateOrderCustomFieldMutation'\n"],"file":"index.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/order/api/mutations/useUpdateCustomLineItemMutation.tsx"],"names":["useUpdateCustomLineItemMutation","onSuccess","onError","values","id","customLineItemId","dto"],"mappings":";;;;;AAAA;;AAIA;;AAaO,IAAMA,+BAA+B,GAAG,SAAlCA,+BAAkC,OAGN;AAAA,MAFvCC,SAEuC,QAFvCA,SAEuC;AAAA,MADvCC,OACuC,QADvCA,OACuC;AACvC,SAAO,6BACL,UAACC,MAAD;AAAA,WACE,uCACEA,MAAM,CAACC,EADT,EAEED,MAAM,CAACE,gBAFT,EAGEF,MAAM,CAACG,GAHT,CADF;AAAA,GADK,EAOL;AACEL,IAAAA,SAAS,EAATA,SADF;AAEEC,IAAAA,OAAO,EAAPA;AAFF,GAPK,CAAP;AAYD,CAhBM","sourcesContent":["import {\n MyOrdersUpdateCustomLineItem,\n CustomLineItemDraftDTO,\n} from '@sentecacommerce/sdk'\nimport { useMutation } from 'react-query'\n\nexport interface UpdateCustomLineItemMutationProps {\n onSuccess?: () => void\n onError?: () => void\n}\n\nexport interface UpdateCustomLineItemProps {\n id: string\n customLineItemId: string\n dto: CustomLineItemDraftDTO\n}\n\nexport const useUpdateCustomLineItemMutation = ({\n onSuccess,\n onError,\n}: UpdateCustomLineItemMutationProps) => {\n return useMutation(\n (values: UpdateCustomLineItemProps) =>\n MyOrdersUpdateCustomLineItem(\n values.id,\n values.customLineItemId,\n values.dto\n ),\n {\n onSuccess,\n onError,\n }\n )\n}\n"],"file":"useUpdateCustomLineItemMutation.js"}
1
+ {"version":3,"sources":["../../../../../src/order/api/mutations/useUpdateCustomLineItemMutation.tsx"],"names":["useUpdateCustomLineItemMutation","onSuccess","onError","values","id","customLineItemId","dto"],"mappings":";;;;;AAAA;;AAIA;;AASO,IAAMA,+BAA+B,GAAG,SAAlCA,+BAAkC,OAG1B;AAAA,MAFnBC,SAEmB,QAFnBA,SAEmB;AAAA,MADnBC,OACmB,QADnBA,OACmB;AACnB,SAAO,6BACL,UAACC,MAAD;AAAA,WACE,uCACEA,MAAM,CAACC,EADT,EAEED,MAAM,CAACE,gBAFT,EAGEF,MAAM,CAACG,GAHT,CADF;AAAA,GADK,EAOL;AACEL,IAAAA,SAAS,EAATA,SADF;AAEEC,IAAAA,OAAO,EAAPA;AAFF,GAPK,CAAP;AAYD,CAhBM","sourcesContent":["import {\n MyOrdersUpdateCustomLineItem,\n CustomLineItemDraftDTO,\n} from '@sentecacommerce/sdk'\nimport { useMutation } from 'react-query'\nimport { CallbackProps } from '../index'\n\nexport interface UpdateCustomLineItemProps {\n id: string\n customLineItemId: string\n dto: CustomLineItemDraftDTO\n}\n\nexport const useUpdateCustomLineItemMutation = ({\n onSuccess,\n onError,\n}: CallbackProps) => {\n return useMutation(\n (values: UpdateCustomLineItemProps) =>\n MyOrdersUpdateCustomLineItem(\n values.id,\n values.customLineItemId,\n values.dto\n ),\n {\n onSuccess,\n onError,\n }\n )\n}\n"],"file":"useUpdateCustomLineItemMutation.js"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.useUpdateOrderCustomFieldMutation = void 0;
5
+
6
+ var _sdk = require("@sentecacommerce/sdk");
7
+
8
+ var _reactQuery = require("react-query");
9
+
10
+ var useUpdateOrderCustomFieldMutation = function useUpdateOrderCustomFieldMutation(callback) {
11
+ return (0, _reactQuery.useMutation)(function (values) {
12
+ return (0, _sdk.MyCartSetCartCustomField)(values.customFields);
13
+ }, {
14
+ onSuccess: callback == null ? void 0 : callback.onSuccess,
15
+ onError: callback == null ? void 0 : callback.onError
16
+ });
17
+ };
18
+
19
+ exports.useUpdateOrderCustomFieldMutation = useUpdateOrderCustomFieldMutation;
20
+ //# sourceMappingURL=useUpdateOrderCustomFieldMutation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/order/api/mutations/useUpdateOrderCustomFieldMutation.tsx"],"names":["useUpdateOrderCustomFieldMutation","callback","values","customFields","onSuccess","onError"],"mappings":";;;;;AAAA;;AAIA;;AAWO,IAAMA,iCAAiC,GAAG,SAApCA,iCAAoC,CAACC,QAAD,EAA8B;AAC7E,SAAO,6BACL,UAACC,MAAD;AAAA,WACE,mCAAyBA,MAAM,CAACC,YAAhC,CADF;AAAA,GADK,EAGL;AACEC,IAAAA,SAAS,EAAEH,QAAF,oBAAEA,QAAQ,CAAEG,SADvB;AAEEC,IAAAA,OAAO,EAAEJ,QAAF,oBAAEA,QAAQ,CAAEI;AAFrB,GAHK,CAAP;AAQD,CATM","sourcesContent":["import {\n MyCartSetCartCustomField,\n SetCustomFieldDTO,\n} from '@sentecacommerce/sdk'\nimport { useMutation } from 'react-query'\n\nexport interface CallbackProps {\n onSuccess?: () => void\n onError?: () => void\n}\n\nexport interface SetCustomFieldProps {\n customFields: SetCustomFieldDTO[]\n}\n\nexport const useUpdateOrderCustomFieldMutation = (callback?: CallbackProps) => {\n return useMutation(\n (values: SetCustomFieldProps) =>\n MyCartSetCartCustomField(values.customFields),\n {\n onSuccess: callback?.onSuccess,\n onError: callback?.onError,\n }\n )\n}\n"],"file":"useUpdateOrderCustomFieldMutation.js"}
@@ -9,4 +9,12 @@ Object.keys(_useUpdateCustomLineItem).forEach(function (key) {
9
9
  if (key in exports && exports[key] === _useUpdateCustomLineItem[key]) return;
10
10
  exports[key] = _useUpdateCustomLineItem[key];
11
11
  });
12
+
13
+ var _useUpdateOrderCustomField = require("./useUpdateOrderCustomField");
14
+
15
+ Object.keys(_useUpdateOrderCustomField).forEach(function (key) {
16
+ if (key === "default" || key === "__esModule") return;
17
+ if (key in exports && exports[key] === _useUpdateOrderCustomField[key]) return;
18
+ exports[key] = _useUpdateOrderCustomField[key];
19
+ });
12
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/order/hooks/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './useUpdateCustomLineItem'\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/order/hooks/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './useUpdateCustomLineItem'\nexport * from './useUpdateOrderCustomField'\n"],"file":"index.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/order/hooks/useUpdateCustomLineItem.tsx"],"names":["useUpdateCustomLineItem","props"],"mappings":";;;;;AAAA;;AAKO,IAAMA,uBAAuB,GAAG,SAA1BA,uBAA0B,CACrCC,KADqC,EAElC;AACH,SAAO,0CAAgCA,KAAhC,CAAP;AACD,CAJM","sourcesContent":["import {\n useUpdateCustomLineItemMutation,\n UpdateCustomLineItemMutationProps,\n} from '../api'\n\nexport const useUpdateCustomLineItem = (\n props: UpdateCustomLineItemMutationProps\n) => {\n return useUpdateCustomLineItemMutation(props)\n}\n"],"file":"useUpdateCustomLineItem.js"}
1
+ {"version":3,"sources":["../../../../src/order/hooks/useUpdateCustomLineItem.tsx"],"names":["useUpdateCustomLineItem","props"],"mappings":";;;;;AAAA;;AAEO,IAAMA,uBAAuB,GAAG,SAA1BA,uBAA0B,CAACC,KAAD,EAA0B;AAC/D,SAAO,0CAAgCA,KAAhC,CAAP;AACD,CAFM","sourcesContent":["import { useUpdateCustomLineItemMutation, CallbackProps } from '../api'\n\nexport const useUpdateCustomLineItem = (props: CallbackProps) => {\n return useUpdateCustomLineItemMutation(props)\n}\n"],"file":"useUpdateCustomLineItem.js"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.useUpdateOrderCustomField = void 0;
5
+
6
+ var _api = require("../api");
7
+
8
+ var useUpdateOrderCustomField = function useUpdateOrderCustomField(props) {
9
+ return (0, _api.useUpdateOrderCustomFieldMutation)(props);
10
+ };
11
+
12
+ exports.useUpdateOrderCustomField = useUpdateOrderCustomField;
13
+ //# sourceMappingURL=useUpdateOrderCustomField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/order/hooks/useUpdateOrderCustomField.tsx"],"names":["useUpdateOrderCustomField","props"],"mappings":";;;;;AAAA;;AAEO,IAAMA,yBAAyB,GAAG,SAA5BA,yBAA4B,CAACC,KAAD,EAA0B;AACjE,SAAO,4CAAkCA,KAAlC,CAAP;AACD,CAFM","sourcesContent":["import { useUpdateOrderCustomFieldMutation, CallbackProps } from '../api'\n\nexport const useUpdateOrderCustomField = (props: CallbackProps) => {\n return useUpdateOrderCustomFieldMutation(props)\n}\n"],"file":"useUpdateOrderCustomField.js"}