merchi_cart 1.3.4 → 1.3.6
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/esm/CartProvider.js +32 -19
- package/esm/forms/FormShipmentAddressAndNotes.js +48 -31
- package/esm/forms/InputsAddress.js +2 -2
- package/esm/panels/PanelEditCartItem.js +29 -14
- package/esm/stripe/StripeCardFields.js +6 -15
- package/esm/stripe/utils.js +1 -0
- package/esm/utilities/address.js +14 -0
- package/esm/utilities/helpers.js +4 -0
- package/lib/CartProvider.js +31 -18
- package/lib/forms/FormShipmentAddressAndNotes.js +47 -30
- package/lib/forms/InputsAddress.js +2 -2
- package/lib/panels/PanelEditCartItem.js +30 -14
- package/lib/stripe/StripeCardFields.js +6 -14
- package/lib/stripe/utils.js +1 -0
- package/lib/utilities/address.js +15 -0
- package/lib/utilities/helpers.js +4 -0
- package/package.json +5 -4
- package/src/CartProvider.tsx +17 -5
- package/src/components/CustomCartProductForm.tsx +123 -0
- package/src/components/product-form-sdk-externals.ts +65 -0
- package/src/forms/FormShipmentAddressAndNotes.tsx +13 -11
- package/src/forms/InputsAddress.tsx +2 -2
- package/src/panels/PanelEditCartItem.tsx +50 -27
- package/src/stripe/StripeCardFields.tsx +4 -14
- package/src/stripe/utils.ts +1 -0
- package/src/utilities/address.ts +13 -0
- package/src/utilities/customForm.ts +71 -0
- package/src/utilities/helpers.ts +2 -0
package/esm/CartProvider.js
CHANGED
|
@@ -25,7 +25,7 @@ import { cartEmbed } from './utilities/helpers';
|
|
|
25
25
|
import { initTabs, tabIdItems, tabShipment } from './utilities/tabs';
|
|
26
26
|
import { Merchi } from 'merchi_sdk_ts';
|
|
27
27
|
import { getCartCookie, getCartCookieToken, setCartCookie } from './utilities/cookie';
|
|
28
|
-
import { makeAddress } from './utilities/address';
|
|
28
|
+
import { makeAddress, sanitizeAddressFields } from './utilities/address';
|
|
29
29
|
import { appendStyleSheetText } from './utilities/helpers';
|
|
30
30
|
import { makeJob } from './utilities/job';
|
|
31
31
|
import { makeProduct } from './utilities/product';
|
|
@@ -362,7 +362,19 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
362
362
|
var tabId = nextTab.tabId,
|
|
363
363
|
tabIndexToSet = nextTab.tabIndexToSet,
|
|
364
364
|
disabled = nextTab.disabled;
|
|
365
|
-
|
|
365
|
+
setTabs(function (prev) {
|
|
366
|
+
var index = tabIndexToSet >= 0 && tabIndexToSet < prev.length ? tabIndexToSet : prev.findIndex(function (t) {
|
|
367
|
+
return t.tabId === tabId;
|
|
368
|
+
});
|
|
369
|
+
if (index < 0 || index >= prev.length) {
|
|
370
|
+
return prev;
|
|
371
|
+
}
|
|
372
|
+
var next = _toConsumableArray(prev);
|
|
373
|
+
next[index] = _objectSpread(_objectSpread({}, next[index]), {}, {
|
|
374
|
+
disabled: disabled
|
|
375
|
+
});
|
|
376
|
+
return next;
|
|
377
|
+
});
|
|
366
378
|
setActiveTabIndex(tabId);
|
|
367
379
|
}
|
|
368
380
|
var _useState11 = useState(false),
|
|
@@ -655,7 +667,7 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
655
667
|
}
|
|
656
668
|
function _updateCartShipmentAddress() {
|
|
657
669
|
_updateCartShipmentAddress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(address) {
|
|
658
|
-
var token, receiverAddress, cartEnt, _cartJson3, query, cartWithShipmentGroups;
|
|
670
|
+
var token, addressFields, receiverAddress, cartEnt, _cartJson3, query, cartWithShipmentGroups;
|
|
659
671
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
660
672
|
while (1) switch (_context6.prev = _context6.next) {
|
|
661
673
|
case 0:
|
|
@@ -663,46 +675,47 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
663
675
|
return getCartCookieToken(domainId);
|
|
664
676
|
case 2:
|
|
665
677
|
token = _context6.sent;
|
|
666
|
-
|
|
678
|
+
addressFields = sanitizeAddressFields(address);
|
|
679
|
+
receiverAddress = makeAddress(addressFields, true);
|
|
667
680
|
cartEnt = makeCart(cart, false, token);
|
|
668
681
|
setFetchingShipmentGroups(true);
|
|
669
|
-
_context6.prev =
|
|
682
|
+
_context6.prev = 7;
|
|
670
683
|
cartEnt.receiverAddress = receiverAddress;
|
|
671
|
-
_context6.next =
|
|
684
|
+
_context6.next = 11;
|
|
672
685
|
return cartEnt.save({
|
|
673
686
|
embed: cartEmbed
|
|
674
687
|
});
|
|
675
|
-
case
|
|
688
|
+
case 11:
|
|
676
689
|
cartEnt = _context6.sent;
|
|
677
690
|
_cartJson3 = cartEnt.toJson();
|
|
678
|
-
saveCheckoutAddress(domainId,
|
|
691
|
+
saveCheckoutAddress(domainId, addressFields);
|
|
679
692
|
query = [];
|
|
680
693
|
query.push(['cart_token', cart.token]);
|
|
681
|
-
_context6.next =
|
|
694
|
+
_context6.next = 18;
|
|
682
695
|
return merchi.authenticatedFetch("/generate-cart-shipment-quotes/".concat(cart.id, "/"), {
|
|
683
696
|
method: 'GET',
|
|
684
697
|
query: query
|
|
685
698
|
});
|
|
686
|
-
case
|
|
699
|
+
case 18:
|
|
687
700
|
cartWithShipmentGroups = _context6.sent;
|
|
688
701
|
setCart(_objectSpread(_objectSpread({}, _cartJson3), {}, {
|
|
689
702
|
shipmentGroups: cartWithShipmentGroups.shipmentGroups || []
|
|
690
703
|
}));
|
|
691
|
-
_context6.next =
|
|
704
|
+
_context6.next = 25;
|
|
692
705
|
break;
|
|
693
|
-
case
|
|
694
|
-
_context6.prev =
|
|
695
|
-
_context6.t0 = _context6["catch"](
|
|
706
|
+
case 22:
|
|
707
|
+
_context6.prev = 22;
|
|
708
|
+
_context6.t0 = _context6["catch"](7);
|
|
696
709
|
alertError(_context6.t0.errorMessage || _context6.t0.message || 'Unable to set address');
|
|
697
|
-
case
|
|
698
|
-
_context6.prev =
|
|
710
|
+
case 25:
|
|
711
|
+
_context6.prev = 25;
|
|
699
712
|
setFetchingShipmentGroups(false);
|
|
700
|
-
return _context6.finish(
|
|
701
|
-
case
|
|
713
|
+
return _context6.finish(25);
|
|
714
|
+
case 28:
|
|
702
715
|
case "end":
|
|
703
716
|
return _context6.stop();
|
|
704
717
|
}
|
|
705
|
-
}, _callee6, null, [[
|
|
718
|
+
}, _callee6, null, [[7, 22, 25, 28]]);
|
|
706
719
|
}));
|
|
707
720
|
return _updateCartShipmentAddress.apply(this, arguments);
|
|
708
721
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
2
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
3
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
4
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
5
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
6
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
10
7
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
10
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
11
11
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
12
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
13
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -22,7 +22,7 @@ import { faMapMarkerAlt } from "@fortawesome/free-solid-svg-icons";
|
|
|
22
22
|
import { useCartContext } from "../CartProvider";
|
|
23
23
|
import { useState } from "react";
|
|
24
24
|
import { getCartCookieToken } from "../utilities/cookie";
|
|
25
|
-
import { makeAddress } from "../utilities/address";
|
|
25
|
+
import { makeAddress, sanitizeAddressFields } from "../utilities/address";
|
|
26
26
|
import { makeCart } from "../utilities/cart";
|
|
27
27
|
import { cartEmbed } from "../utilities/helpers";
|
|
28
28
|
import { tabIdCheckout } from "../utilities/tabs";
|
|
@@ -61,7 +61,22 @@ function FormShipmentAddressAndNotes(_ref) {
|
|
|
61
61
|
register = hookForm.register,
|
|
62
62
|
reset = hookForm.reset;
|
|
63
63
|
function onSubmit() {
|
|
64
|
-
|
|
64
|
+
return _onSubmit.apply(this, arguments);
|
|
65
|
+
}
|
|
66
|
+
function _onSubmit() {
|
|
67
|
+
_onSubmit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
68
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
69
|
+
while (1) switch (_context.prev = _context.next) {
|
|
70
|
+
case 0:
|
|
71
|
+
_context.next = 2;
|
|
72
|
+
return setCartShipmentAddress(getValues());
|
|
73
|
+
case 2:
|
|
74
|
+
case "end":
|
|
75
|
+
return _context.stop();
|
|
76
|
+
}
|
|
77
|
+
}, _callee);
|
|
78
|
+
}));
|
|
79
|
+
return _onSubmit.apply(this, arguments);
|
|
65
80
|
}
|
|
66
81
|
function updateAddress(addr) {
|
|
67
82
|
var oldAddresses = getValues();
|
|
@@ -120,49 +135,51 @@ export function ActiveFormShipmentAddressAndNotes() {
|
|
|
120
135
|
return _saveCartShipmentAddressAndGoToNextTab.apply(this, arguments);
|
|
121
136
|
}
|
|
122
137
|
function _saveCartShipmentAddressAndGoToNextTab() {
|
|
123
|
-
_saveCartShipmentAddressAndGoToNextTab = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
124
|
-
var address, receiverNotes, cartToken,
|
|
125
|
-
return _regeneratorRuntime().wrap(function
|
|
126
|
-
while (1) switch (
|
|
138
|
+
_saveCartShipmentAddressAndGoToNextTab = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(values) {
|
|
139
|
+
var address, receiverNotes, cartToken, addressFields, _receiverAddress, cartEnt;
|
|
140
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
141
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
127
142
|
case 0:
|
|
128
143
|
address = values.receiverAddress, receiverNotes = values.receiverNotes;
|
|
129
|
-
_context.next = 3;
|
|
130
|
-
return getCartCookieToken(domainId);
|
|
131
|
-
case 3:
|
|
132
|
-
cartToken = _context.sent;
|
|
133
144
|
setLoadingTotals(true);
|
|
134
|
-
|
|
145
|
+
_context2.prev = 2;
|
|
146
|
+
_context2.next = 5;
|
|
147
|
+
return getCartCookieToken(domainId);
|
|
148
|
+
case 5:
|
|
149
|
+
cartToken = _context2.sent;
|
|
150
|
+
// Never PATCH an existing Address via cart token — create a fresh embed.
|
|
151
|
+
addressFields = sanitizeAddressFields(address);
|
|
152
|
+
_receiverAddress = makeAddress(addressFields, true);
|
|
135
153
|
cartEnt = makeCart(cart, false, cartToken);
|
|
136
|
-
cartEnt.receiverAddress =
|
|
154
|
+
cartEnt.receiverAddress = _receiverAddress;
|
|
137
155
|
cartEnt.receiverNotes = receiverNotes;
|
|
138
|
-
|
|
139
|
-
_context.next = 12;
|
|
156
|
+
_context2.next = 13;
|
|
140
157
|
return cartEnt.save({
|
|
141
158
|
embed: cartEmbed
|
|
142
159
|
});
|
|
143
|
-
case
|
|
144
|
-
saveCheckoutAddress(domainId,
|
|
145
|
-
setCart(cartEnt.toJson());
|
|
160
|
+
case 13:
|
|
161
|
+
saveCheckoutAddress(domainId, addressFields, receiverNotes);
|
|
162
|
+
setCart(cartEnt.toJson());
|
|
146
163
|
setActiveTabAndEditDisabled({
|
|
147
164
|
tabId: tabIdCheckout,
|
|
148
165
|
tabIndexToSet: 2,
|
|
149
166
|
disabled: false
|
|
150
167
|
});
|
|
151
|
-
|
|
168
|
+
_context2.next = 21;
|
|
152
169
|
break;
|
|
153
|
-
case
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
alertError(
|
|
157
|
-
case
|
|
158
|
-
|
|
170
|
+
case 18:
|
|
171
|
+
_context2.prev = 18;
|
|
172
|
+
_context2.t0 = _context2["catch"](2);
|
|
173
|
+
alertError(_context2.t0.errorMessage || _context2.t0.message || "Unable to set shipment address.");
|
|
174
|
+
case 21:
|
|
175
|
+
_context2.prev = 21;
|
|
159
176
|
setLoadingTotals(false);
|
|
160
|
-
return
|
|
161
|
-
case
|
|
177
|
+
return _context2.finish(21);
|
|
178
|
+
case 24:
|
|
162
179
|
case "end":
|
|
163
|
-
return
|
|
180
|
+
return _context2.stop();
|
|
164
181
|
}
|
|
165
|
-
},
|
|
182
|
+
}, _callee2, null, [[2, 18, 21, 24]]);
|
|
166
183
|
}));
|
|
167
184
|
return _saveCartShipmentAddressAndGoToNextTab.apply(this, arguments);
|
|
168
185
|
}
|
|
@@ -205,13 +205,13 @@ export function InputsAddress(_ref) {
|
|
|
205
205
|
children: addressForm
|
|
206
206
|
}), /*#__PURE__*/_jsxs("div", {
|
|
207
207
|
className: "d-flex align-items-center",
|
|
208
|
-
children: [!!errors.length && /*#__PURE__*/_jsxs("div", {
|
|
208
|
+
children: [!!Object.keys(errors || {}).length && /*#__PURE__*/_jsxs("div", {
|
|
209
209
|
className: "text-danger",
|
|
210
210
|
children: [/*#__PURE__*/_jsx(FontAwesomeIcon, {
|
|
211
211
|
icon: faExclamationTriangle
|
|
212
212
|
}), " Invalid address!"]
|
|
213
213
|
}), /*#__PURE__*/_jsxs("a", {
|
|
214
|
-
className: "ml-auto btn btn-sm btn-link ".concat(!!errors.length && 'text-danger'),
|
|
214
|
+
className: "ml-auto btn btn-sm btn-link ".concat(!!Object.keys(errors || {}).length && 'text-danger'),
|
|
215
215
|
onClick: toggleAddressFieldsOpen,
|
|
216
216
|
children: [/*#__PURE__*/_jsx(FontAwesomeIcon, {
|
|
217
217
|
icon: addressFieldsOpen ? faTimes : faEdit
|
|
@@ -23,6 +23,8 @@ import { LoadingTemplateSm } from '../components/LoadingTemplate';
|
|
|
23
23
|
import { useCartContext } from '../CartProvider';
|
|
24
24
|
import { makeCartItem } from '../utilities/cart';
|
|
25
25
|
import { getCartCookieToken } from '../utilities/cookie';
|
|
26
|
+
import { publishedFormBundle } from '../utilities/customForm';
|
|
27
|
+
import CustomCartProductForm from '../components/CustomCartProductForm';
|
|
26
28
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
27
29
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
28
30
|
var MerchiProductForm = /*#__PURE__*/lazy(function () {
|
|
@@ -76,6 +78,10 @@ function PanelEditCartItem(_ref) {
|
|
|
76
78
|
_useState2 = _slicedToArray(_useState, 2),
|
|
77
79
|
loading = _useState2[0],
|
|
78
80
|
setLoading = _useState2[1];
|
|
81
|
+
var _useState3 = useState(false),
|
|
82
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
83
|
+
customFormActive = _useState4[0],
|
|
84
|
+
setCustomFormActive = _useState4[1];
|
|
79
85
|
var formId = 'edit-cart-item-form';
|
|
80
86
|
|
|
81
87
|
// This action patches the cart item
|
|
@@ -149,27 +155,36 @@ function PanelEditCartItem(_ref) {
|
|
|
149
155
|
id: undefined
|
|
150
156
|
});
|
|
151
157
|
var showForm = activeTabIndex === tabIdItem && !!(cartItem !== null && cartItem !== void 0 && cartItem.id) && !!(cartItem !== null && cartItem !== void 0 && (_cartItem$product = cartItem.product) !== null && _cartItem$product !== void 0 && _cartItem$product.id);
|
|
158
|
+
var hasPublishedCustomForm = !!publishedFormBundle(cartItem === null || cartItem === void 0 ? void 0 : cartItem.product);
|
|
159
|
+
var defaultForm = /*#__PURE__*/_jsx(Suspense, {
|
|
160
|
+
fallback: /*#__PURE__*/_jsx(LoadingTemplateSm, {}),
|
|
161
|
+
children: /*#__PURE__*/_jsx(MerchiProductForm, _objectSpread({
|
|
162
|
+
apiUrl: apiUrl,
|
|
163
|
+
isCartItem: true,
|
|
164
|
+
initJob: _objectSpread({}, cleanCartItem),
|
|
165
|
+
initProduct: cartItem.product,
|
|
166
|
+
onSubmit: onSubmit,
|
|
167
|
+
productFormId: formId,
|
|
168
|
+
hideRequestQuotationButton: true,
|
|
169
|
+
hidePaymentUpfrontButton: true
|
|
170
|
+
}, productFormClassNames))
|
|
171
|
+
});
|
|
152
172
|
return /*#__PURE__*/_jsxs(CartTabPanel, {
|
|
153
173
|
tabId: tabIdItem,
|
|
154
174
|
children: [/*#__PURE__*/_jsx(CartBody, {
|
|
155
175
|
style: {
|
|
156
176
|
padding: '2rem'
|
|
157
177
|
},
|
|
158
|
-
children: showForm && /*#__PURE__*/_jsx(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
productFormId: formId,
|
|
167
|
-
hideRequestQuotationButton: true,
|
|
168
|
-
hidePaymentUpfrontButton: true
|
|
169
|
-
}, productFormClassNames))
|
|
170
|
-
})
|
|
178
|
+
children: showForm && (hasPublishedCustomForm ? /*#__PURE__*/_jsx(CustomCartProductForm, {
|
|
179
|
+
product: cartItem.product,
|
|
180
|
+
initialJob: cleanCartItem,
|
|
181
|
+
apiUrl: apiUrl,
|
|
182
|
+
onSave: onSubmit,
|
|
183
|
+
fallback: defaultForm,
|
|
184
|
+
onActiveChange: setCustomFormActive
|
|
185
|
+
}) : defaultForm)
|
|
171
186
|
}), /*#__PURE__*/_jsxs(CartFooter, {
|
|
172
|
-
children: [/*#__PURE__*/_jsx(ButtonBack, {}), /*#__PURE__*/_jsxs(Button, {
|
|
187
|
+
children: [/*#__PURE__*/_jsx(ButtonBack, {}), !customFormActive && /*#__PURE__*/_jsxs(Button, {
|
|
173
188
|
className: classNameBtnEditCartItem,
|
|
174
189
|
disabled: loading,
|
|
175
190
|
form: formId,
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
1
|
import * as React from "react";
|
|
8
2
|
import StripePaymentButtons from "./StripePaymentButtons";
|
|
9
|
-
import {
|
|
3
|
+
import { CardElement, Elements, useStripe, useElements } from "@stripe/react-stripe-js";
|
|
10
4
|
import { loadStripe } from "@stripe/stripe-js";
|
|
11
5
|
import { CARD_ELEMENT_OPTIONS } from "./utils";
|
|
12
6
|
import pngStripe from "../assets/stripe-payment-secure.png";
|
|
@@ -26,7 +20,7 @@ function InnerForm(_ref) {
|
|
|
26
20
|
var stripe = useStripe();
|
|
27
21
|
var elements = useElements();
|
|
28
22
|
function paymentStart(e) {
|
|
29
|
-
var card = elements.getElement(
|
|
23
|
+
var card = elements.getElement(CardElement);
|
|
30
24
|
setLoadingStripePayment(true);
|
|
31
25
|
e.preventDefault();
|
|
32
26
|
if (!stripe || !elements) {
|
|
@@ -73,13 +67,10 @@ function InnerForm(_ref) {
|
|
|
73
67
|
onSubmit: paymentStart,
|
|
74
68
|
children: /*#__PURE__*/_jsxs("div", {
|
|
75
69
|
className: "merchi-cart-stripe-input-container",
|
|
76
|
-
children: [/*#__PURE__*/_jsx(
|
|
77
|
-
className: inputClass
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}, CARD_ELEMENT_OPTIONS)), /*#__PURE__*/_jsx(CardCvcElement, _objectSpread({
|
|
81
|
-
className: inputClass
|
|
82
|
-
}, CARD_ELEMENT_OPTIONS)), error.message && /*#__PURE__*/_jsx("div", {
|
|
70
|
+
children: [/*#__PURE__*/_jsx(CardElement, {
|
|
71
|
+
className: inputClass,
|
|
72
|
+
options: CARD_ELEMENT_OPTIONS
|
|
73
|
+
}), error.message && /*#__PURE__*/_jsx("div", {
|
|
83
74
|
className: "merchi-cart-stripe-input-error",
|
|
84
75
|
children: error.message
|
|
85
76
|
}), /*#__PURE__*/_jsx(PaymentButton, {
|
package/esm/stripe/utils.js
CHANGED
package/esm/utilities/address.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
1
2
|
import { Merchi } from 'merchi_sdk_ts';
|
|
2
3
|
var merchi = new Merchi();
|
|
3
4
|
export function makeAddress(addressJson, makeDirty) {
|
|
@@ -6,6 +7,19 @@ export function makeAddress(addressJson, makeDirty) {
|
|
|
6
7
|
makeDirty: makeDirty
|
|
7
8
|
});
|
|
8
9
|
}
|
|
10
|
+
|
|
11
|
+
/** Plain address fields only — never reuse an existing address id (cart-token auth cannot PATCH it). */
|
|
12
|
+
export function sanitizeAddressFields(address) {
|
|
13
|
+
var a = address && _typeof(address) === 'object' ? address : {};
|
|
14
|
+
return {
|
|
15
|
+
city: a.city || '',
|
|
16
|
+
country: a.country || '',
|
|
17
|
+
lineOne: a.lineOne || '',
|
|
18
|
+
lineTwo: a.lineTwo || '',
|
|
19
|
+
postcode: a.postcode || '',
|
|
20
|
+
state: a.state || ''
|
|
21
|
+
};
|
|
22
|
+
}
|
|
9
23
|
var isoCountries = {
|
|
10
24
|
AF: "Afghanistan",
|
|
11
25
|
AX: "Aland Islands",
|
package/esm/utilities/helpers.js
CHANGED
|
@@ -184,6 +184,10 @@ var productWithImagesEmbed = {
|
|
|
184
184
|
linkedFile: {}
|
|
185
185
|
}
|
|
186
186
|
},
|
|
187
|
+
// Published custom form pointer for cart-item edit (same shape as product embed).
|
|
188
|
+
productForm: {
|
|
189
|
+
activeVersion: {}
|
|
190
|
+
},
|
|
187
191
|
taxType: {}
|
|
188
192
|
};
|
|
189
193
|
var cartShipmentQuote = {
|
package/lib/CartProvider.js
CHANGED
|
@@ -369,7 +369,19 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
369
369
|
var tabId = nextTab.tabId,
|
|
370
370
|
tabIndexToSet = nextTab.tabIndexToSet,
|
|
371
371
|
disabled = nextTab.disabled;
|
|
372
|
-
|
|
372
|
+
setTabs(function (prev) {
|
|
373
|
+
var index = tabIndexToSet >= 0 && tabIndexToSet < prev.length ? tabIndexToSet : prev.findIndex(function (t) {
|
|
374
|
+
return t.tabId === tabId;
|
|
375
|
+
});
|
|
376
|
+
if (index < 0 || index >= prev.length) {
|
|
377
|
+
return prev;
|
|
378
|
+
}
|
|
379
|
+
var next = _toConsumableArray(prev);
|
|
380
|
+
next[index] = _objectSpread(_objectSpread({}, next[index]), {}, {
|
|
381
|
+
disabled: disabled
|
|
382
|
+
});
|
|
383
|
+
return next;
|
|
384
|
+
});
|
|
373
385
|
setActiveTabIndex(tabId);
|
|
374
386
|
}
|
|
375
387
|
var _useState11 = (0, _react.useState)(false),
|
|
@@ -662,7 +674,7 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
662
674
|
}
|
|
663
675
|
function _updateCartShipmentAddress() {
|
|
664
676
|
_updateCartShipmentAddress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(address) {
|
|
665
|
-
var token, receiverAddress, cartEnt, _cartJson3, query, cartWithShipmentGroups;
|
|
677
|
+
var token, addressFields, receiverAddress, cartEnt, _cartJson3, query, cartWithShipmentGroups;
|
|
666
678
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
667
679
|
while (1) switch (_context6.prev = _context6.next) {
|
|
668
680
|
case 0:
|
|
@@ -670,46 +682,47 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
670
682
|
return (0, _cookie.getCartCookieToken)(domainId);
|
|
671
683
|
case 2:
|
|
672
684
|
token = _context6.sent;
|
|
673
|
-
|
|
685
|
+
addressFields = (0, _address.sanitizeAddressFields)(address);
|
|
686
|
+
receiverAddress = (0, _address.makeAddress)(addressFields, true);
|
|
674
687
|
cartEnt = (0, _cart3.makeCart)(cart, false, token);
|
|
675
688
|
setFetchingShipmentGroups(true);
|
|
676
|
-
_context6.prev =
|
|
689
|
+
_context6.prev = 7;
|
|
677
690
|
cartEnt.receiverAddress = receiverAddress;
|
|
678
|
-
_context6.next =
|
|
691
|
+
_context6.next = 11;
|
|
679
692
|
return cartEnt.save({
|
|
680
693
|
embed: _helpers.cartEmbed
|
|
681
694
|
});
|
|
682
|
-
case
|
|
695
|
+
case 11:
|
|
683
696
|
cartEnt = _context6.sent;
|
|
684
697
|
_cartJson3 = cartEnt.toJson();
|
|
685
|
-
(0, _local_storage.saveCheckoutAddress)(domainId,
|
|
698
|
+
(0, _local_storage.saveCheckoutAddress)(domainId, addressFields);
|
|
686
699
|
query = [];
|
|
687
700
|
query.push(['cart_token', cart.token]);
|
|
688
|
-
_context6.next =
|
|
701
|
+
_context6.next = 18;
|
|
689
702
|
return merchi.authenticatedFetch("/generate-cart-shipment-quotes/".concat(cart.id, "/"), {
|
|
690
703
|
method: 'GET',
|
|
691
704
|
query: query
|
|
692
705
|
});
|
|
693
|
-
case
|
|
706
|
+
case 18:
|
|
694
707
|
cartWithShipmentGroups = _context6.sent;
|
|
695
708
|
setCart(_objectSpread(_objectSpread({}, _cartJson3), {}, {
|
|
696
709
|
shipmentGroups: cartWithShipmentGroups.shipmentGroups || []
|
|
697
710
|
}));
|
|
698
|
-
_context6.next =
|
|
711
|
+
_context6.next = 25;
|
|
699
712
|
break;
|
|
700
|
-
case
|
|
701
|
-
_context6.prev =
|
|
702
|
-
_context6.t0 = _context6["catch"](
|
|
713
|
+
case 22:
|
|
714
|
+
_context6.prev = 22;
|
|
715
|
+
_context6.t0 = _context6["catch"](7);
|
|
703
716
|
alertError(_context6.t0.errorMessage || _context6.t0.message || 'Unable to set address');
|
|
704
|
-
case
|
|
705
|
-
_context6.prev =
|
|
717
|
+
case 25:
|
|
718
|
+
_context6.prev = 25;
|
|
706
719
|
setFetchingShipmentGroups(false);
|
|
707
|
-
return _context6.finish(
|
|
708
|
-
case
|
|
720
|
+
return _context6.finish(25);
|
|
721
|
+
case 28:
|
|
709
722
|
case "end":
|
|
710
723
|
return _context6.stop();
|
|
711
724
|
}
|
|
712
|
-
}, _callee6, null, [[
|
|
725
|
+
}, _callee6, null, [[7, 22, 25, 28]]);
|
|
713
726
|
}));
|
|
714
727
|
return _updateCartShipmentAddress.apply(this, arguments);
|
|
715
728
|
}
|