@sentecacommerce-theme/lib 0.12.29 → 0.12.30

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 (46) hide show
  1. package/dist/cjs/contexts/CheckoutForm/hooks/useBilling/index.js +4 -2
  2. package/dist/cjs/contexts/CheckoutForm/hooks/useBilling/index.js.map +1 -1
  3. package/dist/cjs/contexts/CheckoutForm/hooks/useShipping/index.js +8 -6
  4. package/dist/cjs/contexts/CheckoutForm/hooks/useShipping/index.js.map +1 -1
  5. package/dist/cjs/contexts/CheckoutForm/index.js +16 -9
  6. package/dist/cjs/contexts/CheckoutForm/index.js.map +1 -1
  7. package/dist/cjs/contexts/CheckoutForm/utils/validateBillingAddress.js +1 -2
  8. package/dist/cjs/contexts/CheckoutForm/utils/validateBillingAddress.js.map +1 -1
  9. package/dist/cjs/contexts/CheckoutForm/utils/validateShipping.js +28 -21
  10. package/dist/cjs/contexts/CheckoutForm/utils/validateShipping.js.map +1 -1
  11. package/dist/cjs/hooks/addresses-hooks/useAddressForm/index.js +4 -2
  12. package/dist/cjs/hooks/addresses-hooks/useAddressForm/index.js.map +1 -1
  13. package/dist/cjs/hooks/order-hooks/useOrder/index.js +12 -1
  14. package/dist/cjs/hooks/order-hooks/useOrder/index.js.map +1 -1
  15. package/dist/cjs/hooks/useCheckoutShippingModule/index.js +6 -1
  16. package/dist/cjs/hooks/useCheckoutShippingModule/index.js.map +1 -1
  17. package/dist/cjs/user/api/utils/generateAnonymousToken.js +4 -4
  18. package/dist/cjs/user/api/utils/generateAnonymousToken.js.map +1 -1
  19. package/dist/esm/contexts/CheckoutForm/hooks/useBilling/index.js +4 -2
  20. package/dist/esm/contexts/CheckoutForm/hooks/useBilling/index.js.map +1 -1
  21. package/dist/esm/contexts/CheckoutForm/hooks/useShipping/index.js +8 -6
  22. package/dist/esm/contexts/CheckoutForm/hooks/useShipping/index.js.map +1 -1
  23. package/dist/esm/contexts/CheckoutForm/index.js +13 -9
  24. package/dist/esm/contexts/CheckoutForm/index.js.map +1 -1
  25. package/dist/esm/contexts/CheckoutForm/utils/validateBillingAddress.js +1 -2
  26. package/dist/esm/contexts/CheckoutForm/utils/validateBillingAddress.js.map +1 -1
  27. package/dist/esm/contexts/CheckoutForm/utils/validateShipping.js +25 -18
  28. package/dist/esm/contexts/CheckoutForm/utils/validateShipping.js.map +1 -1
  29. package/dist/esm/hooks/addresses-hooks/useAddressForm/index.js +3 -2
  30. package/dist/esm/hooks/addresses-hooks/useAddressForm/index.js.map +1 -1
  31. package/dist/esm/hooks/order-hooks/useOrder/index.js +10 -1
  32. package/dist/esm/hooks/order-hooks/useOrder/index.js.map +1 -1
  33. package/dist/esm/hooks/useCheckoutShippingModule/index.js +6 -1
  34. package/dist/esm/hooks/useCheckoutShippingModule/index.js.map +1 -1
  35. package/dist/esm/user/api/utils/generateAnonymousToken.js +4 -4
  36. package/dist/esm/user/api/utils/generateAnonymousToken.js.map +1 -1
  37. package/dist/types/contexts/CheckoutForm/hooks/useBilling/index.d.ts +4 -2
  38. package/dist/types/contexts/CheckoutForm/hooks/useShipping/index.d.ts +3 -1
  39. package/dist/types/contexts/CheckoutForm/index.d.ts +4 -1
  40. package/dist/types/contexts/CheckoutForm/utils/validateBillingAddress.d.ts +2 -2
  41. package/dist/types/contexts/CheckoutForm/utils/validateShipping.d.ts +1 -1
  42. package/dist/types/hooks/addresses-hooks/useAddressForm/index.d.ts +2 -1
  43. package/dist/types/hooks/order-hooks/useOrder/index.d.ts +7 -1
  44. package/dist/types/hooks/useCheckoutShippingModule/index.d.ts +2 -2
  45. package/dist/types/user/api/utils/generateAnonymousToken.d.ts +1 -1
  46. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/contexts/CheckoutForm/index.tsx"],"names":["React","createContext","useCallback","useContext","useMemo","useState","myCartApi","useBilling","usePayment","useShipping","useIsAuthenticated","useCheckoutSubmit","defaultShippingValidations","genericBillingAddressValidation","usersApi","useCheckoutShippingModule","BoricaRedirect","CheckoutFormCustomStateProvider","useScrollTo","getElementOffset","CheckoutFormContext","CheckoutFormContextProvider","children","defaultStep","errorLabels","enableSavedAddressList","withPersistBeforePageLeave","shippingValidations","validateBillingAddress","enableSaveBillingAddress","enableSavedBillingAddressList","countryCode","enableSaveAddress","autofillShippingPersonalData","onSubmit","paymentEnabledOnStep","getPaymentMethodsWhenShippingMethodIsSelected","shippingEnabledOnStep","billingEnabledOnStep","customState","initialCustomState","redirectTimeout","onBeforeRedirect","onSuccess","onError","isBoricaInDevMode","withPixelMeta","orderQuery","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","enabled","shippingState","Boolean","validations","moduleKey","moduleData","getIsPaymentMethodsEnabled","methodKey","paymentState","billingState","withSavedBillingAddressList","onBeforeBoricaRedirect","setTimeout","handleCheckoutSubmit","withMeta","scrollToFirstError","interval","setInterval","errorElement","top","clearInterval","handleSubmit","e","preventDefault","Promise","all","persistShippingAddress","persistBillingAddress","catch","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,OAAOA,KAAP,IACEC,aADF,EAEEC,WAFF,EAGEC,UAHF,EAIEC,OAJF,EAKEC,QALF,QAMO,OANP;AAaA,SAASC,SAAT,QAA0B,qBAA1B;AACA,SACEC,UADF,EAGEC,UAHF,EAKEC,WALF,QAOO,SAPP;AAQA,SAASC,kB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AELD,IAAAA,QAAQ,EAAEI,OAAO,CAACJ;AAFb,GAAP;AAID,CAbM;AAeP,OAAO,IAAMa,2BAA2B,GAAG,MAAM;AAC/C,MAAMT,OAAO,GAAGtH,UAAU,CAACiB,mBAAD,CAA1B;;AAEA,MAAI,CAACqG,OAAL,EAAc;AACZ,UAAM,IAAIC,KAAJ,CACJ,+EADI,CAAN;AAGD;;AAED,SAAOD,OAAO,CAACrC,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} 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 { BoricaRedirect, CheckoutFormCustomStateProvider } 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}: 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 })\n const { moduleKey, moduleData } = useCheckoutShippingModule(orderQuery)\n\n const getIsPaymentMethodsEnabled = () => {\n if (paymentEnabledOnStep) {\n return paymentEnabledOnStep === step\n }\n\n if (getPaymentMethodsWhenShippingMethodIsSelected) {\n return Boolean(moduleKey && 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 })\n\n const onBeforeBoricaRedirect = (data: BoricaGeneratePaymentDataResponse) => {\n onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n setBoricaData(data)\n }, redirectTimeout)\n }\n\n const { handleCheckoutSubmit } = useCheckoutSubmit({\n onBeforeBoricaRedirect,\n onSuccess,\n onError: (errors: any) => {\n updateServerErrors(errors)\n onError(errors)\n },\n withMeta: withPixelMeta,\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 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}\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\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\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":["React","createContext","useCallback","useContext","useMemo","useState","myCartApi","useBilling","usePayment","useShipping","useIsAuthenticated","useCheckoutSubmit","defaultShippingValidations","genericBillingAddressValidation","usersApi","useCheckoutShippingModule","BoricaRedirect","CheckoutFormCustomStateProvider","useScrollTo","getElementOffset","CheckoutFormContext","CheckoutFormContextProvider","children","defaultStep","errorLabels","enableSavedAddressList","withPersistBeforePageLeave","shippingValidations","validateBillingAddress","enableSaveBillingAddress","enableSavedBillingAddressList","countryCode","enableSaveAddress","autofillShippingPersonalData","onSubmit","paymentEnabledOnStep","getPaymentMethodsWhenShippingMethodIsSelected","shippingEnabledOnStep","billingEnabledOnStep","customState","initialCustomState","redirectTimeout","onBeforeRedirect","onSuccess","onError","isBoricaInDevMode","withPixelMeta","requiredFieldsOnShippingStep","requiredFieldsOnBillingAddressStep","enableNoShippingMethodMode","orderQuery","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","enabled","shippingState","Boolean","validations","requiredFields","mod","getIsPaymentMethodsEnabled","moduleKey","moduleData","methodKey","paymentState","billingState","withSavedBillingAddressList","requiredFieldsOnShipping","onBeforeBoricaRedirect","setTimeout","handleCheckoutSubmit","withMeta","scrollToFirstError","interval","setInterval","errorElement","top","clearInterval","handleSubmit","e","preventDefault","Promise","all","persistShippingAddress","persistBillingAddress","catch","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,OAAOA,KAAP,IACEC,aADF,EAEEC,WAFF,EAGEC,UAHF,EAIEC,OAJF,EAKEC,QALF,QAMO,OANP;AAaA,SAASC,SAAT,QAA0B,qBAA1B;AACA,SACEC,UADF,EAGEC,UAHF,EAKEC,WALF,QAOO,SAPP;AAQA,SAASC,kBAAT,QAAmC,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AChD,MAAMP,OAAO,GAAG5H,UAAU,CAACiB,mBAAD,CAA1B;;AAEA,MAAI,CAAC2G,OAAL,EAAc;AACZ,UAAM,IAAIC,KAAJ,CACJ,gFADI,CAAN;AAGD;;AAED,SAAOD,OAAO,CAAC/C,aAAf;AACD,CAVM;AAYP,OAAO,IAAMuD,sBAAsB,GAAG,MAAM;AAC1C,MAAMR,OAAO,GAAG5H,UAAU,CAACiB,mBAAD,CAA1B;;AAEA,MAAI,CAAC2G,OAAL,EAAc;AACZ,UAAM,IAAIC,KAAJ,CACJ,0EADI,CAAN;AAGD;;AAED,SAAO;AACLJ,IAAAA,WAAW,EAAEG,OAAO,CAACH,WADhB;AAELD,IAAAA,QAAQ,EAAEI,OAAO,CAACJ;AAFb,GAAP;AAID,CAbM;AAeP,OAAO,IAAMa,2BAA2B,GAAG,MAAM;AAC/C,MAAMT,OAAO,GAAG5H,UAAU,CAACiB,mBAAD,CAA1B;;AAEA,MAAI,CAAC2G,OAAL,EAAc;AACZ,UAAM,IAAIC,KAAJ,CACJ,+EADI,CAAN;AAGD;;AAED,SAAOD,OAAO,CAACtC,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} 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 { BoricaRedirect, CheckoutFormCustomStateProvider } 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}: Props) {\n const orderQuery = myCartApi.useGet()\n const [\n boricaData,\n setBoricaData,\n ] = useState<BoricaGeneratePaymentDataResponse | null>(null)\n\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 onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n setBoricaData(data)\n }, redirectTimeout)\n }\n\n const { handleCheckoutSubmit } = useCheckoutSubmit({\n onBeforeBoricaRedirect,\n onSuccess,\n onError: (errors: any) => {\n updateServerErrors(errors)\n onError(errors)\n },\n withMeta: withPixelMeta,\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}\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\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\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"}
@@ -3,9 +3,8 @@ import _extends from "@babel/runtime/helpers/extends";
3
3
  /* eslint-disable eqeqeq */
4
4
 
5
5
  /* eslint-disable prefer-const */
6
- var requiredCompanyFields = ['vatId', 'companyId', 'companyPerson', 'companyName'];
7
6
  var requiredFields = ['city', 'postalCode', 'streetName'];
8
- export function genericBillingAddressValidation(data, errorLabels) {
7
+ export function genericBillingAddressValidation(data, errorLabels, requiredCompanyFields) {
9
8
  var isWithInvoice = Boolean(data.company);
10
9
  if (!isWithInvoice) return null;
11
10
  var companyErrors = requiredCompanyFields.reduce((errors, field) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/contexts/CheckoutForm/utils/validateBillingAddress.ts"],"names":["requiredCompanyFields","requiredFields","genericBillingAddressValidation","data","errorLabels","isWithInvoice","Boolean","company","companyErrors","reduce","errors","field","trim","fieldIsRequired","fieldErrors","Object","keys","length"],"mappings":";;AAAA;;AACA;AAIA,IAAMA,qBAAqB,GAAG,CAC5B,OAD4B,EAE5B,WAF4B,EAG5B,eAH4B,EAI5B,aAJ4B,CAA9B;AAOA,IAAMC,cAAc,GAAG,CAAC,MAAD,EAAS,YAAT,EAAuB,YAAvB,CAAvB;AAOA,OAAO,SAASC,+BAAT,CACLC,IADK,EAELC,WAFK,EAGyB;AAC9B,MAAMC,aAAa,GAAGC,OAAO,CAACH,IAAI,CAACI,OAAN,CAA7B;AACA,MAAI,CAACF,aAAL,EAAoB,OAAO,IAAP;AAEpB,MAAMG,aAAa,GAAGR,qBAAqB,CAACS,MAAtB,CAA6B,CAACC,MAAD,EAASC,KAAT,KAAmB;AAAA;;AACpE,QAAI,EAACR,IAAD,6BAACA,IAAI,CAAEI,OAAP,oCAAC,cAAgBI,KAAhB,CAAD,aAAC,oBAAwBC,IAAxB,EAAD,CAAJ,EAAqC;AACnC,0BAAYF,MAAZ;AAAoB,SAACC,KAAD,GAASP,WAAW,CAACS;AAAzC;AACD;;AAED,WAAOH,MAAP;AACD,GANqB,EAMnB,EANmB,CAAtB;AAQA,MAAMI,WAAW,GAAGb,cAAc,CAACQ,MAAf,CAAsB,CAACC,MAAD,EAASC,KAAT,KAAmB;AAAA;;AAC3D,QAAI,iBAACR,IAAI,CAACQ,KAAD,CAAL,aAAC,YAAaC,IAAb,EAAD,CAAJ,EAA0B;AACxB,0BAAYF,MAAZ;AAAoB,SAACC,KAAD,GAASP,WAAW,CAACS;AAAzC;AACD;;AAED,WAAOH,MAAP;AACD,GANmB,EAMjB,EANiB,CAApB;;AAQA,MAAMA,MAAM,gBACPF,aADO,EAEPM,WAFO,CAAZ;;AAKA,SAAOC,MAAM,CAACC,IAAP,CAAYN,MAAZ,EAAoBO,MAApB,GAA6BP,MAA7B,GAAsC,IAA7C;AACD","sourcesContent":["/* eslint-disable eqeqeq */\n/* eslint-disable prefer-const */\nimport { AddressDTO } from '@sentecacommerce/sdk'\nimport { CheckoutFormErrorLabelsType, CheckoutFormErrorsResultType } from '..'\n\nconst requiredCompanyFields = [\n 'vatId',\n 'companyId',\n 'companyPerson',\n 'companyName',\n]\n\nconst requiredFields = ['city', 'postalCode', 'streetName']\n\nexport type BillingAddressValidationType = (\n data: AddressDTO,\n errorLabels: CheckoutFormErrorLabelsType\n) => CheckoutFormErrorsResultType\n\nexport function genericBillingAddressValidation(\n data: AddressDTO,\n errorLabels: CheckoutFormErrorLabelsType\n): CheckoutFormErrorsResultType {\n const isWithInvoice = Boolean(data.company)\n if (!isWithInvoice) return null\n\n const companyErrors = requiredCompanyFields.reduce((errors, field) => {\n if (!data?.company?.[field]?.trim()) {\n return { ...errors, [field]: errorLabels.fieldIsRequired }\n }\n\n return errors\n }, {})\n\n const fieldErrors = requiredFields.reduce((errors, field) => {\n if (!data[field]?.trim()) {\n return { ...errors, [field]: errorLabels.fieldIsRequired }\n }\n\n return errors\n }, {})\n\n const errors = {\n ...companyErrors,\n ...fieldErrors,\n }\n\n return Object.keys(errors).length ? errors : null\n}\n"],"file":"validateBillingAddress.js"}
1
+ {"version":3,"sources":["../../../../../src/contexts/CheckoutForm/utils/validateBillingAddress.ts"],"names":["requiredFields","genericBillingAddressValidation","data","errorLabels","requiredCompanyFields","isWithInvoice","Boolean","company","companyErrors","reduce","errors","field","trim","fieldIsRequired","fieldErrors","Object","keys","length"],"mappings":";;AAAA;;AACA;AAIA,IAAMA,cAAc,GAAG,CAAC,MAAD,EAAS,YAAT,EAAuB,YAAvB,CAAvB;AASA,OAAO,SAASC,+BAAT,CACLC,IADK,EAELC,WAFK,EAGLC,qBAHK,EAIyB;AAC9B,MAAMC,aAAa,GAAGC,OAAO,CAACJ,IAAI,CAACK,OAAN,CAA7B;AACA,MAAI,CAACF,aAAL,EAAoB,OAAO,IAAP;AAEpB,MAAMG,aAAa,GAAGJ,qBAAqB,CAACK,MAAtB,CAA6B,CAACC,MAAD,EAASC,KAAT,KAAmB;AAAA;;AACpE,QAAI,EAACT,IAAD,6BAACA,IAAI,CAAEK,OAAP,oCAAC,cAAgBI,KAAhB,CAAD,aAAC,oBAAwBC,IAAxB,EAAD,CAAJ,EAAqC;AACnC,0BAAYF,MAAZ;AAAoB,SAACC,KAAD,GAASR,WAAW,CAACU;AAAzC;AACD;;AAED,WAAOH,MAAP;AACD,GANqB,EAMnB,EANmB,CAAtB;AAQA,MAAMI,WAAW,GAAGd,cAAc,CAACS,MAAf,CAAsB,CAACC,MAAD,EAASC,KAAT,KAAmB;AAAA;;AAC3D,QAAI,iBAACT,IAAI,CAACS,KAAD,CAAL,aAAC,YAAaC,IAAb,EAAD,CAAJ,EAA0B;AACxB,0BAAYF,MAAZ;AAAoB,SAACC,KAAD,GAASR,WAAW,CAACU;AAAzC;AACD;;AAED,WAAOH,MAAP;AACD,GANmB,EAMjB,EANiB,CAApB;;AAQA,MAAMA,MAAM,gBACPF,aADO,EAEPM,WAFO,CAAZ;;AAKA,SAAOC,MAAM,CAACC,IAAP,CAAYN,MAAZ,EAAoBO,MAApB,GAA6BP,MAA7B,GAAsC,IAA7C;AACD","sourcesContent":["/* eslint-disable eqeqeq */\n/* eslint-disable prefer-const */\nimport { AddressDTO } from '@sentecacommerce/sdk'\nimport { CheckoutFormErrorLabelsType, CheckoutFormErrorsResultType } from '..'\n\nconst requiredFields = ['city', 'postalCode', 'streetName']\n\nexport type BillingAddressValidationType = (\n data: AddressDTO,\n errorLabels: CheckoutFormErrorLabelsType,\n requiredFields: string[],\n requiredFieldsOnShipping: string[]\n) => CheckoutFormErrorsResultType\n\nexport function genericBillingAddressValidation(\n data: AddressDTO,\n errorLabels: CheckoutFormErrorLabelsType,\n requiredCompanyFields: string[]\n): CheckoutFormErrorsResultType {\n const isWithInvoice = Boolean(data.company)\n if (!isWithInvoice) return null\n\n const companyErrors = requiredCompanyFields.reduce((errors, field) => {\n if (!data?.company?.[field]?.trim()) {\n return { ...errors, [field]: errorLabels.fieldIsRequired }\n }\n\n return errors\n }, {})\n\n const fieldErrors = requiredFields.reduce((errors, field) => {\n if (!data[field]?.trim()) {\n return { ...errors, [field]: errorLabels.fieldIsRequired }\n }\n\n return errors\n }, {})\n\n const errors = {\n ...companyErrors,\n ...fieldErrors,\n }\n\n return Object.keys(errors).length ? errors : null\n}\n"],"file":"validateBillingAddress.js"}
@@ -3,7 +3,6 @@ import _extends from "@babel/runtime/helpers/extends";
3
3
  /* eslint-disable prefer-const */
4
4
  import { emailRegex, phoneNumberRegex } from '../../../utils/validations';
5
5
  import { ShippingModulesTypeEnum } from '../../../api.v2';
6
- var alwaysRequiredField = ['firstName', 'lastName', 'email', 'phoneNumber'];
7
6
  export function genericAddressValidation(_ref) {
8
7
  var _mod$moduleData, _data$quarter, _data$streetName, _data$additionalAddre;
9
8
 
@@ -126,10 +125,14 @@ export var defaultShippingValidations = {
126
125
  Default: pickupFromStoreValidation
127
126
  }
128
127
  };
129
- export function validateShipping(data, mod, errorLabels, validations) {
130
- var _mod$moduleData5, _validations$mod$modu;
128
+ var defaultRequiredFields = ['firstName', 'lastName', 'email', 'phoneNumber'];
129
+ export function validateShipping(data, mod, errorLabels, validations, requiredFields, enableNoShippingMethodMode) {
130
+ if (requiredFields === void 0) {
131
+ requiredFields = defaultRequiredFields;
132
+ }
131
133
 
132
- var globalErrors = alwaysRequiredField.reduce((errors, field) => {
134
+ var validateErrors = {};
135
+ var globalErrors = requiredFields.reduce((errors, field) => {
133
136
  var _data$field;
134
137
 
135
138
  if (!(data != null && (_data$field = data[field]) != null && _data$field.trim != null && _data$field.trim())) {
@@ -149,23 +152,27 @@ export function validateShipping(data, mod, errorLabels, validations) {
149
152
  globalErrors.phoneNumber = (errorLabels == null ? void 0 : errorLabels.invalidPhoneNumber) || '';
150
153
  }
151
154
 
152
- if (!(mod != null && mod.moduleKey) || !(mod != null && (_mod$moduleData5 = mod.moduleData) != null && _mod$moduleData5.methodKey)) {
153
- return _extends({}, globalErrors, {
154
- courier: errorLabels.selectCourier
155
- });
156
- }
155
+ if (!enableNoShippingMethodMode) {
156
+ var _mod$moduleData5, _validations;
157
157
 
158
- var validate = (_validations$mod$modu = validations[mod.moduleKey]) == null ? void 0 : _validations$mod$modu[mod.moduleData.methodKey];
158
+ if (!(mod != null && mod.moduleKey) || !(mod != null && (_mod$moduleData5 = mod.moduleData) != null && _mod$moduleData5.methodKey)) {
159
+ return _extends({}, globalErrors, {
160
+ courier: errorLabels.selectCourier
161
+ });
162
+ }
159
163
 
160
- if (!validate) {
161
- throw new Error("Validation for shipping with provider: " + mod.moduleKey + " and method key: " + mod.moduleData.methodKey + " not found");
162
- }
164
+ var validate = (_validations = validations[mod == null ? void 0 : mod.moduleKey]) == null ? void 0 : _validations[mod == null ? void 0 : mod.moduleData.methodKey];
163
165
 
164
- var validateErrors = validate({
165
- data,
166
- mod,
167
- errorLabels
168
- }) || {};
166
+ if (!validate) {
167
+ throw new Error("Validation for shipping with provider: " + (mod == null ? void 0 : mod.moduleKey) + " and method key: " + (mod == null ? void 0 : mod.moduleData.methodKey) + " not found");
168
+ }
169
+
170
+ validateErrors = validate({
171
+ data,
172
+ mod,
173
+ errorLabels
174
+ }) || {};
175
+ }
169
176
 
170
177
  var errors = _extends({}, globalErrors, validateErrors);
171
178
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/contexts/CheckoutForm/utils/validateShipping.ts"],"names":["emailRegex","phoneNumberRegex","ShippingModulesTypeEnum","alwaysRequiredField","genericAddressValidation","data","mod","errorLabels","address","moduleData","city","cityIsRequired","quarter","trim","streetNumber","entrance","building","apartment","any","fillStreetNumberBuildingEntranceOrApartment","street","streetName","additionalAddressInfo","cantFindStreetOrQuarterMessage","streetIsRequired","quarterIsRequired","fanAddressValidation","errors","fieldIsRequired","Object","keys","length","genericOfficeValidation","office","officeIsRequired","pickupFromStoreValidation","stockLocation","pickupFromStore","noStoreSelected","undefined","defaultShippingValidations","Speedy","Address","Office","Econt","Evropat","Fan","PickUpFromStore","Default","validateShipping","validations","globalErrors","reduce","field","email","test","emailIsRequired","phoneNumber","invalidPhoneNumber","moduleKey","methodKey","courier","selectCourier","validate","Error","validateErrors"],"mappings":";;AAAA;AAQA,SAASA,UAAT,EAAqBC,gBAArB,QAA6C,4BAA7C;AACA,SAASC,uBAAT,QAAwC,iBAAxC;AAE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BACKT,YADL;AAEEU,MAAAA,OAAO,EAAEtD,WAAW,CAACuD;AAFvB;AAID;;AAED,MAAMC,QAAQ,4BAAGb,WAAW,CAAC5C,GAAG,CAACqD,SAAL,CAAd,qBAAG,sBAA6BrD,GAAG,CAACG,UAAJ,CAAemD,SAA5C,CAAjB;;AAEA,MAAI,CAACG,QAAL,EAAe;AACb,UAAM,IAAIC,KAAJ,6CACsC1D,GAAG,CAACqD,SAD1C,yBACuErD,GAAG,CAACG,UAAJ,CAAemD,SADtF,gBAAN;AAGD;;AAED,MAAMK,cAAc,GAAGF,QAAQ,CAAC;AAAE1D,IAAAA,IAAF;AAAQC,IAAAA,GAAR;AAAaC,IAAAA;AAAb,GAAD,CAAR,IAAwC,EAA/D;;AAEA,MAAMoB,MAAoC,gBACrCwB,YADqC,EAErCc,cAFqC,CAA1C;;AAKA,SAAOpC,MAAM,CAACC,IAAP,CAAYH,MAAZ,EAAoBI,MAApB,GAA6BJ,MAA7B,GAAsC,IAA7C;AACD","sourcesContent":["/* eslint-disable prefer-const */\nimport { AddressDTO } from '@sentecacommerce/sdk'\nimport { ShippingModule } from '../../../hooks/useCheckoutShippingModule'\n\nimport {\n CheckoutFormErrorLabelsType,\n CheckoutFormErrorsResultType,\n} from '../index'\nimport { emailRegex, phoneNumberRegex } from '../../../utils/validations'\nimport { ShippingModulesTypeEnum } from '../../../api.v2'\n\nconst alwaysRequiredField = ['firstName', 'lastName', 'email', 'phoneNumber']\n\ntype ValidationProps = {\n data?: AddressDTO | null\n mod?: ShippingModule | null\n errorLabels: CheckoutFormErrorLabelsType\n}\n\nexport function genericAddressValidation({\n data,\n mod,\n errorLabels,\n}: ValidationProps): CheckoutFormErrorsResultType {\n const address = mod?.moduleData?.address\n\n if (!data) return\n\n if (!address?.city) {\n // City is always required\n return {\n city: errorLabels.cityIsRequired,\n }\n }\n\n // case 1: city + quarter + anything else\n if (address?.quarter || data.quarter?.trim()) {\n if (\n !data.streetNumber?.trim() &&\n !data.entrance?.trim() &&\n !data.building?.trim() &&\n !data.apartment?.trim()\n ) {\n return {\n any: errorLabels.fillStreetNumberBuildingEntranceOrApartment,\n }\n }\n }\n // case 2: city + street + anything else\n else if (address?.street || data.streetName?.trim()) {\n if (\n !data.streetNumber?.trim() &&\n !data.entrance?.trim() &&\n !data.building?.trim() &&\n !data.apartment?.trim()\n ) {\n return {\n any: errorLabels.fillStreetNumberBuildingEntranceOrApartment,\n }\n }\n }\n // case 3: city + additional info\n else if (!data.additionalAddressInfo?.trim()) {\n return {\n additionalAddressInfo: errorLabels.cantFindStreetOrQuarterMessage,\n street: errorLabels.streetIsRequired,\n quarter: errorLabels.quarterIsRequired,\n }\n }\n}\n\nexport function fanAddressValidation({\n data,\n mod,\n errorLabels,\n}: ValidationProps): CheckoutFormErrorsResultType {\n const address = mod?.moduleData?.address\n const errors: CheckoutFormErrorsResultType = {}\n\n if (!data) return\n\n // City, Street and StreetNumber are always required\n if (!address?.city) {\n errors.city = errorLabels.cityIsRequired\n }\n\n if (!address?.street) {\n errors.street = errorLabels.streetIsRequired\n }\n\n if (!data.streetNumber) {\n errors.streetNumber = errorLabels.fieldIsRequired\n }\n\n return Object.keys(errors).length ? errors : null\n}\n\nexport function genericOfficeValidation({\n mod,\n errorLabels,\n}: ValidationProps): CheckoutFormErrorsResultType {\n let errors: CheckoutFormErrorsResultType = {}\n\n const address = mod?.moduleData?.address\n\n if (!address?.city) {\n errors.city = errorLabels.cityIsRequired\n }\n\n if (!address?.office) {\n errors.office = errorLabels.officeIsRequired\n }\n\n return Object.keys(errors).length ? errors : null\n}\n\nexport function pickupFromStoreValidation({\n mod,\n errorLabels,\n}: ValidationProps): CheckoutFormErrorsResultType {\n return !mod?.moduleData?.stockLocation\n ? { pickupFromStore: errorLabels.noStoreSelected }\n : undefined\n}\n\nexport const defaultShippingValidations: ShippingValidationsType = {\n [ShippingModulesTypeEnum.Speedy]: {\n Address: genericAddressValidation,\n Office: genericOfficeValidation,\n },\n [ShippingModulesTypeEnum.Econt]: {\n Address: genericAddressValidation,\n Office: genericOfficeValidation,\n },\n [ShippingModulesTypeEnum.Evropat]: {\n Address: genericAddressValidation,\n Office: genericOfficeValidation,\n },\n [ShippingModulesTypeEnum.Fan]: {\n Address: fanAddressValidation,\n },\n [ShippingModulesTypeEnum.PickUpFromStore]: {\n Default: pickupFromStoreValidation,\n },\n}\n\nexport interface ShippingValidationsType {\n [key: string]: {\n [key: string]: (\n data: ValidationProps\n ) => { [key: string]: string } | null | undefined\n }\n}\n\nexport function validateShipping(\n data: AddressDTO | null | undefined,\n mod: ShippingModule | undefined,\n errorLabels: CheckoutFormErrorLabelsType,\n validations: ShippingValidationsType\n): CheckoutFormErrorsResultType {\n const globalErrors: CheckoutFormErrorsResultType = alwaysRequiredField.reduce(\n (errors, field) => {\n if (!data?.[field]?.trim?.()) {\n return {\n ...errors,\n [field]: errorLabels.fieldIsRequired,\n }\n }\n\n return errors\n },\n {}\n )\n\n if (data?.email && !emailRegex.test(data.email)) {\n globalErrors.email = errorLabels.emailIsRequired\n }\n\n if (data?.phoneNumber && !phoneNumberRegex.test(data?.phoneNumber)) {\n globalErrors.phoneNumber = errorLabels?.invalidPhoneNumber || ''\n }\n\n if (!mod?.moduleKey || !mod?.moduleData?.methodKey) {\n return {\n ...globalErrors,\n courier: errorLabels.selectCourier,\n }\n }\n\n const validate = validations[mod.moduleKey]?.[mod.moduleData.methodKey]\n\n if (!validate) {\n throw new Error(\n `Validation for shipping with provider: ${mod.moduleKey} and method key: ${mod.moduleData.methodKey} not found`\n )\n }\n\n const validateErrors = validate({ data, mod, errorLabels }) || {}\n\n const errors: CheckoutFormErrorsResultType = {\n ...globalErrors,\n ...validateErrors,\n }\n\n return Object.keys(errors).length ? errors : null\n}\n"],"file":"validateShipping.js"}
1
+ {"version":3,"sources":["../../../../../src/contexts/CheckoutForm/utils/validateShipping.ts"],"names":["emailRegex","phoneNumberRegex","ShippingModulesTypeEnum","genericAddressValidation","data","mod","errorLabels","address","moduleData","city","cityIsRequired","quarter","trim","streetNumber","entrance","building","apartment","any","fillStreetNumberBuildingEntranceOrApartment","street","streetName","additionalAddressInfo","cantFindStreetOrQuarterMessage","streetIsRequired","quarterIsRequired","fanAddressValidation","errors","fieldIsRequired","Object","keys","length","genericOfficeValidation","office","officeIsRequired","pickupFromStoreValidation","stockLocation","pickupFromStore","noStoreSelected","undefined","defaultShippingValidations","Speedy","Address","Office","Econt","Evropat","Fan","PickUpFromStore","Default","defaultRequiredFields","validateShipping","validations","requiredFields","enableNoShippingMethodMode","validateErrors","globalErrors","reduce","field","email","test","emailIsRequired","phoneNumber","invalidPhoneNumber","moduleKey","methodKey","courier","selectCourier","validate","Error"],"mappings":";;AAAA;AAQA,SAASA,UAAT,EAAqBC,gBAArB,QAA6C,4BAA7C;AACA,SAASC,uBAAT,QAAwC,iBAAxC;AAQA,OAAO,SAASC,wBAAT,OAI2C;AAAA;;AAAA,MAJT;AACvCC,IAAAA,IADuC;AAEvCC,IAAAA,GAFuC;AAGvCC,IAAAA;AAHuC,GAIS;AAChD,MAAMC,OAAO,GAAGF,GAAH,uCAAGA,GAAG,CAAEG,UAAR,qBAAG,gBAAiBD,OAAjC;AAEA,MAAI,CAACH,IAAL,EAAW;;AAEX,MAAI,EAACG,OAAD,YAACA,OAAO,CAAEE,IAAV,CAAJ,EAAoB;AAClB;AACA,WAAO;AACLA,MAAAA,IAAI,EAAEH,WAAW,CAACI;AADb,KAAP;AAGD,GAV+C,CAYhD;;;AACA,MAAIH,OAAO,QAAP,IAAAA,OAAO,CAAEI,OAAT,qBAAoBP,IAAI,CAACO,OAAzB,aAAoB,cAAcC,IAAd,EAAxB,EAA8C;AAAA;;AAC5C,QACE,wBAACR,IAAI,CAACS,YAAN,aAAC,mBAAmBD,IAAnB,EAAD,KACA,oBAACR,IAAI,CAACU,QAAN,aAAC,eAAeF,IAAf,EAAD,CADA,IAEA,oBAACR,IAAI,CAACW,QAAN,aAAC,eAAeH,IAAf,EAAD,CAFA,IAGA,qBAACR,IA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BACrC4B,YADqC,EAErCD,cAFqC,CAA1C;;AAKA,SAAOzB,MAAM,CAACC,IAAP,CAAYH,MAAZ,EAAoBI,MAApB,GAA6BJ,MAA7B,GAAsC,IAA7C;AACD","sourcesContent":["/* eslint-disable prefer-const */\nimport { AddressDTO } from '@sentecacommerce/sdk'\nimport { ShippingModule } from '../../../hooks/useCheckoutShippingModule'\n\nimport {\n CheckoutFormErrorLabelsType,\n CheckoutFormErrorsResultType,\n} from '../index'\nimport { emailRegex, phoneNumberRegex } from '../../../utils/validations'\nimport { ShippingModulesTypeEnum } from '../../../api.v2'\n\ntype ValidationProps = {\n data?: AddressDTO | null\n mod?: ShippingModule | null\n errorLabels: CheckoutFormErrorLabelsType\n}\n\nexport function genericAddressValidation({\n data,\n mod,\n errorLabels,\n}: ValidationProps): CheckoutFormErrorsResultType {\n const address = mod?.moduleData?.address\n\n if (!data) return\n\n if (!address?.city) {\n // City is always required\n return {\n city: errorLabels.cityIsRequired,\n }\n }\n\n // case 1: city + quarter + anything else\n if (address?.quarter || data.quarter?.trim()) {\n if (\n !data.streetNumber?.trim() &&\n !data.entrance?.trim() &&\n !data.building?.trim() &&\n !data.apartment?.trim()\n ) {\n return {\n any: errorLabels.fillStreetNumberBuildingEntranceOrApartment,\n }\n }\n }\n // case 2: city + street + anything else\n else if (address?.street || data.streetName?.trim()) {\n if (\n !data.streetNumber?.trim() &&\n !data.entrance?.trim() &&\n !data.building?.trim() &&\n !data.apartment?.trim()\n ) {\n return {\n any: errorLabels.fillStreetNumberBuildingEntranceOrApartment,\n }\n }\n }\n // case 3: city + additional info\n else if (!data.additionalAddressInfo?.trim()) {\n return {\n additionalAddressInfo: errorLabels.cantFindStreetOrQuarterMessage,\n street: errorLabels.streetIsRequired,\n quarter: errorLabels.quarterIsRequired,\n }\n }\n}\n\nexport function fanAddressValidation({\n data,\n mod,\n errorLabels,\n}: ValidationProps): CheckoutFormErrorsResultType {\n const address = mod?.moduleData?.address\n const errors: CheckoutFormErrorsResultType = {}\n\n if (!data) return\n\n // City, Street and StreetNumber are always required\n if (!address?.city) {\n errors.city = errorLabels.cityIsRequired\n }\n\n if (!address?.street) {\n errors.street = errorLabels.streetIsRequired\n }\n\n if (!data.streetNumber) {\n errors.streetNumber = errorLabels.fieldIsRequired\n }\n\n return Object.keys(errors).length ? errors : null\n}\n\nexport function genericOfficeValidation({\n mod,\n errorLabels,\n}: ValidationProps): CheckoutFormErrorsResultType {\n let errors: CheckoutFormErrorsResultType = {}\n\n const address = mod?.moduleData?.address\n\n if (!address?.city) {\n errors.city = errorLabels.cityIsRequired\n }\n\n if (!address?.office) {\n errors.office = errorLabels.officeIsRequired\n }\n\n return Object.keys(errors).length ? errors : null\n}\n\nexport function pickupFromStoreValidation({\n mod,\n errorLabels,\n}: ValidationProps): CheckoutFormErrorsResultType {\n return !mod?.moduleData?.stockLocation\n ? { pickupFromStore: errorLabels.noStoreSelected }\n : undefined\n}\n\nexport const defaultShippingValidations: ShippingValidationsType = {\n [ShippingModulesTypeEnum.Speedy]: {\n Address: genericAddressValidation,\n Office: genericOfficeValidation,\n },\n [ShippingModulesTypeEnum.Econt]: {\n Address: genericAddressValidation,\n Office: genericOfficeValidation,\n },\n [ShippingModulesTypeEnum.Evropat]: {\n Address: genericAddressValidation,\n Office: genericOfficeValidation,\n },\n [ShippingModulesTypeEnum.Fan]: {\n Address: fanAddressValidation,\n },\n [ShippingModulesTypeEnum.PickUpFromStore]: {\n Default: pickupFromStoreValidation,\n },\n}\n\nexport interface ShippingValidationsType {\n [key: string]: {\n [key: string]: (\n data: ValidationProps\n ) => { [key: string]: string } | null | undefined\n }\n}\n\nconst defaultRequiredFields = ['firstName', 'lastName', 'email', 'phoneNumber']\n\nexport function validateShipping(\n data: AddressDTO | null | undefined,\n mod: ShippingModule | undefined,\n errorLabels: CheckoutFormErrorLabelsType,\n validations: ShippingValidationsType,\n requiredFields: string[] = defaultRequiredFields,\n enableNoShippingMethodMode?: boolean\n): CheckoutFormErrorsResultType {\n let validateErrors: { [key: string]: string } = {}\n\n const globalErrors: CheckoutFormErrorsResultType = requiredFields.reduce(\n (errors, field) => {\n if (!data?.[field]?.trim?.()) {\n return {\n ...errors,\n [field]: errorLabels.fieldIsRequired,\n }\n }\n\n return errors\n },\n {}\n )\n\n if (data?.email && !emailRegex.test(data.email)) {\n globalErrors.email = errorLabels.emailIsRequired\n }\n\n if (data?.phoneNumber && !phoneNumberRegex.test(data?.phoneNumber)) {\n globalErrors.phoneNumber = errorLabels?.invalidPhoneNumber || ''\n }\n\n if (!enableNoShippingMethodMode) {\n if (!mod?.moduleKey || !mod?.moduleData?.methodKey) {\n return {\n ...globalErrors,\n courier: errorLabels.selectCourier,\n }\n }\n\n const validate =\n validations[mod?.moduleKey as string]?.[mod?.moduleData.methodKey]\n\n if (!validate) {\n throw new Error(\n `Validation for shipping with provider: ${mod?.moduleKey} and method key: ${mod?.moduleData.methodKey} not found`\n )\n }\n\n validateErrors = validate({ data, mod, errorLabels }) || {}\n }\n\n const errors: CheckoutFormErrorsResultType = {\n ...globalErrors,\n ...validateErrors,\n }\n\n return Object.keys(errors).length ? errors : null\n}\n"],"file":"validateShipping.js"}
@@ -21,7 +21,8 @@ export var AddressFormContextProvider = (_ref) => {
21
21
  address: currentAddress,
22
22
  onSuccess,
23
23
  validations = defaultShippingValidations,
24
- errorLabels
24
+ errorLabels,
25
+ requiredFields = ['firstName', 'lastName', 'email', 'phoneNumber']
25
26
  } = _ref;
26
27
  var emptyAddress = {
27
28
  _id: (currentAddress == null ? void 0 : currentAddress._id) || '',
@@ -82,7 +83,7 @@ export var AddressFormContextProvider = (_ref) => {
82
83
  };
83
84
  }, []);
84
85
  var addressErrors = useMemo(() => {
85
- return validateShipping(address, moduleData, errorLabels, validations);
86
+ return validateShipping(address, moduleData, errorLabels, validations, requiredFields);
86
87
  }, [address, moduleData, errorLabels, validations]);
87
88
  /**
88
89
  * Format all platform and merchant modules
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/hooks/addresses-hooks/useAddressForm/index.tsx"],"names":["React","useCallback","useEffect","useMemo","useState","addressesApi","myCartApi","validateShipping","defaultShippingValidations","useErrors","Couriers","AddressFormContext","createContext","AddressFormContextProvider","children","address","currentAddress","onSuccess","validations","errorLabels","emptyAddress","_id","createdAt","Date","now","updatedAt","setAddress","isSubmitting","setIsSubmitting","moduleData","setModuleData","addNewAddress","error","addNewError","useAdd","updateAddress","updateError","useUpdate","data","moduleTypesRaw","isLoading","isModuleTypesLoading","useGetAllShippingMethods","selectModule","moduleKey","methodKey","setModuleAddressData","key","value","formatMethod","method","select","addressErrors","modules","platformMethods","platformShippingMethods","map","merchantMethods","merchantsShippingMethods","methods","flat","result","reduce","current","onChange","name","addNewErrors","updateErrors","errors","hasErrors","Boolean","Object","keys","length","handleSubmit","e","preventDefault","id","dto","undefined","state","formKey","addressState","setAddressState","onInputChange","isValid","useAddressForm","context","useContext","Error"],"mappings":";AAAA,OAAOA,KAAP,IAAgBC,WAAhB,EAA6BC,SAA7B,EAAwCC,OAAxC,EAAiDC,QAAjD,QAAiE,OAAjE;AAMA,SAASC,YAAT,QAA6B,2BAA7B;AACA,SAASC,SAAT,QAA0B,wBAA1B;AACA,SACEC,gBADF,EAEEC,0BAFF,QAIO,sCAJP;AAMA,SAASC,SAAT,QAA6C,sBAA7C;AAEA,WAAYC,QAAZ;;WAAYA,Q;AAAAA,EAAAA,Q;AAAAA,EAAAA,Q;AAAAA,EAAAA,Q;GAAAA,Q,KAAAA,Q;;AAiCZ,IAAMC,kBAAkB,gBAAGX,KAAK,CAACY,aAAN,CACzB,EADyB,CAA3B;AAMA,OAAO,IAAMC,0BAA0B,GAAG,UAYpC;AAAA;;AAAA,MAZqC;AACzCC,IAAAA,QADyC;AAEzCC,IAAAA,OAAO,EAAEC,cAFgC;AAGzCC,IAAAA,SAHyC;AAIzCC,IAAAA,WAAW,GAAGV,0BAJ2B;AAKzCW,IAAAA;AALyC,GAYrC;AACJ,MAAMC,YAAwB,GAAG;AAC/BC,I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,EAAEnE,OAJT;AAKLoE,MAAAA,eAAe,EAAEzD,UALZ;AAML0D,MAAAA,aAAa,EAAEpB,QANV;AAOLnC,MAAAA,UAPK;AAQLiB,MAAAA,oBARK;AASLsB,MAAAA,MAAM,EAAEzC,YAAY,GAAGyC,MAAH,GAAY,EAT3B;AAULzC,MAAAA,YAVK;AAWL0D,MAAAA,OAAO,EAAE,CAAChB;AAXL,KAAP;AAaD,GAdoB,EAclB,CACDxC,UADC,EAEDd,OAFC,EAGDyB,SAHC,EAIDa,OAJC,EAKDP,oBALC,EAMDkB,QANC,EAODrC,YAPC,EAQDyC,MARC,EASDC,SATC,CAdkB,CAArB;AA0BA,sBACE,oBAAC,kBAAD,CAAoB,QAApB;AAA6B,IAAA,KAAK,EAAEW;AAApC,kBACE;AAAM,IAAA,QAAQ,EAAEN,YAAhB;AAA8B,IAAA,UAAU;AAAxC,KACG5D,QADH,CADF,CADF;AAOD,CAnNM;AAqNP,OAAO,IAAMwE,cAAc,GAAG,MAAM;AAClC,MAAMC,OAAO,GAAGvF,KAAK,CAACwF,UAAN,CAAiB7E,kBAAjB,CAAhB;;AAEA,MAAI,CAAC4E,OAAL,EAAc;AACZ,UAAM,IAAIE,KAAJ,CACJ,iEADI,CAAN;AAGD;;AAED,SAAOF,OAAP;AACD,CAVM","sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from 'react'\nimport {\n AddressModuleDataDTO,\n ShippingMethodDTO,\n AddressDTO,\n} from '@sentecacommerce/sdk'\nimport { addressesApi } from '../../../api/addressesApi'\nimport { myCartApi } from '../../../api/myCartApi'\nimport {\n validateShipping,\n defaultShippingValidations,\n ShippingValidationsType,\n} from '../../../contexts/CheckoutForm/utils'\nimport { ShippingFormErrorLabels } from '../../../contexts/CheckoutForm'\nimport { useErrors, DefaultFormErrors } from '../../error-handling'\n\nexport enum Couriers {\n 'Speedy' = 'Speedy',\n 'Econt' = 'Econt',\n 'Evropat' = 'Evropat',\n}\n\nexport type AddressFormModule = {\n methods: {\n key?: string\n select: () => void\n }[]\n}\n\ntype Modules = {\n [key in Couriers]: AddressFormModule\n}\n\ntype AddressFormContextValue = {\n formKey: string\n modules: Modules\n isLoading: boolean\n addressState?: AddressDTO\n setAddressState: React.Dispatch<AddressDTO>\n onInputChange: (name: string, value: any) => void\n moduleData?: AddressModuleDataDTO\n setModuleAddressData: (key: string, value: any) => void\n isSubmitting: boolean\n isValid: boolean\n errors: {\n [key: string]: string | undefined\n }\n}\n\nconst AddressFormContext = React.createContext<AddressFormContextValue>(\n {} as any\n)\n\nexport type AddressFormLabelsType = ShippingFormErrorLabels & DefaultFormErrors\n\nexport const AddressFormContextProvider = ({\n children,\n address: currentAddress,\n onSuccess,\n validations = defaultShippingValidations,\n errorLabels,\n}: {\n children: JSX.Element | JSX.Element[]\n address?: AddressDTO\n onSuccess: () => void\n validations?: ShippingValidationsType\n errorLabels: AddressFormLabelsType\n}) => {\n const emptyAddress: AddressDTO = {\n _id: currentAddress?._id || '',\n createdAt: Date.now(),\n updatedAt: Date.now(),\n }\n \n const [address, setAddress] = useState(currentAddress || emptyAddress)\n\n const [isSubmitting, setIsSubmitting] = useState(false)\n\n const [moduleData, setModuleData] = useState(currentAddress?.moduleData?.[0])\n\n const [addNewAddress, { error: addNewError }] = addressesApi.useAdd({\n onSuccess,\n })\n const [updateAddress, { error: updateError }] = addressesApi.useUpdate(\n onSuccess\n )\n\n const {\n data: moduleTypesRaw,\n isLoading: isModuleTypesLoading,\n } = myCartApi.useGetAllShippingMethods()\n\n const isLoading = isModuleTypesLoading\n\n // set initial data\n useEffect(() => {\n if (!address && currentAddress) {\n setAddress(currentAddress)\n setModuleData(currentAddress.moduleData?.[0])\n }\n }, [address, currentAddress])\n\n const selectModule = (moduleKey: string, methodKey: string) => {\n setModuleData({ moduleKey, moduleData: { methodKey } })\n }\n\n const setModuleAddressData = useCallback(\n (key: string, value: any) => {\n if (!moduleData) return\n\n const data = { ...moduleData }\n\n if (!data.moduleData) data.moduleData = {}\n\n data.moduleData.address = {\n ...(data.moduleData.address || {}),\n [key]: value,\n }\n\n setModuleData(data)\n },\n [moduleData]\n )\n\n const formatMethod = useCallback((method: ShippingMethodDTO) => {\n return {\n moduleKey: method.moduleKey,\n select: () =>\n selectModule(method.moduleKey as string, method.methodKey as string),\n methodKey: method.methodKey,\n }\n }, [])\n\n const addressErrors = useMemo(() => {\n return validateShipping(\n address,\n moduleData,\n errorLabels as any,\n validations\n )\n }, [address, moduleData, errorLabels, validations])\n\n /**\n * Format all platform and merchant modules\n */\n const modules = useMemo((): Modules => {\n const platformMethods =\n moduleTypesRaw?.platformShippingMethods?.map?.(formatMethod) || []\n\n const merchantMethods =\n moduleTypesRaw?.merchantsShippingMethods?.map?.((data) => {\n return data?.methods?.map?.(formatMethod)\n }) || []\n\n const data = [...platformMethods, ...merchantMethods.flat()]\n\n const result = data.reduce((current, method) => {\n return {\n ...current,\n [method.moduleKey as Couriers]: {\n methods: [\n ...(current[method.moduleKey as Couriers]?.methods || []),\n {\n key: method.methodKey,\n select: method.select,\n },\n ],\n },\n }\n }, {})\n\n return (result as unknown) as Modules\n }, [moduleTypesRaw, formatMethod])\n\n /**\n * On input change\n */\n const onChange = useCallback(\n (name: string, value: any) => {\n if (!address) return\n\n setAddress({\n ...address,\n [name]: value,\n })\n },\n [address]\n )\n\n const addNewErrors = useErrors<AddressFormLabelsType>(\n addNewError,\n errorLabels\n )\n const updateErrors = useErrors<AddressFormLabelsType>(\n updateError,\n errorLabels\n )\n\n const errors = useMemo(() => {\n return {\n ...(addressErrors || {}),\n ...(updateErrors || {}),\n ...(addNewErrors || {}),\n }\n }, [addressErrors, updateErrors, addNewErrors])\n\n const hasErrors = Boolean(Object.keys(errors).length)\n\n const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n setIsSubmitting(true)\n\n if (hasErrors) return\n\n if (currentAddress?._id) {\n updateAddress({\n id: currentAddress._id,\n dto: {\n ...address,\n moduleData: moduleData && [moduleData],\n },\n })\n\n return\n }\n\n addNewAddress({\n ...address,\n _id: undefined,\n moduleData: moduleData && [moduleData],\n })\n }\n\n const state = useMemo((): AddressFormContextValue => {\n return {\n formKey: `${moduleData?.moduleKey}-${moduleData?.moduleData?.methodKey}`,\n modules,\n isLoading,\n addressState: address,\n setAddressState: setAddress,\n onInputChange: onChange,\n moduleData,\n setModuleAddressData,\n errors: isSubmitting ? errors : {},\n isSubmitting,\n isValid: !hasErrors,\n }\n }, [\n moduleData,\n address,\n isLoading,\n modules,\n setModuleAddressData,\n onChange,\n isSubmitting,\n errors,\n hasErrors,\n ])\n\n return (\n <AddressFormContext.Provider value={state}>\n <form onSubmit={handleSubmit} noValidate>\n {children}\n </form>\n </AddressFormContext.Provider>\n )\n}\n\nexport const useAddressForm = () => {\n const context = React.useContext(AddressFormContext)\n\n if (!context) {\n throw new Error(\n 'useAddressForm must be used within a AddressFormContextProvider'\n )\n }\n\n return context\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../../src/hooks/addresses-hooks/useAddressForm/index.tsx"],"names":["React","useCallback","useEffect","useMemo","useState","addressesApi","myCartApi","validateShipping","defaultShippingValidations","useErrors","Couriers","AddressFormContext","createContext","AddressFormContextProvider","children","address","currentAddress","onSuccess","validations","errorLabels","requiredFields","emptyAddress","_id","createdAt","Date","now","updatedAt","setAddress","isSubmitting","setIsSubmitting","moduleData","setModuleData","addNewAddress","error","addNewError","useAdd","updateAddress","updateError","useUpdate","data","moduleTypesRaw","isLoading","isModuleTypesLoading","useGetAllShippingMethods","selectModule","moduleKey","methodKey","setModuleAddressData","key","value","formatMethod","method","select","addressErrors","modules","platformMethods","platformShippingMethods","map","merchantMethods","merchantsShippingMethods","methods","flat","result","reduce","current","onChange","name","addNewErrors","updateErrors","errors","hasErrors","Boolean","Object","keys","length","handleSubmit","e","preventDefault","id","dto","undefined","state","formKey","addressState","setAddressState","onInputChange","isValid","useAddressForm","context","useContext","Error"],"mappings":";AAAA,OAAOA,KAAP,IAAgBC,WAAhB,E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QAAQ,EAAEN,YAAhB;AAA8B,IAAA,UAAU;AAAxC,KACG7D,QADH,CADF,CADF;AAOD,CAtNM;AAwNP,OAAO,IAAMyE,cAAc,GAAG,MAAM;AAClC,MAAMC,OAAO,GAAGxF,KAAK,CAACyF,UAAN,CAAiB9E,kBAAjB,CAAhB;;AAEA,MAAI,CAAC6E,OAAL,EAAc;AACZ,UAAM,IAAIE,KAAJ,CACJ,iEADI,CAAN;AAGD;;AAED,SAAOF,OAAP;AACD,CAVM","sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from 'react'\nimport {\n AddressModuleDataDTO,\n ShippingMethodDTO,\n AddressDTO,\n} from '@sentecacommerce/sdk'\nimport { addressesApi } from '../../../api/addressesApi'\nimport { myCartApi } from '../../../api/myCartApi'\nimport {\n validateShipping,\n defaultShippingValidations,\n ShippingValidationsType,\n} from '../../../contexts/CheckoutForm/utils'\nimport { ShippingFormErrorLabels } from '../../../contexts/CheckoutForm'\nimport { useErrors, DefaultFormErrors } from '../../error-handling'\n\nexport enum Couriers {\n 'Speedy' = 'Speedy',\n 'Econt' = 'Econt',\n 'Evropat' = 'Evropat',\n}\n\nexport type AddressFormModule = {\n methods: {\n key?: string\n select: () => void\n }[]\n}\n\ntype Modules = {\n [key in Couriers]: AddressFormModule\n}\n\ntype AddressFormContextValue = {\n formKey: string\n modules: Modules\n isLoading: boolean\n addressState?: AddressDTO\n setAddressState: React.Dispatch<AddressDTO>\n onInputChange: (name: string, value: any) => void\n moduleData?: AddressModuleDataDTO\n setModuleAddressData: (key: string, value: any) => void\n isSubmitting: boolean\n isValid: boolean\n errors: {\n [key: string]: string | undefined\n }\n}\n\nconst AddressFormContext = React.createContext<AddressFormContextValue>(\n {} as any\n)\n\nexport type AddressFormLabelsType = ShippingFormErrorLabels & DefaultFormErrors\n\nexport const AddressFormContextProvider = ({\n children,\n address: currentAddress,\n onSuccess,\n validations = defaultShippingValidations,\n errorLabels,\n requiredFields = ['firstName', 'lastName', 'email', 'phoneNumber'],\n}: {\n children: JSX.Element | JSX.Element[]\n address?: AddressDTO\n onSuccess: () => void\n validations?: ShippingValidationsType\n errorLabels: AddressFormLabelsType\n requiredFields?: string[]\n}) => {\n const emptyAddress: AddressDTO = {\n _id: currentAddress?._id || '',\n createdAt: Date.now(),\n updatedAt: Date.now(),\n }\n\n const [address, setAddress] = useState(currentAddress || emptyAddress)\n\n const [isSubmitting, setIsSubmitting] = useState(false)\n\n const [moduleData, setModuleData] = useState(currentAddress?.moduleData?.[0])\n\n const [addNewAddress, { error: addNewError }] = addressesApi.useAdd({\n onSuccess,\n })\n const [updateAddress, { error: updateError }] = addressesApi.useUpdate(\n onSuccess\n )\n\n const {\n data: moduleTypesRaw,\n isLoading: isModuleTypesLoading,\n } = myCartApi.useGetAllShippingMethods()\n\n const isLoading = isModuleTypesLoading\n\n // set initial data\n useEffect(() => {\n if (!address && currentAddress) {\n setAddress(currentAddress)\n setModuleData(currentAddress.moduleData?.[0])\n }\n }, [address, currentAddress])\n\n const selectModule = (moduleKey: string, methodKey: string) => {\n setModuleData({ moduleKey, moduleData: { methodKey } })\n }\n\n const setModuleAddressData = useCallback(\n (key: string, value: any) => {\n if (!moduleData) return\n\n const data = { ...moduleData }\n\n if (!data.moduleData) data.moduleData = {}\n\n data.moduleData.address = {\n ...(data.moduleData.address || {}),\n [key]: value,\n }\n\n setModuleData(data)\n },\n [moduleData]\n )\n\n const formatMethod = useCallback((method: ShippingMethodDTO) => {\n return {\n moduleKey: method.moduleKey,\n select: () =>\n selectModule(method.moduleKey as string, method.methodKey as string),\n methodKey: method.methodKey,\n }\n }, [])\n\n const addressErrors = useMemo(() => {\n return validateShipping(\n address,\n moduleData,\n errorLabels as any,\n validations,\n requiredFields\n )\n }, [address, moduleData, errorLabels, validations])\n\n /**\n * Format all platform and merchant modules\n */\n const modules = useMemo((): Modules => {\n const platformMethods =\n moduleTypesRaw?.platformShippingMethods?.map?.(formatMethod) || []\n\n const merchantMethods =\n moduleTypesRaw?.merchantsShippingMethods?.map?.((data) => {\n return data?.methods?.map?.(formatMethod)\n }) || []\n\n const data = [...platformMethods, ...merchantMethods.flat()]\n\n const result = data.reduce((current, method) => {\n return {\n ...current,\n [method.moduleKey as Couriers]: {\n methods: [\n ...(current[method.moduleKey as Couriers]?.methods || []),\n {\n key: method.methodKey,\n select: method.select,\n },\n ],\n },\n }\n }, {})\n\n return (result as unknown) as Modules\n }, [moduleTypesRaw, formatMethod])\n\n /**\n * On input change\n */\n const onChange = useCallback(\n (name: string, value: any) => {\n if (!address) return\n\n setAddress({\n ...address,\n [name]: value,\n })\n },\n [address]\n )\n\n const addNewErrors = useErrors<AddressFormLabelsType>(\n addNewError,\n errorLabels\n )\n const updateErrors = useErrors<AddressFormLabelsType>(\n updateError,\n errorLabels\n )\n\n const errors = useMemo(() => {\n return {\n ...(addressErrors || {}),\n ...(updateErrors || {}),\n ...(addNewErrors || {}),\n }\n }, [addressErrors, updateErrors, addNewErrors])\n\n const hasErrors = Boolean(Object.keys(errors).length)\n\n const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n setIsSubmitting(true)\n\n if (hasErrors) return\n\n if (currentAddress?._id) {\n updateAddress({\n id: currentAddress._id,\n dto: {\n ...address,\n moduleData: moduleData && [moduleData],\n },\n })\n\n return\n }\n\n addNewAddress({\n ...address,\n _id: undefined,\n moduleData: moduleData && [moduleData],\n })\n }\n\n const state = useMemo((): AddressFormContextValue => {\n return {\n formKey: `${moduleData?.moduleKey}-${moduleData?.moduleData?.methodKey}`,\n modules,\n isLoading,\n addressState: address,\n setAddressState: setAddress,\n onInputChange: onChange,\n moduleData,\n setModuleAddressData,\n errors: isSubmitting ? errors : {},\n isSubmitting,\n isValid: !hasErrors,\n }\n }, [\n moduleData,\n address,\n isLoading,\n modules,\n setModuleAddressData,\n onChange,\n isSubmitting,\n errors,\n hasErrors,\n ])\n\n return (\n <AddressFormContext.Provider value={state}>\n <form onSubmit={handleSubmit} noValidate>\n {children}\n </form>\n </AddressFormContext.Provider>\n )\n}\n\nexport const useAddressForm = () => {\n const context = React.useContext(AddressFormContext)\n\n if (!context) {\n throw new Error(\n 'useAddressForm must be used within a AddressFormContextProvider'\n )\n }\n\n return context\n}\n"],"file":"index.js"}
@@ -1,4 +1,6 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
1
2
  import React from 'react';
3
+ import { getTranslatableField } from '../../../index';
2
4
  import { myOrdersApi } from '../../../api/myOrdersApi';
3
5
  export var useOrder = (_ref) => {
4
6
  var {
@@ -8,7 +10,7 @@ export var useOrder = (_ref) => {
8
10
  var orderQuery = myOrdersApi.useGetById(id);
9
11
  var order = data || orderQuery.data;
10
12
  var result = React.useMemo(() => {
11
- var _order$shippings, _shipping$deliveries, _shipping$deliveries$, _order$shippingAddres, _order$shippingAddres2, _order$shippingAddres3, _order$shippingAddres4, _order$shippingAddres5, _order$shippingAddres6, _order$lineItemsCount;
13
+ var _order$shippings, _shipping$deliveries, _shipping$deliveries$, _order$shippingAddres, _order$shippingAddres2, _order$shippingAddres3, _order$shippingAddres4, _order$shippingAddres5, _order$shippingAddres6, _order$lineItemsCount, _order$customLineItem;
12
14
 
13
15
  var shipping = order == null ? void 0 : (_order$shippings = order.shippings) == null ? void 0 : _order$shippings[0];
14
16
  var parcels = shipping == null ? void 0 : (_shipping$deliveries = shipping.deliveries) == null ? void 0 : (_shipping$deliveries$ = _shipping$deliveries[0]) == null ? void 0 : _shipping$deliveries$.parcels;
@@ -20,10 +22,17 @@ export var useOrder = (_ref) => {
20
22
  orderRefNumber: order == null ? void 0 : order.orderRefNumber,
21
23
  createdAt: order == null ? void 0 : order.createdAt,
22
24
  discountCodes: mapDiscountCodes(order == null ? void 0 : order.discountCodes),
25
+ customLineItems: order == null ? void 0 : (_order$customLineItem = order.customLineItems) == null ? void 0 : _order$customLineItem.map(customLineItem => {
26
+ return _extends({}, customLineItem, {
27
+ name: getTranslatableField(customLineItem.name)
28
+ });
29
+ }),
30
+ shippingAddress: order == null ? void 0 : order.shippingAddress,
23
31
  shippingMethod: {
24
32
  isOffice: isShippingMethodOffice,
25
33
  isAddress: isShippingMethodOffice ? false : true
26
34
  },
35
+ billingAddress: order == null ? void 0 : order.billingAddress,
27
36
  trackingData: mapTrackingData(parcels)
28
37
  };
29
38
  return orderData;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/hooks/order-hooks/useOrder/index.ts"],"names":["React","myOrdersApi","useOrder","data","id","orderQuery","useGetById","order","result","useMemo","shipping","shippings","parcels","deliveries","isShippingMethodOffice","Boolean","shippingAddress","moduleData","address","office","orderData","lineItems","lineItemsCount","status","orderRefNumber","createdAt","discountCodes","mapDiscountCodes","shippingMethod","isOffice","isAddress","trackingData","mapTrackingData","map","parcel","courierName","provider","trackingId","trackingUrl","providerMeta","trackUrl","codes","codeNames","filter","code","discountCode","resource","name","value"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AASA,SAASC,WAAT,QAA4B,0BAA5B;AAsBA,OAAO,IAAMC,QAAQ,GAAG,UAMH;AAAA,MANI;AACvBC,IAAAA,IADuB;AAEvBC,IAAAA;AAFuB,GAMJ;AACnB,MAAMC,UAAU,GAAGJ,WAAW,CAACK,UAAZ,CAAuBF,EAAvB,CAAnB;AAEA,MAAMG,KAAK,GAAGJ,IAAI,IAAIE,UAAU,CAACF,IAAjC;AAEA,MAAMK,MAAM,GAAGR,KAAK,CAACS,OAAN,CAAc,MAAM;AAAA;;AACjC,QAAMC,QAAQ,GAAGH,KAAH,wCAAGA,KAAK,CAAEI,SAAV,qBAAG,iBAAmB,CAAnB,CAAjB;AACA,QAAMC,OAAO,GAAGF,QAAH,4CAAGA,QAAQ,CAAEG,UAAb,8CAAG,qBAAuB,CAAvB,CAAH,qBAAG,sBAA2BD,OAA3C;AAEA,QAAME,sBAAsB,GAAGC,OAAO,CACpCR,KADoC,6CACpCA,KAAK,CAAES,eAD6B,+CACpC,sBAAwBC,UADY,+CACpC,uBAAqC,CAArC,CADoC,+CACpC,uBAAy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EjB,UAAV,8CAAE,oBAAoBsB,YAAtB,qBAAE,sBAAkCC;AAH1C,KAAP;AAKD,GAND,MAMM,EAPR;AASD;;AAED,SAASb,gBAAT,CAA0Bc,KAA1B,EAAyD;AACvD,MAAMC,SAAS,GAAGD,KAAH,oBAAGA,KAAK,CAAEE,MAAP,CAAeC,IAAD,IAAUA,IAAI,CAACrB,MAAL,KAAgB,UAAxC,CAAlB;AAEA,SAAOmB,SAAP,oBAAOA,SAAS,CAAET,GAAX,CAAgBW,IAAD,IAAU;AAC9B,WAAOA,IAAI,CAACC,YAAL,CAAkBC,QAAlB,CAA2BC,IAA3B,CAAgC,CAAhC,EAAmCC,KAA1C;AACD,GAFM,CAAP;AAGD","sourcesContent":["import React from 'react'\nimport {\n DiscountCodeInfoDTO,\n LineItemDTO,\n OrderDTO,\n OrderDTOStatusEnum,\n ShippingDeliveryParcelDTO,\n} from '@sentecacommerce/sdk'\n\nimport { myOrdersApi } from '../../../api/myOrdersApi'\n\ntype TrackingProp = {\n provider?: string\n trackingId?: string\n trackingUrl?: string\n}\n\ntype UseOrderProps = {\n lineItems?: LineItemDTO[]\n lineItemsCount: number\n createdAt?: number\n orderRefNumber?: string\n status?: OrderDTOStatusEnum\n discountCodes?: string[]\n shippingMethod: {\n isOffice: boolean\n isAddress: boolean\n }\n trackingData: TrackingProp[]\n}\n\nexport const useOrder = ({\n data,\n id,\n}: {\n data?: OrderDTO\n id?: string\n}): UseOrderProps => {\n const orderQuery = myOrdersApi.useGetById(id)\n\n const order = data || orderQuery.data\n\n const result = React.useMemo(() => {\n const shipping = order?.shippings?.[0]\n const parcels = shipping?.deliveries?.[0]?.parcels\n\n const isShippingMethodOffice = Boolean(\n order?.shippingAddress?.moduleData?.[0]?.moduleData?.address?.office\n ?.address\n )\n\n const orderData: UseOrderProps = {\n lineItems: order?.lineItems,\n lineItemsCount: order?.lineItemsCount ?? 0,\n status: order?.status,\n orderRefNumber: order?.orderRefNumber,\n createdAt: order?.createdAt,\n discountCodes: mapDiscountCodes(order?.discountCodes),\n\n shippingMethod: {\n isOffice: isShippingMethodOffice,\n isAddress: isShippingMethodOffice ? false : true,\n },\n\n trackingData: mapTrackingData(parcels),\n }\n return orderData\n }, [order])\n\n return result\n}\n\nfunction mapTrackingData(parcels?: ShippingDeliveryParcelDTO[]) {\n return (\n parcels?.map((parcel) => {\n return {\n courierName: parcel?.moduleData?.trackingData?.provider,\n trackingId: parcel?.moduleData?.trackingData?.trackingId,\n trackingUrl: parcel?.moduleData?.providerMeta?.trackUrl,\n }\n }) || []\n )\n}\n\nfunction mapDiscountCodes(codes?: DiscountCodeInfoDTO[]) {\n const codeNames = codes?.filter((code) => code.status !== 'NotValid')\n\n return codeNames?.map((code) => {\n return code.discountCode.resource.name[0].value\n })\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../../src/hooks/order-hooks/useOrder/index.ts"],"names":["React","getTranslatableField","myOrdersApi","useOrder","data","id","orderQuery","useGetById","order","result","useMemo","shipping","shippings","parcels","deliveries","isShippingMethodOffice","Boolean","shippingAddress","moduleData","address","office","orderData","lineItems","lineItemsCount","status","orderRefNumber","createdAt","discountCodes","mapDiscountCodes","customLineItems","map","customLineItem","name","shippingMethod","isOffice","isAddress","billingAddress","trackingData","mapTrackingData","parcel","courierName","provider","trackingId","trackingUrl","providerMeta","trackUrl","codes","codeNames","filter","code","discountCode","resource","value"],"mappings":";AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAWA,SAASC,oBAAT,QAAqC,gBAArC;AACA,SAASC,WAAT,QAA4B,0BAA5B;AA6BA,OAAO,IAAMC,QAAQ,GAAG,UAMH;AAAA,MANI;AACvBC,IAAAA,IADuB;AAEvBC,IAAAA;AAFuB,GAMJ;AACnB,MAAMC,UAAU,GAAGJ,WAAW,CAACK,UAAZ,CAAuBF,EAAvB,CAAnB;AAEA,MAAMG,KAAK,GAAGJ,IAAI,IAAIE,UAAU,CAACF,IAAjC;AAEA,MAAMK,MAAM,GAAGT,KAAK,CAAC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derDTO,\n OrderDTOStatusEnum,\n ShippingDeliveryParcelDTO,\n CustomLineItemDTO,\n AddressDTO,\n} from '@sentecacommerce/sdk'\n\nimport { getTranslatableField } from '../../../index'\nimport { myOrdersApi } from '../../../api/myOrdersApi'\n\ntype TrackingProp = {\n provider?: string\n trackingId?: string\n trackingUrl?: string\n}\n\nexport type MappedCustomLineItemDTO = CustomLineItemDTO & {\n name: string\n}\n\ntype UseOrderProps = {\n lineItems?: LineItemDTO[]\n lineItemsCount: number\n createdAt?: number\n orderRefNumber?: string\n status?: OrderDTOStatusEnum\n discountCodes?: string[]\n shippingMethod: {\n isOffice: boolean\n isAddress: boolean\n }\n trackingData: TrackingProp[]\n customLineItems?: MappedCustomLineItemDTO[]\n shippingAddress: AddressDTO\n billingAddress?: AddressDTO\n}\n\nexport const useOrder = ({\n data,\n id,\n}: {\n data?: OrderDTO\n id?: string\n}): UseOrderProps => {\n const orderQuery = myOrdersApi.useGetById(id)\n\n const order = data || orderQuery.data\n\n const result = React.useMemo(() => {\n const shipping = order?.shippings?.[0]\n const parcels = shipping?.deliveries?.[0]?.parcels\n\n const isShippingMethodOffice = Boolean(\n order?.shippingAddress?.moduleData?.[0]?.moduleData?.address?.office\n ?.address\n )\n\n const orderData: UseOrderProps = {\n lineItems: order?.lineItems,\n lineItemsCount: order?.lineItemsCount ?? 0,\n status: order?.status,\n orderRefNumber: order?.orderRefNumber,\n createdAt: order?.createdAt,\n discountCodes: mapDiscountCodes(order?.discountCodes),\n customLineItems: order?.customLineItems?.map((customLineItem) => {\n return {\n ...customLineItem,\n name: getTranslatableField(customLineItem.name),\n } as MappedCustomLineItemDTO\n }),\n shippingAddress: order?.shippingAddress as AddressDTO,\n\n shippingMethod: {\n isOffice: isShippingMethodOffice,\n isAddress: isShippingMethodOffice ? false : true,\n },\n billingAddress: order?.billingAddress,\n\n trackingData: mapTrackingData(parcels),\n }\n return orderData\n }, [order])\n\n return result\n}\n\nfunction mapTrackingData(parcels?: ShippingDeliveryParcelDTO[]) {\n return (\n parcels?.map((parcel) => {\n return {\n courierName: parcel?.moduleData?.trackingData?.provider,\n trackingId: parcel?.moduleData?.trackingData?.trackingId,\n trackingUrl: parcel?.moduleData?.providerMeta?.trackUrl,\n }\n }) || []\n )\n}\n\nfunction mapDiscountCodes(codes?: DiscountCodeInfoDTO[]) {\n const codeNames = codes?.filter((code) => code.status !== 'NotValid')\n\n return codeNames?.map((code) => {\n return code.discountCode.resource.name[0].value\n })\n}\n"],"file":"index.js"}
@@ -1,12 +1,17 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import { useMemo } from 'react';
3
- export var useCheckoutShippingModule = orderQuery => {
3
+ export var useCheckoutShippingModule = function useCheckoutShippingModule(orderQuery, isEnabled) {
4
+ if (isEnabled === void 0) {
5
+ isEnabled = true;
6
+ }
7
+
4
8
  var {
5
9
  data: cartData
6
10
  } = orderQuery;
7
11
  return useMemo(() => {
8
12
  var _cartData$shippings;
9
13
 
14
+ if (!isEnabled) return;
10
15
  var shipping = cartData == null ? void 0 : (_cartData$shippings = cartData.shippings) == null ? void 0 : _cartData$shippings[0];
11
16
  return {
12
17
  moduleKey: shipping == null ? void 0 : shipping.moduleKey,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/hooks/useCheckoutShippingModule/index.tsx"],"names":["useMemo","useCheckoutShippingModule","orderQuery","data","cartData","shipping","shippings","moduleKey","moduleData","methodKey","moduleMethodKey"],"mappings":";AACA,SAASA,OAAT,QAAwB,OAAxB;AAGA,OAAO,IAAMC,yBAAyB,GACpCC,UADuC,IAEpB;AACnB,MAAM;AAAEC,IAAAA,IAAI,EAAEC;AAAR,MAAqBF,UAA3B;AAEA,SAAOF,OAAO,CAAC,MAAM;AAAA;;AACnB,QAAMK,QAAQ,GAAGD,QAAH,2CAAGA,QAAQ,CAAEE,SAAb,qBAAG,oBAAsB,CAAtB,CAAjB;AAEA,WAAO;AACLC,MAAAA,SAAS,EAAEF,QAAF,oBAAEA,QAAQ,CAAEE,SADhB;AAELC,MAAAA,UAAU,eACLH,QADK,oBACLA,QAAQ,CAAEG,UADL;AAERC,QAAAA,SAAS,EAAEJ,QAAF,oBAAEA,QAAQ,CAAEK;AAFb;AAFL,KAAP;AAOD,GAVa,EAUX,CAACN,QAAD,CAVW,CAAd;AAWD,CAhBM","sourcesContent":["import { OrderDTO } from '@sentecacommerce/sdk'\nimport { useMemo } from 'react'\nimport { QueryResult } from 'react-query'\n\nexport const useCheckoutShippingModule = (\n orderQuery: QueryResult<OrderDTO, unknown>\n): ShippingModule => {\n const { data: cartData } = orderQuery\n\n return useMemo(() => {\n const shipping = cartData?.shippings?.[0]\n\n return {\n moduleKey: shipping?.moduleKey,\n moduleData: {\n ...shipping?.moduleData,\n methodKey: shipping?.moduleMethodKey,\n },\n }\n }, [cartData])\n}\n\nexport type ShippingModule = {\n moduleKey?: string\n moduleData?: any\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/hooks/useCheckoutShippingModule/index.tsx"],"names":["useMemo","useCheckoutShippingModule","orderQuery","isEnabled","data","cartData","shipping","shippings","moduleKey","moduleData","methodKey","moduleMethodKey"],"mappings":";AACA,SAASA,OAAT,QAAwB,OAAxB;AAGA,OAAO,IAAMC,yBAAyB,GAAG,SAA5BA,yBAA4B,CACvCC,UADuC,EAEvCC,SAFuC,EAGpB;AAAA,MADnBA,SACmB;AADnBA,IAAAA,SACmB,GADP,IACO;AAAA;;AACnB,MAAM;AAAEC,IAAAA,IAAI,EAAEC;AAAR,MAAqBH,UAA3B;AAEA,SAAOF,OAAO,CAAC,MAAM;AAAA;;AACnB,QAAI,CAACG,SAAL,EAAgB;AAEhB,QAAMG,QAAQ,GAAGD,QAAH,2CAAGA,QAAQ,CAAEE,SAAb,qBAAG,oBAAsB,CAAtB,CAAjB;AAEA,WAAO;AACLC,MAAAA,SAAS,EAAEF,QAAF,oBAAEA,QAAQ,CAAEE,SADhB;AAELC,MAAAA,UAAU,eACLH,QADK,oBACLA,QAAQ,CAAEG,UADL;AAERC,QAAAA,SAAS,EAAEJ,QAAF,oBAAEA,QAAQ,CAAEK;AAFb;AAFL,KAAP;AAOD,GAZa,EAYX,CAACN,QAAD,CAZW,CAAd;AAaD,CAnBM","sourcesContent":["import { OrderDTO } from '@sentecacommerce/sdk'\nimport { useMemo } from 'react'\nimport { QueryResult } from 'react-query'\n\nexport const useCheckoutShippingModule = (\n orderQuery: QueryResult<OrderDTO, unknown>,\n isEnabled = true\n): ShippingModule => {\n const { data: cartData } = orderQuery\n\n return useMemo(() => {\n if (!isEnabled) return\n\n const shipping = cartData?.shippings?.[0]\n\n return {\n moduleKey: shipping?.moduleKey,\n moduleData: {\n ...shipping?.moduleData,\n methodKey: shipping?.moduleMethodKey,\n },\n }\n }, [cartData])\n}\n\nexport type ShippingModule =\n | {\n moduleKey?: string\n moduleData?: any\n }\n | undefined\n"],"file":"index.js"}
@@ -2,11 +2,11 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import { AuthCreateAnonymousToken, TokenRequestDTOGrantTypeEnum, HttpClient } from '@sentecacommerce/sdk';
3
3
  import { generateGuid, prefetchSDKConfig } from '../../../';
4
4
  export var generateAnonymousToken = /*#__PURE__*/function () {
5
- var _ref = _asyncToGenerator(function* (interfaceKey, store) {
5
+ var _ref = _asyncToGenerator(function* () {
6
6
  if (!HttpClient.defaultConfig) {
7
7
  prefetchSDKConfig({
8
- interfaceKey: interfaceKey || process.env.INTERFACE_KEY,
9
- storeKey: store || process.env.STORE
8
+ interfaceKey: process.env.DEFAULT_INTERFACE_KEY,
9
+ storeKey: process.env.STORE
10
10
  });
11
11
  }
12
12
 
@@ -16,7 +16,7 @@ export var generateAnonymousToken = /*#__PURE__*/function () {
16
16
  });
17
17
  });
18
18
 
19
- return function generateAnonymousToken(_x, _x2) {
19
+ return function generateAnonymousToken() {
20
20
  return _ref.apply(this, arguments);
21
21
  };
22
22
  }();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/user/api/utils/generateAnonymousToken.ts"],"names":["AuthCreateAnonymousToken","TokenRequestDTOGrantTypeEnum","HttpClient","generateGuid","prefetchSDKConfig","generateAnonymousToken","interfaceKey","store","defaultConfig","process","env","INTERFACE_KEY","storeKey","STORE","grantType","Implicit","anonymousId"],"mappings":";AAAA,SACEA,wBADF,EAEEC,4BAFF,EAGEC,UAHF,QAIO,sBAJP;AAKA,SAASC,YAAT,EAAuBC,iBAAvB,QAAgD,WAAhD;AAEA,OAAO,IAAMC,sBAAsB;AAAA,+BAAG,WACpCC,YADoC,EAEpCC,KAFoC,EAGjC;AACH,QAAI,CAACL,UAAU,CAACM,aAAhB,EAA+B;AAC7BJ,MAAAA,iBAAiB,CAAC;AAChBE,QAAAA,YAAY,EAAEA,YAAY,IAAKG,OAAO,CAACC,GAAR,CAAYC,aAD3B;AAEhBC,QAAAA,QAAQ,EAAEL,KAAK,IAAKE,OAAO,CAACC,GAAR,CAAYG;AAFhB,OAAD,CAAjB;AAID;;AAED,WAAOb,wBAAwB,CAC7B,EAD6B,EAE7B;AACEc,MAAAA,SAAS,EAAEb,4BAA4B,CAACc,QAD1C;AAEEC,MAAAA,WAAW,EAAEb,YAAY;AAF3B,KAF6B,CAA/B;AAOD,GAlBkC;;AAAA,kBAAtBE,sBAAsB;AAAA;AAAA;AAAA,GAA5B","sourcesContent":["import {\n AuthCreateAnonymousToken,\n TokenRequestDTOGrantTypeEnum,\n HttpClient,\n} from '@sentecacommerce/sdk'\nimport { generateGuid, prefetchSDKConfig } from '../../../'\n\nexport const generateAnonymousToken = async (\n interfaceKey?: string,\n store?: string\n) => {\n if (!HttpClient.defaultConfig) {\n prefetchSDKConfig({\n interfaceKey: interfaceKey || (process.env.INTERFACE_KEY as string),\n storeKey: store || (process.env.STORE as string),\n })\n }\n\n return AuthCreateAnonymousToken(\n {},\n {\n grantType: TokenRequestDTOGrantTypeEnum.Implicit,\n anonymousId: generateGuid(),\n }\n )\n}\n"],"file":"generateAnonymousToken.js"}
1
+ {"version":3,"sources":["../../../../../src/user/api/utils/generateAnonymousToken.ts"],"names":["AuthCreateAnonymousToken","TokenRequestDTOGrantTypeEnum","HttpClient","generateGuid","prefetchSDKConfig","generateAnonymousToken","defaultConfig","interfaceKey","process","env","DEFAULT_INTERFACE_KEY","storeKey","STORE","grantType","Implicit","anonymousId"],"mappings":";AAAA,SACEA,wBADF,EAEEC,4BAFF,EAGEC,UAHF,QAIO,sBAJP;AAKA,SAASC,YAAT,EAAuBC,iBAAvB,QAAgD,WAAhD;AAEA,OAAO,IAAMC,sBAAsB;AAAA,+BAAG,aAAY;AAChD,QAAI,CAACH,UAAU,CAACI,aAAhB,EAA+B;AAC7BF,MAAAA,iBAAiB,CAAC;AAChBG,QAAAA,YAAY,EAAEC,OAAO,CAACC,GAAR,CAAYC,qBADV;AAEhBC,QAAAA,QAAQ,EAAEH,OAAO,CAACC,GAAR,CAAYG;AAFN,OAAD,CAAjB;AAID;;AAED,WAAOZ,wBAAwB,CAC7B,EAD6B,EAE7B;AACEa,MAAAA,SAAS,EAAEZ,4BAA4B,CAACa,QAD1C;AAEEC,MAAAA,WAAW,EAAEZ,YAAY;AAF3B,KAF6B,CAA/B;AAOD,GAfkC;;AAAA,kBAAtBE,sBAAsB;AAAA;AAAA;AAAA,GAA5B","sourcesContent":["import {\n AuthCreateAnonymousToken,\n TokenRequestDTOGrantTypeEnum,\n HttpClient,\n} from '@sentecacommerce/sdk'\nimport { generateGuid, prefetchSDKConfig } from '../../../'\n\nexport const generateAnonymousToken = async () => {\n if (!HttpClient.defaultConfig) {\n prefetchSDKConfig({\n interfaceKey: process.env.DEFAULT_INTERFACE_KEY as string,\n storeKey: process.env.STORE as string,\n })\n }\n\n return AuthCreateAnonymousToken(\n {},\n {\n grantType: TokenRequestDTOGrantTypeEnum.Implicit,\n anonymousId: generateGuid(),\n }\n )\n}\n"],"file":"generateAnonymousToken.js"}
@@ -2,7 +2,7 @@ import { CheckoutFormErrorLabelsType, CheckoutFormErrorsResultType } from '../..
2
2
  import { AddressDTO, OrderDTO } from '@sentecacommerce/sdk';
3
3
  import { QueryResult } from 'react-query';
4
4
  import { SavedBillingAddress } from '../useSavedBillingList';
5
- export declare const useBilling: ({ orderQuery, errorLabels, withSavedBillingAddressList, enableSaveBillingAddress, withPersistBeforePageLeave, countryCode, validateBillingAddress, enabled, }: UseBillingProps) => UseBillingResultType;
5
+ export declare const useBilling: ({ orderQuery, errorLabels, withSavedBillingAddressList, enableSaveBillingAddress, withPersistBeforePageLeave, countryCode, validateBillingAddress, enabled, requiredFields, requiredFieldsOnShipping, }: UseBillingProps) => UseBillingResultType;
6
6
  declare type UseBillingProps = {
7
7
  orderQuery: QueryResult<OrderDTO, unknown>;
8
8
  errorLabels: CheckoutFormErrorLabelsType;
@@ -11,7 +11,9 @@ declare type UseBillingProps = {
11
11
  withPersistBeforePageLeave: boolean;
12
12
  countryCode: string;
13
13
  enabled: boolean;
14
- validateBillingAddress: (address: AddressDTO, errors: CheckoutFormErrorLabelsType) => CheckoutFormErrorsResultType;
14
+ requiredFields: string[];
15
+ requiredFieldsOnShipping: string[];
16
+ validateBillingAddress: (address: AddressDTO, errors: CheckoutFormErrorLabelsType, requiredCompanyFields: string[], requiredFields: string[]) => CheckoutFormErrorsResultType;
15
17
  };
16
18
  export declare type UseBillingResultType = {
17
19
  isSubmitting: boolean;
@@ -2,7 +2,7 @@ import { QueryResult } from 'react-query';
2
2
  import { AddressDTO, CustomerDTO, OrderDTO } from '@sentecacommerce/sdk';
3
3
  import { CheckoutFormErrorLabelsType, CheckoutFormErrorsResultType } from '../../';
4
4
  import { ShippingValidationsType } from '../../utils';
5
- export declare const useShipping: ({ withPersistBeforePageLeave, orderQuery, validations, enableSavedAddressList, errorLabels, enableSaveAddress, autofillShippingPersonalData, userQuery, enabled, countryCode }: UseShippingProps) => UseShippingResultType;
5
+ export declare const useShipping: ({ withPersistBeforePageLeave, orderQuery, validations, enableSavedAddressList, errorLabels, enableSaveAddress, autofillShippingPersonalData, userQuery, enabled, countryCode, requiredFields, enableNoShippingMethodMode, }: UseShippingProps) => UseShippingResultType;
6
6
  declare type UseGeographicalData = {
7
7
  latitude: number;
8
8
  longitude: number;
@@ -20,6 +20,8 @@ declare type UseShippingProps = {
20
20
  userQuery: QueryResult<CustomerDTO, unknown>;
21
21
  enabled: boolean;
22
22
  countryCode: string;
23
+ requiredFields: string[];
24
+ enableNoShippingMethodMode: boolean;
23
25
  };
24
26
  declare type Address = AddressDTO & {
25
27
  isSelectable: boolean;
@@ -5,7 +5,7 @@ import { UseBillingResultType, UsePaymentResultType, UseShippingResultType } fro
5
5
  import { ShippingValidationsType, BillingAddressValidationType } from './utils';
6
6
  export declare const CheckoutFormContext: React.Context<CheckoutFormContextType>;
7
7
  export declare type CheckoutCustomState = {};
8
- export declare function CheckoutFormContextProvider({ children, defaultStep, errorLabels, enableSavedAddressList, withPersistBeforePageLeave, shippingValidations, validateBillingAddress, enableSaveBillingAddress, enableSavedBillingAddressList, countryCode, enableSaveAddress, autofillShippingPersonalData, onSubmit, paymentEnabledOnStep, getPaymentMethodsWhenShippingMethodIsSelected, shippingEnabledOnStep, billingEnabledOnStep, customState: initialCustomState, redirectTimeout, onBeforeRedirect, onSuccess, onError, isBoricaInDevMode, withPixelMeta, }: Props): JSX.Element;
8
+ export declare function CheckoutFormContextProvider({ children, defaultStep, errorLabels, enableSavedAddressList, withPersistBeforePageLeave, shippingValidations, validateBillingAddress, enableSaveBillingAddress, enableSavedBillingAddressList, countryCode, enableSaveAddress, autofillShippingPersonalData, onSubmit, paymentEnabledOnStep, getPaymentMethodsWhenShippingMethodIsSelected, shippingEnabledOnStep, billingEnabledOnStep, customState: initialCustomState, redirectTimeout, onBeforeRedirect, onSuccess, onError, isBoricaInDevMode, withPixelMeta, requiredFieldsOnShippingStep, requiredFieldsOnBillingAddressStep, enableNoShippingMethodMode, }: Props): JSX.Element;
9
9
  export declare type CheckoutFormOnSubmitData = {
10
10
  isShippingValid: boolean;
11
11
  setIsShippingSubmitting: (value: boolean) => void;
@@ -48,6 +48,9 @@ declare type Props = {
48
48
  billingEnabledOnStep: CheckoutFormStepsEnum;
49
49
  isBoricaInDevMode?: boolean;
50
50
  withPixelMeta?: boolean;
51
+ requiredFieldsOnShippingStep?: string[];
52
+ requiredFieldsOnBillingAddressStep?: string[];
53
+ enableNoShippingMethodMode?: boolean;
51
54
  };
52
55
  declare type ServerErrors = {
53
56
  [key: string]: any;
@@ -1,4 +1,4 @@
1
1
  import { AddressDTO } from '@sentecacommerce/sdk';
2
2
  import { CheckoutFormErrorLabelsType, CheckoutFormErrorsResultType } from '..';
3
- export declare type BillingAddressValidationType = (data: AddressDTO, errorLabels: CheckoutFormErrorLabelsType) => CheckoutFormErrorsResultType;
4
- export declare function genericBillingAddressValidation(data: AddressDTO, errorLabels: CheckoutFormErrorLabelsType): CheckoutFormErrorsResultType;
3
+ export declare type BillingAddressValidationType = (data: AddressDTO, errorLabels: CheckoutFormErrorLabelsType, requiredFields: string[], requiredFieldsOnShipping: string[]) => CheckoutFormErrorsResultType;
4
+ export declare function genericBillingAddressValidation(data: AddressDTO, errorLabels: CheckoutFormErrorLabelsType, requiredCompanyFields: string[]): CheckoutFormErrorsResultType;
@@ -18,5 +18,5 @@ export interface ShippingValidationsType {
18
18
  } | null | undefined;
19
19
  };
20
20
  }
21
- export declare function validateShipping(data: AddressDTO | null | undefined, mod: ShippingModule | undefined, errorLabels: CheckoutFormErrorLabelsType, validations: ShippingValidationsType): CheckoutFormErrorsResultType;
21
+ export declare function validateShipping(data: AddressDTO | null | undefined, mod: ShippingModule | undefined, errorLabels: CheckoutFormErrorLabelsType, validations: ShippingValidationsType, requiredFields?: string[], enableNoShippingMethodMode?: boolean): CheckoutFormErrorsResultType;
22
22
  export {};