@sentecacommerce-theme/lib 0.12.65 → 0.12.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/analytics/Releva/api/query/useRelevaQuery.js +1 -0
- package/dist/cjs/analytics/Releva/api/query/useRelevaQuery.js.map +1 -1
- package/dist/cjs/checkout/api/keys.js +7 -1
- package/dist/cjs/checkout/api/keys.js.map +1 -1
- package/dist/cjs/checkout/api/queries/index.js +8 -0
- package/dist/cjs/checkout/api/queries/index.js.map +1 -1
- package/dist/cjs/checkout/api/queries/useBnpCalculateForCartQuery.js +40 -0
- package/dist/cjs/checkout/api/queries/useBnpCalculateForCartQuery.js.map +1 -0
- package/dist/cjs/checkout/hooks/index.js +8 -0
- package/dist/cjs/checkout/hooks/index.js.map +1 -1
- package/dist/cjs/checkout/hooks/useBnpCalculateForCart.js +83 -0
- package/dist/cjs/checkout/hooks/useBnpCalculateForCart.js.map +1 -0
- package/dist/cjs/contexts/CheckoutForm/hooks/useBilling/index.js.map +1 -1
- package/dist/cjs/contexts/CheckoutForm/hooks/usePayment/index.js +8 -2
- package/dist/cjs/contexts/CheckoutForm/hooks/usePayment/index.js.map +1 -1
- package/dist/cjs/contexts/CheckoutForm/hooks/useShipping/index.js.map +1 -1
- package/dist/cjs/contexts/CheckoutForm/index.js +1 -0
- package/dist/cjs/contexts/CheckoutForm/index.js.map +1 -1
- package/dist/cjs/hooks/order-hooks/useReferralOrders/index.js.map +1 -1
- package/dist/cjs/hooks/useLineItem/index.js +4 -0
- package/dist/cjs/hooks/useLineItem/index.js.map +1 -1
- package/dist/cjs/hooks/user-hooks/useSubscribeToNewsletter/index.js +12 -4
- package/dist/cjs/hooks/user-hooks/useSubscribeToNewsletter/index.js.map +1 -1
- package/dist/cjs/order/api/index.js +8 -0
- package/dist/cjs/order/api/index.js.map +1 -1
- package/dist/cjs/order/api/utils/getOrderById.js +8 -0
- package/dist/cjs/order/api/utils/getOrderById.js.map +1 -0
- package/dist/cjs/order/api/utils/index.js +12 -0
- package/dist/cjs/order/api/utils/index.js.map +1 -0
- package/dist/cjs/product/api/keys.js +11 -0
- package/dist/cjs/product/api/keys.js.map +1 -0
- package/dist/cjs/product/api/queries/index.js +12 -0
- package/dist/cjs/product/api/queries/index.js.map +1 -0
- package/dist/cjs/product/api/queries/useBnpOffersQuery.js +48 -0
- package/dist/cjs/product/api/queries/useBnpOffersQuery.js.map +1 -0
- package/dist/cjs/product/hooks/index.js +12 -0
- package/dist/cjs/product/hooks/index.js.map +1 -0
- package/dist/cjs/product/hooks/useBnpOffers.js +72 -0
- package/dist/cjs/product/hooks/useBnpOffers.js.map +1 -0
- package/dist/cjs/product/index.js +8 -0
- package/dist/cjs/product/index.js.map +1 -1
- package/dist/esm/analytics/Releva/api/query/useRelevaQuery.js +1 -0
- package/dist/esm/analytics/Releva/api/query/useRelevaQuery.js.map +1 -1
- package/dist/esm/checkout/api/keys.js +3 -0
- package/dist/esm/checkout/api/keys.js.map +1 -1
- package/dist/esm/checkout/api/queries/index.js +1 -0
- package/dist/esm/checkout/api/queries/index.js.map +1 -1
- package/dist/esm/checkout/api/queries/useBnpCalculateForCartQuery.js +10 -0
- package/dist/esm/checkout/api/queries/useBnpCalculateForCartQuery.js.map +1 -0
- package/dist/esm/checkout/hooks/index.js +1 -0
- package/dist/esm/checkout/hooks/index.js.map +1 -1
- package/dist/esm/checkout/hooks/useBnpCalculateForCart.js +66 -0
- package/dist/esm/checkout/hooks/useBnpCalculateForCart.js.map +1 -0
- package/dist/esm/contexts/CheckoutForm/hooks/useBilling/index.js.map +1 -1
- package/dist/esm/contexts/CheckoutForm/hooks/usePayment/index.js +5 -2
- package/dist/esm/contexts/CheckoutForm/hooks/usePayment/index.js.map +1 -1
- package/dist/esm/contexts/CheckoutForm/hooks/useShipping/index.js.map +1 -1
- package/dist/esm/contexts/CheckoutForm/index.js +1 -0
- package/dist/esm/contexts/CheckoutForm/index.js.map +1 -1
- package/dist/esm/hooks/order-hooks/useReferralOrders/index.js.map +1 -1
- package/dist/esm/hooks/useLineItem/index.js +2 -0
- package/dist/esm/hooks/useLineItem/index.js.map +1 -1
- package/dist/esm/hooks/user-hooks/useSubscribeToNewsletter/index.js +9 -4
- package/dist/esm/hooks/user-hooks/useSubscribeToNewsletter/index.js.map +1 -1
- package/dist/esm/order/api/index.js +1 -0
- package/dist/esm/order/api/index.js.map +1 -1
- package/dist/esm/order/api/utils/getOrderById.js +3 -0
- package/dist/esm/order/api/utils/getOrderById.js.map +1 -0
- package/dist/esm/order/api/utils/index.js +2 -0
- package/dist/esm/order/api/utils/index.js.map +1 -0
- package/dist/esm/product/api/keys.js +4 -0
- package/dist/esm/product/api/keys.js.map +1 -0
- package/dist/esm/product/api/queries/index.js +2 -0
- package/dist/esm/product/api/queries/index.js.map +1 -0
- package/dist/esm/product/api/queries/useBnpOffersQuery.js +18 -0
- package/dist/esm/product/api/queries/useBnpOffersQuery.js.map +1 -0
- package/dist/esm/product/hooks/index.js +2 -0
- package/dist/esm/product/hooks/index.js.map +1 -0
- package/dist/esm/product/hooks/useBnpOffers.js +57 -0
- package/dist/esm/product/hooks/useBnpOffers.js.map +1 -0
- package/dist/esm/product/index.js +1 -0
- package/dist/esm/product/index.js.map +1 -1
- package/dist/types/checkout/api/keys.d.ts +2 -0
- package/dist/types/checkout/api/queries/index.d.ts +1 -0
- package/dist/types/checkout/api/queries/useBnpCalculateForCartQuery.d.ts +4 -0
- package/dist/types/checkout/hooks/index.d.ts +1 -0
- package/dist/types/checkout/hooks/useBnpCalculateForCart.d.ts +50 -0
- package/dist/types/contexts/CheckoutForm/hooks/useBilling/index.d.ts +1 -1
- package/dist/types/contexts/CheckoutForm/hooks/usePayment/index.d.ts +2 -0
- package/dist/types/contexts/CheckoutForm/hooks/useShipping/index.d.ts +1 -1
- package/dist/types/contexts/CheckoutForm/index.d.ts +3 -2
- package/dist/types/hooks/order-hooks/useReferralOrders/index.d.ts +1 -0
- package/dist/types/hooks/useLineItem/index.d.ts +2 -2
- package/dist/types/order/api/index.d.ts +1 -0
- package/dist/types/order/api/utils/getOrderById.d.ts +2 -0
- package/dist/types/order/api/utils/index.d.ts +1 -0
- package/dist/types/product/api/keys.d.ts +1 -0
- package/dist/types/product/api/queries/index.d.ts +1 -0
- package/dist/types/product/api/queries/useBnpOffersQuery.d.ts +5 -0
- package/dist/types/product/hooks/index.d.ts +1 -0
- package/dist/types/product/hooks/useBnpOffers.d.ts +37 -0
- package/dist/types/product/index.d.ts +1 -0
- package/package.json +4 -4
@@ -9,6 +9,10 @@ var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
9
9
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
11
11
|
|
12
|
+
var _sdk = require("@sentecacommerce/sdk");
|
13
|
+
|
14
|
+
exports.OfferDTOStatusEnum = _sdk.OfferDTOStatusEnum;
|
15
|
+
|
12
16
|
var _utils = require("../../utils");
|
13
17
|
|
14
18
|
var _usePrefetchProduct2 = require("../usePrefetchProduct");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/hooks/useLineItem/index.tsx"],"names":["useLineItem","props","slug","onMouseEnter","onMouseLeave","onMouseDown","data","React","useMemo","mappedAttributes","Object","keys","attributes","reduce","map","key","current","count","length","elements","attribute","_id","value","label","extra","customFields","custom","Boolean","field","name","brand","brands","collapseKey","variantId","offerId","offer","sku","images","ratings","reviewRatingStatistics","price","originalPrice","discountedPrice","variantOptions","variantsCount","categories","category","inventory","hasAvailableQuantity","inventorySnapshot","canOrder","availableQuantity","maxQuantity","labels","mapLabelData","getCustomFieldByKey","getAttributeByKey","callback","now","Date","getTime","currentLabels","filter","el","validFrom","validTo"],"mappings":";;;;;;;;;AAAA;;AAUA;;AACA;;
|
1
|
+
{"version":3,"sources":["../../../../src/hooks/useLineItem/index.tsx"],"names":["useLineItem","props","slug","onMouseEnter","onMouseLeave","onMouseDown","data","React","useMemo","mappedAttributes","Object","keys","attributes","reduce","map","key","current","count","length","elements","attribute","_id","value","label","extra","customFields","custom","Boolean","field","name","brand","brands","collapseKey","variantId","offerId","offer","sku","images","ratings","reviewRatingStatistics","price","originalPrice","discountedPrice","variantOptions","variantsCount","categories","category","inventory","hasAvailableQuantity","inventorySnapshot","canOrder","availableQuantity","maxQuantity","labels","mapLabelData","getCustomFieldByKey","getAttributeByKey","callback","now","Date","getTime","currentLabels","filter","el","validFrom","validTo"],"mappings":";;;;;;;;;AAAA;;AACA;;;;AAUA;;AACA;;AAuDO,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAACC,KAAD,EAA4B;AAAA,4BACD,6CAClD,iCAAqBA,KAArB,oBAAqBA,KAAK,CAAEC,IAA5B,CADkD,CADC;AAAA,MAC7CC,aAD6C,uBAC7CA,YAD6C;AAAA,MAC/BC,aAD+B,uBAC/BA,YAD+B;AAAA,MACjBC,YADiB,uBACjBA,WADiB;;AAKrD,MAAMC,IAAkB,GAAGC,kBAAMC,OAAN,CAAc,YAAM;AAAA;;AAC7C,QAAMC,gBAAgB,mBAAGC,MAAM,CAACC,IAAP,CAAYV,KAAZ,oBAAYA,KAAK,CAAEW,UAAnB,CAAH,qBAAG,aAAgCC,MAAhC,CACvB,UAACC,GAAD,EAAMC,GAAN,EAAc;AAAA;;AACZ,UAAMC,OAAO,GAAGf,KAAH,oBAAGA,KAAK,CAAEW,UAAP,CAAkBG,GAAlB,CAAhB;AACAD,MAAAA,GAAG,CAACC,GAAD,CAAH,GAAW;AACTE,QAAAA,KAAK,qBAAED,OAAF,oBAAEA,OAAO,CAAEE,MAAX,8BAAqB,CADjB;AAETC,QAAAA,QAAQ,EAAEH,OAAF,oBAAEA,OAAO,CAAEF,GAAT,CAAa,UAACM,SAAD,EAAoB;AACzC,iBAAO;AACLC,YAAAA,GAAG,EAAED,SAAF,oBAAEA,SAAS,CAAEE,KADX;AAELC,YAAAA,KAAK,EAAE,iCAAqBH,SAArB,oBAAqBA,SAAS,CAAEG,KAAhC,CAFF;AAGLC,YA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aAAP,oBAAOA,aAAa,CAAE/C,GAAf,CAAmB,UAACiD,EAAD;AAAA,WAAQA,EAAE,CAAChD,GAAX;AAAA,GAAnB,CAAP;AACD,CAZD","sourcesContent":["import React from 'react'\nimport {\n SearchResultDTO,\n ImageDTO,\n MoneyDTO,\n ReviewRatingStatisticsDTO,\n OfferDTO,\n OfferDTOStatusEnum,\n ProductVariantLabelDTO,\n} from '@sentecacommerce/sdk'\n\nimport { getTranslatableField } from '../../utils'\nimport { usePrefetchProduct } from '../usePrefetchProduct'\n\nexport { OfferDTOStatusEnum }\n\nexport interface BaseProductType {\n name: string\n slug: string\n variantId: string\n offerId?: string\n offer?: OfferDTO\n collapseKey?: string\n sku: string\n images?: ImageDTO[]\n inventory: {\n hasAvailableQuantity: boolean\n availableQuantity: number\n maxQuantity?: number\n }\n onMouseEnter: (callback: () => void) => void\n onMouseLeave: () => void\n onMouseDown: (callback: () => void) => void\n}\n\nexport interface AttributeType {\n _id: string\n label: string\n extra?: any\n}\n\nexport interface AttributesType {\n count: number\n elements: AttributeType[]\n}\n\ninterface LineItemType extends BaseProductType {\n name: string\n brand?: {\n name: string\n slug: string\n }\n _id: string\n labels?: string[]\n price?: MoneyDTO\n discountedPrice?: MoneyDTO\n variantOptions: number\n variantsCount: number\n categories: {\n name: string\n slug: string\n }[]\n ratings: ReviewRatingStatisticsDTO\n getAttributeByKey: (key: string) => AttributesType\n getCustomFieldByKey: (key: string) => any\n}\n\nexport const useLineItem = (props: SearchResultDTO) => {\n const { onMouseEnter, onMouseLeave, onMouseDown } = usePrefetchProduct(\n getTranslatableField(props?.slug)\n )\n\n const data: LineItemType = React.useMemo(() => {\n const mappedAttributes = Object.keys(props?.attributes)?.reduce(\n (map, key) => {\n const current = props?.attributes[key]\n map[key] = {\n count: current?.length ?? 0,\n elements: current?.map((attribute: any) => {\n return {\n _id: attribute?.value,\n label: getTranslatableField(attribute?.label),\n extra: attribute?.extra,\n }\n }),\n }\n return map\n },\n {}\n )\n\n const customFields = props?.custom?.reduce(\n (map: { [key: string]: any }, current) => {\n if (Boolean(current.value) && current.value !== '0') {\n return { ...map, [current.field]: current.value }\n }\n return map\n },\n {}\n )\n\n return {\n _id: props?._id,\n name: getTranslatableField(props?.name),\n brand: {\n name: getTranslatableField(props?.brands?.[0]?.name),\n slug: getTranslatableField(props?.brands?.[0]?.slug),\n },\n slug: getTranslatableField(props?.slug),\n collapseKey: props?.collapseKey,\n variantId: props?.variantId,\n offerId: props?.offer?._id,\n offer: props?.offer,\n sku: props?.sku,\n images: props?.images || {},\n ratings: props?.reviewRatingStatistics,\n price: props?.offer?.originalPrice,\n discountedPrice: props?.offer?.discountedPrice,\n variantOptions: props?.variantOptions ?? 0,\n variantsCount: props?.variantsCount ?? 0,\n categories: props?.categories.map((category) => ({\n name: getTranslatableField(category.name),\n slug: getTranslatableField(category.slug),\n })),\n inventory: {\n hasAvailableQuantity: props?.inventorySnapshot?.canOrder ? true : false,\n availableQuantity: props?.inventorySnapshot?.canOrder\n ? props?.inventorySnapshot?.availableQuantity ?? 0\n : 0,\n maxQuantity: props?.offer?.maxQuantity,\n },\n labels: mapLabelData(props?.labels),\n getCustomFieldByKey: (key: string) => customFields?.[key],\n getAttributeByKey: (key: string) => mappedAttributes?.[key],\n onMouseEnter: (callback) => onMouseEnter(callback),\n onMouseLeave: () => onMouseLeave(),\n onMouseDown: (callback) => () => onMouseDown(callback),\n }\n }, [props])\n\n return data\n}\n\nconst mapLabelData = (data?: ProductVariantLabelDTO[]) => {\n // Filter only labels that are currently active\n const now = new Date().getTime()\n const currentLabels = data?.filter((el) => {\n if (!el.validFrom || !el.validTo) {\n return el\n } else {\n return el.validFrom < now && el.validTo > now\n }\n })\n\n return currentLabels?.map((el) => el.key)\n}\n"],"file":"index.js"}
|
@@ -3,6 +3,8 @@
|
|
3
3
|
exports.__esModule = true;
|
4
4
|
exports.useSubscribeToNewsletter = void 0;
|
5
5
|
|
6
|
+
var _react = require("react");
|
7
|
+
|
6
8
|
var _consentsApi = require("../../../api/consentsApi");
|
7
9
|
|
8
10
|
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } it = o[Symbol.iterator](); return it.next.bind(it); }
|
@@ -15,11 +17,17 @@ var useSubscribeToNewsletter = function useSubscribeToNewsletter(_ref) {
|
|
15
17
|
var callback = _ref.callback;
|
16
18
|
var keys = ['AGRPOLICY', 'AGRNEWSLETTER'];
|
17
19
|
|
18
|
-
var _consentsApi$useAppro = _consentsApi.consentsApi.useApprove({
|
19
|
-
onSuccess: callback
|
20
|
-
}),
|
20
|
+
var _consentsApi$useAppro = _consentsApi.consentsApi.useApprove({}),
|
21
21
|
sub = _consentsApi$useAppro[0],
|
22
|
-
|
22
|
+
_consentsApi$useAppro2 = _consentsApi$useAppro[1],
|
23
|
+
onError = _consentsApi$useAppro2.error,
|
24
|
+
isSuccess = _consentsApi$useAppro2.isSuccess;
|
25
|
+
|
26
|
+
(0, _react.useEffect)(function () {
|
27
|
+
if (isSuccess) {
|
28
|
+
callback == null ? void 0 : callback();
|
29
|
+
}
|
30
|
+
}, [isSuccess]);
|
23
31
|
|
24
32
|
var subscribe = function subscribe(email) {
|
25
33
|
for (var _iterator = _createForOfIteratorHelperLoose(keys), _step; !(_step = _iterator()).done;) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../src/hooks/user-hooks/useSubscribeToNewsletter/index.ts"],"names":["useSubscribeToNewsletter","callback","keys","consentsApi","useApprove","
|
1
|
+
{"version":3,"sources":["../../../../../src/hooks/user-hooks/useSubscribeToNewsletter/index.ts"],"names":["useSubscribeToNewsletter","callback","keys","consentsApi","useApprove","sub","onError","error","isSuccess","subscribe","email","key","consentKey"],"mappings":";;;;;AAAA;;AACA;;;;;;;;AAEO,IAAMA,wBAAwB,GAAG,SAA3BA,wBAA2B,OAIlC;AAAA,MAHJC,QAGI,QAHJA,QAGI;AACJ,MAAMC,IAAI,GAAG,CAAC,WAAD,EAAc,eAAd,CAAb;;AADI,8BAEyCC,yBAAYC,UAAZ,CAAuB,EAAvB,CAFzC;AAAA,MAEGC,GAFH;AAAA;AAAA,MAEiBC,OAFjB,0BAEUC,KAFV;AAAA,MAE0BC,SAF1B,0BAE0BA,SAF1B;;AAIJ,wBAAU,YAAM;AACd,QAAIA,SAAJ,EAAe;AACbP,MAAAA,QAAQ,QAAR,YAAAA,QAAQ;AACT;AACF,GAJD,EAIG,CAACO,SAAD,CAJH;;AAMA,MAAMC,SAAS,GAAG,SAAZA,SAAY,CAACC,KAAD,EAAmB;AACnC,yDAAkBR,IAAlB,wCAAwB;AAAA,UAAbS,GAAa;AACtBN,MAAAA,GAAG,CAAC;AAAEK,QAAAA,KAAK,EAALA,KAAF;AAASE,QAAAA,UAAU,EAAED;AAArB,OAAD,CAAH;AACD;AACF,GAJD;;AAMA,SAAO;AAAEF,IAAAA,SAAS,EAATA,SAAF;AAAaH,IAAAA,OAAO,EAAPA;AAAb,GAAP;AACD,CArBM","sourcesContent":["import React, { useEffect } from 'react'\nimport { consentsApi } from '../../../api/consentsApi'\n\nexport const useSubscribeToNewsletter = ({\n callback,\n}: {\n callback?: () => void\n}) => {\n const keys = ['AGRPOLICY', 'AGRNEWSLETTER']\n const [sub, { error: onError, isSuccess }] = consentsApi.useApprove({})\n\n useEffect(() => {\n if (isSuccess) {\n callback?.()\n }\n }, [isSuccess])\n\n const subscribe = (email: string) => {\n for (const key of keys) {\n sub({ email, consentKey: key })\n }\n }\n\n return { subscribe, onError }\n}\n"],"file":"index.js"}
|
@@ -17,4 +17,12 @@ Object.keys(_mutations).forEach(function (key) {
|
|
17
17
|
if (key in exports && exports[key] === _mutations[key]) return;
|
18
18
|
exports[key] = _mutations[key];
|
19
19
|
});
|
20
|
+
|
21
|
+
var _utils = require("./utils");
|
22
|
+
|
23
|
+
Object.keys(_utils).forEach(function (key) {
|
24
|
+
if (key === "default" || key === "__esModule") return;
|
25
|
+
if (key in exports && exports[key] === _utils[key]) return;
|
26
|
+
exports[key] = _utils[key];
|
27
|
+
});
|
20
28
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/order/api/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './queries'\nexport * from './mutations'\n"],"file":"index.js"}
|
1
|
+
{"version":3,"sources":["../../../../src/order/api/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './queries'\nexport * from './mutations'\nexport * from './utils'\n"],"file":"index.js"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../../src/order/api/utils/getOrderById.ts"],"names":[],"mappings":";;;;AAAA","sourcesContent":["import { MyOrdersGetById } from '@sentecacommerce/sdk'\nexport { MyOrdersGetById as getOrderById }\n"],"file":"getOrderById.js"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
exports.__esModule = true;
|
4
|
+
|
5
|
+
var _getOrderById = require("./getOrderById");
|
6
|
+
|
7
|
+
Object.keys(_getOrderById).forEach(function (key) {
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
9
|
+
if (key in exports && exports[key] === _getOrderById[key]) return;
|
10
|
+
exports[key] = _getOrderById[key];
|
11
|
+
});
|
12
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../../src/order/api/utils/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './getOrderById'\n"],"file":"index.js"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
exports.__esModule = true;
|
4
|
+
exports.getBnpProductOffersKey = void 0;
|
5
|
+
|
6
|
+
var getBnpProductOffersKey = function getBnpProductOffersKey(sku) {
|
7
|
+
return ['product-bnp-offers', sku];
|
8
|
+
};
|
9
|
+
|
10
|
+
exports.getBnpProductOffersKey = getBnpProductOffersKey;
|
11
|
+
//# sourceMappingURL=keys.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../src/product/api/keys.ts"],"names":["getBnpProductOffersKey","sku"],"mappings":";;;;;AAAO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAyB,CAACC,GAAD,EAAiB;AACrD,SAAO,CAAC,oBAAD,EAAuBA,GAAvB,CAAP;AACD,CAFM","sourcesContent":["export const getBnpProductOffersKey = (sku: string) => {\n return ['product-bnp-offers', sku]\n}\n"],"file":"keys.js"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
exports.__esModule = true;
|
4
|
+
|
5
|
+
var _useBnpOffersQuery = require("./useBnpOffersQuery");
|
6
|
+
|
7
|
+
Object.keys(_useBnpOffersQuery).forEach(function (key) {
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
9
|
+
if (key in exports && exports[key] === _useBnpOffersQuery[key]) return;
|
10
|
+
exports[key] = _useBnpOffersQuery[key];
|
11
|
+
});
|
12
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../../src/product/api/queries/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './useBnpOffersQuery'\n"],"file":"index.js"}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
exports.__esModule = true;
|
6
|
+
exports.useBnpOffersQuery = void 0;
|
7
|
+
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
9
|
+
|
10
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
11
|
+
|
12
|
+
var _reactQuery = require("react-query");
|
13
|
+
|
14
|
+
var _sdk = require("@sentecacommerce/sdk");
|
15
|
+
|
16
|
+
var _keys = require("../keys");
|
17
|
+
|
18
|
+
var useBnpOffersQuery = function useBnpOffersQuery(_ref) {
|
19
|
+
var sku = _ref.sku,
|
20
|
+
_ref$preferredInstall = _ref.preferredInstallmentCentAmount,
|
21
|
+
preferredInstallmentCentAmount = _ref$preferredInstall === void 0 ? 0 : _ref$preferredInstall,
|
22
|
+
_ref$downPaymentCentA = _ref.downPaymentCentAmount,
|
23
|
+
downPaymentCentAmount = _ref$downPaymentCentA === void 0 ? 0 : _ref$downPaymentCentA;
|
24
|
+
return (0, _reactQuery.useQuery)((0, _keys.getBnpProductOffersKey)(sku), /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
25
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
26
|
+
while (1) {
|
27
|
+
switch (_context.prev = _context.next) {
|
28
|
+
case 0:
|
29
|
+
_context.next = 2;
|
30
|
+
return (0, _sdk.MyPaymentsBnpCalculateForSKU)(sku, {
|
31
|
+
preferredInstallmentCentAmount: preferredInstallmentCentAmount,
|
32
|
+
downPaymentCentAmount: downPaymentCentAmount
|
33
|
+
});
|
34
|
+
|
35
|
+
case 2:
|
36
|
+
return _context.abrupt("return", _context.sent);
|
37
|
+
|
38
|
+
case 3:
|
39
|
+
case "end":
|
40
|
+
return _context.stop();
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}, _callee);
|
44
|
+
})));
|
45
|
+
};
|
46
|
+
|
47
|
+
exports.useBnpOffersQuery = useBnpOffersQuery;
|
48
|
+
//# sourceMappingURL=useBnpOffersQuery.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../../src/product/api/queries/useBnpOffersQuery.ts"],"names":["useBnpOffersQuery","sku","preferredInstallmentCentAmount","downPaymentCentAmount"],"mappings":";;;;;;;;;;;AACA;;AACA;;AACA;;AAEO,IAAMA,iBAAiB,GAAG,SAApBA,iBAAoB,OAQ3B;AAAA,MAPJC,GAOI,QAPJA,GAOI;AAAA,mCANJC,8BAMI;AAAA,MANJA,8BAMI,sCAN6B,CAM7B;AAAA,mCALJC,qBAKI;AAAA,MALJA,qBAKI,sCALoB,CAKpB;AACJ,SAAO,0BACL,kCAAuBF,GAAvB,CADK,6FAEL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBACQ,uCAA6BA,GAA7B,EAAkC;AACtCC,cAAAA,8BAA8B,EAA9BA,8BADsC;AAEtCC,cAAAA,qBAAqB,EAArBA;AAFsC,aAAlC,CADR;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAFK,GAAP;AAQD,CAjBM","sourcesContent":["import React from 'react'\nimport { useQuery } from 'react-query'\nimport { MyPaymentsBnpCalculateForSKU } from '@sentecacommerce/sdk'\nimport { getBnpProductOffersKey } from '../keys'\n\nexport const useBnpOffersQuery = ({\n sku,\n preferredInstallmentCentAmount = 0,\n downPaymentCentAmount = 0,\n}: {\n sku: string\n preferredInstallmentCentAmount?: number\n downPaymentCentAmount?: number\n}) => {\n return useQuery(\n getBnpProductOffersKey(sku),\n async () =>\n await MyPaymentsBnpCalculateForSKU(sku, {\n preferredInstallmentCentAmount,\n downPaymentCentAmount,\n })\n )\n}\n"],"file":"useBnpOffersQuery.js"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
exports.__esModule = true;
|
4
|
+
|
5
|
+
var _useBnpOffers = require("./useBnpOffers");
|
6
|
+
|
7
|
+
Object.keys(_useBnpOffers).forEach(function (key) {
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
9
|
+
if (key in exports && exports[key] === _useBnpOffers[key]) return;
|
10
|
+
exports[key] = _useBnpOffers[key];
|
11
|
+
});
|
12
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../src/product/hooks/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './useBnpOffers'\n"],"file":"index.js"}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
exports.__esModule = true;
|
6
|
+
exports.useBnpOffers = void 0;
|
7
|
+
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
9
|
+
|
10
|
+
var _react = require("react");
|
11
|
+
|
12
|
+
var _queries = require("../api/queries");
|
13
|
+
|
14
|
+
var _index = require("../../index");
|
15
|
+
|
16
|
+
var useBnpOffers = function useBnpOffers(props) {
|
17
|
+
var _useConfigState, _useConfigState$price, _response$data2, _response$data2$;
|
18
|
+
|
19
|
+
var configLocale = (_useConfigState = (0, _index.useConfigState)()) == null ? void 0 : (_useConfigState$price = _useConfigState.price) == null ? void 0 : _useConfigState$price.locale;
|
20
|
+
var response = (0, _queries.useBnpOffersQuery)(props);
|
21
|
+
return (0, _react.useMemo)(function () {
|
22
|
+
var _response$data, _response$data$, _response$data$$offer;
|
23
|
+
|
24
|
+
return (0, _extends2["default"])({}, response, {
|
25
|
+
data: response == null ? void 0 : (_response$data = response.data) == null ? void 0 : (_response$data$ = _response$data[0]) == null ? void 0 : (_response$data$$offer = _response$data$.offers) == null ? void 0 : _response$data$$offer.map(function (offer) {
|
26
|
+
var _totalRepaymentAmount = (0, _index.decodePrice)(offer.totalRepaymentAmount);
|
27
|
+
|
28
|
+
var _correctDownPaymentAmount = (0, _index.decodePrice)(offer.correctDownPaymentAmount);
|
29
|
+
|
30
|
+
var _installmentAmount = (0, _index.decodePrice)(offer.installmentAmount);
|
31
|
+
|
32
|
+
var _processingFeeAmount = (0, _index.decodePrice)(offer.processingFeeAmount);
|
33
|
+
|
34
|
+
var totalRepaymentAmount = (0, _index.formatAsCurrency)({
|
35
|
+
price: _totalRepaymentAmount,
|
36
|
+
precision: offer.totalRepaymentAmount.fractionDigits,
|
37
|
+
currency: offer.totalRepaymentAmount.currencyCode,
|
38
|
+
locale: configLocale || 'en'
|
39
|
+
});
|
40
|
+
var correctDownPaymentAmount = (0, _index.formatAsCurrency)({
|
41
|
+
price: _correctDownPaymentAmount,
|
42
|
+
precision: offer.correctDownPaymentAmount.fractionDigits,
|
43
|
+
currency: offer.correctDownPaymentAmount.currencyCode,
|
44
|
+
locale: configLocale || 'en'
|
45
|
+
});
|
46
|
+
var installmentAmount = (0, _index.formatAsCurrency)({
|
47
|
+
price: _installmentAmount,
|
48
|
+
precision: offer.installmentAmount.fractionDigits,
|
49
|
+
currency: offer.installmentAmount.currencyCode,
|
50
|
+
locale: configLocale || 'en'
|
51
|
+
});
|
52
|
+
var processingFeeAmount = (0, _index.formatAsCurrency)({
|
53
|
+
price: _processingFeeAmount,
|
54
|
+
precision: offer.processingFeeAmount.fractionDigits,
|
55
|
+
currency: offer.processingFeeAmount.currencyCode,
|
56
|
+
locale: configLocale || 'en'
|
57
|
+
});
|
58
|
+
return (0, _extends2["default"])({}, offer, {
|
59
|
+
totalRepaymentAmount: totalRepaymentAmount,
|
60
|
+
correctDownPaymentAmount: correctDownPaymentAmount,
|
61
|
+
installmentAmount: installmentAmount,
|
62
|
+
processingFeeAmount: processingFeeAmount
|
63
|
+
});
|
64
|
+
}).sort(function (offer, offer2) {
|
65
|
+
return Number(offer.maturity) - Number(offer2.maturity);
|
66
|
+
})
|
67
|
+
});
|
68
|
+
}, [response == null ? void 0 : (_response$data2 = response.data) == null ? void 0 : (_response$data2$ = _response$data2[0]) == null ? void 0 : _response$data2$.offers]);
|
69
|
+
};
|
70
|
+
|
71
|
+
exports.useBnpOffers = useBnpOffers;
|
72
|
+
//# sourceMappingURL=useBnpOffers.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../src/product/hooks/useBnpOffers.ts"],"names":["useBnpOffers","props","configLocale","price","locale","response","data","offers","map","offer","_totalRepaymentAmount","totalRepaymentAmount","_correctDownPaymentAmount","correctDownPaymentAmount","_installmentAmount","installmentAmount","_processingFeeAmount","processingFeeAmount","precision","fractionDigits","currency","currencyCode","sort","offer2","Number","maturity"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAEO,IAAMA,YAAY,GAAG,SAAfA,YAAe,CAACC,KAAD,EAItB;AAAA;;AACJ,MAAMC,YAAoB,sBAAG,4BAAH,8CAAG,gBAAkBC,KAArB,qBAAG,sBAAyBC,MAAtD;AACA,MAAMC,QAAQ,GAAG,gCAAkBJ,KAAlB,CAAjB;AAEA,SAAO,oBACL;AAAA;;AAAA,yCACKI,QADL;AAEEC,MAAAA,IAAI,EAAED,QAAF,sCAAEA,QAAQ,CAAEC,IAAZ,wCAAE,eAAiB,CAAjB,CAAF,8CAAE,gBAAqBC,MAAvB,qBAAE,sBACFC,GADE,CACE,UAACC,KAAD,EAAW;AACf,YAAMC,qBAAqB,GAAG,wBAAYD,KAAK,CAACE,oBAAlB,CAA9B;;AACA,YAAMC,yBAAyB,GAAG,wBAChCH,KAAK,CAACI,wBAD0B,CAAlC;;AAGA,YAAMC,kBAAkB,GAAG,wBAAYL,KAAK,CAACM,iBAAlB,CAA3B;;AACA,YAAMC,oBAAoB,GAAG,wBAAYP,KAAK,CAACQ,mBAAlB,CAA7B;;AAEA,YAAMN,oBAAoB,GAAG,6BAAiB;AAC5CR,UAAAA,KAAK,EAAEO,qBAD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AACf,KAAK,CAACgB,QAAP,CAAN,GAAyBD,MAAM,CAACD,MAAM,CAACE,QAAR,CAAlD;AAAA,OA9CE;AAFR;AAAA,GADK,EAoDL,CAACpB,QAAD,uCAACA,QAAQ,CAAEC,IAAX,yCAAC,gBAAiB,CAAjB,CAAD,qBAAC,iBAAqBC,MAAtB,CApDK,CAAP;AAsDD,CA9DM","sourcesContent":["import React, { useMemo } from 'react'\nimport { useBnpOffersQuery } from '../api/queries'\nimport { decodePrice, formatAsCurrency, useConfigState } from '../../index'\n\nexport const useBnpOffers = (props: {\n sku: string\n preferredInstallmentCentAmount?: number\n downPaymentCentAmount?: number\n}) => {\n const configLocale: string = useConfigState()?.price?.locale\n const response = useBnpOffersQuery(props)\n\n return useMemo(\n () => ({\n ...response,\n data: response?.data?.[0]?.offers\n ?.map((offer) => {\n const _totalRepaymentAmount = decodePrice(offer.totalRepaymentAmount)\n const _correctDownPaymentAmount = decodePrice(\n offer.correctDownPaymentAmount\n )\n const _installmentAmount = decodePrice(offer.installmentAmount)\n const _processingFeeAmount = decodePrice(offer.processingFeeAmount)\n\n const totalRepaymentAmount = formatAsCurrency({\n price: _totalRepaymentAmount,\n precision: offer.totalRepaymentAmount.fractionDigits,\n currency: offer.totalRepaymentAmount.currencyCode,\n locale: configLocale || 'en',\n })\n\n const correctDownPaymentAmount = formatAsCurrency({\n price: _correctDownPaymentAmount,\n precision: offer.correctDownPaymentAmount.fractionDigits,\n currency: offer.correctDownPaymentAmount.currencyCode,\n locale: configLocale || 'en',\n })\n\n const installmentAmount = formatAsCurrency({\n price: _installmentAmount,\n precision: offer.installmentAmount.fractionDigits,\n currency: offer.installmentAmount.currencyCode,\n locale: configLocale || 'en',\n })\n\n const processingFeeAmount = formatAsCurrency({\n price: _processingFeeAmount,\n precision: offer.processingFeeAmount.fractionDigits,\n currency: offer.processingFeeAmount.currencyCode,\n locale: configLocale || 'en',\n })\n\n return {\n ...offer,\n totalRepaymentAmount,\n correctDownPaymentAmount,\n installmentAmount,\n processingFeeAmount,\n }\n })\n .sort(\n (offer, offer2) => Number(offer.maturity) - Number(offer2.maturity)\n ),\n }),\n [response?.data?.[0]?.offers]\n )\n}\n"],"file":"useBnpOffers.js"}
|
@@ -9,4 +9,12 @@ Object.keys(_api).forEach(function (key) {
|
|
9
9
|
if (key in exports && exports[key] === _api[key]) return;
|
10
10
|
exports[key] = _api[key];
|
11
11
|
});
|
12
|
+
|
13
|
+
var _hooks = require("./hooks");
|
14
|
+
|
15
|
+
Object.keys(_hooks).forEach(function (key) {
|
16
|
+
if (key === "default" || key === "__esModule") return;
|
17
|
+
if (key in exports && exports[key] === _hooks[key]) return;
|
18
|
+
exports[key] = _hooks[key];
|
19
|
+
});
|
12
20
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/product/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './api'"],"file":"index.js"}
|
1
|
+
{"version":3,"sources":["../../../src/product/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './api'\nexport * from './hooks'\n"],"file":"index.js"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/analytics/Releva/api/query/useRelevaQuery.ts"],"names":["useQuery","useRelevaQuery","payload","isReady","token","interfaceKey","url","fetch","method","headers","Authorization","InterfaceKey","body","JSON","stringify","then","res","json","retry","cacheTime","enabled","order","orderId"],"mappings":";AAAA,SAASA,QAAT,QAAyB,aAAzB;AAGA,OAAO,IAAMC,cAAc,GAAG,CAC5BC,OAD4B,EAE5BC,OAF4B,EAG5BC,KAH4B,EAI5BC,YAJ4B,KAKzB;AACH,SAAOL,QAAQ,CACb,CAAC,CAACE,OAAF,IAAa,2BADA,iCAEb,aAAY;AACV,QAAMI,GAAG,GAAG,qBAAZ;AAEA,WAAOC,KAAK,CAACD,GAAD,EAAM;AAChBE,MAAAA,MAAM,EAAE,MADQ;AAEhBC,MAAAA,OAAO,EAAE;AACP,wBAAgB,kBADT;AAEPC,QAAAA,aAAa,cAAYN,KAFlB;AAGPO,QAAAA,YAAY,OAAKN;AAHV,OAFO;AAOhBO,MAAAA,IAAI,EAAEC,IAAI,CAACC,SAAL,CAAeZ,OAAf;AAPU,KAAN,CAAL,CAQJa,IARI,CAQEC,GAAD,IAASA,GAAG,CAACC,IAAJ,EARV,CAAP;AASD,GAdY,GAeb;AACEC,IAAAA,KAAK,EAAE,KADT;AAEEC,IAAAA,SAAS,EAAE,CAFb;AAGEC,IAAAA,OAAO,
|
1
|
+
{"version":3,"sources":["../../../../../../src/analytics/Releva/api/query/useRelevaQuery.ts"],"names":["useQuery","useRelevaQuery","payload","isReady","token","interfaceKey","url","fetch","method","headers","Authorization","InterfaceKey","body","JSON","stringify","then","res","json","retry","cacheTime","refetchOnWindowFocus","enabled","order","orderId"],"mappings":";AAAA,SAASA,QAAT,QAAyB,aAAzB;AAGA,OAAO,IAAMC,cAAc,GAAG,CAC5BC,OAD4B,EAE5BC,OAF4B,EAG5BC,KAH4B,EAI5BC,YAJ4B,KAKzB;AACH,SAAOL,QAAQ,CACb,CAAC,CAACE,OAAF,IAAa,2BADA,iCAEb,aAAY;AACV,QAAMI,GAAG,GAAG,qBAAZ;AAEA,WAAOC,KAAK,CAACD,GAAD,EAAM;AAChBE,MAAAA,MAAM,EAAE,MADQ;AAEhBC,MAAAA,OAAO,EAAE;AACP,wBAAgB,kBADT;AAEPC,QAAAA,aAAa,cAAYN,KAFlB;AAGPO,QAAAA,YAAY,OAAKN;AAHV,OAFO;AAOhBO,MAAAA,IAAI,EAAEC,IAAI,CAACC,SAAL,CAAeZ,OAAf;AAPU,KAAN,CAAL,CAQJa,IARI,CAQEC,GAAD,IAASA,GAAG,CAACC,IAAJ,EARV,CAAP;AASD,GAdY,GAeb;AACEC,IAAAA,KAAK,EAAE,KADT;AAEEC,IAAAA,SAAS,EAAE,CAFb;AAGEC,IAAAA,oBAAoB,EAAE,KAHxB;AAIEC,IAAAA,OAAO,EAAElB,OAAO,IAAI,CAAC,EAACD,OAAD,YAACA,OAAO,CAAEoB,KAAT,CAAeC,OAAhB;AAJvB,GAfa,CAAf;AAsBD,CA5BM","sourcesContent":["import { useQuery } from 'react-query'\nimport { PayloadDTO } from '../../types'\n\nexport const useRelevaQuery = (\n payload?: PayloadDTO,\n isReady?: boolean,\n token?: string,\n interfaceKey?: string\n) => {\n return useQuery(\n !!payload && 'releva-recommenders-query',\n async () => {\n const url = '/hub/releva/collect'\n\n return fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${token}`,\n InterfaceKey: `${interfaceKey}`,\n },\n body: JSON.stringify(payload),\n }).then((res) => res.json())\n },\n {\n retry: false,\n cacheTime: 0,\n refetchOnWindowFocus: false,\n enabled: isReady && !!payload?.order.orderId,\n }\n )\n}\n"],"file":"useRelevaQuery.js"}
|
@@ -5,4 +5,7 @@ export var CheckoutQueryKeysEnum;
|
|
5
5
|
export var getVerifyBoricaResponseKey = order => {
|
6
6
|
return "Borica Response for Order: " + order;
|
7
7
|
};
|
8
|
+
export var getBnpLoanCalculatorKey = preferredInstallmentCentAmount => {
|
9
|
+
return ['bnp-loan-calculator', preferredInstallmentCentAmount];
|
10
|
+
};
|
8
11
|
//# sourceMappingURL=keys.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/checkout/api/keys.ts"],"names":["CheckoutQueryKeysEnum","getVerifyBoricaResponseKey","order"],"mappings":"AAAA,WAAYA,qBAAZ;;WAAYA,qB,MAAAA,qB,KAAAA,qB;;
|
1
|
+
{"version":3,"sources":["../../../../src/checkout/api/keys.ts"],"names":["CheckoutQueryKeysEnum","getVerifyBoricaResponseKey","order","getBnpLoanCalculatorKey","preferredInstallmentCentAmount"],"mappings":"AAAA,WAAYA,qBAAZ;;WAAYA,qB,MAAAA,qB,KAAAA,qB;;AAEZ,OAAO,IAAMC,0BAA0B,GAAIC,KAAD,IAAmB;AAC3D,yCAAqCA,KAArC;AACD,CAFM;AAIP,OAAO,IAAMC,uBAAuB,GAClCC,8BADqC,IAElC;AACH,SAAO,CAAC,qBAAD,EAAwBA,8BAAxB,CAAP;AACD,CAJM","sourcesContent":["export enum CheckoutQueryKeysEnum {}\n\nexport const getVerifyBoricaResponseKey = (order: string) => {\n return `Borica Response for Order: ${order}`\n}\n\nexport const getBnpLoanCalculatorKey = (\n preferredInstallmentCentAmount: number\n) => {\n return ['bnp-loan-calculator', preferredInstallmentCentAmount]\n}\n"],"file":"keys.js"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../src/checkout/api/queries/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAd","sourcesContent":["export * from './useVerifyBoricaResponseQuery'"],"file":"index.js"}
|
1
|
+
{"version":3,"sources":["../../../../../src/checkout/api/queries/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAd;AACA,cAAc,+BAAd","sourcesContent":["export * from './useVerifyBoricaResponseQuery'\nexport * from './useBnpCalculateForCartQuery'\n"],"file":"index.js"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
2
|
+
import { useQuery } from 'react-query';
|
3
|
+
import { MyPaymentsBnpCalculateLoanOrder } from '@sentecacommerce/sdk';
|
4
|
+
import { getBnpLoanCalculatorKey } from '../keys';
|
5
|
+
export var useBnpCalculateForCartQuery = props => {
|
6
|
+
return useQuery(getBnpLoanCalculatorKey(props.preferredInstallmentCentAmount), /*#__PURE__*/_asyncToGenerator(function* () {
|
7
|
+
return yield MyPaymentsBnpCalculateLoanOrder(props);
|
8
|
+
}));
|
9
|
+
};
|
10
|
+
//# sourceMappingURL=useBnpCalculateForCartQuery.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../../src/checkout/api/queries/useBnpCalculateForCartQuery.ts"],"names":["useQuery","MyPaymentsBnpCalculateLoanOrder","getBnpLoanCalculatorKey","useBnpCalculateForCartQuery","props","preferredInstallmentCentAmount"],"mappings":";AACA,SAASA,QAAT,QAAyB,aAAzB;AACA,SAASC,+BAAT,QAAgD,sBAAhD;AACA,SAASC,uBAAT,QAAwC,SAAxC;AAEA,OAAO,IAAMC,2BAA2B,GAAIC,KAAD,IAGrC;AACJ,SAAOJ,QAAQ,CACbE,uBAAuB,CAACE,KAAK,CAACC,8BAAP,CADV,iCAEb;AAAA,iBAAkBJ,+BAA+B,CAACG,KAAD,CAAjD;AAAA,GAFa,EAAf;AAID,CARM","sourcesContent":["import React from 'react'\nimport { useQuery } from 'react-query'\nimport { MyPaymentsBnpCalculateLoanOrder } from '@sentecacommerce/sdk'\nimport { getBnpLoanCalculatorKey } from '../keys'\n\nexport const useBnpCalculateForCartQuery = (props: {\n preferredInstallmentCentAmount: number\n downPaymentCentAmount: number\n}) => {\n return useQuery(\n getBnpLoanCalculatorKey(props.preferredInstallmentCentAmount),\n async () => await MyPaymentsBnpCalculateLoanOrder(props)\n )\n}\n"],"file":"useBnpCalculateForCartQuery.js"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/checkout/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAAd","sourcesContent":["export * from './useVerifyBoricaResponse'\n"],"file":"index.js"}
|
1
|
+
{"version":3,"sources":["../../../../src/checkout/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAAd;AACA,cAAc,0BAAd","sourcesContent":["export * from './useVerifyBoricaResponse'\nexport * from './useBnpCalculateForCart'\n"],"file":"index.js"}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
2
|
+
import { useMemo } from 'react';
|
3
|
+
import { useBnpCalculateForCartQuery } from '../api';
|
4
|
+
import { decodePrice, formatAsCurrency, useConfigState } from '../../index';
|
5
|
+
export var useBnpCalculateForCart = props => {
|
6
|
+
var _useConfigState, _useConfigState$price, _response$data3, _response$data3$;
|
7
|
+
|
8
|
+
var {
|
9
|
+
preferredInstallmentCentAmount = 0,
|
10
|
+
downPaymentCentAmount = 0
|
11
|
+
} = props != null ? props : {};
|
12
|
+
var response = useBnpCalculateForCartQuery({
|
13
|
+
preferredInstallmentCentAmount,
|
14
|
+
downPaymentCentAmount
|
15
|
+
});
|
16
|
+
var configLocale = (_useConfigState = useConfigState()) == null ? void 0 : (_useConfigState$price = _useConfigState.price) == null ? void 0 : _useConfigState$price.locale;
|
17
|
+
return useMemo(() => {
|
18
|
+
var _response$data, _response$data2, _response$data2$, _response$data2$$offe;
|
19
|
+
|
20
|
+
return _extends({}, response, {
|
21
|
+
data: _extends({}, response == null ? void 0 : (_response$data = response.data) == null ? void 0 : _response$data[0], {
|
22
|
+
offers: response == null ? void 0 : (_response$data2 = response.data) == null ? void 0 : (_response$data2$ = _response$data2[0]) == null ? void 0 : (_response$data2$$offe = _response$data2$.offers) == null ? void 0 : _response$data2$$offe.map(offer => {
|
23
|
+
var _totalRepaymentAmount = decodePrice(offer.totalRepaymentAmount);
|
24
|
+
|
25
|
+
var _correctDownPaymentAmount = decodePrice(offer.correctDownPaymentAmount);
|
26
|
+
|
27
|
+
var _installmentAmount = decodePrice(offer.installmentAmount);
|
28
|
+
|
29
|
+
var _processingFeeAmount = decodePrice(offer.processingFeeAmount);
|
30
|
+
|
31
|
+
var totalRepaymentAmount = formatAsCurrency({
|
32
|
+
price: _totalRepaymentAmount,
|
33
|
+
precision: offer.totalRepaymentAmount.fractionDigits,
|
34
|
+
currency: offer.totalRepaymentAmount.currencyCode,
|
35
|
+
locale: configLocale || 'en'
|
36
|
+
});
|
37
|
+
var correctDownPaymentAmount = formatAsCurrency({
|
38
|
+
price: _correctDownPaymentAmount,
|
39
|
+
precision: offer.correctDownPaymentAmount.fractionDigits,
|
40
|
+
currency: offer.correctDownPaymentAmount.currencyCode,
|
41
|
+
locale: configLocale || 'en'
|
42
|
+
});
|
43
|
+
var installmentAmount = formatAsCurrency({
|
44
|
+
price: _installmentAmount,
|
45
|
+
precision: offer.installmentAmount.fractionDigits,
|
46
|
+
currency: offer.installmentAmount.currencyCode,
|
47
|
+
locale: configLocale || 'en'
|
48
|
+
});
|
49
|
+
var processingFeeAmount = formatAsCurrency({
|
50
|
+
price: _processingFeeAmount,
|
51
|
+
precision: offer.processingFeeAmount.fractionDigits,
|
52
|
+
currency: offer.processingFeeAmount.currencyCode,
|
53
|
+
locale: configLocale || 'en'
|
54
|
+
});
|
55
|
+
return _extends({}, offer, {
|
56
|
+
totalRepaymentAmount,
|
57
|
+
correctDownPaymentAmount,
|
58
|
+
installmentAmount,
|
59
|
+
processingFeeAmount
|
60
|
+
});
|
61
|
+
}).sort((offer, offer2) => Number(offer.maturity) - Number(offer2.maturity))
|
62
|
+
})
|
63
|
+
});
|
64
|
+
}, [response == null ? void 0 : (_response$data3 = response.data) == null ? void 0 : (_response$data3$ = _response$data3[0]) == null ? void 0 : _response$data3$.offers]);
|
65
|
+
};
|
66
|
+
//# sourceMappingURL=useBnpCalculateForCart.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../src/checkout/hooks/useBnpCalculateForCart.ts"],"names":["useMemo","useBnpCalculateForCartQuery","decodePrice","formatAsCurrency","useConfigState","useBnpCalculateForCart","props","preferredInstallmentCentAmount","downPaymentCentAmount","response","configLocale","price","locale","data","offers","map","offer","_totalRepaymentAmount","totalRepaymentAmount","_correctDownPaymentAmount","correctDownPaymentAmount","_installmentAmount","installmentAmount","_processingFeeAmount","processingFeeAmount","precision","fractionDigits","currency","currencyCode","sort","offer2","Number","maturity"],"mappings":";AAAA,SAAgBA,OAAhB,QAA+B,OAA/B;AACA,SAASC,2BAAT,QAA4C,QAA5C;AACA,SAASC,WAAT,EAAsBC,gBAAtB,EAAwCC,cAAxC,QAA8D,aAA9D;AAEA,OAAO,IAAMC,sBAAsB,G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, formatAsCurrency, useConfigState } from '../../index'\n\nexport const useBnpCalculateForCart = (props?: {\n preferredInstallmentCentAmount?: number\n downPaymentCentAmount?: number\n}) => {\n const { preferredInstallmentCentAmount = 0, downPaymentCentAmount = 0 } =\n props ?? {}\n\n const response = useBnpCalculateForCartQuery({\n preferredInstallmentCentAmount,\n downPaymentCentAmount,\n })\n const configLocale: string = useConfigState()?.price?.locale\n\n return useMemo(\n () => ({\n ...response,\n data: {\n ...response?.data?.[0],\n offers: response?.data?.[0]?.offers\n ?.map((offer) => {\n const _totalRepaymentAmount = decodePrice(\n offer.totalRepaymentAmount\n )\n const _correctDownPaymentAmount = decodePrice(\n offer.correctDownPaymentAmount\n )\n const _installmentAmount = decodePrice(offer.installmentAmount)\n const _processingFeeAmount = decodePrice(offer.processingFeeAmount)\n\n const totalRepaymentAmount = formatAsCurrency({\n price: _totalRepaymentAmount,\n precision: offer.totalRepaymentAmount.fractionDigits,\n currency: offer.totalRepaymentAmount.currencyCode,\n locale: configLocale || 'en',\n })\n\n const correctDownPaymentAmount = formatAsCurrency({\n price: _correctDownPaymentAmount,\n precision: offer.correctDownPaymentAmount.fractionDigits,\n currency: offer.correctDownPaymentAmount.currencyCode,\n locale: configLocale || 'en',\n })\n\n const installmentAmount = formatAsCurrency({\n price: _installmentAmount,\n precision: offer.installmentAmount.fractionDigits,\n currency: offer.installmentAmount.currencyCode,\n locale: configLocale || 'en',\n })\n\n const processingFeeAmount = formatAsCurrency({\n price: _processingFeeAmount,\n precision: offer.processingFeeAmount.fractionDigits,\n currency: offer.processingFeeAmount.currencyCode,\n locale: configLocale || 'en',\n })\n\n return {\n ...offer,\n totalRepaymentAmount,\n correctDownPaymentAmount,\n installmentAmount,\n processingFeeAmount,\n }\n })\n .sort(\n (offer, offer2) => Number(offer.maturity) - Number(offer2.maturity)\n ),\n },\n }),\n [response?.data?.[0]?.offers]\n )\n}\n"],"file":"useBnpCalculateForCart.js"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/contexts/CheckoutForm/hooks/useBilling/index.ts"],"names":["useCallback","useEffect","useMemo","useState","useCheckoutBillingAddress","companiesApi","updateObjProp","useSavedBillingList","usePersistOnBeforeUnload","IS_NEW","useBilling","orderQuery","errorLabels","withSavedBillingAddressList","enableSaveBillingAddress","withPersistBeforePageLeave","countryCode","validateBillingAddress","enabled","requiredFields","requiredFieldsOnShipping","emptyBillingAddress","_id","streetName","company","undefined","isDefaultBillingAddress","createdAt","updatedAt","isBillingAddressSubmitting","setIsBillingAddressSubmitting","isWithBillingAddress","setIsWithBillingAddress","saveBillingAddress","useAdd","handleBillingAddressChange","currentBillingAddress","savedBillingAddress","billingAddress","setBillingAddress","isAddingNew","setIsAddingNew","billingAddressList","Boolean","selectedBillingAddress","billingAddressErrors","onInputChange","name","value","data","companyName","companyId","split","persistBillingAddress","Promise","resolve","reject","onSuccess","order","onError","handleSaveBillingAddress","custom","filter","field","Date","now","resetBillingAddress","updateIsWithBillingAddress","callback","initialValue","some","updateIsAddingNew","isSubmitting","errors","isValid","updateIsSubmitting","canSaveBillingAddress"],"mappings":";;AAAA,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,OAAjC,EAA0CC,QAA1C,QAA0D,OAA1D;AAKA,SAASC,yBAAT,QAA0C,6CAA1C;AACA,SAASC,YAAT,QAA6B,8BAA7B;AAGA,SAASC,aAAT,QAA8B,aAA9B;AAEA,SACEC,mBADF,QAGO,wBAHP;AAIA,SAASC,wBAAT,QAAyC,6BAAzC;AAEA,IAAMC,MAAM,GAAG,OAAf;AAEA,OAAO,IAAMC,UAAU,GAAG,UAWmB;AAAA,MAXlB;AACzBC,IAAAA,UADyB;AAEzBC,IAAAA,WAFyB;AAGzBC,IAAAA,2BAHyB;AAIzBC,IAAAA,wBAJyB;AAKzBC,IAAAA,0BALyB;AAMzBC,IAAAA,WANyB;AAOzBC,IAAAA,sBAPyB;AAQzBC,IAAAA,OARyB;AASzBC,IAAAA,cATyB;AAUzBC,IAAA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AA,WAAW,EAAE,EADN;AAEPC,QAAAA,SAAS,EAAE;AAFJ,OAJc;AAQvBU,MAAAA,MAAM,EAAE,CACN;AACEE,QAAAA,KAAK,EAAEtD,MADT;AAEEuC,QAAAA,KAAK,EAAEA,KAAK,GAAG,CAAH,GAAO;AAFrB,OADM;AARe,KAAzB;AAgBAT,IAAAA,iBAAiB,CAACU,IAAD,CAAjB;AACAR,IAAAA,cAAc,CAACO,KAAD,CAAd;AACD,GApBkC,EAqBnC,CAACV,cAAD,CArBmC,CAArC;AAwBA,SAAOpC,OAAO,CAAC,MAAM;AACnB,WAAO;AACLsE,MAAAA,YAAY,EAAE3C,0BADT;AAEL4C,MAAAA,MAAM,EAAE5C,0BAA0B,GAAGgB,oBAAoB,IAAI,IAA3B,GAAkC,IAF/D;AAGLI,MAAAA,IAAI,EAAEX,cAHD;AAILoC,MAAAA,OAAO,EAAE,CAAC7B,oBAJL;AAKL8B,MAAAA,kBAAkB,EAAE7C,6BALf;AAMLgB,MAAAA,aANK;AAOLO,MAAAA,qBAPK;AAQLX,MAAAA,kBARK;AASLT,MAAAA,kBAAkB,EAAE2B,wBATf;AAUL7B,MAAAA,oBAVK;AAWLoC,MAAAA,0BAXK;AAYLS,MAAAA,qBAAqB,EAAE9D,wBAZlB;AAaL0B,MAAAA,WAAW,EAAEG,OAAO,CAACH,WAAD,CAbf;AAcL+B,MAAAA;AAdK,KAAP;AAgBD,GAjBa,EAiBX,CACD1C,0BADC,EAEDW,WAFC,EAGD+B,iBAHC,EAIDzD,wBAJC,EAKD8C,wBALC,EAMDlB,kBANC,EAODW,qBAPC,EAQDP,aARC,EASDD,oBATC,EAUDP,cAVC,EAWDP,oBAXC,EAYDoC,0BAZC,CAjBW,CAAd;AA+BD,CA7OM","sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react'\nimport {\n CheckoutFormErrorLabelsType,\n CheckoutFormErrorsResultType,\n} from '../..'\nimport { useCheckoutBillingAddress } from '../../../../hooks/useCheckoutBillingAddress'\nimport { companiesApi } from '../../../../api/companiesApi'\nimport { AddressDTO, OrderDTO } from '@sentecacommerce/sdk'\n\nimport { updateObjProp } from '../../utils'\nimport { QueryResult } from 'react-query'\nimport {\n useSavedBillingList,\n SavedBillingAddress,\n} from '../useSavedBillingList'\nimport { usePersistOnBeforeUnload } from '../usePersistOnBeforeUnload'\n\nconst IS_NEW = 'isNew'\n\nexport const useBilling = ({\n orderQuery,\n errorLabels,\n withSavedBillingAddressList,\n enableSaveBillingAddress,\n withPersistBeforePageLeave,\n countryCode,\n validateBillingAddress,\n enabled,\n requiredFields,\n requiredFieldsOnShipping,\n}: UseBillingProps): UseBillingResultType => {\n const emptyBillingAddress = useMemo(() => {\n return {\n _id: '',\n streetName: '',\n company: undefined,\n isDefaultBillingAddress: false,\n createdAt: 0,\n updatedAt: 0,\n countryCode,\n }\n }, [countryCode])\n\n const [isBillingAddressSubmitting, setIsBillingAddressSubmitting] = useState(\n false\n )\n\n const [isWithBillingAddress, setIsWithBillingAddress] = useState<\n null | boolean\n >(null)\n\n const [saveBillingAddress] = companiesApi.useAdd()\n\n const {\n handleBillingAddressChange,\n currentBillingAddress: savedBillingAddress,\n } = useCheckoutBillingAddress(orderQuery)\n\n const [billingAddress, setBillingAddress] = useState(savedBillingAddress)\n const [isAddingNew, setIsAddingNew] = useState<boolean | null>(null)\n\n const billingAddressList = useSavedBillingList({\n enabled: Boolean(\n enabled && isWithBillingAddress && withSavedBillingAddressList\n ),\n selectedBillingAddress: billingAddress,\n setBillingAddress,\n handleBillingAddressChange,\n })\n\n const billingAddressErrors = useMemo(() => {\n return (\n billingAddress &&\n validateBillingAddress(\n billingAddress,\n errorLabels,\n requiredFields,\n requiredFieldsOnShipping\n )\n )\n }, [billingAddress, errorLabels, validateBillingAddress])\n\n /**\n * On input change with nested fields support\n *\n * @param name example name: 'company.companyPerson'\n * @param value\n */\n const onInputChange = useCallback(\n async (name: string, value: any) => {\n const data = billingAddress && { ...billingAddress }\n\n // add an empty company when company is undefined\n if (data && !data?.company)\n data.company = { companyName: '', companyId: '' }\n\n if (data) updateObjProp(data, value, name.split('.'))\n\n setBillingAddress(data)\n },\n [billingAddress]\n )\n\n /**\n * Save current billing address state\n */\n const persistBillingAddress = useCallback(() => {\n if (!billingAddress || !isWithBillingAddress) return\n\n return new Promise((resolve, reject) => {\n handleBillingAddressChange(billingAddress, {\n onSuccess: (order: OrderDTO) => resolve(order),\n onError: () => reject(),\n })\n })\n }, [billingAddress])\n\n /**\n * Save the filled billing address\n */\n const handleSaveBillingAddress = useCallback(() => {\n if (!enableSaveBillingAddress) return\n\n setIsBillingAddressSubmitting(true)\n\n if (billingAddressErrors || !billingAddress) {\n return\n }\n\n const data = {\n ...billingAddress,\n custom: billingAddress?.custom?.filter(({ field }) => field !== IS_NEW),\n createdAt: Date.now(),\n updatedAt: Date.now(),\n }\n\n saveBillingAddress(data)\n handleBillingAddressChange(data)\n setIsAddingNew(false)\n }, [billingAddress, enableSaveBillingAddress, billingAddressErrors])\n\n /**\n * Clear billing address\n */\n const resetBillingAddress = useCallback(() => {\n handleBillingAddressChange(emptyBillingAddress)\n setBillingAddress(emptyBillingAddress)\n }, [emptyBillingAddress])\n\n const updateIsWithBillingAddress = useCallback(\n (value: boolean) => {\n if (!value) {\n setIsWithBillingAddress(false)\n\n resetBillingAddress()\n return\n }\n\n setIsWithBillingAddress(true)\n },\n [resetBillingAddress]\n )\n\n /**\n * Set initial data\n */\n useEffect(() => {\n if (billingAddress || typeof savedBillingAddress === 'undefined') return\n\n setBillingAddress(savedBillingAddress || emptyBillingAddress)\n }, [savedBillingAddress, billingAddress, emptyBillingAddress])\n\n /**\n * Set initial isWithBillingAddress\n */\n useEffect(() => {\n if (!billingAddress || isWithBillingAddress !== null) return\n\n setIsWithBillingAddress(Boolean(billingAddress.company))\n }, [billingAddress, isWithBillingAddress])\n\n // persist data before page exit\n usePersistOnBeforeUnload({\n enabled: withPersistBeforePageLeave,\n callback: persistBillingAddress,\n })\n\n /**\n * Set initial value\n */\n useEffect(() => {\n if (!billingAddress || isAddingNew !== null) return\n\n const initialValue =\n billingAddress?.custom?.some(\n ({ field, value }) => field === IS_NEW && value === 1\n ) || false\n\n setIsAddingNew(initialValue)\n }, [billingAddress, isAddingNew])\n\n const updateIsAddingNew = useCallback(\n (value: boolean) => {\n const data: AddressDTO = {\n _id: billingAddress?._id || '',\n createdAt: Date.now(),\n updatedAt: Date.now(),\n company: {\n companyName: '',\n companyId: '',\n },\n custom: [\n {\n field: IS_NEW,\n value: value ? 1 : 0,\n },\n ],\n }\n\n setBillingAddress(data)\n setIsAddingNew(value)\n },\n [billingAddress]\n )\n\n return useMemo(() => {\n return {\n isSubmitting: isBillingAddressSubmitting,\n errors: isBillingAddressSubmitting ? billingAddressErrors || null : null,\n data: billingAddress,\n isValid: !billingAddressErrors,\n updateIsSubmitting: setIsBillingAddressSubmitting,\n onInputChange,\n persistBillingAddress,\n billingAddressList,\n saveBillingAddress: handleSaveBillingAddress,\n isWithBillingAddress,\n updateIsWithBillingAddress,\n canSaveBillingAddress: enableSaveBillingAddress,\n isAddingNew: Boolean(isAddingNew),\n updateIsAddingNew,\n }\n }, [\n isBillingAddressSubmitting,\n isAddingNew,\n updateIsAddingNew,\n enableSaveBillingAddress,\n handleSaveBillingAddress,\n billingAddressList,\n persistBillingAddress,\n onInputChange,\n billingAddressErrors,\n billingAddress,\n isWithBillingAddress,\n updateIsWithBillingAddress,\n ])\n}\n\ntype UseBillingProps = {\n orderQuery: QueryResult<OrderDTO, unknown>\n errorLabels: CheckoutFormErrorLabelsType\n withSavedBillingAddressList: boolean\n enableSaveBillingAddress: boolean\n withPersistBeforePageLeave: boolean\n countryCode: string\n enabled: boolean\n requiredFields: string[]\n requiredFieldsOnShipping: string[]\n validateBillingAddress: (\n address: AddressDTO,\n errors: CheckoutFormErrorLabelsType,\n requiredCompanyFields: string[],\n requiredFields: string[]\n ) => CheckoutFormErrorsResultType\n}\n\nexport type UseBillingResultType = {\n isSubmitting: boolean\n errors?: CheckoutFormErrorsResultType\n isValid: boolean\n data?: AddressDTO\n updateIsSubmitting: (value: boolean) => void\n onInputChange?: (name: string, value: any) => void\n persistBillingAddress: () => void\n saveBillingAddress: () => void\n\n billingAddressList?: SavedBillingAddress[]\n\n canSaveBillingAddress: boolean\n\n isWithBillingAddress: null | boolean\n updateIsWithBillingAddress: (data: boolean) => void\n\n isAddingNew: boolean\n updateIsAddingNew: (value: boolean) => void\n}\n"],"file":"index.js"}
|
1
|
+
{"version":3,"sources":["../../../../../../src/contexts/CheckoutForm/hooks/useBilling/index.ts"],"names":["useCallback","useEffect","useMemo","useState","useCheckoutBillingAddress","companiesApi","updateObjProp","useSavedBillingList","usePersistOnBeforeUnload","IS_NEW","useBilling","orderQuery","errorLabels","withSavedBillingAddressList","enableSaveBillingAddress","withPersistBeforePageLeave","countryCode","validateBillingAddress","enabled","requiredFields","requiredFieldsOnShipping","emptyBillingAddress","_id","streetName","company","undefined","isDefaultBillingAddress","createdAt","updatedAt","isBillingAddressSubmitting","setIsBillingAddressSubmitting","isWithBillingAddress","setIsWithBillingAddress","saveBillingAddress","useAdd","handleBillingAddressChange","currentBillingAddress","savedBillingAddress","billingAddress","setBillingAddress","isAddingNew","setIsAddingNew","billingAddressList","Boolean","selectedBillingAddress","billingAddressErrors","onInputChange","name","value","data","companyName","companyId","split","persistBillingAddress","Promise","resolve","reject","onSuccess","order","onError","handleSaveBillingAddress","custom","filter","field","Date","now","resetBillingAddress","updateIsWithBillingAddress","callback","initialValue","some","updateIsAddingNew","isSubmitting","errors","isValid","updateIsSubmitting","canSaveBillingAddress"],"mappings":";;AAAA,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,OAAjC,EAA0CC,QAA1C,QAA0D,OAA1D;AAKA,SAASC,yBAAT,QAA0C,6CAA1C;AACA,SAASC,YAAT,QAA6B,8BAA7B;AAGA,SAASC,aAAT,QAA8B,aAA9B;AAEA,SACEC,mBADF,QAGO,wBAHP;AAIA,SAASC,wBAAT,QAAyC,6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,iBAHC,EAIDzD,wBAJC,EAKD8C,wBALC,EAMDlB,kBANC,EAODW,qBAPC,EAQDP,aARC,EASDD,oBATC,EAUDP,cAVC,EAWDP,oBAXC,EAYDoC,0BAZC,CAjBW,CAAd;AA+BD,CA7OM","sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react'\nimport {\n CheckoutFormErrorLabelsType,\n CheckoutFormErrorsResultType,\n} from '../..'\nimport { useCheckoutBillingAddress } from '../../../../hooks/useCheckoutBillingAddress'\nimport { companiesApi } from '../../../../api/companiesApi'\nimport { AddressDTO, OrderDTO } from '@sentecacommerce/sdk'\n\nimport { updateObjProp } from '../../utils'\nimport { QueryResult } from 'react-query'\nimport {\n useSavedBillingList,\n SavedBillingAddress,\n} from '../useSavedBillingList'\nimport { usePersistOnBeforeUnload } from '../usePersistOnBeforeUnload'\n\nconst IS_NEW = 'isNew'\n\nexport const useBilling = ({\n orderQuery,\n errorLabels,\n withSavedBillingAddressList,\n enableSaveBillingAddress,\n withPersistBeforePageLeave,\n countryCode,\n validateBillingAddress,\n enabled,\n requiredFields,\n requiredFieldsOnShipping,\n}: UseBillingProps): UseBillingResultType => {\n const emptyBillingAddress = useMemo(() => {\n return {\n _id: '',\n streetName: '',\n company: undefined,\n isDefaultBillingAddress: false,\n createdAt: 0,\n updatedAt: 0,\n countryCode,\n }\n }, [countryCode])\n\n const [isBillingAddressSubmitting, setIsBillingAddressSubmitting] = useState(\n false\n )\n\n const [isWithBillingAddress, setIsWithBillingAddress] = useState<\n null | boolean\n >(null)\n\n const [saveBillingAddress] = companiesApi.useAdd()\n\n const {\n handleBillingAddressChange,\n currentBillingAddress: savedBillingAddress,\n } = useCheckoutBillingAddress(orderQuery)\n\n const [billingAddress, setBillingAddress] = useState(savedBillingAddress)\n const [isAddingNew, setIsAddingNew] = useState<boolean | null>(null)\n\n const billingAddressList = useSavedBillingList({\n enabled: Boolean(\n enabled && isWithBillingAddress && withSavedBillingAddressList\n ),\n selectedBillingAddress: billingAddress,\n setBillingAddress,\n handleBillingAddressChange,\n })\n\n const billingAddressErrors = useMemo(() => {\n return (\n billingAddress &&\n validateBillingAddress(\n billingAddress,\n errorLabels,\n requiredFields,\n requiredFieldsOnShipping\n )\n )\n }, [billingAddress, errorLabels, validateBillingAddress])\n\n /**\n * On input change with nested fields support\n *\n * @param name example name: 'company.companyPerson'\n * @param value\n */\n const onInputChange = useCallback(\n async (name: string, value: any) => {\n const data = billingAddress && { ...billingAddress }\n\n // add an empty company when company is undefined\n if (data && !data?.company)\n data.company = { companyName: '', companyId: '' }\n\n if (data) updateObjProp(data, value, name.split('.'))\n\n setBillingAddress(data)\n },\n [billingAddress]\n )\n\n /**\n * Save current billing address state\n */\n const persistBillingAddress = useCallback(() => {\n if (!billingAddress || !isWithBillingAddress) return\n\n return new Promise((resolve, reject) => {\n handleBillingAddressChange(billingAddress, {\n onSuccess: (order: OrderDTO) => resolve(order),\n onError: () => reject(),\n })\n })\n }, [billingAddress])\n\n /**\n * Save the filled billing address\n */\n const handleSaveBillingAddress = useCallback(() => {\n if (!enableSaveBillingAddress) return\n\n setIsBillingAddressSubmitting(true)\n\n if (billingAddressErrors || !billingAddress) {\n return\n }\n\n const data = {\n ...billingAddress,\n custom: billingAddress?.custom?.filter(({ field }) => field !== IS_NEW),\n createdAt: Date.now(),\n updatedAt: Date.now(),\n }\n\n saveBillingAddress(data)\n handleBillingAddressChange(data)\n setIsAddingNew(false)\n }, [billingAddress, enableSaveBillingAddress, billingAddressErrors])\n\n /**\n * Clear billing address\n */\n const resetBillingAddress = useCallback(() => {\n handleBillingAddressChange(emptyBillingAddress)\n setBillingAddress(emptyBillingAddress)\n }, [emptyBillingAddress])\n\n const updateIsWithBillingAddress = useCallback(\n (value: boolean) => {\n if (!value) {\n setIsWithBillingAddress(false)\n\n resetBillingAddress()\n return\n }\n\n setIsWithBillingAddress(true)\n },\n [resetBillingAddress]\n )\n\n /**\n * Set initial data\n */\n useEffect(() => {\n if (billingAddress || typeof savedBillingAddress === 'undefined') return\n\n setBillingAddress(savedBillingAddress || emptyBillingAddress)\n }, [savedBillingAddress, billingAddress, emptyBillingAddress])\n\n /**\n * Set initial isWithBillingAddress\n */\n useEffect(() => {\n if (!billingAddress || isWithBillingAddress !== null) return\n\n setIsWithBillingAddress(Boolean(billingAddress.company))\n }, [billingAddress, isWithBillingAddress])\n\n // persist data before page exit\n usePersistOnBeforeUnload({\n enabled: withPersistBeforePageLeave,\n callback: persistBillingAddress,\n })\n\n /**\n * Set initial value\n */\n useEffect(() => {\n if (!billingAddress || isAddingNew !== null) return\n\n const initialValue =\n billingAddress?.custom?.some(\n ({ field, value }) => field === IS_NEW && value === 1\n ) || false\n\n setIsAddingNew(initialValue)\n }, [billingAddress, isAddingNew])\n\n const updateIsAddingNew = useCallback(\n (value: boolean) => {\n const data: AddressDTO = {\n _id: billingAddress?._id || '',\n createdAt: Date.now(),\n updatedAt: Date.now(),\n company: {\n companyName: '',\n companyId: '',\n },\n custom: [\n {\n field: IS_NEW,\n value: value ? 1 : 0,\n },\n ],\n }\n\n setBillingAddress(data)\n setIsAddingNew(value)\n },\n [billingAddress]\n )\n\n return useMemo(() => {\n return {\n isSubmitting: isBillingAddressSubmitting,\n errors: isBillingAddressSubmitting ? billingAddressErrors || null : null,\n data: billingAddress,\n isValid: !billingAddressErrors,\n updateIsSubmitting: setIsBillingAddressSubmitting,\n onInputChange,\n persistBillingAddress,\n billingAddressList,\n saveBillingAddress: handleSaveBillingAddress,\n isWithBillingAddress,\n updateIsWithBillingAddress,\n canSaveBillingAddress: enableSaveBillingAddress,\n isAddingNew: Boolean(isAddingNew),\n updateIsAddingNew,\n }\n }, [\n isBillingAddressSubmitting,\n isAddingNew,\n updateIsAddingNew,\n enableSaveBillingAddress,\n handleSaveBillingAddress,\n billingAddressList,\n persistBillingAddress,\n onInputChange,\n billingAddressErrors,\n billingAddress,\n isWithBillingAddress,\n updateIsWithBillingAddress,\n ])\n}\n\ntype UseBillingProps = {\n orderQuery: QueryResult<OrderDTO, unknown>\n errorLabels: CheckoutFormErrorLabelsType\n withSavedBillingAddressList: boolean\n enableSaveBillingAddress: boolean\n withPersistBeforePageLeave: boolean\n countryCode?: string\n enabled: boolean\n requiredFields: string[]\n requiredFieldsOnShipping: string[]\n validateBillingAddress: (\n address: AddressDTO,\n errors: CheckoutFormErrorLabelsType,\n requiredCompanyFields: string[],\n requiredFields: string[]\n ) => CheckoutFormErrorsResultType\n}\n\nexport type UseBillingResultType = {\n isSubmitting: boolean\n errors?: CheckoutFormErrorsResultType\n isValid: boolean\n data?: AddressDTO\n updateIsSubmitting: (value: boolean) => void\n onInputChange?: (name: string, value: any) => void\n persistBillingAddress: () => void\n saveBillingAddress: () => void\n\n billingAddressList?: SavedBillingAddress[]\n\n canSaveBillingAddress: boolean\n\n isWithBillingAddress: null | boolean\n updateIsWithBillingAddress: (data: boolean) => void\n\n isAddingNew: boolean\n updateIsAddingNew: (value: boolean) => void\n}\n"],"file":"index.js"}
|