@sentecacommerce-theme/lib 0.12.72 → 0.12.78
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/api/myOrdersApi/index.js +4 -2
- package/dist/cjs/api/myOrdersApi/index.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/useUniCreditCalculateForCartQuery.js +40 -0
- package/dist/cjs/checkout/api/queries/useUniCreditCalculateForCartQuery.js.map +1 -0
- package/dist/cjs/checkout/contexts/UniCreditResponseContext.js +29 -0
- package/dist/cjs/checkout/contexts/UniCreditResponseContext.js.map +1 -0
- package/dist/cjs/checkout/contexts/index.js +8 -0
- package/dist/cjs/checkout/contexts/index.js.map +1 -1
- 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 +1 -0
- package/dist/cjs/checkout/hooks/useBnpCalculateForCart.js.map +1 -1
- package/dist/cjs/checkout/hooks/useUniCreditCalculateForCart.js +82 -0
- package/dist/cjs/checkout/hooks/useUniCreditCalculateForCart.js.map +1 -0
- package/dist/cjs/checkout/ssr/captureUniCreditOrder.js +36 -0
- package/dist/cjs/checkout/ssr/captureUniCreditOrder.js.map +1 -0
- package/dist/cjs/checkout/ssr/index.js +8 -0
- package/dist/cjs/checkout/ssr/index.js.map +1 -1
- package/dist/cjs/contexts/CheckoutForm/Components/UniCreditRedirect/index.js +71 -0
- package/dist/cjs/contexts/CheckoutForm/Components/UniCreditRedirect/index.js.map +1 -0
- package/dist/cjs/contexts/CheckoutForm/Components/index.js +8 -0
- package/dist/cjs/contexts/CheckoutForm/Components/index.js.map +1 -1
- package/dist/cjs/contexts/CheckoutForm/hooks/usePayment/index.js.map +1 -1
- package/dist/cjs/contexts/CheckoutForm/index.js +61 -16
- package/dist/cjs/contexts/CheckoutForm/index.js.map +1 -1
- package/dist/cjs/hooks/order-hooks/useOrder/index.js +1 -5
- package/dist/cjs/hooks/order-hooks/useOrder/index.js.map +1 -1
- package/dist/cjs/hooks/order-hooks/useOrderPaymentMethods/index.js.map +1 -1
- package/dist/cjs/hooks/order-hooks/useUpdateOrderPaymentMethod/index.js.map +1 -1
- package/dist/cjs/hooks/subscriptions-hooks/useAllSubscriptions/index.js +1 -1
- package/dist/cjs/hooks/subscriptions-hooks/useAllSubscriptions/index.js.map +1 -1
- package/dist/cjs/hooks/useCheckoutSubmit/index.js +37 -16
- package/dist/cjs/hooks/useCheckoutSubmit/index.js.map +1 -1
- package/dist/cjs/listing/api/queries/useLabelsQuery.js +2 -1
- package/dist/cjs/listing/api/queries/useLabelsQuery.js.map +1 -1
- package/dist/cjs/listing/hooks/useListingFilters.js +3 -1
- package/dist/cjs/listing/hooks/useListingFilters.js.map +1 -1
- package/dist/cjs/product/api/keys.js +7 -1
- package/dist/cjs/product/api/keys.js.map +1 -1
- package/dist/cjs/product/api/queries/index.js +8 -0
- package/dist/cjs/product/api/queries/index.js.map +1 -1
- package/dist/cjs/product/api/queries/useUniCreditOffersQuery.js +45 -0
- package/dist/cjs/product/api/queries/useUniCreditOffersQuery.js.map +1 -0
- package/dist/cjs/product/hooks/index.js +8 -0
- package/dist/cjs/product/hooks/index.js.map +1 -1
- package/dist/cjs/product/hooks/useUniCreditOffers.js +72 -0
- package/dist/cjs/product/hooks/useUniCreditOffers.js.map +1 -0
- package/dist/cjs/ui/hooks/index.js +12 -0
- package/dist/cjs/ui/hooks/index.js.map +1 -0
- package/dist/cjs/ui/hooks/useToasts.js +96 -0
- package/dist/cjs/ui/hooks/useToasts.js.map +1 -0
- package/dist/cjs/ui/index.js +8 -0
- package/dist/cjs/ui/index.js.map +1 -1
- package/dist/cjs/ui/toastUtils/ErrorIcon.js +26 -0
- package/dist/cjs/ui/toastUtils/ErrorIcon.js.map +1 -0
- package/dist/cjs/ui/toastUtils/InfoIcon.js +26 -0
- package/dist/cjs/ui/toastUtils/InfoIcon.js.map +1 -0
- package/dist/cjs/ui/toastUtils/SuccessIcon.js +26 -0
- package/dist/cjs/ui/toastUtils/SuccessIcon.js.map +1 -0
- package/dist/cjs/ui/toastUtils/WarningIcon.js +26 -0
- package/dist/cjs/ui/toastUtils/WarningIcon.js.map +1 -0
- package/dist/cjs/ui/toastUtils/index.js +44 -0
- package/dist/cjs/ui/toastUtils/index.js.map +1 -0
- package/dist/cjs/ui/toastUtils/utils.js +107 -0
- package/dist/cjs/ui/toastUtils/utils.js.map +1 -0
- package/dist/esm/api/myOrdersApi/index.js +2 -1
- package/dist/esm/api/myOrdersApi/index.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/useUniCreditCalculateForCartQuery.js +10 -0
- package/dist/esm/checkout/api/queries/useUniCreditCalculateForCartQuery.js.map +1 -0
- package/dist/esm/checkout/contexts/UniCreditResponseContext.js +17 -0
- package/dist/esm/checkout/contexts/UniCreditResponseContext.js.map +1 -0
- package/dist/esm/checkout/contexts/index.js +1 -0
- package/dist/esm/checkout/contexts/index.js.map +1 -1
- 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 +1 -0
- package/dist/esm/checkout/hooks/useBnpCalculateForCart.js.map +1 -1
- package/dist/esm/checkout/hooks/useUniCreditCalculateForCart.js +66 -0
- package/dist/esm/checkout/hooks/useUniCreditCalculateForCart.js.map +1 -0
- package/dist/esm/checkout/ssr/captureUniCreditOrder.js +12 -0
- package/dist/esm/checkout/ssr/captureUniCreditOrder.js.map +1 -0
- package/dist/esm/checkout/ssr/index.js +1 -0
- package/dist/esm/checkout/ssr/index.js.map +1 -1
- package/dist/esm/contexts/CheckoutForm/Components/UniCreditRedirect/index.js +63 -0
- package/dist/esm/contexts/CheckoutForm/Components/UniCreditRedirect/index.js.map +1 -0
- package/dist/esm/contexts/CheckoutForm/Components/index.js +1 -0
- package/dist/esm/contexts/CheckoutForm/Components/index.js.map +1 -1
- package/dist/esm/contexts/CheckoutForm/hooks/usePayment/index.js.map +1 -1
- package/dist/esm/contexts/CheckoutForm/index.js +28 -2
- package/dist/esm/contexts/CheckoutForm/index.js.map +1 -1
- package/dist/esm/hooks/order-hooks/useOrder/index.js +1 -5
- package/dist/esm/hooks/order-hooks/useOrder/index.js.map +1 -1
- package/dist/esm/hooks/order-hooks/useOrderPaymentMethods/index.js.map +1 -1
- package/dist/esm/hooks/order-hooks/useUpdateOrderPaymentMethod/index.js.map +1 -1
- package/dist/esm/hooks/subscriptions-hooks/useAllSubscriptions/index.js +1 -1
- package/dist/esm/hooks/subscriptions-hooks/useAllSubscriptions/index.js.map +1 -1
- package/dist/esm/hooks/useCheckoutSubmit/index.js +10 -3
- package/dist/esm/hooks/useCheckoutSubmit/index.js.map +1 -1
- package/dist/esm/listing/api/queries/useLabelsQuery.js +2 -1
- package/dist/esm/listing/api/queries/useLabelsQuery.js.map +1 -1
- package/dist/esm/listing/hooks/useListingFilters.js +3 -1
- package/dist/esm/listing/hooks/useListingFilters.js.map +1 -1
- package/dist/esm/product/api/keys.js +3 -0
- package/dist/esm/product/api/keys.js.map +1 -1
- package/dist/esm/product/api/queries/index.js +1 -0
- package/dist/esm/product/api/queries/index.js.map +1 -1
- package/dist/esm/product/api/queries/useUniCreditOffersQuery.js +16 -0
- package/dist/esm/product/api/queries/useUniCreditOffersQuery.js.map +1 -0
- package/dist/esm/product/hooks/index.js +1 -0
- package/dist/esm/product/hooks/index.js.map +1 -1
- package/dist/esm/product/hooks/useUniCreditOffers.js +57 -0
- package/dist/esm/product/hooks/useUniCreditOffers.js.map +1 -0
- package/dist/esm/ui/hooks/index.js +2 -0
- package/dist/esm/ui/hooks/index.js.map +1 -0
- package/dist/esm/ui/hooks/useToasts.js +74 -0
- package/dist/esm/ui/hooks/useToasts.js.map +1 -0
- package/dist/esm/ui/index.js +1 -0
- package/dist/esm/ui/index.js.map +1 -1
- package/dist/esm/ui/toastUtils/ErrorIcon.js +16 -0
- package/dist/esm/ui/toastUtils/ErrorIcon.js.map +1 -0
- package/dist/esm/ui/toastUtils/InfoIcon.js +16 -0
- package/dist/esm/ui/toastUtils/InfoIcon.js.map +1 -0
- package/dist/esm/ui/toastUtils/SuccessIcon.js +16 -0
- package/dist/esm/ui/toastUtils/SuccessIcon.js.map +1 -0
- package/dist/esm/ui/toastUtils/WarningIcon.js +16 -0
- package/dist/esm/ui/toastUtils/WarningIcon.js.map +1 -0
- package/dist/esm/ui/toastUtils/index.js +6 -0
- package/dist/esm/ui/toastUtils/index.js.map +1 -0
- package/dist/esm/ui/toastUtils/utils.js +82 -0
- package/dist/esm/ui/toastUtils/utils.js.map +1 -0
- package/dist/types/checkout/api/keys.d.ts +1 -0
- package/dist/types/checkout/api/queries/index.d.ts +1 -0
- package/dist/types/checkout/api/queries/useBnpCalculateForCartQuery.d.ts +1 -1
- package/dist/types/checkout/api/queries/useUniCreditCalculateForCartQuery.d.ts +3 -0
- package/dist/types/checkout/contexts/UniCreditResponseContext.d.ts +6 -0
- package/dist/types/checkout/contexts/index.d.ts +1 -0
- package/dist/types/checkout/hooks/index.d.ts +1 -0
- package/dist/types/checkout/hooks/useBnpCalculateForCart.d.ts +5 -3
- package/dist/types/checkout/hooks/useUniCreditCalculateForCart.d.ts +53 -0
- package/dist/types/checkout/ssr/captureUniCreditOrder.d.ts +2 -0
- package/dist/types/checkout/ssr/index.d.ts +1 -0
- package/dist/types/contexts/CheckoutForm/Components/UniCreditRedirect/index.d.ts +5 -0
- package/dist/types/contexts/CheckoutForm/Components/index.d.ts +1 -0
- package/dist/types/contexts/CheckoutForm/hooks/usePayment/index.d.ts +2 -2
- package/dist/types/contexts/CheckoutForm/index.d.ts +1 -0
- package/dist/types/hooks/order-hooks/useOrderPaymentMethods/index.d.ts +4 -4
- package/dist/types/hooks/useCheckoutSubmit/index.d.ts +3 -2
- 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 +1 -1
- package/dist/types/product/api/queries/useUniCreditOffersQuery.d.ts +4 -0
- package/dist/types/product/hooks/index.d.ts +1 -0
- package/dist/types/product/hooks/useBnpOffers.d.ts +2 -2
- package/dist/types/product/hooks/useUniCreditOffers.d.ts +36 -0
- package/dist/types/ui/hooks/index.d.ts +1 -0
- package/dist/types/ui/hooks/useToasts.d.ts +20 -0
- package/dist/types/ui/index.d.ts +1 -0
- package/dist/types/ui/toastUtils/ErrorIcon.d.ts +1 -0
- package/dist/types/ui/toastUtils/InfoIcon.d.ts +1 -0
- package/dist/types/ui/toastUtils/SuccessIcon.d.ts +1 -0
- package/dist/types/ui/toastUtils/WarningIcon.d.ts +1 -0
- package/dist/types/ui/toastUtils/index.d.ts +5 -0
- package/dist/types/ui/toastUtils/utils.d.ts +11 -0
- package/package.json +4 -4
@@ -16,6 +16,8 @@ var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
16
16
|
|
17
17
|
var _react = _interopRequireWildcard(require("react"));
|
18
18
|
|
19
|
+
var _sdk = require("@sentecacommerce/sdk");
|
20
|
+
|
19
21
|
var _myCartApi = require("../../api/myCartApi");
|
20
22
|
|
21
23
|
var _hooks = require("./hooks");
|
@@ -84,19 +86,23 @@ function CheckoutFormContextProvider(_ref) {
|
|
84
86
|
boricaData = _useState[0],
|
85
87
|
setBoricaData = _useState[1];
|
86
88
|
|
87
|
-
var _useState2 = (0, _react.useState)(
|
88
|
-
|
89
|
-
|
89
|
+
var _useState2 = (0, _react.useState)(null),
|
90
|
+
uniCreditData = _useState2[0],
|
91
|
+
setUniCreditData = _useState2[1];
|
92
|
+
|
93
|
+
var _useState3 = (0, _react.useState)(defaultStep),
|
94
|
+
step = _useState3[0],
|
95
|
+
setStep = _useState3[1];
|
90
96
|
|
91
|
-
var
|
92
|
-
isRedirecting =
|
93
|
-
setIsRedirecting =
|
97
|
+
var _useState4 = (0, _react.useState)(false),
|
98
|
+
isRedirecting = _useState4[0],
|
99
|
+
setIsRedirecting = _useState4[1];
|
94
100
|
|
95
101
|
var fieldsWithError = [];
|
96
102
|
|
97
|
-
var
|
98
|
-
serverErrors =
|
99
|
-
setServerErrors =
|
103
|
+
var _useState5 = (0, _react.useState)(null),
|
104
|
+
serverErrors = _useState5[0],
|
105
|
+
setServerErrors = _useState5[1];
|
100
106
|
|
101
107
|
var collectFieldsWithError = function collectFieldsWithError(error) {
|
102
108
|
fieldsWithError.push(error);
|
@@ -200,9 +206,19 @@ function CheckoutFormContextProvider(_ref) {
|
|
200
206
|
}, redirectTimeout);
|
201
207
|
};
|
202
208
|
|
209
|
+
var onBeforeUniCreditRedirect = function onBeforeUniCreditRedirect(data) {
|
210
|
+
if (disablePaymentRedirects) return;
|
211
|
+
onBeforeRedirect == null ? void 0 : onBeforeRedirect();
|
212
|
+
setIsRedirecting(true);
|
213
|
+
setTimeout(function () {
|
214
|
+
setUniCreditData(data);
|
215
|
+
}, redirectTimeout);
|
216
|
+
};
|
217
|
+
|
203
218
|
var _useCheckoutSubmit = (0, _useCheckoutSubmit2.useCheckoutSubmit)({
|
204
219
|
onBeforeBoricaRedirect: onBeforeBoricaRedirect,
|
205
220
|
onBeforePaypalRedirect: onBeforePaypalRedirect,
|
221
|
+
onBeforeUniCreditRedirect: onBeforeUniCreditRedirect,
|
206
222
|
onSuccess: onSuccess,
|
207
223
|
onError: function onError(errors) {
|
208
224
|
updateServerErrors(errors);
|
@@ -230,13 +246,13 @@ function CheckoutFormContextProvider(_ref) {
|
|
230
246
|
};
|
231
247
|
|
232
248
|
var handleSubmit = /*#__PURE__*/function () {
|
233
|
-
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
234
|
-
return _regenerator["default"].wrap(function
|
249
|
+
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(e) {
|
250
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
235
251
|
while (1) {
|
236
|
-
switch (
|
252
|
+
switch (_context2.prev = _context2.next) {
|
237
253
|
case 0:
|
238
254
|
e.preventDefault();
|
239
|
-
|
255
|
+
_context2.next = 3;
|
240
256
|
return Promise.all([shippingState.persistShippingAddress(), billingState.persistBillingAddress()])["catch"](function () {});
|
241
257
|
|
242
258
|
case 3:
|
@@ -254,15 +270,41 @@ function CheckoutFormContextProvider(_ref) {
|
|
254
270
|
updateServerErrors: updateServerErrors,
|
255
271
|
scrollToFirstError: scrollToFirstError,
|
256
272
|
shippingState: shippingState,
|
257
|
-
shippingAddress: shippingState.data
|
273
|
+
shippingAddress: shippingState.data,
|
274
|
+
setLoanInfo: function () {
|
275
|
+
var _setLoanInfo = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(loanInfo) {
|
276
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
277
|
+
while (1) {
|
278
|
+
switch (_context.prev = _context.next) {
|
279
|
+
case 0:
|
280
|
+
_context.next = 2;
|
281
|
+
return (0, _sdk.MyCartSetLoanInfo)(loanInfo);
|
282
|
+
|
283
|
+
case 2:
|
284
|
+
return _context.abrupt("return", _context.sent);
|
285
|
+
|
286
|
+
case 3:
|
287
|
+
case "end":
|
288
|
+
return _context.stop();
|
289
|
+
}
|
290
|
+
}
|
291
|
+
}, _callee);
|
292
|
+
}));
|
293
|
+
|
294
|
+
function setLoanInfo(_x2) {
|
295
|
+
return _setLoanInfo.apply(this, arguments);
|
296
|
+
}
|
297
|
+
|
298
|
+
return setLoanInfo;
|
299
|
+
}()
|
258
300
|
});
|
259
301
|
|
260
302
|
case 4:
|
261
303
|
case "end":
|
262
|
-
return
|
304
|
+
return _context2.stop();
|
263
305
|
}
|
264
306
|
}
|
265
|
-
},
|
307
|
+
}, _callee2);
|
266
308
|
}));
|
267
309
|
|
268
310
|
return function handleSubmit(_x) {
|
@@ -293,6 +335,9 @@ function CheckoutFormContextProvider(_ref) {
|
|
293
335
|
}, children), !!boricaData && /*#__PURE__*/_react["default"].createElement(_Components.BoricaRedirect, {
|
294
336
|
isInDevMode: isBoricaInDevMode,
|
295
337
|
formData: boricaData
|
338
|
+
}), !!uniCreditData && /*#__PURE__*/_react["default"].createElement(_Components.UniCreditRedirect, {
|
339
|
+
isInDevMode: isBoricaInDevMode,
|
340
|
+
formData: uniCreditData
|
296
341
|
}))));
|
297
342
|
}
|
298
343
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/CheckoutForm/index.tsx"],"names":["CheckoutFormContext","CheckoutFormContextProvider","children","defaultStep","errorLabels","enableSavedAddressList","withPersistBeforePageLeave","shippingValidations","defaultShippingValidations","validateBillingAddress","genericBillingAddressValidation","enableSaveBillingAddress","enableSavedBillingAddressList","countryCode","enableSaveAddress","autofillShippingPersonalData","onSubmit","paymentEnabledOnStep","getPaymentMethodsWhenShippingMethodIsSelected","shippingEnabledOnStep","billingEnabledOnStep","customState","initialCustomState","redirectTimeout","onBeforeRedirect","onSuccess","onError","isBoricaInDevMode","withPixelMeta","requiredFieldsOnShippingStep","requiredFieldsOnBillingAddressStep","enableNoShippingMethodMode","disablePaymentRedirects","orderQuery","myCartApi","useGet","boricaData","setBoricaData","step","setStep","isRedirecting","setIsRedirecting","fieldsWithError","serverErrors","setServerErrors","collectFieldsWithError","error","push","handleStepChange","newStep","window","scrollTo","updateServerErrors","errors","formattedErrors","reduce","data","code","response","internalError","isAuthenticated","isShippingEnabled","userQuery","usersApi","enabled","shippingState","Boolean","validations","requiredFields","mod","getIsPaymentMethodsEnabled","moduleKey","moduleData","methodKey","paymentState","billingState","withSavedBillingAddressList","requiredFieldsOnShipping","onBeforeBoricaRedirect","setTimeout","onBeforePaypalRedirect","location","replace","redirectUrl","withMeta","handleCheckoutSubmit","scrollToFirstError","interval","setInterval","errorElement","top","clearInterval","handleSubmit","e","preventDefault","Promise","all","persistShippingAddress","persistBillingAddress","isShippingValid","isValid","setIsShippingSubmitting","updateIsSubmitting","isBillingValid","setIsBillingSubmitting","isPaymentValid","setIsPaymentSubmitting","loanInfo","updateStep","saveOrder","shippingAddress","state","errorRef","errorFields","CheckoutFormStepsEnum","useCheckoutFormStep","context","Error","currentStep","useCheckoutFormOrder","useCheckoutFormErrorLabels","useCheckoutFormServerErrors","useCheckoutFormBillingState","useCheckoutFormShippingState","useCheckoutErrorFields","useCheckoutFormPaymentState"],"mappings":";;;;;;;;;;;;;;;;AAAA;;AAeA;;AACA;;AAQA;;AACA;;AAEA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AAEO,IAAMA,mBAAmB,gBAAG,0BACjC,EADiC,CAA5B;;;AAMA,SAASC,2BAAT,OAyCG;AAAA,MAxCRC,QAwCQ,QAxCRA,QAwCQ;AAAA,MAvCRC,WAuCQ,QAvCRA,WAuCQ;AAAA,MAtCRC,WAsCQ,QAtCRA,WAsCQ;AAAA,MArCRC,sBAqCQ,QArCRA,sBAqCQ;AAAA,MApCRC,0BAoCQ,QApCRA,0BAoCQ;AAAA,mCAnCRC,mBAmCQ;AAAA,MAnCRA,mBAmCQ,sCAnCcC,iCAmCd;AAAA,mCAlCRC,sBAkCQ;AAAA,MAlCRA,sBAkCQ,sCAlCiBC,sCAkCjB;AAAA,MAjCRC,wBAiCQ,QAjCRA,wBAiCQ;AAAA,MAhCRC,6BAgCQ,QAhCRA,6BAgCQ;AAAA,MA/BRC,WA+BQ,QA/BRA,WA+BQ;AAAA,MA9BRC,iBA8BQ,QA9BRA,iBA8BQ;AAAA,MA7BRC,4BA6BQ,QA7BRA,4BA6BQ;AAAA,MA5BRC,QA4BQ,QA5BRA,QA4BQ;AAAA,MA1BRC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AED,SAAOD,OAAO,CAAC1C,YAAf;AACD,CAVM","sourcesContent":["import React, {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useState,\n} from 'react'\nimport {\n BoricaGeneratePaymentDataResponse,\n OrderDTO,\n AddressDTO,\n PaypalGeneratePaymentUrlResponseDTO,\n OrderLoanInfoDTO,\n} from '@sentecacommerce/sdk'\nimport { MutateFunction, QueryResult } from 'react-query'\nimport { myCartApi } from '../../api/myCartApi'\nimport {\n useBilling,\n UseBillingResultType,\n usePayment,\n UsePaymentResultType,\n useShipping,\n UseShippingResultType,\n} from './hooks'\nimport { useIsAuthenticated } from '../../user/hooks'\nimport { useCheckoutSubmit } from '../../hooks/useCheckoutSubmit'\n\nimport {\n ShippingValidationsType,\n defaultShippingValidations,\n genericBillingAddressValidation,\n BillingAddressValidationType,\n} from './utils'\nimport { usersApi } from '../../api/usersApi'\nimport { useCheckoutShippingModule } from '../../hooks/useCheckoutShippingModule'\nimport { CheckoutFormCustomStateProvider, BoricaRedirect } from './Components'\nimport { useScrollTo } from '../../hooks/ui-hooks'\nimport { getElementOffset } from '../../utils/getElementOffset'\n\nexport const CheckoutFormContext = createContext<CheckoutFormContextType>(\n {} as any\n)\n\nexport type CheckoutCustomState = {}\n\nexport function CheckoutFormContextProvider({\n children,\n defaultStep,\n errorLabels,\n enableSavedAddressList,\n withPersistBeforePageLeave,\n shippingValidations = defaultShippingValidations,\n validateBillingAddress = genericBillingAddressValidation,\n enableSaveBillingAddress,\n enableSavedBillingAddressList,\n countryCode,\n enableSaveAddress,\n autofillShippingPersonalData,\n onSubmit,\n\n paymentEnabledOnStep,\n getPaymentMethodsWhenShippingMethodIsSelected,\n shippingEnabledOnStep,\n billingEnabledOnStep,\n\n customState: initialCustomState = {},\n redirectTimeout = 420,\n onBeforeRedirect,\n onSuccess,\n onError,\n isBoricaInDevMode,\n withPixelMeta = false,\n requiredFieldsOnShippingStep = [\n 'firstName',\n 'lastName',\n 'email',\n 'phoneNumber',\n ],\n requiredFieldsOnBillingAddressStep = [\n 'vatId',\n 'companyId',\n 'companyPerson',\n 'companyName',\n ],\n enableNoShippingMethodMode = false,\n disablePaymentRedirects = false,\n}: Props) {\n const orderQuery = myCartApi.useGet()\n const [\n boricaData,\n setBoricaData,\n ] = useState<BoricaGeneratePaymentDataResponse | null>(null)\n const [step, setStep] = useState<CheckoutFormStepsEnum>(defaultStep)\n const [isRedirecting, setIsRedirecting] = useState(false)\n\n const fieldsWithError: HTMLElement[] = []\n\n const [serverErrors, setServerErrors] = useState<ServerErrors>(null)\n\n const collectFieldsWithError = (error: HTMLElement) => {\n fieldsWithError.push(error)\n }\n\n const handleStepChange = useCallback((newStep: CheckoutFormStepsEnum) => {\n window.scrollTo(0, 0)\n\n setStep(newStep)\n }, [])\n\n const updateServerErrors = useCallback((errors: any[]) => {\n // Example Error\n // [{\n // code: \"OutOfStock\"\n // message: \"Some of the ordered line items are out of stock at the time of placing the order.\"\n // responses: {\n // availableQuantity: 1\n // sku: \"200000095849\"\n // status: \"unavailable\"\n // }\n // }]\n const formattedErrors = errors?.reduce?.(\n (data: ServerErrors, error: any) => {\n return {\n ...data,\n [error?.code || 'internal']: error?.response,\n }\n },\n {}\n )\n setServerErrors(formattedErrors || { internalError: errors })\n }, [])\n\n const { isAuthenticated } = useIsAuthenticated()\n\n const isShippingEnabled = shippingEnabledOnStep === step\n\n const userQuery = usersApi.useGet(\n {},\n { enabled: isShippingEnabled && autofillShippingPersonalData }\n )\n\n const shippingState = useShipping({\n errorLabels,\n orderQuery,\n enableSavedAddressList: Boolean(isAuthenticated && enableSavedAddressList),\n enableSaveAddress: Boolean(isAuthenticated && enableSaveAddress),\n withPersistBeforePageLeave: !isRedirecting && withPersistBeforePageLeave,\n validations: shippingValidations,\n autofillShippingPersonalData: Boolean(\n isAuthenticated && autofillShippingPersonalData\n ),\n userQuery,\n enabled: isShippingEnabled,\n countryCode,\n requiredFields: requiredFieldsOnShippingStep,\n enableNoShippingMethodMode,\n })\n const mod = useCheckoutShippingModule(orderQuery, !enableNoShippingMethodMode)\n\n const getIsPaymentMethodsEnabled = () => {\n if (paymentEnabledOnStep) {\n return paymentEnabledOnStep === step\n }\n\n if (\n !enableNoShippingMethodMode &&\n getPaymentMethodsWhenShippingMethodIsSelected\n ) {\n return Boolean(mod?.moduleKey && mod?.moduleData.methodKey)\n }\n\n return false\n }\n\n const paymentState = usePayment({\n errorLabels,\n orderQuery,\n enabled: getIsPaymentMethodsEnabled(),\n })\n\n const billingState = useBilling({\n errorLabels,\n orderQuery,\n validateBillingAddress,\n enableSaveBillingAddress: Boolean(\n isAuthenticated && enableSaveBillingAddress\n ),\n withSavedBillingAddressList: Boolean(\n isAuthenticated && enableSavedBillingAddressList\n ),\n withPersistBeforePageLeave: !isRedirecting && withPersistBeforePageLeave,\n countryCode,\n enabled: billingEnabledOnStep === step,\n requiredFields: requiredFieldsOnBillingAddressStep,\n requiredFieldsOnShipping: requiredFieldsOnShippingStep,\n })\n\n const onBeforeBoricaRedirect = (data: BoricaGeneratePaymentDataResponse) => {\n if (disablePaymentRedirects) return\n\n onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n setBoricaData(data)\n }, redirectTimeout)\n }\n\n const onBeforePaypalRedirect = (\n data: PaypalGeneratePaymentUrlResponseDTO\n ) => {\n if (disablePaymentRedirects) return\n\n onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n window.location.replace(data.redirectUrl)\n }, redirectTimeout)\n }\n const { handleCheckoutSubmit } = useCheckoutSubmit({\n onBeforeBoricaRedirect,\n onBeforePaypalRedirect,\n onSuccess,\n onError: (errors: any) => {\n updateServerErrors(errors)\n onError(errors)\n },\n withMeta: withPixelMeta,\n disablePaymentRedirects,\n })\n\n const { scrollTo } = useScrollTo(fieldsWithError[0], 0)\n\n const scrollToFirstError = () => {\n const interval = setInterval(() => {\n const errorElement = fieldsWithError[0]\n if (!errorElement) return\n\n scrollTo(getElementOffset(errorElement).top - 100)\n clearInterval(interval)\n }, 50)\n\n setTimeout(() => {\n clearInterval(interval)\n }, 1000)\n }\n\n const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n\n await Promise.all([\n shippingState.persistShippingAddress(),\n billingState.persistBillingAddress(),\n ]).catch(() => {})\n\n onSubmit({\n isShippingValid: shippingState.isValid,\n setIsShippingSubmitting: shippingState.updateIsSubmitting,\n isBillingValid: billingState.isValid,\n setIsBillingSubmitting: billingState.updateIsSubmitting,\n isPaymentValid: paymentState.isValid,\n setIsPaymentSubmitting: paymentState.updateIsSubmitting,\n loanInfo: paymentState.loanInfo,\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 loanInfo?: OrderLoanInfoDTO\n}\n\ntype Props = {\n children: any\n defaultStep: CheckoutFormStepsEnum\n errorLabels: CheckoutFormErrorLabelsType\n withPersistBeforePageLeave: boolean\n countryCode?: string\n onSubmit: (data: CheckoutFormOnSubmitData) => void\n onError: (error: any) => void\n onSuccess: (order: OrderDTO) => void\n\n redirectTimeout?: number\n onBeforeRedirect?: () => void\n\n customState?: CheckoutCustomState\n\n enableSavedAddressList: boolean\n shippingValidations?: ShippingValidationsType\n enableSaveAddress: boolean\n autofillShippingPersonalData: boolean\n autoSelectDefaultShippingAddress: boolean\n\n enableSaveBillingAddress: boolean\n validateBillingAddress?: BillingAddressValidationType\n enableSavedBillingAddressList: boolean\n autoSelectDefaultBillingAddress: boolean\n\n paymentEnabledOnStep?: CheckoutFormStepsEnum\n getPaymentMethodsWhenShippingMethodIsSelected?: boolean\n\n shippingEnabledOnStep: CheckoutFormStepsEnum\n\n billingEnabledOnStep: CheckoutFormStepsEnum\n\n isBoricaInDevMode?: boolean\n\n withPixelMeta?: boolean\n requiredFieldsOnShippingStep?: string[]\n requiredFieldsOnBillingAddressStep?: string[]\n enableNoShippingMethodMode?: boolean\n disablePaymentRedirects?: boolean\n}\n\ntype ServerErrors = { [key: string]: any } | null\n\nexport enum CheckoutFormStepsEnum {\n Basket = 'Basket',\n Shipping = 'Shipping',\n BillingAddress = 'BillingAddress',\n Payment = 'Payment',\n Preview = 'Preview',\n All = 'All',\n}\n\nexport type CheckoutFormErrorsResultType =\n | {\n [key: string]: string\n }\n | null\n | undefined\n\nexport type ShippingFormErrorLabels = {\n fieldIsRequired: string\n fillStreetNumberBuildingEntranceOrApartment: string\n streetIsRequired: string\n invalidPhoneNumber?: string\n quarterIsRequired: string\n cantFindStreetOrQuarterMessage: string\n cityIsRequired: string\n emailIsRequired: string\n officeIsRequired: string\n selectCourier: string\n noStoreSelected: string\n}\n\nexport type CheckoutFormErrorLabelsType = ShippingFormErrorLabels & {\n selectPaymentMethod: string\n}\n\nexport type CheckoutFormContextType = {\n setStep: (step: CheckoutFormStepsEnum) => void\n step: CheckoutFormStepsEnum\n serverErrors: ServerErrors\n updateServerErrors: (errors: any) => void\n errorRef: (error: HTMLElement) => void\n errorFields: HTMLElement[]\n errorLabels: CheckoutFormErrorLabelsType\n orderQuery: QueryResult<OrderDTO, unknown>\n shippingState: UseShippingResultType\n paymentState: UsePaymentResultType\n billingState: UseBillingResultType\n}\n\nexport const useCheckoutFormStep = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormStep must be used within a CheckoutFormContextProvider'\n )\n }\n\n return useMemo(() => {\n return {\n currentStep: context.step,\n updateStep: context.setStep,\n }\n }, [context])\n}\n\nexport const useCheckoutFormOrder = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormOrder must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.orderQuery\n}\n\nexport const useCheckoutFormErrorLabels = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormErrorLabels must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.errorLabels\n}\n\nexport const useCheckoutFormServerErrors = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormServerErrors must be used within a CheckoutFormContextProvider'\n )\n }\n\n return useMemo(() => {\n return {\n serverErrors: context.serverErrors,\n updateServerErrors: context.updateServerErrors,\n }\n }, [context])\n}\n\nexport const useCheckoutFormBillingState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormBillingState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.billingState\n}\n\nexport const useCheckoutFormShippingState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormShippingState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.shippingState\n}\n\nexport const useCheckoutErrorFields = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutErrorFields must be used within a CheckoutFormContextProvider'\n )\n }\n\n return {\n errorFields: context.errorFields,\n errorRef: context.errorRef,\n }\n}\n\nexport const useCheckoutFormPaymentState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormPaymentState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.paymentState\n}\n"],"file":"index.js"}
|
1
|
+
{"version":3,"sources":["../../../../src/contexts/CheckoutForm/index.tsx"],"names":["CheckoutFormContext","CheckoutFormContextProvider","children","defaultStep","errorLabels","enableSavedAddressList","withPersistBeforePageLeave","shippingValidations","defaultShippingValidations","validateBillingAddress","genericBillingAddressValidation","enableSaveBillingAddress","enableSavedBillingAddressList","countryCode","enableSaveAddress","autofillShippingPersonalData","onSubmit","paymentEnabledOnStep","getPaymentMethodsWhenShippingMethodIsSelected","shippingEnabledOnStep","billingEnabledOnStep","customState","initialCustomState","redirectTimeout","onBeforeRedirect","onSuccess","onError","isBoricaInDevMode","withPixelMeta","requiredFieldsOnShippingStep","requiredFieldsOnBillingAddressStep","enableNoShippingMethodMode","disablePaymentRedirects","orderQuery","myCartApi","useGet","boricaData","setBoricaData","uniCreditData","setUniCreditData","step","setStep","isRedirecting","setIsRedirecting","fieldsWithError","serverErrors","setServerErrors","collectFieldsWithError","error","push","handleStepChange","newStep","window","scrollTo","updateServerErrors","errors","formattedErrors","reduce","data","code","response","internalError","isAuthenticated","isShippingEnabled","userQuery","usersApi","enabled","shippingState","Boolean","validations","requiredFields","mod","getIsPaymentMethodsEnabled","moduleKey","moduleData","methodKey","paymentState","billingState","withSavedBillingAddressList","requiredFieldsOnShipping","onBeforeBoricaRedirect","setTimeout","onBeforePaypalRedirect","location","replace","redirectUrl","onBeforeUniCreditRedirect","withMeta","handleCheckoutSubmit","scrollToFirstError","interval","setInterval","errorElement","top","clearInterval","handleSubmit","e","preventDefault","Promise","all","persistShippingAddress","persistBillingAddress","isShippingValid","isValid","setIsShippingSubmitting","updateIsSubmitting","isBillingValid","setIsBillingSubmitting","isPaymentValid","setIsPaymentSubmitting","loanInfo","updateStep","saveOrder","shippingAddress","setLoanInfo","state","errorRef","errorFields","CheckoutFormStepsEnum","useCheckoutFormStep","context","Error","currentStep","useCheckoutFormOrder","useCheckoutFormErrorLabels","useCheckoutFormServerErrors","useCheckoutFormBillingState","useCheckoutFormShippingState","useCheckoutErrorFields","useCheckoutFormPaymentState"],"mappings":";;;;;;;;;;;;;;;;AAAA;;AAOA;;AAUA;;AACA;;AAQA;;AACA;;AAEA;;AAMA;;AACA;;AACA;;AAKA;;AACA;;AAEO,IAAMA,mBAAmB,gBAAG,0BACjC,EADiC,CAA5B;;;AAMA,SAASC,2BAAT,OAyCG;AAAA,MAxCRC,QAwCQ,QAxCRA,QAwCQ;AAAA,MAvCRC,WAuCQ,QAvCRA,WAuCQ;AAAA,MAtCRC,WAsCQ,QAtCRA,WAsCQ;AAAA,MArCRC,sBAqCQ,QArCRA,sBAqCQ;AAAA,MApCRC,0BAoCQ,QApCRA,0BAoCQ;AAAA,mCAnCRC,mBAmCQ;AAAA,MAnCRA,mBAmCQ,sCAnCcC,iCAmCd;AAAA,mCAlCRC,sBAkCQ;AAAA,MAlCRA,sBAkCQ,sCAlCiBC,sCAkCjB;AAAA,MAjCRC,wBAiCQ,QAjCRA,wBAiCQ;AAAA,MAhCRC,6BAgCQ,QAhCRA,6BAgCQ;AAAA,MA/BRC,WA+BQ,QA/BRA,WA+BQ;AAAA,MA9BRC,iBA8BQ,QA9BRA,iBA8BQ;AAAA,MA7BRC,4BA6BQ,QA7BRA,4BA6BQ;AAAA,MA5BRC,QA4BQ,QA5BRA,QA4BQ;AAAA,MA1BRC,oBA0BQ,QA1BRA,oBA0BQ;AAAA,MAzBRC,6CAyBQ,QAzBRA,6CAyBQ;AAAA,MAxBRC,qBAwBQ,QAxBRA,qBAwBQ;AAAA,MAvBRC,oBAuBQ,QAvBRA,oBAuBQ;AAAA,8BArBRC,WAqBQ;AAAA,MArBKC,kBAqBL,iC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AN;AAGD;;AAED,SAAOD,OAAO,CAACrD,aAAf;AACD,CAVM;;;;AAYA,IAAM6D,sBAAsB,GAAG,SAAzBA,sBAAyB,GAAM;AAC1C,MAAMR,OAAO,GAAG,uBAAWxH,mBAAX,CAAhB;;AAEA,MAAI,CAACwH,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;;;;AAeA,IAAMa,2BAA2B,GAAG,SAA9BA,2BAA8B,GAAM;AAC/C,MAAMT,OAAO,GAAG,uBAAWxH,mBAAX,CAAhB;;AAEA,MAAI,CAACwH,OAAL,EAAc;AACZ,UAAM,IAAIC,KAAJ,CACJ,+EADI,CAAN;AAGD;;AAED,SAAOD,OAAO,CAAC5C,YAAf;AACD,CAVM","sourcesContent":["import React, {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useState,\n} from 'react'\nimport {\n BoricaGeneratePaymentDataResponse,\n OrderDTO,\n AddressDTO,\n PaypalGeneratePaymentUrlResponseDTO,\n OrderLoanInfoDTO,\n MyCartSetLoanInfo,\n UniCreditSessionStartResponseDTO,\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 {\n CheckoutFormCustomStateProvider,\n BoricaRedirect,\n UniCreditRedirect,\n} from './Components'\nimport { useScrollTo } from '../../hooks/ui-hooks'\nimport { getElementOffset } from '../../utils/getElementOffset'\n\nexport const CheckoutFormContext = createContext<CheckoutFormContextType>(\n {} as any\n)\n\nexport type CheckoutCustomState = {}\n\nexport function CheckoutFormContextProvider({\n children,\n defaultStep,\n errorLabels,\n enableSavedAddressList,\n withPersistBeforePageLeave,\n shippingValidations = defaultShippingValidations,\n validateBillingAddress = genericBillingAddressValidation,\n enableSaveBillingAddress,\n enableSavedBillingAddressList,\n countryCode,\n enableSaveAddress,\n autofillShippingPersonalData,\n onSubmit,\n\n paymentEnabledOnStep,\n getPaymentMethodsWhenShippingMethodIsSelected,\n shippingEnabledOnStep,\n billingEnabledOnStep,\n\n customState: initialCustomState = {},\n redirectTimeout = 420,\n onBeforeRedirect,\n onSuccess,\n onError,\n isBoricaInDevMode,\n withPixelMeta = false,\n requiredFieldsOnShippingStep = [\n 'firstName',\n 'lastName',\n 'email',\n 'phoneNumber',\n ],\n requiredFieldsOnBillingAddressStep = [\n 'vatId',\n 'companyId',\n 'companyPerson',\n 'companyName',\n ],\n enableNoShippingMethodMode = false,\n disablePaymentRedirects = false,\n}: Props) {\n const orderQuery = myCartApi.useGet()\n const [\n boricaData,\n setBoricaData,\n ] = useState<BoricaGeneratePaymentDataResponse | null>(null)\n const [\n uniCreditData,\n setUniCreditData,\n ] = useState<UniCreditSessionStartResponseDTO | null>(null)\n const [step, setStep] = useState<CheckoutFormStepsEnum>(defaultStep)\n const [isRedirecting, setIsRedirecting] = useState(false)\n\n const fieldsWithError: HTMLElement[] = []\n\n const [serverErrors, setServerErrors] = useState<ServerErrors>(null)\n\n const collectFieldsWithError = (error: HTMLElement) => {\n fieldsWithError.push(error)\n }\n\n const handleStepChange = useCallback((newStep: CheckoutFormStepsEnum) => {\n window.scrollTo(0, 0)\n\n setStep(newStep)\n }, [])\n\n const updateServerErrors = useCallback((errors: any[]) => {\n // Example Error\n // [{\n // code: \"OutOfStock\"\n // message: \"Some of the ordered line items are out of stock at the time of placing the order.\"\n // responses: {\n // availableQuantity: 1\n // sku: \"200000095849\"\n // status: \"unavailable\"\n // }\n // }]\n const formattedErrors = errors?.reduce?.(\n (data: ServerErrors, error: any) => {\n return {\n ...data,\n [error?.code || 'internal']: error?.response,\n }\n },\n {}\n )\n setServerErrors(formattedErrors || { internalError: errors })\n }, [])\n\n const { isAuthenticated } = useIsAuthenticated()\n\n const isShippingEnabled = shippingEnabledOnStep === step\n\n const userQuery = usersApi.useGet(\n {},\n { enabled: isShippingEnabled && autofillShippingPersonalData }\n )\n\n const shippingState = useShipping({\n errorLabels,\n orderQuery,\n enableSavedAddressList: Boolean(isAuthenticated && enableSavedAddressList),\n enableSaveAddress: Boolean(isAuthenticated && enableSaveAddress),\n withPersistBeforePageLeave: !isRedirecting && withPersistBeforePageLeave,\n validations: shippingValidations,\n autofillShippingPersonalData: Boolean(\n isAuthenticated && autofillShippingPersonalData\n ),\n userQuery,\n enabled: isShippingEnabled,\n countryCode,\n requiredFields: requiredFieldsOnShippingStep,\n enableNoShippingMethodMode,\n })\n const mod = useCheckoutShippingModule(orderQuery, !enableNoShippingMethodMode)\n\n const getIsPaymentMethodsEnabled = () => {\n if (paymentEnabledOnStep) {\n return paymentEnabledOnStep === step\n }\n\n if (\n !enableNoShippingMethodMode &&\n getPaymentMethodsWhenShippingMethodIsSelected\n ) {\n return Boolean(mod?.moduleKey && mod?.moduleData.methodKey)\n }\n\n return false\n }\n\n const paymentState = usePayment({\n errorLabels,\n orderQuery,\n enabled: getIsPaymentMethodsEnabled(),\n })\n\n const billingState = useBilling({\n errorLabels,\n orderQuery,\n validateBillingAddress,\n enableSaveBillingAddress: Boolean(\n isAuthenticated && enableSaveBillingAddress\n ),\n withSavedBillingAddressList: Boolean(\n isAuthenticated && enableSavedBillingAddressList\n ),\n withPersistBeforePageLeave: !isRedirecting && withPersistBeforePageLeave,\n countryCode,\n enabled: billingEnabledOnStep === step,\n requiredFields: requiredFieldsOnBillingAddressStep,\n requiredFieldsOnShipping: requiredFieldsOnShippingStep,\n })\n\n const onBeforeBoricaRedirect = (data: BoricaGeneratePaymentDataResponse) => {\n if (disablePaymentRedirects) return\n\n onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n setBoricaData(data)\n }, redirectTimeout)\n }\n\n const onBeforePaypalRedirect = (\n data: PaypalGeneratePaymentUrlResponseDTO\n ) => {\n if (disablePaymentRedirects) return\n\n onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n window.location.replace(data.redirectUrl)\n }, redirectTimeout)\n }\n const onBeforeUniCreditRedirect = (\n data: UniCreditSessionStartResponseDTO\n ) => {\n if (disablePaymentRedirects) return\n\n onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n setUniCreditData(data)\n }, redirectTimeout)\n }\n\n const { handleCheckoutSubmit } = useCheckoutSubmit({\n onBeforeBoricaRedirect,\n onBeforePaypalRedirect,\n onBeforeUniCreditRedirect,\n onSuccess,\n onError: (errors: any) => {\n updateServerErrors(errors)\n onError(errors)\n },\n withMeta: withPixelMeta,\n disablePaymentRedirects,\n })\n\n const { scrollTo } = useScrollTo(fieldsWithError[0], 0)\n\n const scrollToFirstError = () => {\n const interval = setInterval(() => {\n const errorElement = fieldsWithError[0]\n if (!errorElement) return\n\n scrollTo(getElementOffset(errorElement).top - 100)\n clearInterval(interval)\n }, 50)\n\n setTimeout(() => {\n clearInterval(interval)\n }, 1000)\n }\n\n const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n\n await Promise.all([\n shippingState.persistShippingAddress(),\n billingState.persistBillingAddress(),\n ]).catch(() => {})\n\n onSubmit({\n isShippingValid: shippingState.isValid,\n setIsShippingSubmitting: shippingState.updateIsSubmitting,\n isBillingValid: billingState.isValid,\n setIsBillingSubmitting: billingState.updateIsSubmitting,\n isPaymentValid: paymentState.isValid,\n setIsPaymentSubmitting: paymentState.updateIsSubmitting,\n loanInfo: paymentState.loanInfo,\n step,\n updateStep: setStep,\n saveOrder: handleCheckoutSubmit,\n updateServerErrors,\n scrollToFirstError,\n shippingState,\n shippingAddress: shippingState.data,\n setLoanInfo: async (loanInfo: OrderLoanInfoDTO) =>\n await MyCartSetLoanInfo(loanInfo),\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 {!!uniCreditData && (\n <UniCreditRedirect\n isInDevMode={isBoricaInDevMode}\n formData={uniCreditData}\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 loanInfo?: OrderLoanInfoDTO\n setLoanInfo?: (loanInfo: OrderLoanInfoDTO) => Promise<OrderDTO>\n}\n\ntype Props = {\n children: any\n defaultStep: CheckoutFormStepsEnum\n errorLabels: CheckoutFormErrorLabelsType\n withPersistBeforePageLeave: boolean\n countryCode?: string\n onSubmit: (data: CheckoutFormOnSubmitData) => void\n onError: (error: any) => void\n onSuccess: (order: OrderDTO) => void\n\n redirectTimeout?: number\n onBeforeRedirect?: () => void\n\n customState?: CheckoutCustomState\n\n enableSavedAddressList: boolean\n shippingValidations?: ShippingValidationsType\n enableSaveAddress: boolean\n autofillShippingPersonalData: boolean\n autoSelectDefaultShippingAddress: boolean\n\n enableSaveBillingAddress: boolean\n validateBillingAddress?: BillingAddressValidationType\n enableSavedBillingAddressList: boolean\n autoSelectDefaultBillingAddress: boolean\n\n paymentEnabledOnStep?: CheckoutFormStepsEnum\n getPaymentMethodsWhenShippingMethodIsSelected?: boolean\n\n shippingEnabledOnStep: CheckoutFormStepsEnum\n\n billingEnabledOnStep: CheckoutFormStepsEnum\n\n isBoricaInDevMode?: boolean\n\n withPixelMeta?: boolean\n requiredFieldsOnShippingStep?: string[]\n requiredFieldsOnBillingAddressStep?: string[]\n enableNoShippingMethodMode?: boolean\n disablePaymentRedirects?: boolean\n}\n\ntype ServerErrors = { [key: string]: any } | null\n\nexport enum CheckoutFormStepsEnum {\n Basket = 'Basket',\n Shipping = 'Shipping',\n BillingAddress = 'BillingAddress',\n Payment = 'Payment',\n Preview = 'Preview',\n All = 'All',\n}\n\nexport type CheckoutFormErrorsResultType =\n | {\n [key: string]: string\n }\n | null\n | undefined\n\nexport type ShippingFormErrorLabels = {\n fieldIsRequired: string\n fillStreetNumberBuildingEntranceOrApartment: string\n streetIsRequired: string\n invalidPhoneNumber?: string\n quarterIsRequired: string\n cantFindStreetOrQuarterMessage: string\n cityIsRequired: string\n emailIsRequired: string\n officeIsRequired: string\n selectCourier: string\n noStoreSelected: string\n}\n\nexport type CheckoutFormErrorLabelsType = ShippingFormErrorLabels & {\n selectPaymentMethod: string\n}\n\nexport type CheckoutFormContextType = {\n setStep: (step: CheckoutFormStepsEnum) => void\n step: CheckoutFormStepsEnum\n serverErrors: ServerErrors\n updateServerErrors: (errors: any) => void\n errorRef: (error: HTMLElement) => void\n errorFields: HTMLElement[]\n errorLabels: CheckoutFormErrorLabelsType\n orderQuery: QueryResult<OrderDTO, unknown>\n shippingState: UseShippingResultType\n paymentState: UsePaymentResultType\n billingState: UseBillingResultType\n}\n\nexport const useCheckoutFormStep = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormStep must be used within a CheckoutFormContextProvider'\n )\n }\n\n return useMemo(() => {\n return {\n currentStep: context.step,\n updateStep: context.setStep,\n }\n }, [context])\n}\n\nexport const useCheckoutFormOrder = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormOrder must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.orderQuery\n}\n\nexport const useCheckoutFormErrorLabels = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormErrorLabels must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.errorLabels\n}\n\nexport const useCheckoutFormServerErrors = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormServerErrors must be used within a CheckoutFormContextProvider'\n )\n }\n\n return useMemo(() => {\n return {\n serverErrors: context.serverErrors,\n updateServerErrors: context.updateServerErrors,\n }\n }, [context])\n}\n\nexport const useCheckoutFormBillingState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormBillingState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.billingState\n}\n\nexport const useCheckoutFormShippingState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormShippingState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.shippingState\n}\n\nexport const useCheckoutErrorFields = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutErrorFields must be used within a CheckoutFormContextProvider'\n )\n }\n\n return {\n errorFields: context.errorFields,\n errorRef: context.errorRef,\n }\n}\n\nexport const useCheckoutFormPaymentState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormPaymentState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.paymentState\n}\n"],"file":"index.js"}
|
@@ -49,11 +49,7 @@ var useOrder = function useOrder(_ref) {
|
|
49
49
|
platformPaymentMethod: {
|
50
50
|
id: platform == null ? void 0 : platform._id,
|
51
51
|
key: platform == null ? void 0 : platform.moduleKey,
|
52
|
-
type: platform == null ? void 0 : platform.type
|
53
|
-
name: (0, _index.getTranslatableField)(platform == null ? void 0 : platform.name),
|
54
|
-
description: (0, _index.getTranslatableField)(platform == null ? void 0 : platform.description),
|
55
|
-
currencyCode: platform == null ? void 0 : platform.currencyCode,
|
56
|
-
countryCode: platform == null ? void 0 : platform.countryCode
|
52
|
+
type: platform == null ? void 0 : platform.type
|
57
53
|
},
|
58
54
|
shippingMethod: {
|
59
55
|
isOffice: isShippingMethodOffice,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../src/hooks/order-hooks/useOrder/index.ts"],"names":["useOrder","data","id","orderQuery","myOrdersApi","useGetById","order","result","React","useMemo","shipping","shippings","parcels","deliveries","isShippingMethodOffice","Boolean","shippingAddress","moduleData","address","office","platform","payments","orderData","lineItems","lineItemsCount","status","orderRefNumber","createdAt","discountCodes","mapDiscountCodes","customLineItems","map","customLineItem","name","paymentStatus","platformPaymentMethod","_id","key","moduleKey","type","
|
1
|
+
{"version":3,"sources":["../../../../../src/hooks/order-hooks/useOrder/index.ts"],"names":["useOrder","data","id","orderQuery","myOrdersApi","useGetById","order","result","React","useMemo","shipping","shippings","parcels","deliveries","isShippingMethodOffice","Boolean","shippingAddress","moduleData","address","office","platform","payments","orderData","lineItems","lineItemsCount","status","orderRefNumber","createdAt","discountCodes","mapDiscountCodes","customLineItems","map","customLineItem","name","paymentStatus","platformPaymentMethod","_id","key","moduleKey","type","shippingMethod","isOffice","isAddress","billingAddress","trackingData","mapTrackingData","parcel","courierName","provider","trackingId","trackingUrl","providerMeta","trackUrl","codes","codeNames","filter","code","discountCode","resource","value"],"mappings":";;;;;;;;;AAAA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AAtB,qBAAE,sBAAkCI,QAD1C;AAELC,MAAAA,UAAU,EAAEH,MAAF,2CAAEA,MAAM,CAAE7B,UAAV,8CAAE,oBAAoB2B,YAAtB,qBAAE,sBAAkCK,UAFzC;AAGLC,MAAAA,WAAW,EAAEJ,MAAF,2CAAEA,MAAM,CAAE7B,UAAV,8CAAE,oBAAoBkC,YAAtB,qBAAE,sBAAkCC;AAH1C,KAAP;AAKD,GAND,MAMM,EAPR;AASD;;AAED,SAASvB,gBAAT,CAA0BwB,KAA1B,EAAyD;AACvD,MAAMC,SAAS,GAAGD,KAAH,oBAAGA,KAAK,CAAEE,MAAP,CAAc,UAACC,IAAD;AAAA,WAAUA,IAAI,CAAC/B,MAAL,KAAgB,UAA1B;AAAA,GAAd,CAAlB;AAEA,SAAO6B,SAAP,oBAAOA,SAAS,CAAEvB,GAAX,CAAe,UAACyB,IAAD,EAAU;AAC9B,WAAOA,IAAI,CAACC,YAAL,CAAkBC,QAAlB,CAA2BzB,IAA3B,CAAgC,CAAhC,EAAmC0B,KAA1C;AACD,GAFM,CAAP;AAGD","sourcesContent":["import React from 'react'\nimport {\n DiscountCodeInfoDTO,\n LineItemDTO,\n OrderDTO,\n OrderDTOStatusEnum,\n ShippingDeliveryParcelDTO,\n CustomLineItemDTO,\n AddressDTO,\n PaymentStatusUpdateDTOStatusEnum,\n PaymentDTOTypeEnum,\n PaymentMethodDTOTypeEnum,\n} from '@sentecacommerce/sdk'\n\nimport {\n getTranslatableField,\n MappedPlatformPaymentMethodDTO,\n} from '../../../index'\nimport { myOrdersApi } from '../../../api/myOrdersApi'\n\nexport { PaymentStatusUpdateDTOStatusEnum }\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 paymentStatus: PaymentStatusUpdateDTOStatusEnum\n trackingData: TrackingProp[]\n customLineItems?: MappedCustomLineItemDTO[]\n shippingAddress: AddressDTO\n billingAddress?: AddressDTO\n platformPaymentMethod: MappedPlatformPaymentMethodDTO\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 platform = order?.payments?.[0]\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 paymentStatus: (platform?.status as unknown) as PaymentStatusUpdateDTOStatusEnum,\n platformPaymentMethod: {\n id: platform?._id as string,\n key: platform?.moduleKey as string,\n type: platform?.type as any,\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 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../src/hooks/order-hooks/useOrderPaymentMethods/index.tsx"],"names":["useOrderPaymentMethods","orderId","queryKey","queryData","data","platform","platformPaymentMethods","map","id","_id","key","type","moduleKey","name","description","currencyCode","countryCode","merchant","merchantsPaymentMethods","methods","flat","merchantPaymentMethods"],"mappings":";;;;;;;;;;;;;AACA;;AAIA;;AACA;;AAgBO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAyB,OAAsC;AAAA,MAAnCC,OAAmC,QAAnCA,OAAmC;AAC1E,MAAMC,QAAQ,GAAG,wBAAiB,qBAAjB,EAAwCD,OAAxC,CAAjB;AAEA,MAAME,SAAS,GAAG,0BAChBD,QADgB,6FAEhB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB,oCAA0BD,OAA1B,CAAlB;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAFgB,GAAlB;AAKA,MAAMG,IAAI,GAAGD,SAAS,CAACC,IAAvB;AAEA,MAAMC,QAEO,GAAGD,IAAH,oBAAGA,IAAI,CAAEE,sBAAN,CAA6BC,GAA7B,CAAiC,UAACF,QAAD;AAAA,WAAe;AAC9DG,MAAAA,EAAE,EAAEH,QAAQ,CAACI,GADiD;AAE9DC,MAAAA,GAAG,EAAEL,QAAQ,CAACK,GAFgD;AAG9DC,MAAAA,IAAI,EAAEN,QAAQ,CAACM,IAH+C;AAI9DC,MAAAA,SAAS,EAAEP,QAAF,oBAAEA,QAAQ,CAAEO,SAJyC;AAK9DC,MAAAA,IAAI,EAAE,4BAAqBR,QAAQ,CAACQ,IAA9B,CALwD;AAM9DC,MAAAA,WAAW,EAAE,4BAAqBT,QAAQ,CAACS,WAA9B,CANiD;AAO9DC,MAAAA,YAAY,EAAEV,QAAQ,CAACU,YAPuC;AAQ9DC,MAAAA,WAAW,EAAEX,QAAQ,CAACW;AARwC,KAAf;AAAA,GAAjC,CAFhB;AAaA,MAAMC,QAEO,GAAGb,IAAH,oBAAGA,IAAI,CAAEc,uBAAN,CACbX,GADa,CACT;AAAA,QAAGY,OAAH,SAAGA,OAAH;AAAA,WACHA,OAAO,CACJZ,GADH,CACO,UAACU,QAAD;AAAA,aAAe;AAClBT,QAAAA,EAAE,EAAES,QAAQ,CAACR,GADK;AAElBC,QAAAA,GAAG,EAAEO,QAAQ,CAACP,GAFI;AAGlBC,QAAAA,IAAI,EAAEM,QAAQ,CAACN,IAHG;AAIlBC,QAAAA,SAAS,EAAEK,QAAF,oBAAEA,QAAQ,CAAEL,SAJH;AAKlBC,QAAAA,IAAI,EAAE,4BAAqBI,QAAQ,CAACJ,IAA9B,CALY;AAMlBC,QAAAA,WAAW,EAAE,4BAAqBG,QAAQ,CAACH,WAA9B,CANK;AAOlBE,QAAAA,WAAW,EAAEC,QAAQ,CAACD,WAPJ;AAQlBD,QAAAA,YAAY,EAAEE,QAAQ,CAACF;AARL,OAAf;AAAA,KADP,EAWGK,IAXH,EADG;AAAA,GADS,EAebA,IAfa,EAFhB;AAmBA,uCACKjB,SADL;AAEEC,IAAAA,IAAI,EAAE;AACJE,MAAAA,sBAAsB,EAAED,QADpB;AAEJgB,MAAAA,sBAAsB,EAAEJ;AAFpB;AAFR;AAOD,CAjDM","sourcesContent":["import React from 'react'\nimport {\n MyOrdersGetPaymentMethods,\n PaymentMethodDTOTypeEnum,\n} from '@sentecacommerce/sdk'\nimport { useQuery } from 'react-query'\nimport { generateQueryKey, getTranslatableField } from '../../../'\n\nexport interface MappedPlatformPaymentMethodDTO {\n id: string\n key: string\n type: PaymentMethodDTOTypeEnum\n moduleKey?: string\n name
|
1
|
+
{"version":3,"sources":["../../../../../src/hooks/order-hooks/useOrderPaymentMethods/index.tsx"],"names":["useOrderPaymentMethods","orderId","queryKey","queryData","data","platform","platformPaymentMethods","map","id","_id","key","type","moduleKey","name","description","currencyCode","countryCode","merchant","merchantsPaymentMethods","methods","flat","merchantPaymentMethods"],"mappings":";;;;;;;;;;;;;AACA;;AAIA;;AACA;;AAgBO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAyB,OAAsC;AAAA,MAAnCC,OAAmC,QAAnCA,OAAmC;AAC1E,MAAMC,QAAQ,GAAG,wBAAiB,qBAAjB,EAAwCD,OAAxC,CAAjB;AAEA,MAAME,SAAS,GAAG,0BAChBD,QADgB,6FAEhB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB,oCAA0BD,OAA1B,CAAlB;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAFgB,GAAlB;AAKA,MAAMG,IAAI,GAAGD,SAAS,CAACC,IAAvB;AAEA,MAAMC,QAEO,GAAGD,IAAH,oBAAGA,IAAI,CAAEE,sBAAN,CAA6BC,GAA7B,CAAiC,UAACF,QAAD;AAAA,WAAe;AAC9DG,MAAAA,EAAE,EAAEH,QAAQ,CAACI,GADiD;AAE9DC,MAAAA,GAAG,EAAEL,QAAQ,CAACK,GAFgD;AAG9DC,MAAAA,IAAI,EAAEN,QAAQ,CAACM,IAH+C;AAI9DC,MAAAA,SAAS,EAAEP,QAAF,oBAAEA,QAAQ,CAAEO,SAJyC;AAK9DC,MAAAA,IAAI,EAAE,4BAAqBR,QAAQ,CAACQ,IAA9B,CALwD;AAM9DC,MAAAA,WAAW,EAAE,4BAAqBT,QAAQ,CAACS,WAA9B,CANiD;AAO9DC,MAAAA,YAAY,EAAEV,QAAQ,CAACU,YAPuC;AAQ9DC,MAAAA,WAAW,EAAEX,QAAQ,CAACW;AARwC,KAAf;AAAA,GAAjC,CAFhB;AAaA,MAAMC,QAEO,GAAGb,IAAH,oBAAGA,IAAI,CAAEc,uBAAN,CACbX,GADa,CACT;AAAA,QAAGY,OAAH,SAAGA,OAAH;AAAA,WACHA,OAAO,CACJZ,GADH,CACO,UAACU,QAAD;AAAA,aAAe;AAClBT,QAAAA,EAAE,EAAES,QAAQ,CAACR,GADK;AAElBC,QAAAA,GAAG,EAAEO,QAAQ,CAACP,GAFI;AAGlBC,QAAAA,IAAI,EAAEM,QAAQ,CAACN,IAHG;AAIlBC,QAAAA,SAAS,EAAEK,QAAF,oBAAEA,QAAQ,CAAEL,SAJH;AAKlBC,QAAAA,IAAI,EAAE,4BAAqBI,QAAQ,CAACJ,IAA9B,CALY;AAMlBC,QAAAA,WAAW,EAAE,4BAAqBG,QAAQ,CAACH,WAA9B,CANK;AAOlBE,QAAAA,WAAW,EAAEC,QAAQ,CAACD,WAPJ;AAQlBD,QAAAA,YAAY,EAAEE,QAAQ,CAACF;AARL,OAAf;AAAA,KADP,EAWGK,IAXH,EADG;AAAA,GADS,EAebA,IAfa,EAFhB;AAmBA,uCACKjB,SADL;AAEEC,IAAAA,IAAI,EAAE;AACJE,MAAAA,sBAAsB,EAAED,QADpB;AAEJgB,MAAAA,sBAAsB,EAAEJ;AAFpB;AAFR;AAOD,CAjDM","sourcesContent":["import React from 'react'\nimport {\n MyOrdersGetPaymentMethods,\n PaymentMethodDTOTypeEnum,\n} from '@sentecacommerce/sdk'\nimport { useQuery } from 'react-query'\nimport { generateQueryKey, getTranslatableField } from '../../../'\n\nexport interface MappedPlatformPaymentMethodDTO {\n id: string\n key: string\n type: PaymentMethodDTOTypeEnum\n moduleKey?: string\n name?: string\n description?: string\n currencyCode?: string\n countryCode?: string\n}\n\nexport interface MappedMerchantPaymentMethodDTO\n extends MappedPlatformPaymentMethodDTO {}\n\nexport const useOrderPaymentMethods = ({ orderId }: { orderId: string }) => {\n const queryKey = generateQueryKey('orderPaymentMethods', orderId)\n\n const queryData = useQuery(\n queryKey,\n async () => await MyOrdersGetPaymentMethods(orderId)\n )\n\n const data = queryData.data\n\n const platform:\n | MappedPlatformPaymentMethodDTO[]\n | undefined = data?.platformPaymentMethods.map((platform) => ({\n id: platform._id,\n key: platform.key,\n type: platform.type,\n moduleKey: platform?.moduleKey,\n name: getTranslatableField(platform.name),\n description: getTranslatableField(platform.description),\n currencyCode: platform.currencyCode,\n countryCode: platform.countryCode,\n }))\n\n const merchant:\n | MappedMerchantPaymentMethodDTO[]\n | undefined = data?.merchantsPaymentMethods\n .map(({ methods }) =>\n methods\n .map((merchant) => ({\n id: merchant._id,\n key: merchant.key,\n type: merchant.type,\n moduleKey: merchant?.moduleKey,\n name: getTranslatableField(merchant.name),\n description: getTranslatableField(merchant.description),\n countryCode: merchant.countryCode,\n currencyCode: merchant.currencyCode,\n }))\n .flat()\n )\n .flat() as MappedMerchantPaymentMethodDTO[]\n\n return {\n ...queryData,\n data: {\n platformPaymentMethods: platform,\n merchantPaymentMethods: merchant,\n },\n }\n}\n"],"file":"index.js"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../src/hooks/order-hooks/useUpdateOrderPaymentMethod/index.ts"],"names":["useUpdateOrderPaymentMethod","orderId","method","onSuccess","onError","payMyOrder","resourceId","id","resourceType","IdReferenceDTOResourceTypeEnum","Payment","orderData","paymentDto","payments","_id","payment","type","key","moduleKey"],"mappings":";;;;;;;;;;;AACA;;AACA;;AAIA;;AAMO,IAAMA,2BAA2B,GAAG,SAA9BA,2BAA8B,OAUrC;AAAA,MATJC,OASI,QATJA,OASI;AAAA,MARJC,MAQI,QARJA,MAQI;AAAA,4BAPJC,SAOI;AAAA,MAPJA,SAOI,+BAPQ,YAAM,CAAE,CAOhB;AAAA,0BANJC,OAMI;AAAA,MANJA,OAMI,6BANM,YAAM,CAAE,CAMd;;AAAA,qBACiB,oBADjB;AAAA,MACGC,UADH;;AAGJ,SAAO,yHACL;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAC0B,2CAAiCJ,OAAjC,EAA0C;AAChEC,cAAAA,MAAM,EAAE;AACNI,gBAAAA,UAAU,EAAEJ,MAAM,CAACK,EADb;AAENC,gBAAAA,YAAY,EAAEC,oCAA+BC;AAFvC;AADwD,aAA1C,CAD1B;;AAAA;AACQC,YAAAA,SADR;AAQQC,YAAAA,UARR,0BAQqBD,SAAS,CAACE,QAR/B,qBAQqB,oBAAqB,CAArB,CARrB;AAAA,6CAUSR,UAAU,CAAC;AAChBJ,cAAAA,OAAO,EAAEU,SAAS,CAACG,GADH;AAEhBC,cAAAA,OAAO,EAAE;AACPR,gBAAAA,EAAE,EAAEK,UAAU,CAACE,GADR;AAEPE,gBAAAA,IAAI,EAAEJ,UAAU,CAACI,IAFV;AAGPC,gBAAAA,GAAG,EAAEL,UAAU,CAACM;AAHT;AAFO,aAAD,CAVnB;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GADK,IAoBL;AACEf,IAAAA,SAAS,EAATA,SADF;AAEEC,IAAAA,OAAO,EAAPA;AAFF,GApBK,CAAP;AAyBD,CAtCM","sourcesContent":["import React from 'react'\nimport { useMutation } from 'react-query'\nimport {\n IdReferenceDTOResourceTypeEnum,\n MyOrdersSetPlatformPaymentMethod,\n} from '@sentecacommerce/sdk'\nimport {\n MappedPlatformPaymentMethodDTO,\n MappedMerchantPaymentMethodDTO,\n usePayOrder,\n} from '../../../'\n\nexport const useUpdateOrderPaymentMethod = ({\n orderId,\n method,\n onSuccess = () => {},\n onError = () => {},\n}: {\n orderId: string\n method: MappedPlatformPaymentMethodDTO | MappedMerchantPaymentMethodDTO\n onSuccess?: (data?: unknown) => void\n onError?: (error?: unknown) => void\n}) => {\n const [payMyOrder] = usePayOrder()\n\n return useMutation(\n async () => {\n const orderData = await MyOrdersSetPlatformPaymentMethod(orderId, {\n method: {\n resourceId: method.id,\n resourceType: IdReferenceDTOResourceTypeEnum.Payment,\n },\n })\n\n const paymentDto = orderData.payments?.[0]\n\n return payMyOrder({\n orderId: orderData._id,\n payment: {\n id: paymentDto._id,\n type: paymentDto.type,\n key: paymentDto.moduleKey,\n },\n })\n },\n {\n onSuccess,\n onError,\n }\n )\n}\n"],"file":"index.js"}
|
1
|
+
{"version":3,"sources":["../../../../../src/hooks/order-hooks/useUpdateOrderPaymentMethod/index.ts"],"names":["useUpdateOrderPaymentMethod","orderId","method","onSuccess","onError","payMyOrder","resourceId","id","resourceType","IdReferenceDTOResourceTypeEnum","Payment","orderData","paymentDto","payments","_id","payment","type","key","moduleKey"],"mappings":";;;;;;;;;;;AACA;;AACA;;AAIA;;AAMO,IAAMA,2BAA2B,GAAG,SAA9BA,2BAA8B,OAUrC;AAAA,MATJC,OASI,QATJA,OASI;AAAA,MARJC,MAQI,QARJA,MAQI;AAAA,4BAPJC,SAOI;AAAA,MAPJA,SAOI,+BAPQ,YAAM,CAAE,CAOhB;AAAA,0BANJC,OAMI;AAAA,MANJA,OAMI,6BANM,YAAM,CAAE,CAMd;;AAAA,qBACiB,oBADjB;AAAA,MACGC,UADH;;AAGJ,SAAO,yHACL;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAC0B,2CAAiCJ,OAAjC,EAA0C;AAChEC,cAAAA,MAAM,EAAE;AACNI,gBAAAA,UAAU,EAAEJ,MAAM,CAACK,EADb;AAENC,gBAAAA,YAAY,EAAEC,oCAA+BC;AAFvC;AADwD,aAA1C,CAD1B;;AAAA;AACQC,YAAAA,SADR;AAQQC,YAAAA,UARR,0BAQqBD,SAAS,CAACE,QAR/B,qBAQqB,oBAAqB,CAArB,CARrB;AAAA,6CAUSR,UAAU,CAAC;AAChBJ,cAAAA,OAAO,EAAEU,SAAS,CAACG,GADH;AAEhBC,cAAAA,OAAO,EAAE;AACPR,gBAAAA,EAAE,EAAEK,UAAU,CAACE,GADR;AAEPE,gBAAAA,IAAI,EAAEJ,UAAU,CAACI,IAFV;AAGPC,gBAAAA,GAAG,EAAEL,UAAU,CAACM;AAHT;AAFO,aAAD,CAVnB;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GADK,IAoBL;AACEf,IAAAA,SAAS,EAATA,SADF;AAEEC,IAAAA,OAAO,EAAPA;AAFF,GApBK,CAAP;AAyBD,CAtCM","sourcesContent":["import React from 'react'\nimport { useMutation } from 'react-query'\nimport {\n IdReferenceDTOResourceTypeEnum,\n MyOrdersSetPlatformPaymentMethod,\n} from '@sentecacommerce/sdk'\nimport {\n MappedPlatformPaymentMethodDTO,\n MappedMerchantPaymentMethodDTO,\n usePayOrder,\n} from '../../../'\n\nexport const useUpdateOrderPaymentMethod = ({\n orderId,\n method,\n onSuccess = () => {},\n onError = () => {},\n}: {\n orderId: string\n method: MappedPlatformPaymentMethodDTO | MappedMerchantPaymentMethodDTO\n onSuccess?: (data?: unknown) => void\n onError?: (error?: unknown) => void\n}) => {\n const [payMyOrder] = usePayOrder()\n\n return useMutation(\n async () => {\n const orderData = await MyOrdersSetPlatformPaymentMethod(orderId, {\n method: {\n resourceId: method.id,\n resourceType: IdReferenceDTOResourceTypeEnum.Payment,\n },\n })\n\n const paymentDto = orderData.payments?.[0]\n\n return payMyOrder({\n orderId: orderData._id,\n payment: {\n id: paymentDto._id,\n type: paymentDto.type as any,\n key: paymentDto.moduleKey as string,\n },\n })\n },\n {\n onSuccess,\n onError,\n }\n )\n}\n"],"file":"index.js"}
|
@@ -57,7 +57,7 @@ var useAllSubscriptions = function useAllSubscriptions(_ref) {
|
|
57
57
|
}
|
58
58
|
}, [isAllFetching, allSubs]);
|
59
59
|
var mySubscriptions = (0, _react.useMemo)(function () {
|
60
|
-
if (!isFetching) {
|
60
|
+
if (!isFetching && Boolean(userSubs == null ? void 0 : userSubs.length)) {
|
61
61
|
return userSubs == null ? void 0 : userSubs.reduce(function (res, curr) {
|
62
62
|
var _extends3;
|
63
63
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../src/hooks/subscriptions-hooks/useAllSubscriptions/index.ts"],"names":["useAllSubscriptions","onSubscribeCallback","onUnsubscribeCallback","tag","allSubs","data","isAllFetching","isFetching","userSubs","onSuccess","subscribe","subscribeError","error","subscribeLoading","isLoading","unsubscribe","unsubscribeError","unsubscribeLoading","allSubscriptions","reduce","res","curr","key","label","description","isRequired","id","_id","mySubscriptions","consentKey","checkedSubs","Object","keys","checkedSubsState","setCheckedSubsState","clickSub","sub","requiredSubs","filter","checkRequiredSubs","some","checkSubscription","handleClick","acc","acceptChecked","email","consentKeys","el"],"mappings":";;;;;;;;;AAAA;;AACA;;AAOA;;AAEO,IAAMA,mBAAmB,GAAG,SAAtBA,mBAAsB,OAQ7B;AAAA,MAPJC,mBAOI,QAPJA,mBAOI;AAAA,MANJC,qBAMI,QANJA,qBAMI;AAAA,MALJC,GAKI,QALJA,GAKI;;AAAA,8BACiD,kCACnDA,GADmD,CADjD;AAAA,MACUC,OADV,yBACIC,IADJ;AAAA,MAC+BC,aAD/B,yBACmBC,UADnB;;AAAA,yBAImC,6BAJnC;AAAA,MAIUC,QAJV,oBAIIH,IAJJ;AAAA,MAIoBE,UAJpB,oBAIoBA,UAJpB;;AAAA,sBAQA,yBAAa;AACfE,IAAAA,SAAS,EAAER;AADI,GAAb,CARA;AAAA,MAMFS,SANE;AAAA;AAAA,MAOOC,cAPP,kBAOAC,KAPA;AAAA,MAOkCC,gBAPlC,kBAOuBC,SAPvB;;AAAA,wBAcA,2BAAe;AACjBL,IAAAA,SAAS,EAAEP;AADM,GAAf,CAdA;AAAA,MAYFa,WAZE;AAAA;AAAA,MAaOC,gBAbP,oBAaAJ,KAbA;AAAA,MAaoCK,kBAbpC,oBAayBH,SAbzB;;AAkBJ,MAAMI,gBAAgB,GAAG,oBAAQ,YAAM;AACrC,QAAI,CAACZ,aAAL,EAAoB;AAClB,aAAOF,OAAP,oBAAOA,OAAO,CAAEe,MAAT,CACL,UAACC,GAAD,EAAMC,IAAN;AAAA;;AAAA,6CACKD,GADL,6BAEGC,IAAI,CAACC,GAFR,IAEc;AACVC,UAAAA,KAAK,EAAE,iCAAqBF,IAAI,CAACE,KAA1B,CADG;AAEVC,UAAAA,WAAW,EAAE,iCAAqBH,IAAI,CAACG,WAA1B,CAFH;AAGVC,UAAAA,UAAU,EAAEJ,IAAI,CAACI,UAHP;AAIVC,UAAAA,EAAE,EAAEL,IAAI,CAACM;AAJC,SAFd;AAAA,OADK,EAUL,EAVK,CAAP;AAYD;AACF,GAfwB,EAetB,CAACrB,aAAD,EAAgBF,OAAhB,CAfsB,CAAzB;AAiBA,MAAMwB,eAAe,GAAG,oBAAQ,YAAM;AACpC,QAAI,CAACrB,
|
1
|
+
{"version":3,"sources":["../../../../../src/hooks/subscriptions-hooks/useAllSubscriptions/index.ts"],"names":["useAllSubscriptions","onSubscribeCallback","onUnsubscribeCallback","tag","allSubs","data","isAllFetching","isFetching","userSubs","onSuccess","subscribe","subscribeError","error","subscribeLoading","isLoading","unsubscribe","unsubscribeError","unsubscribeLoading","allSubscriptions","reduce","res","curr","key","label","description","isRequired","id","_id","mySubscriptions","Boolean","length","consentKey","checkedSubs","Object","keys","checkedSubsState","setCheckedSubsState","clickSub","sub","requiredSubs","filter","checkRequiredSubs","some","checkSubscription","handleClick","acc","acceptChecked","email","consentKeys","el"],"mappings":";;;;;;;;;AAAA;;AACA;;AAOA;;AAEO,IAAMA,mBAAmB,GAAG,SAAtBA,mBAAsB,OAQ7B;AAAA,MAPJC,mBAOI,QAPJA,mBAOI;AAAA,MANJC,qBAMI,QANJA,qBAMI;AAAA,MALJC,GAKI,QALJA,GAKI;;AAAA,8BACiD,kCACnDA,GADmD,CADjD;AAAA,MACUC,OADV,yBACIC,IADJ;AAAA,MAC+BC,aAD/B,yBACmBC,UADnB;;AAAA,yBAImC,6BAJnC;AAAA,MAIUC,QAJV,oBAIIH,IAJJ;AAAA,MAIoBE,UAJpB,oBAIoBA,UAJpB;;AAAA,sBAQA,yBAAa;AACfE,IAAAA,SAAS,EAAER;AADI,GAAb,CARA;AAAA,MAMFS,SANE;AAAA;AAAA,MAOOC,cAPP,kBAOAC,KAPA;AAAA,MAOkCC,gBAPlC,kBAOuBC,SAPvB;;AAAA,wBAcA,2BAAe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K;AAULF,IAAAA,YAAY,EAAZA,YAVK;AAWLzB,IAAAA,SAAS,EAAED,gBAAgB,IAAII,kBAX1B;AAYL6B,IAAAA,aAAa,EAAbA;AAZK,GAAP;AAcD,CA9IM","sourcesContent":["import { useMemo, useState, useCallback } from 'react'\nimport {\n useSubscriptionsByTag,\n useSubscription,\n useSubscribe,\n useUnsubscribe,\n useBulkSubscribe,\n} from '../index'\nimport { getTranslatableField } from '../../../utils'\n\nexport const useAllSubscriptions = ({\n onSubscribeCallback,\n onUnsubscribeCallback,\n tag,\n}: {\n onSubscribeCallback?: () => void\n onUnsubscribeCallback?: () => void\n tag: string\n}) => {\n const { data: allSubs, isFetching: isAllFetching } = useSubscriptionsByTag(\n tag\n )\n const { data: userSubs, isFetching } = useSubscription()\n const [\n subscribe,\n { error: subscribeError, isLoading: subscribeLoading },\n ] = useSubscribe({\n onSuccess: onSubscribeCallback,\n })\n const [\n unsubscribe,\n { error: unsubscribeError, isLoading: unsubscribeLoading },\n ] = useUnsubscribe({\n onSuccess: onUnsubscribeCallback,\n })\n\n const allSubscriptions = useMemo(() => {\n if (!isAllFetching) {\n return allSubs?.reduce(\n (res, curr) => ({\n ...res,\n [curr.key]: {\n label: getTranslatableField(curr.label),\n description: getTranslatableField(curr.description),\n isRequired: curr.isRequired,\n id: curr._id,\n },\n }),\n {}\n )\n }\n }, [isAllFetching, allSubs])\n\n const mySubscriptions = useMemo(() => {\n if (!isFetching && Boolean(userSubs?.length)) {\n return userSubs?.reduce(\n (res, curr) => ({\n ...res,\n [curr.consentKey]: curr.consentKey,\n }),\n {}\n )\n }\n }, [userSubs, isFetching])\n\n const checkedSubs = useMemo(() => {\n if (!isAllFetching && allSubscriptions) {\n return Object.keys(allSubscriptions).reduce(\n (res, curr) => ({\n ...res,\n [curr]: false,\n }),\n {}\n )\n }\n }, [allSubscriptions, isAllFetching])\n\n const [checkedSubsState, setCheckedSubsState] = useState(checkedSubs)\n\n const clickSub = useCallback(\n (sub: string) => {\n if (checkedSubs) {\n checkedSubs[sub] = !checkedSubs[sub]\n setCheckedSubsState(\n Object.keys(checkedSubs).reduce(\n (res, curr) => ({\n ...res,\n [curr]: checkedSubs[curr],\n }),\n {}\n )\n )\n }\n },\n [checkedSubs]\n )\n\n const requiredSubs = useMemo(() => {\n return Object.keys(allSubscriptions || {}).filter(\n (sub) => allSubscriptions?.[sub].isRequired\n )\n }, [allSubscriptions])\n\n const checkRequiredSubs = useCallback(() => {\n return !requiredSubs.some((sub) => !checkedSubs?.[sub])\n }, [checkedSubs, requiredSubs])\n\n const checkSubscription = useCallback(\n (key: string): boolean => {\n return key === mySubscriptions?.[key]\n },\n [mySubscriptions]\n )\n\n const handleClick = useCallback(\n (key: string) => {\n if (checkSubscription(key)) {\n return unsubscribe({ consentKey: key })\n }\n subscribe({ consentKey: key })\n },\n [checkSubscription, subscribe, unsubscribe]\n )\n\n const [acc] = useBulkSubscribe({})\n\n const acceptChecked = useCallback(\n (email: string) => {\n acc({\n email: email,\n consentKeys: Object.keys(checkedSubs || {}).filter(\n (el) => checkedSubs?.[el] === true\n ),\n })\n },\n [acc, checkedSubs]\n )\n\n return {\n isAllFetching,\n allSubscriptions,\n checkSubscription,\n handleClick,\n subscribeError,\n unsubscribeError,\n checkedSubs,\n clickSub,\n checkRequiredSubs,\n requiredSubs,\n isLoading: subscribeLoading || unsubscribeLoading,\n acceptChecked,\n }\n}\n"],"file":"index.js"}
|
@@ -21,6 +21,7 @@ var useCheckoutSubmit = function useCheckoutSubmit(_ref) {
|
|
21
21
|
var onSuccess = _ref.onSuccess,
|
22
22
|
onBeforeBoricaRedirect = _ref.onBeforeBoricaRedirect,
|
23
23
|
onBeforePaypalRedirect = _ref.onBeforePaypalRedirect,
|
24
|
+
onBeforeUniCreditRedirect = _ref.onBeforeUniCreditRedirect,
|
24
25
|
onError = _ref.onError,
|
25
26
|
withMeta = _ref.withMeta,
|
26
27
|
disablePaymentRedirects = _ref.disablePaymentRedirects;
|
@@ -29,7 +30,7 @@ var useCheckoutSubmit = function useCheckoutSubmit(_ref) {
|
|
29
30
|
|
30
31
|
var _myOrdersApi$useCreat = _.myOrdersApi.useCreate(withMeta ? districtMeta : {}, /*#__PURE__*/function () {
|
31
32
|
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(result) {
|
32
|
-
var paypalPayment, boricaPayment, boricaResult, paypalResponse;
|
33
|
+
var paypalPayment, boricaPayment, uniCreditPayment, boricaResult, paypalResponse, uniCreditStartSessionResponse;
|
33
34
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
34
35
|
while (1) {
|
35
36
|
switch (_context.prev = _context.next) {
|
@@ -37,56 +38,76 @@ var useCheckoutSubmit = function useCheckoutSubmit(_ref) {
|
|
37
38
|
// Analytics
|
38
39
|
(0, _purchase.purchase)(result, Config);
|
39
40
|
paypalPayment = result.payments.find(function (payment) {
|
40
|
-
return payment.type === _sdk.
|
41
|
+
return payment.type === _sdk.PaymentDTOTypeEnum.PaymentServiceProvider && payment.moduleKey === 'Paypal';
|
41
42
|
});
|
42
43
|
boricaPayment = result.payments.find(function (payment) {
|
43
|
-
return payment.type === _sdk.
|
44
|
+
return payment.type === _sdk.PaymentDTOTypeEnum.PaymentServiceProvider && payment.moduleKey === 'Borica';
|
45
|
+
});
|
46
|
+
uniCreditPayment = result.payments.find(function (payment) {
|
47
|
+
return payment.type === _sdk.PaymentDTOTypeEnum.PaymentServiceProvider && payment.moduleKey === 'UniCredit';
|
44
48
|
});
|
45
49
|
|
46
50
|
if (!disablePaymentRedirects) {
|
47
|
-
_context.next =
|
51
|
+
_context.next = 6;
|
48
52
|
break;
|
49
53
|
}
|
50
54
|
|
51
55
|
return _context.abrupt("return", onSuccess == null ? void 0 : onSuccess(result));
|
52
56
|
|
53
|
-
case
|
57
|
+
case 6:
|
54
58
|
if (!boricaPayment) {
|
55
|
-
_context.next =
|
59
|
+
_context.next = 13;
|
56
60
|
break;
|
57
61
|
}
|
58
62
|
|
59
|
-
_context.next =
|
63
|
+
_context.next = 9;
|
60
64
|
return _.myPaymentsBoricaApi.pay({
|
61
65
|
orderId: result._id,
|
62
66
|
paymentId: boricaPayment._id
|
63
67
|
});
|
64
68
|
|
65
|
-
case
|
69
|
+
case 9:
|
66
70
|
boricaResult = _context.sent;
|
67
71
|
onBeforeBoricaRedirect == null ? void 0 : onBeforeBoricaRedirect(boricaResult);
|
68
|
-
_context.next =
|
72
|
+
_context.next = 28;
|
69
73
|
break;
|
70
74
|
|
71
|
-
case
|
75
|
+
case 13:
|
72
76
|
if (!paypalPayment) {
|
73
|
-
_context.next =
|
77
|
+
_context.next = 20;
|
74
78
|
break;
|
75
79
|
}
|
76
80
|
|
77
|
-
_context.next =
|
81
|
+
_context.next = 16;
|
78
82
|
return (0, _sdk.MyPaymentsPaypalPayMyOrder)(result._id, paypalPayment._id);
|
79
83
|
|
80
|
-
case
|
84
|
+
case 16:
|
81
85
|
paypalResponse = _context.sent;
|
82
86
|
onBeforePaypalRedirect == null ? void 0 : onBeforePaypalRedirect(paypalResponse);
|
83
|
-
_context.next =
|
87
|
+
_context.next = 28;
|
88
|
+
break;
|
89
|
+
|
90
|
+
case 20:
|
91
|
+
if (!uniCreditPayment) {
|
92
|
+
_context.next = 27;
|
93
|
+
break;
|
94
|
+
}
|
95
|
+
|
96
|
+
_context.next = 23;
|
97
|
+
return (0, _sdk.MyPaymentsUnicreditStartSession)({}, {
|
98
|
+
orderId: result._id
|
99
|
+
});
|
100
|
+
|
101
|
+
case 23:
|
102
|
+
uniCreditStartSessionResponse = _context.sent;
|
103
|
+
onBeforeUniCreditRedirect == null ? void 0 : onBeforeUniCreditRedirect(uniCreditStartSessionResponse);
|
104
|
+
_context.next = 28;
|
84
105
|
break;
|
85
106
|
|
86
|
-
case
|
107
|
+
case 27:
|
87
108
|
onSuccess == null ? void 0 : onSuccess(result);
|
88
109
|
|
89
|
-
case
|
110
|
+
case 28:
|
90
111
|
case "end":
|
91
112
|
return _context.stop();
|
92
113
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/hooks/useCheckoutSubmit/index.ts"],"names":["useCheckoutSubmit","onSuccess","onBeforeBoricaRedirect","onBeforePaypalRedirect","onError","withMeta","disablePaymentRedirects","Config","districtMeta","myOrdersApi","useCreate","result","paypalPayment","payments","find","payment","type","
|
1
|
+
{"version":3,"sources":["../../../../src/hooks/useCheckoutSubmit/index.ts"],"names":["useCheckoutSubmit","onSuccess","onBeforeBoricaRedirect","onBeforePaypalRedirect","onBeforeUniCreditRedirect","onError","withMeta","disablePaymentRedirects","Config","districtMeta","myOrdersApi","useCreate","result","paypalPayment","payments","find","payment","type","PaymentDTOTypeEnum","PaymentServiceProvider","moduleKey","boricaPayment","uniCreditPayment","myPaymentsBoricaApi","pay","orderId","_id","paymentId","boricaResult","paypalResponse","uniCreditStartSessionResponse","handleCheckoutSubmit"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAQA;;AACA;;AAEO,IAAMA,iBAAiB,GAAG,SAApBA,iBAAoB,OAkB3B;AAAA,MAjBJC,SAiBI,QAjBJA,SAiBI;AAAA,MAhBJC,sBAgBI,QAhBJA,sBAgBI;AAAA,MAfJC,sBAeI,QAfJA,sBAeI;AAAA,MAdJC,yBAcI,QAdJA,yBAcI;AAAA,MAbJC,OAaI,QAbJA,OAaI;AAAA,MAZJC,QAYI,QAZJA,QAYI;AAAA,MAXJC,uBAWI,QAXJA,uBAWI;AACJ,MAAMC,MAAM,GAAG,gCAAf;AAEA,MAAMC,YAAY,GAAG,wBAArB;;AAHI,8BAK2BC,cAAYC,SAAZ,CAC7BL,QAAQ,GAAGG,YAAH,GAAkB,EADG;AAAA,8FAE7B,iBAAOG,MAAP;AAAA;AAAA;AAAA;AAAA;AAAA;AACE;AACA,sCAASA,MAAT,EAAiBJ,MAAjB;AAEMK,cAAAA,aAJR,GAIwBD,MAAM,CAACE,QAAP,CAAgBC,IAAhB,CACpB,UAACC,OAAD;AAAA,uBACEA,OAAO,CAAC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CgD,0CAC1C,EAD0C,EAE1C;AAAEG,gBAAAA,OAAO,EAAEb,MAAM,CAACc;AAAlB,eAF0C,CAtChD;;AAAA;AAsCUI,cAAAA,6BAtCV;AA2CI1B,cAAAA,yBAAyB,QAAzB,YAAAA,yBAAyB,CAAG0B,6BAAH,CAAzB;AA3CJ;AAAA;;AAAA;AA6CI7B,cAAAA,SAAS,QAAT,YAAAA,SAAS,CAAGW,MAAH,CAAT;;AA7CJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAF6B;;AAAA;AAAA;AAAA;AAAA,OAkD7BP,OAlD6B,CAL3B;AAAA,MAKG0B,oBALH;;AA0DJ,SAAO;AACLA,IAAAA,oBAAoB,EAApBA;AADK,GAAP;AAGD,CA/EM","sourcesContent":["import { myOrdersApi, myPaymentsBoricaApi, useDistrictMeta } from '../../'\nimport {\n BoricaGeneratePaymentDataResponse,\n OrderDTO,\n MyPaymentsPaypalPayMyOrder,\n MyPaymentsUnicreditStartSession,\n PaymentDTOTypeEnum,\n UniCreditSessionStartResponseDTO,\n} from '@sentecacommerce/sdk'\nimport { useConfigState } from '../useConfig'\nimport { purchase } from '../../analytics/purchase'\n\nexport const useCheckoutSubmit = ({\n onSuccess,\n onBeforeBoricaRedirect,\n onBeforePaypalRedirect,\n onBeforeUniCreditRedirect,\n onError,\n withMeta,\n disablePaymentRedirects,\n}: {\n onSuccess?: (result: OrderDTO) => void\n onBeforeBoricaRedirect?: (formData: BoricaGeneratePaymentDataResponse) => void\n onBeforeUniCreditRedirect?: (\n formData: UniCreditSessionStartResponseDTO\n ) => void\n onError?: (error: any) => void\n withMeta?: boolean\n onBeforePaypalRedirect: any\n disablePaymentRedirects: boolean\n}) => {\n const Config = useConfigState()\n\n const districtMeta = useDistrictMeta()\n\n const [handleCheckoutSubmit] = myOrdersApi.useCreate(\n withMeta ? districtMeta : {},\n async (result: OrderDTO) => {\n // Analytics\n purchase(result, Config)\n\n const paypalPayment = result.payments.find(\n (payment) =>\n payment.type === PaymentDTOTypeEnum.PaymentServiceProvider &&\n payment.moduleKey === 'Paypal'\n )\n\n const boricaPayment = result.payments.find(\n (payment) =>\n payment.type === PaymentDTOTypeEnum.PaymentServiceProvider &&\n payment.moduleKey === 'Borica'\n )\n\n const uniCreditPayment = result.payments.find(\n (payment) =>\n payment.type === PaymentDTOTypeEnum.PaymentServiceProvider &&\n payment.moduleKey === 'UniCredit'\n )\n\n if (disablePaymentRedirects) return onSuccess?.(result)\n\n if (boricaPayment) {\n const boricaResult = await myPaymentsBoricaApi.pay({\n orderId: result._id,\n paymentId: boricaPayment._id,\n })\n onBeforeBoricaRedirect?.(boricaResult)\n } else if (paypalPayment) {\n const paypalResponse = await MyPaymentsPaypalPayMyOrder(\n result._id,\n paypalPayment._id\n )\n\n onBeforePaypalRedirect?.(paypalResponse)\n } else if (uniCreditPayment) {\n const uniCreditStartSessionResponse = await MyPaymentsUnicreditStartSession(\n {},\n { orderId: result._id }\n )\n\n onBeforeUniCreditRedirect?.(uniCreditStartSessionResponse)\n } else {\n onSuccess?.(result)\n }\n },\n onError\n )\n\n return {\n handleCheckoutSubmit,\n }\n}\n"],"file":"index.js"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../src/listing/api/queries/useLabelsQuery.ts"],"names":["useLabelsQuery","labels","keys","ListingQueryKeysEnum","filter","map","el","join","limit","cacheTime"],"mappings":";;;;;;;;;;;AACA;;AACA;;AACA;;AAIO,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,OAA4C;AAAA,yBAAzCC,MAAyC;AAAA,MAAzCA,MAAyC,4BAAhC,EAAgC;AACxE,MAAMC,IAAI,IAAIC,2BAAqBH,cAAzB,SAA4CC,MAA5C,CAAV;AACA,SAAO,0BACLC,IADK,6FAEL;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA,6CACE,uBAAa;AACXE,cAAAA,MAAM,mCAAYH,MAAZ,oBAAYA,MAAM,CAAEI,GAAR,CAAY,UAACC,EAAD;AAAA,8BAAYA,EAAZ;AAAA,eAAZ,EAA+BC,IAA/B,CAAoC,GAApC,CAAZ,+BAAwD,EAAxD,CADK;AAEXC,cAAAA,KAAK,EAAE;AAFI,aAAb,CADF;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAFK,IAOL;AAAEC,IAAAA,SAAS,EAAE;
|
1
|
+
{"version":3,"sources":["../../../../../src/listing/api/queries/useLabelsQuery.ts"],"names":["useLabelsQuery","labels","keys","ListingQueryKeysEnum","filter","map","el","join","limit","cacheTime","refetchOnWindowFocus"],"mappings":";;;;;;;;;;;AACA;;AACA;;AACA;;AAIO,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,OAA4C;AAAA,yBAAzCC,MAAyC;AAAA,MAAzCA,MAAyC,4BAAhC,EAAgC;AACxE,MAAMC,IAAI,IAAIC,2BAAqBH,cAAzB,SAA4CC,MAA5C,CAAV;AACA,SAAO,0BACLC,IADK,6FAEL;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA,6CACE,uBAAa;AACXE,cAAAA,MAAM,mCAAYH,MAAZ,oBAAYA,MAAM,CAAEI,GAAR,CAAY,UAACC,EAAD;AAAA,8BAAYA,EAAZ;AAAA,eAAZ,EAA+BC,IAA/B,CAAoC,GAApC,CAAZ,+BAAwD,EAAxD,CADK;AAEXC,cAAAA,KAAK,EAAE;AAFI,aAAb,CADF;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAFK,IAOL;AAAEC,IAAAA,SAAS,EAAE,CAAb;AAAgBC,IAAAA,oBAAoB,EAAE;AAAtC,GAPK,CAAP;AASD,CAXM","sourcesContent":["import React from 'react'\nimport { LabelsFilter, LabelDTO } from '@sentecacommerce/sdk'\nimport { useQuery } from 'react-query'\nimport { ListingQueryKeysEnum } from '../keys'\n\nexport interface RawLabelType extends LabelDTO {}\n\nexport const useLabelsQuery = ({ labels = [] }: { labels?: string[] }) => {\n const keys = [ListingQueryKeysEnum.useLabelsQuery, ...labels]\n return useQuery(\n keys,\n async () =>\n LabelsFilter({\n filter: `key;in;${labels?.map((el) => `\"${el}\"`).join(',') ?? ''}`,\n limit: 20,\n }),\n { cacheTime: 0, refetchOnWindowFocus: false }\n )\n}\n"],"file":"useLabelsQuery.js"}
|
@@ -53,6 +53,8 @@ function ListingFiltersProvider(_ref) {
|
|
53
53
|
var result = aggregates == null ? void 0 : aggregates.sort(function (a, b) {
|
54
54
|
return a.order - b.order;
|
55
55
|
}).map(function (currentAggregate) {
|
56
|
+
var _listing$slugAliases$, _listing$slugAliases;
|
57
|
+
|
56
58
|
var type = currentAggregate.aggregationType.toString();
|
57
59
|
var term = currentAggregate.aggregationDefinition.split(':')[0];
|
58
60
|
var filter = currentAggregate.filterDefinition;
|
@@ -64,7 +66,7 @@ function ListingFiltersProvider(_ref) {
|
|
64
66
|
filter: filter,
|
65
67
|
router: router,
|
66
68
|
type: type,
|
67
|
-
slug: slug,
|
69
|
+
slug: (_listing$slugAliases$ = (_listing$slugAliases = config.listing.slugAliases) == null ? void 0 : _listing$slugAliases[slug]) != null ? _listing$slugAliases$ : slug,
|
68
70
|
pageType: pageType
|
69
71
|
});
|
70
72
|
var selectedCount = generatedFilters == null ? void 0 : generatedFilters.reduce(function (count, res) {
|