merchi_cart 1.3.8 → 1.3.10

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.
@@ -88,20 +88,21 @@ export function FormCustomerNew() {
88
88
  id: user.id
89
89
  }, true);
90
90
  cartEnt = makeCart(_objectSpread({}, cart), false, cartToken);
91
+ cartEnt.sendWhatsapp = false;
91
92
  cartEnt.client = clientEnt;
92
- _context.next = 17;
93
+ _context.next = 18;
93
94
  return cartEnt.save({
94
95
  embed: cartEmbed
95
96
  });
96
- case 17:
97
+ case 18:
97
98
  _cart = _context.sent;
98
99
  cartJson = _cart.toJson();
99
100
  if (cartJson !== null && cartJson !== void 0 && (_cartJson$client = cartJson.client) !== null && _cartJson$client !== void 0 && _cartJson$client.id) {
100
- _context.next = 21;
101
+ _context.next = 22;
101
102
  break;
102
103
  }
103
104
  throw new Error('Unable to attach client to cart.');
104
- case 21:
105
+ case 22:
105
106
  saveCheckoutCustomer(domainId, {
106
107
  id: user.id,
107
108
  name: customerJson.name,
@@ -110,23 +111,23 @@ export function FormCustomerNew() {
110
111
  });
111
112
  setCartClient(cartJson.client);
112
113
  setCart(cartJson);
113
- _context.next = 29;
114
+ _context.next = 30;
114
115
  break;
115
- case 26:
116
- _context.prev = 26;
116
+ case 27:
117
+ _context.prev = 27;
117
118
  _context.t0 = _context["catch"](2);
118
119
  setError({
119
120
  message: _context.t0.errorMessage || _context.t0.message || 'Unable to attach client to cart.'
120
121
  });
121
- case 29:
122
- _context.prev = 29;
122
+ case 30:
123
+ _context.prev = 30;
123
124
  setLoading(false);
124
- return _context.finish(29);
125
- case 32:
125
+ return _context.finish(30);
126
+ case 33:
126
127
  case "end":
127
128
  return _context.stop();
128
129
  }
129
- }, _callee, null, [[2, 26, 29, 32]]);
130
+ }, _callee, null, [[2, 27, 30, 33]]);
130
131
  }));
131
132
  return _actionCreateNewCustomer.apply(this, arguments);
132
133
  }
@@ -88,20 +88,21 @@ function FormReturningCustomer() {
88
88
  id: userId
89
89
  }, true);
90
90
  cartEnt = makeCart(_objectSpread({}, cart), false, cartToken);
91
+ cartEnt.sendWhatsapp = false;
91
92
  cartEnt.client = clientEnt;
92
- _context.next = 18;
93
+ _context.next = 19;
93
94
  return cartEnt.save({
94
95
  embed: cartEmbed
95
96
  });
96
- case 18:
97
+ case 19:
97
98
  _cart = _context.sent;
98
99
  cartJson = _cart.toJson();
99
100
  if (cartJson !== null && cartJson !== void 0 && (_cartJson$client = cartJson.client) !== null && _cartJson$client !== void 0 && _cartJson$client.id) {
100
- _context.next = 22;
101
+ _context.next = 23;
101
102
  break;
102
103
  }
103
104
  throw new Error('Unable to attach client to cart.');
104
- case 22:
105
+ case 23:
105
106
  saveCheckoutCustomer(domainId, {
106
107
  id: userId,
107
108
  name: user.name || (savedCustomer === null || savedCustomer === void 0 ? void 0 : savedCustomer.name),
@@ -109,24 +110,24 @@ function FormReturningCustomer() {
109
110
  });
110
111
  setCartClient(cartJson.client);
111
112
  setCart(cartJson);
112
- _context.next = 31;
113
+ _context.next = 32;
113
114
  break;
114
- case 27:
115
- _context.prev = 27;
115
+ case 28:
116
+ _context.prev = 28;
116
117
  _context.t0 = _context["catch"](3);
117
118
  alertError(_context.t0.errorMessage || _context.t0.message);
118
119
  setError({
119
120
  message: _context.t0.errorMessage || _context.t0.message || 'Server error.'
120
121
  });
121
- case 31:
122
- _context.prev = 31;
122
+ case 32:
123
+ _context.prev = 32;
123
124
  setLoading(false);
124
- return _context.finish(31);
125
- case 34:
125
+ return _context.finish(32);
126
+ case 35:
126
127
  case "end":
127
128
  return _context.stop();
128
129
  }
129
- }, _callee, null, [[3, 27, 31, 34]]);
130
+ }, _callee, null, [[3, 28, 32, 35]]);
130
131
  }));
131
132
  return _submit.apply(this, arguments);
132
133
  }
@@ -0,0 +1,255 @@
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 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; }
4
+ 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; }
5
+ 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; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ 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); }
8
+ 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); } }
9
+ 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); }); }; }
10
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
+ 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."); }
12
+ 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); }
13
+ 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; }
14
+ 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; } }
15
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
+ import * as React from 'react';
17
+ import { useForm } from 'react-hook-form';
18
+ import InputAcceptUserTermsAndConditions from './InputAcceptUserTermsAndConditions';
19
+ import { Button } from '../buttons';
20
+ import InputSelect from './InputSelect';
21
+ import InputText from './InputText';
22
+ import { useCartContext } from '../CartProvider';
23
+ import { cartEmbed, phoneOptions } from '../utilities/helpers';
24
+ import InputError from './InputError';
25
+ import { createNewCustomer, makeUser } from '../utilities/user';
26
+ import { makeCart } from '../utilities/cart';
27
+ import { getCartCookieToken } from '../utilities/cookie';
28
+ import { getSavedCheckoutCustomer, saveCheckoutCustomer } from '../utilities/local_storage';
29
+ import { emailValidation } from './FormNewCustomer';
30
+ import { jsx as _jsx } from "react/jsx-runtime";
31
+ import { jsxs as _jsxs } from "react/jsx-runtime";
32
+ function FormWhatsappCustomer() {
33
+ var _savedCustomer$phoneN, _savedCustomer$phoneN2;
34
+ var _useCartContext = useCartContext(),
35
+ cart = _useCartContext.cart,
36
+ classNameBtnPrimary = _useCartContext.classNameBtnPrimary,
37
+ classNameCartFormGroup = _useCartContext.classNameCartFormGroup,
38
+ classNameCartFormGroupButton = _useCartContext.classNameCartFormGroupButton,
39
+ domainId = _useCartContext.domainId,
40
+ setCart = _useCartContext.setCart,
41
+ setCartClient = _useCartContext.setCartClient,
42
+ showUserTermsAndConditions = _useCartContext.showUserTermsAndConditions;
43
+ var _React$useState = React.useState(false),
44
+ _React$useState2 = _slicedToArray(_React$useState, 2),
45
+ loading = _React$useState2[0],
46
+ setLoading = _React$useState2[1];
47
+ var _React$useState3 = React.useState({}),
48
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
49
+ error = _React$useState4[0],
50
+ setError = _React$useState4[1];
51
+ var _React$useState5 = React.useState(true),
52
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
53
+ acceptConditions = _React$useState6[0],
54
+ setAcceptConditions = _React$useState6[1];
55
+ var savedCustomer = getSavedCheckoutCustomer(domainId);
56
+ function actionWhatsappCheckout(_x) {
57
+ return _actionWhatsappCheckout.apply(this, arguments);
58
+ }
59
+ function _actionWhatsappCheckout() {
60
+ _actionWhatsappCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(customerJson) {
61
+ var _cartJson$client, _customerJson$emailAd, r, user, cartToken, clientEnt, cartEnt, _cart, cartJson;
62
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
63
+ while (1) switch (_context.prev = _context.next) {
64
+ case 0:
65
+ setError({});
66
+ setLoading(true);
67
+ _context.prev = 2;
68
+ _context.next = 5;
69
+ return createNewCustomer(_objectSpread(_objectSpread({}, customerJson), {}, {
70
+ registeredUnderDomains: [{
71
+ id: domainId
72
+ }]
73
+ }));
74
+ case 5:
75
+ r = _context.sent;
76
+ user = r.user;
77
+ if (user !== null && user !== void 0 && user.id) {
78
+ _context.next = 9;
79
+ break;
80
+ }
81
+ throw new Error('Unable to create customer.');
82
+ case 9:
83
+ _context.next = 11;
84
+ return getCartCookieToken(domainId);
85
+ case 11:
86
+ cartToken = _context.sent;
87
+ clientEnt = makeUser({
88
+ id: user.id
89
+ }, true);
90
+ cartEnt = makeCart(_objectSpread({}, cart), false, cartToken);
91
+ cartEnt.sendWhatsapp = true;
92
+ cartEnt.client = clientEnt;
93
+ _context.next = 18;
94
+ return cartEnt.save({
95
+ embed: cartEmbed
96
+ });
97
+ case 18:
98
+ _cart = _context.sent;
99
+ cartJson = _cart.toJson();
100
+ if (cartJson !== null && cartJson !== void 0 && (_cartJson$client = cartJson.client) !== null && _cartJson$client !== void 0 && _cartJson$client.id) {
101
+ _context.next = 22;
102
+ break;
103
+ }
104
+ throw new Error('Unable to attach client to cart.');
105
+ case 22:
106
+ saveCheckoutCustomer(domainId, {
107
+ id: user.id,
108
+ name: customerJson.name,
109
+ emailAddress: (_customerJson$emailAd = customerJson.emailAddresses) === null || _customerJson$emailAd === void 0 || (_customerJson$emailAd = _customerJson$emailAd[0]) === null || _customerJson$emailAd === void 0 ? void 0 : _customerJson$emailAd.emailAddress,
110
+ phoneNumbers: customerJson.phoneNumbers
111
+ });
112
+ setCartClient(cartJson.client);
113
+ setCart(cartJson);
114
+ _context.next = 30;
115
+ break;
116
+ case 27:
117
+ _context.prev = 27;
118
+ _context.t0 = _context["catch"](2);
119
+ setError({
120
+ message: _context.t0.errorMessage || _context.t0.message || 'Unable to attach client to cart.'
121
+ });
122
+ case 30:
123
+ _context.prev = 30;
124
+ setLoading(false);
125
+ return _context.finish(30);
126
+ case 33:
127
+ case "end":
128
+ return _context.stop();
129
+ }
130
+ }, _callee, null, [[2, 27, 30, 33]]);
131
+ }));
132
+ return _actionWhatsappCheckout.apply(this, arguments);
133
+ }
134
+ var _useForm = useForm({
135
+ defaultValues: {
136
+ emailAddresses: [{
137
+ emailAddress: (savedCustomer === null || savedCustomer === void 0 ? void 0 : savedCustomer.emailAddress) || ''
138
+ }],
139
+ name: (savedCustomer === null || savedCustomer === void 0 ? void 0 : savedCustomer.name) || '',
140
+ phoneNumbers: [{
141
+ code: (savedCustomer === null || savedCustomer === void 0 || (_savedCustomer$phoneN = savedCustomer.phoneNumbers) === null || _savedCustomer$phoneN === void 0 || (_savedCustomer$phoneN = _savedCustomer$phoneN[0]) === null || _savedCustomer$phoneN === void 0 ? void 0 : _savedCustomer$phoneN.code) || 'AU',
142
+ number: (savedCustomer === null || savedCustomer === void 0 || (_savedCustomer$phoneN2 = savedCustomer.phoneNumbers) === null || _savedCustomer$phoneN2 === void 0 || (_savedCustomer$phoneN2 = _savedCustomer$phoneN2[0]) === null || _savedCustomer$phoneN2 === void 0 ? void 0 : _savedCustomer$phoneN2.number) || ''
143
+ }]
144
+ }
145
+ }),
146
+ control = _useForm.control,
147
+ handleSubmit = _useForm.handleSubmit,
148
+ watch = _useForm.watch;
149
+ function onSubmit(_x2) {
150
+ return _onSubmit.apply(this, arguments);
151
+ }
152
+ function _onSubmit() {
153
+ _onSubmit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(values) {
154
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
155
+ while (1) switch (_context2.prev = _context2.next) {
156
+ case 0:
157
+ if (!(showUserTermsAndConditions && !acceptConditions)) {
158
+ _context2.next = 2;
159
+ break;
160
+ }
161
+ return _context2.abrupt("return");
162
+ case 2:
163
+ _context2.next = 4;
164
+ return actionWhatsappCheckout(_objectSpread({}, values));
165
+ case 4:
166
+ case "end":
167
+ return _context2.stop();
168
+ }
169
+ }, _callee2);
170
+ }));
171
+ return _onSubmit.apply(this, arguments);
172
+ }
173
+ function validatePhone() {
174
+ var phone = watch('phoneNumbers.0.number');
175
+ if (!phone) return 'Phone number is required for WhatsApp checkout';
176
+ if (isNaN(phone)) return 'Phone number must be a number';
177
+ return true;
178
+ }
179
+ return /*#__PURE__*/_jsxs("form", {
180
+ onSubmit: handleSubmit(onSubmit),
181
+ children: [/*#__PURE__*/_jsx(InputText, {
182
+ control: control,
183
+ label: "Full Name",
184
+ name: "name",
185
+ placeholder: "John Smith",
186
+ rules: {
187
+ required: 'Full name is required.'
188
+ }
189
+ }), /*#__PURE__*/_jsx(InputText, {
190
+ control: control,
191
+ label: "Email",
192
+ name: "emailAddresses[0].emailAddress",
193
+ placeholder: "john@example.com",
194
+ rules: {
195
+ required: 'Email is required.',
196
+ validate: emailValidation
197
+ }
198
+ }), /*#__PURE__*/_jsxs("div", {
199
+ style: {
200
+ display: 'flex',
201
+ gap: '1rem'
202
+ },
203
+ children: [/*#__PURE__*/_jsx("div", {
204
+ style: {
205
+ flexGrow: 1
206
+ },
207
+ children: /*#__PURE__*/_jsx(InputSelect, {
208
+ control: control,
209
+ label: "Country Code",
210
+ name: "phoneNumbers[0].code",
211
+ options: phoneOptions
212
+ })
213
+ }), /*#__PURE__*/_jsx("div", {
214
+ style: {
215
+ flexGrow: 1
216
+ },
217
+ children: /*#__PURE__*/_jsx(InputText, {
218
+ control: control,
219
+ label: "WhatsApp Number",
220
+ name: "phoneNumbers[0].number",
221
+ placeholder: "0400 000 000",
222
+ rules: {
223
+ required: 'WhatsApp number is required',
224
+ validate: validatePhone
225
+ },
226
+ type: "phone"
227
+ })
228
+ })]
229
+ }), /*#__PURE__*/_jsx("small", {
230
+ className: classNameCartFormGroup,
231
+ children: "By continuing, you agree to receive order updates via WhatsApp at this number."
232
+ }), showUserTermsAndConditions && /*#__PURE__*/_jsxs("div", {
233
+ className: classNameCartFormGroup,
234
+ children: [/*#__PURE__*/_jsx(InputAcceptUserTermsAndConditions, {
235
+ isChecked: acceptConditions,
236
+ setIsChecked: setAcceptConditions
237
+ }), !acceptConditions && /*#__PURE__*/_jsx(InputError, {
238
+ error: {
239
+ message: 'You must agree to the user profile terms and conditions to proceed.'
240
+ }
241
+ })]
242
+ }), /*#__PURE__*/_jsx(InputError, {
243
+ error: error || {}
244
+ }), /*#__PURE__*/_jsx("div", {
245
+ className: classNameCartFormGroupButton,
246
+ children: /*#__PURE__*/_jsx(Button, {
247
+ className: classNameBtnPrimary,
248
+ disabled: loading,
249
+ type: "submit",
250
+ children: loading ? 'Loading...' : 'Continue with WhatsApp'
251
+ })
252
+ })]
253
+ });
254
+ }
255
+ export default FormWhatsappCustomer;
@@ -3,4 +3,5 @@ import FormReturningCustomer from "./FormReturningCustomer";
3
3
  import FormShipmentAddressAndNotes, { ActiveFormShipmentAddressAndNotes } from "./FormShipmentAddressAndNotes";
4
4
  import FormSquarePayment from "./FormSquarePayment";
5
5
  import FormStripePayment from "./FormStripePayment";
6
- export { ActiveFormShipmentAddressAndNotes, FormCustomerNew, FormReturningCustomer, FormShipmentAddressAndNotes, FormSquarePayment, FormStripePayment };
6
+ import FormWhatsappCustomer from "./FormWhatsappCustomer";
7
+ export { ActiveFormShipmentAddressAndNotes, FormCustomerNew, FormReturningCustomer, FormShipmentAddressAndNotes, FormSquarePayment, FormStripePayment, FormWhatsappCustomer };
@@ -5,9 +5,10 @@ import CartShipment from '../components/CartShipment';
5
5
  import { CartBody, CartTabPanel, Title } from '../components';
6
6
  import FormNewCustomer from '../forms/FormNewCustomer';
7
7
  import FormReturningCustomer from '../forms/FormReturningCustomer';
8
+ import FormWhatsappCustomer from '../forms/FormWhatsappCustomer';
8
9
  import FormSquarePayment from '../forms/FormSquarePayment';
9
10
  import FormStripePayment from '../forms/FormStripePayment';
10
- import { faCoins, faCreditCard, faUserPlus, faUserTag } from '@fortawesome/free-solid-svg-icons';
11
+ import { faCoins, faCreditCard, faPhone, faUserPlus, faUserTag } from '@fortawesome/free-solid-svg-icons';
11
12
  import { useCartContext } from '../CartProvider';
12
13
  import DiscountInputGroup from '../components/DiscountInputGroup';
13
14
  import CartTotalsListGroup from '../components/CartTotalsListGroup';
@@ -23,6 +24,7 @@ function PanelClientCheckout() {
23
24
  var needsShipping = cartItemsNeedShipment(cart);
24
25
  var domain = cart.domain;
25
26
  var company = domain && domain.company;
27
+ var whatsappEnabled = Boolean(domain === null || domain === void 0 ? void 0 : domain.enableWhatsappNotifications);
26
28
  return /*#__PURE__*/_jsx(CartTabPanel, {
27
29
  tabId: tabIdCheckout,
28
30
  children: /*#__PURE__*/_jsx(CartBody, {
@@ -87,6 +89,14 @@ function PanelClientCheckout() {
87
89
  title: "Checkout as returning customer"
88
90
  }), /*#__PURE__*/_jsx(FormReturningCustomer, {})]
89
91
  })
92
+ }), whatsappEnabled && /*#__PURE__*/_jsx(CheckoutContainer, {
93
+ children: /*#__PURE__*/_jsxs(InnerContainer, {
94
+ paddingBottom: "0px",
95
+ children: [/*#__PURE__*/_jsx(Title, {
96
+ icon: faPhone,
97
+ title: "Checkout with WhatsApp"
98
+ }), /*#__PURE__*/_jsx(FormWhatsappCustomer, {})]
99
+ })
90
100
  })]
91
101
  })
92
102
  })
@@ -97,20 +97,21 @@ function FormCustomerNew() {
97
97
  id: user.id
98
98
  }, true);
99
99
  cartEnt = (0, _cart2.makeCart)(_objectSpread({}, cart), false, cartToken);
100
+ cartEnt.sendWhatsapp = false;
100
101
  cartEnt.client = clientEnt;
101
- _context.next = 17;
102
+ _context.next = 18;
102
103
  return cartEnt.save({
103
104
  embed: _helpers.cartEmbed
104
105
  });
105
- case 17:
106
+ case 18:
106
107
  _cart = _context.sent;
107
108
  cartJson = _cart.toJson();
108
109
  if (cartJson !== null && cartJson !== void 0 && (_cartJson$client = cartJson.client) !== null && _cartJson$client !== void 0 && _cartJson$client.id) {
109
- _context.next = 21;
110
+ _context.next = 22;
110
111
  break;
111
112
  }
112
113
  throw new Error('Unable to attach client to cart.');
113
- case 21:
114
+ case 22:
114
115
  (0, _local_storage.saveCheckoutCustomer)(domainId, {
115
116
  id: user.id,
116
117
  name: customerJson.name,
@@ -119,23 +120,23 @@ function FormCustomerNew() {
119
120
  });
120
121
  setCartClient(cartJson.client);
121
122
  setCart(cartJson);
122
- _context.next = 29;
123
+ _context.next = 30;
123
124
  break;
124
- case 26:
125
- _context.prev = 26;
125
+ case 27:
126
+ _context.prev = 27;
126
127
  _context.t0 = _context["catch"](2);
127
128
  setError({
128
129
  message: _context.t0.errorMessage || _context.t0.message || 'Unable to attach client to cart.'
129
130
  });
130
- case 29:
131
- _context.prev = 29;
131
+ case 30:
132
+ _context.prev = 30;
132
133
  setLoading(false);
133
- return _context.finish(29);
134
- case 32:
134
+ return _context.finish(30);
135
+ case 33:
135
136
  case "end":
136
137
  return _context.stop();
137
138
  }
138
- }, _callee, null, [[2, 26, 29, 32]]);
139
+ }, _callee, null, [[2, 27, 30, 33]]);
139
140
  }));
140
141
  return _actionCreateNewCustomer.apply(this, arguments);
141
142
  }
@@ -96,20 +96,21 @@ function FormReturningCustomer() {
96
96
  id: userId
97
97
  }, true);
98
98
  cartEnt = (0, _cart2.makeCart)(_objectSpread({}, cart), false, cartToken);
99
+ cartEnt.sendWhatsapp = false;
99
100
  cartEnt.client = clientEnt;
100
- _context.next = 18;
101
+ _context.next = 19;
101
102
  return cartEnt.save({
102
103
  embed: _helpers.cartEmbed
103
104
  });
104
- case 18:
105
+ case 19:
105
106
  _cart = _context.sent;
106
107
  cartJson = _cart.toJson();
107
108
  if (cartJson !== null && cartJson !== void 0 && (_cartJson$client = cartJson.client) !== null && _cartJson$client !== void 0 && _cartJson$client.id) {
108
- _context.next = 22;
109
+ _context.next = 23;
109
110
  break;
110
111
  }
111
112
  throw new Error('Unable to attach client to cart.');
112
- case 22:
113
+ case 23:
113
114
  (0, _local_storage.saveCheckoutCustomer)(domainId, {
114
115
  id: userId,
115
116
  name: user.name || (savedCustomer === null || savedCustomer === void 0 ? void 0 : savedCustomer.name),
@@ -117,24 +118,24 @@ function FormReturningCustomer() {
117
118
  });
118
119
  setCartClient(cartJson.client);
119
120
  setCart(cartJson);
120
- _context.next = 31;
121
+ _context.next = 32;
121
122
  break;
122
- case 27:
123
- _context.prev = 27;
123
+ case 28:
124
+ _context.prev = 28;
124
125
  _context.t0 = _context["catch"](3);
125
126
  alertError(_context.t0.errorMessage || _context.t0.message);
126
127
  setError({
127
128
  message: _context.t0.errorMessage || _context.t0.message || 'Server error.'
128
129
  });
129
- case 31:
130
- _context.prev = 31;
130
+ case 32:
131
+ _context.prev = 32;
131
132
  setLoading(false);
132
- return _context.finish(31);
133
- case 34:
133
+ return _context.finish(32);
134
+ case 35:
134
135
  case "end":
135
136
  return _context.stop();
136
137
  }
137
- }, _callee, null, [[3, 27, 31, 34]]);
138
+ }, _callee, null, [[3, 28, 32, 35]]);
138
139
  }));
139
140
  return _submit.apply(this, arguments);
140
141
  }
@@ -0,0 +1,263 @@
1
+ "use strict";
2
+
3
+ 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); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ var _reactHookForm = require("react-hook-form");
10
+ var _InputAcceptUserTermsAndConditions = _interopRequireDefault(require("./InputAcceptUserTermsAndConditions"));
11
+ var _buttons = require("../buttons");
12
+ var _InputSelect = _interopRequireDefault(require("./InputSelect"));
13
+ var _InputText = _interopRequireDefault(require("./InputText"));
14
+ var _CartProvider = require("../CartProvider");
15
+ var _helpers = require("../utilities/helpers");
16
+ var _InputError = _interopRequireDefault(require("./InputError"));
17
+ var _user = require("../utilities/user");
18
+ var _cart2 = require("../utilities/cart");
19
+ var _cookie = require("../utilities/cookie");
20
+ var _local_storage = require("../utilities/local_storage");
21
+ var _FormNewCustomer = require("./FormNewCustomer");
22
+ var _jsxRuntime = require("react/jsx-runtime");
23
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
24
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
25
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
26
+ 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; }
27
+ 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; }
28
+ 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; }
29
+ 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; }
30
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
31
+ 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); }
32
+ 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); } }
33
+ 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); }); }; }
34
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
35
+ 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."); }
36
+ 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); }
37
+ 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; }
38
+ 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; } }
39
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
40
+ function FormWhatsappCustomer() {
41
+ var _savedCustomer$phoneN, _savedCustomer$phoneN2;
42
+ var _useCartContext = (0, _CartProvider.useCartContext)(),
43
+ cart = _useCartContext.cart,
44
+ classNameBtnPrimary = _useCartContext.classNameBtnPrimary,
45
+ classNameCartFormGroup = _useCartContext.classNameCartFormGroup,
46
+ classNameCartFormGroupButton = _useCartContext.classNameCartFormGroupButton,
47
+ domainId = _useCartContext.domainId,
48
+ setCart = _useCartContext.setCart,
49
+ setCartClient = _useCartContext.setCartClient,
50
+ showUserTermsAndConditions = _useCartContext.showUserTermsAndConditions;
51
+ var _React$useState = React.useState(false),
52
+ _React$useState2 = _slicedToArray(_React$useState, 2),
53
+ loading = _React$useState2[0],
54
+ setLoading = _React$useState2[1];
55
+ var _React$useState3 = React.useState({}),
56
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
57
+ error = _React$useState4[0],
58
+ setError = _React$useState4[1];
59
+ var _React$useState5 = React.useState(true),
60
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
61
+ acceptConditions = _React$useState6[0],
62
+ setAcceptConditions = _React$useState6[1];
63
+ var savedCustomer = (0, _local_storage.getSavedCheckoutCustomer)(domainId);
64
+ function actionWhatsappCheckout(_x) {
65
+ return _actionWhatsappCheckout.apply(this, arguments);
66
+ }
67
+ function _actionWhatsappCheckout() {
68
+ _actionWhatsappCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(customerJson) {
69
+ var _cartJson$client, _customerJson$emailAd, r, user, cartToken, clientEnt, cartEnt, _cart, cartJson;
70
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
71
+ while (1) switch (_context.prev = _context.next) {
72
+ case 0:
73
+ setError({});
74
+ setLoading(true);
75
+ _context.prev = 2;
76
+ _context.next = 5;
77
+ return (0, _user.createNewCustomer)(_objectSpread(_objectSpread({}, customerJson), {}, {
78
+ registeredUnderDomains: [{
79
+ id: domainId
80
+ }]
81
+ }));
82
+ case 5:
83
+ r = _context.sent;
84
+ user = r.user;
85
+ if (user !== null && user !== void 0 && user.id) {
86
+ _context.next = 9;
87
+ break;
88
+ }
89
+ throw new Error('Unable to create customer.');
90
+ case 9:
91
+ _context.next = 11;
92
+ return (0, _cookie.getCartCookieToken)(domainId);
93
+ case 11:
94
+ cartToken = _context.sent;
95
+ clientEnt = (0, _user.makeUser)({
96
+ id: user.id
97
+ }, true);
98
+ cartEnt = (0, _cart2.makeCart)(_objectSpread({}, cart), false, cartToken);
99
+ cartEnt.sendWhatsapp = true;
100
+ cartEnt.client = clientEnt;
101
+ _context.next = 18;
102
+ return cartEnt.save({
103
+ embed: _helpers.cartEmbed
104
+ });
105
+ case 18:
106
+ _cart = _context.sent;
107
+ cartJson = _cart.toJson();
108
+ if (cartJson !== null && cartJson !== void 0 && (_cartJson$client = cartJson.client) !== null && _cartJson$client !== void 0 && _cartJson$client.id) {
109
+ _context.next = 22;
110
+ break;
111
+ }
112
+ throw new Error('Unable to attach client to cart.');
113
+ case 22:
114
+ (0, _local_storage.saveCheckoutCustomer)(domainId, {
115
+ id: user.id,
116
+ name: customerJson.name,
117
+ emailAddress: (_customerJson$emailAd = customerJson.emailAddresses) === null || _customerJson$emailAd === void 0 || (_customerJson$emailAd = _customerJson$emailAd[0]) === null || _customerJson$emailAd === void 0 ? void 0 : _customerJson$emailAd.emailAddress,
118
+ phoneNumbers: customerJson.phoneNumbers
119
+ });
120
+ setCartClient(cartJson.client);
121
+ setCart(cartJson);
122
+ _context.next = 30;
123
+ break;
124
+ case 27:
125
+ _context.prev = 27;
126
+ _context.t0 = _context["catch"](2);
127
+ setError({
128
+ message: _context.t0.errorMessage || _context.t0.message || 'Unable to attach client to cart.'
129
+ });
130
+ case 30:
131
+ _context.prev = 30;
132
+ setLoading(false);
133
+ return _context.finish(30);
134
+ case 33:
135
+ case "end":
136
+ return _context.stop();
137
+ }
138
+ }, _callee, null, [[2, 27, 30, 33]]);
139
+ }));
140
+ return _actionWhatsappCheckout.apply(this, arguments);
141
+ }
142
+ var _useForm = (0, _reactHookForm.useForm)({
143
+ defaultValues: {
144
+ emailAddresses: [{
145
+ emailAddress: (savedCustomer === null || savedCustomer === void 0 ? void 0 : savedCustomer.emailAddress) || ''
146
+ }],
147
+ name: (savedCustomer === null || savedCustomer === void 0 ? void 0 : savedCustomer.name) || '',
148
+ phoneNumbers: [{
149
+ code: (savedCustomer === null || savedCustomer === void 0 || (_savedCustomer$phoneN = savedCustomer.phoneNumbers) === null || _savedCustomer$phoneN === void 0 || (_savedCustomer$phoneN = _savedCustomer$phoneN[0]) === null || _savedCustomer$phoneN === void 0 ? void 0 : _savedCustomer$phoneN.code) || 'AU',
150
+ number: (savedCustomer === null || savedCustomer === void 0 || (_savedCustomer$phoneN2 = savedCustomer.phoneNumbers) === null || _savedCustomer$phoneN2 === void 0 || (_savedCustomer$phoneN2 = _savedCustomer$phoneN2[0]) === null || _savedCustomer$phoneN2 === void 0 ? void 0 : _savedCustomer$phoneN2.number) || ''
151
+ }]
152
+ }
153
+ }),
154
+ control = _useForm.control,
155
+ handleSubmit = _useForm.handleSubmit,
156
+ watch = _useForm.watch;
157
+ function onSubmit(_x2) {
158
+ return _onSubmit.apply(this, arguments);
159
+ }
160
+ function _onSubmit() {
161
+ _onSubmit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(values) {
162
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
163
+ while (1) switch (_context2.prev = _context2.next) {
164
+ case 0:
165
+ if (!(showUserTermsAndConditions && !acceptConditions)) {
166
+ _context2.next = 2;
167
+ break;
168
+ }
169
+ return _context2.abrupt("return");
170
+ case 2:
171
+ _context2.next = 4;
172
+ return actionWhatsappCheckout(_objectSpread({}, values));
173
+ case 4:
174
+ case "end":
175
+ return _context2.stop();
176
+ }
177
+ }, _callee2);
178
+ }));
179
+ return _onSubmit.apply(this, arguments);
180
+ }
181
+ function validatePhone() {
182
+ var phone = watch('phoneNumbers.0.number');
183
+ if (!phone) return 'Phone number is required for WhatsApp checkout';
184
+ if (isNaN(phone)) return 'Phone number must be a number';
185
+ return true;
186
+ }
187
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("form", {
188
+ onSubmit: handleSubmit(onSubmit),
189
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_InputText["default"], {
190
+ control: control,
191
+ label: "Full Name",
192
+ name: "name",
193
+ placeholder: "John Smith",
194
+ rules: {
195
+ required: 'Full name is required.'
196
+ }
197
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputText["default"], {
198
+ control: control,
199
+ label: "Email",
200
+ name: "emailAddresses[0].emailAddress",
201
+ placeholder: "john@example.com",
202
+ rules: {
203
+ required: 'Email is required.',
204
+ validate: _FormNewCustomer.emailValidation
205
+ }
206
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
207
+ style: {
208
+ display: 'flex',
209
+ gap: '1rem'
210
+ },
211
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
212
+ style: {
213
+ flexGrow: 1
214
+ },
215
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputSelect["default"], {
216
+ control: control,
217
+ label: "Country Code",
218
+ name: "phoneNumbers[0].code",
219
+ options: _helpers.phoneOptions
220
+ })
221
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
222
+ style: {
223
+ flexGrow: 1
224
+ },
225
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputText["default"], {
226
+ control: control,
227
+ label: "WhatsApp Number",
228
+ name: "phoneNumbers[0].number",
229
+ placeholder: "0400 000 000",
230
+ rules: {
231
+ required: 'WhatsApp number is required',
232
+ validate: validatePhone
233
+ },
234
+ type: "phone"
235
+ })
236
+ })]
237
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("small", {
238
+ className: classNameCartFormGroup,
239
+ children: "By continuing, you agree to receive order updates via WhatsApp at this number."
240
+ }), showUserTermsAndConditions && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
241
+ className: classNameCartFormGroup,
242
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_InputAcceptUserTermsAndConditions["default"], {
243
+ isChecked: acceptConditions,
244
+ setIsChecked: setAcceptConditions
245
+ }), !acceptConditions && /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputError["default"], {
246
+ error: {
247
+ message: 'You must agree to the user profile terms and conditions to proceed.'
248
+ }
249
+ })]
250
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputError["default"], {
251
+ error: error || {}
252
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
253
+ className: classNameCartFormGroupButton,
254
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.Button, {
255
+ className: classNameBtnPrimary,
256
+ disabled: loading,
257
+ type: "submit",
258
+ children: loading ? 'Loading...' : 'Continue with WhatsApp'
259
+ })
260
+ })]
261
+ });
262
+ }
263
+ var _default = exports["default"] = FormWhatsappCustomer;
@@ -40,11 +40,18 @@ Object.defineProperty(exports, "FormStripePayment", {
40
40
  return _FormStripePayment["default"];
41
41
  }
42
42
  });
43
+ Object.defineProperty(exports, "FormWhatsappCustomer", {
44
+ enumerable: true,
45
+ get: function get() {
46
+ return _FormWhatsappCustomer["default"];
47
+ }
48
+ });
43
49
  var _FormNewCustomer = _interopRequireDefault(require("./FormNewCustomer"));
44
50
  var _FormReturningCustomer = _interopRequireDefault(require("./FormReturningCustomer"));
45
51
  var _FormShipmentAddressAndNotes = _interopRequireWildcard(require("./FormShipmentAddressAndNotes"));
46
52
  var _FormSquarePayment = _interopRequireDefault(require("./FormSquarePayment"));
47
53
  var _FormStripePayment = _interopRequireDefault(require("./FormStripePayment"));
54
+ var _FormWhatsappCustomer = _interopRequireDefault(require("./FormWhatsappCustomer"));
48
55
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
49
56
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
50
57
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -11,6 +11,7 @@ var _CartShipment = _interopRequireDefault(require("../components/CartShipment")
11
11
  var _components = require("../components");
12
12
  var _FormNewCustomer = _interopRequireDefault(require("../forms/FormNewCustomer"));
13
13
  var _FormReturningCustomer = _interopRequireDefault(require("../forms/FormReturningCustomer"));
14
+ var _FormWhatsappCustomer = _interopRequireDefault(require("../forms/FormWhatsappCustomer"));
14
15
  var _FormSquarePayment = _interopRequireDefault(require("../forms/FormSquarePayment"));
15
16
  var _FormStripePayment = _interopRequireDefault(require("../forms/FormStripePayment"));
16
17
  var _freeSolidSvgIcons = require("@fortawesome/free-solid-svg-icons");
@@ -28,6 +29,7 @@ function PanelClientCheckout() {
28
29
  var needsShipping = (0, _shipment.cartItemsNeedShipment)(cart);
29
30
  var domain = cart.domain;
30
31
  var company = domain && domain.company;
32
+ var whatsappEnabled = Boolean(domain === null || domain === void 0 ? void 0 : domain.enableWhatsappNotifications);
31
33
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.CartTabPanel, {
32
34
  tabId: _tabs.tabIdCheckout,
33
35
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.CartBody, {
@@ -92,6 +94,14 @@ function PanelClientCheckout() {
92
94
  title: "Checkout as returning customer"
93
95
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_FormReturningCustomer["default"], {})]
94
96
  })
97
+ }), whatsappEnabled && /*#__PURE__*/(0, _jsxRuntime.jsx)(_containers.CheckoutContainer, {
98
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_containers.InnerContainer, {
99
+ paddingBottom: "0px",
100
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Title, {
101
+ icon: _freeSolidSvgIcons.faPhone,
102
+ title: "Checkout with WhatsApp"
103
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_FormWhatsappCustomer["default"], {})]
104
+ })
95
105
  })]
96
106
  })
97
107
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "merchi_cart",
3
- "version": "1.3.8",
3
+ "version": "1.3.10",
4
4
  "description": "Merchi's cart",
5
5
  "source": "src/index.ts",
6
6
  "main": "lib/index.js",
@@ -90,9 +90,9 @@
90
90
  "browser-or-node": "^3.0.0-pre.0",
91
91
  "js-cookie": "^3.0.5",
92
92
  "lodash": "^4.17.21",
93
- "merchi_product_form": "^1.18.0",
93
+ "merchi_product_form": "^1.19.3",
94
94
  "merchi_sdk_product_form": "^1.0.9",
95
- "merchi_sdk_ts": "^1.28.0",
95
+ "merchi_sdk_ts": "^1.32.1",
96
96
  "react-country-region-selector": "^3.6.1",
97
97
  "react-geosuggest": "^2.14.1",
98
98
  "react-hook-form": "7.45.4",
@@ -48,7 +48,8 @@ export function FormCustomerNew() {
48
48
  // patch cart with new user
49
49
  const cartToken = await getCartCookieToken((domainId as number));
50
50
  const clientEnt = makeUser({id: user.id}, true);
51
- const cartEnt = makeCart({...cart}, false, cartToken);
51
+ const cartEnt = makeCart({ ...cart }, false, cartToken);
52
+ cartEnt.sendWhatsapp = false;
52
53
  cartEnt.client = clientEnt;
53
54
  const _cart = await cartEnt.save({embed: cartEmbed});
54
55
  const cartJson = _cart.toJson();
@@ -57,7 +57,8 @@ function FormReturningCustomer() {
57
57
  // Attach by id only — extra user fields trigger a forbidden user PATCH.
58
58
  const cartToken = await getCartCookieToken((domainId as number));
59
59
  const clientEnt = makeUser({id: userId}, true);
60
- const cartEnt = makeCart({...cart}, false, cartToken);
60
+ const cartEnt = makeCart({ ...cart }, false, cartToken);
61
+ cartEnt.sendWhatsapp = false;
61
62
  cartEnt.client = clientEnt;
62
63
  const _cart = await cartEnt.save({embed: cartEmbed});
63
64
  const cartJson = _cart.toJson();
@@ -0,0 +1,179 @@
1
+ import * as React from 'react';
2
+ import { useForm } from 'react-hook-form';
3
+ import InputAcceptUserTermsAndConditions from './InputAcceptUserTermsAndConditions';
4
+ import { Button } from '../buttons';
5
+ import InputSelect from './InputSelect';
6
+ import InputText from './InputText';
7
+ import { useCartContext } from '../CartProvider';
8
+ import { cartEmbed, phoneOptions } from '../utilities/helpers';
9
+ import InputError from './InputError';
10
+ import { createNewCustomer, makeUser } from '../utilities/user';
11
+ import { makeCart } from '../utilities/cart';
12
+ import { getCartCookieToken } from '../utilities/cookie';
13
+ import {
14
+ getSavedCheckoutCustomer,
15
+ saveCheckoutCustomer,
16
+ } from '../utilities/local_storage';
17
+ import { emailValidation } from './FormNewCustomer';
18
+
19
+ function FormWhatsappCustomer() {
20
+ const {
21
+ cart,
22
+ classNameBtnPrimary,
23
+ classNameCartFormGroup,
24
+ classNameCartFormGroupButton,
25
+ domainId,
26
+ setCart,
27
+ setCartClient,
28
+ showUserTermsAndConditions,
29
+ } = useCartContext();
30
+ const [loading, setLoading] = React.useState(false);
31
+ const [error, setError] = React.useState(({} as any));
32
+ const [acceptConditions, setAcceptConditions] = React.useState(true);
33
+ const savedCustomer = getSavedCheckoutCustomer(domainId);
34
+
35
+ async function actionWhatsappCheckout(customerJson: any) {
36
+ setError({});
37
+ setLoading(true);
38
+ try {
39
+ const r = await createNewCustomer({
40
+ ...customerJson,
41
+ registeredUnderDomains: [{ id: domainId }],
42
+ });
43
+ const { user } = r;
44
+ if (!user?.id) {
45
+ throw new Error('Unable to create customer.');
46
+ }
47
+
48
+ const cartToken = await getCartCookieToken((domainId as number));
49
+ const clientEnt = makeUser({ id: user.id }, true);
50
+ const cartEnt = makeCart({ ...cart }, false, cartToken);
51
+ cartEnt.sendWhatsapp = true;
52
+ cartEnt.client = clientEnt;
53
+ const _cart = await cartEnt.save({ embed: cartEmbed });
54
+ const cartJson = _cart.toJson();
55
+ if (!cartJson?.client?.id) {
56
+ throw new Error('Unable to attach client to cart.');
57
+ }
58
+ saveCheckoutCustomer(domainId, {
59
+ id: user.id,
60
+ name: customerJson.name,
61
+ emailAddress: customerJson.emailAddresses?.[0]?.emailAddress,
62
+ phoneNumbers: customerJson.phoneNumbers,
63
+ });
64
+ setCartClient(cartJson.client);
65
+ setCart(cartJson);
66
+ } catch (e: any) {
67
+ setError({
68
+ message:
69
+ e.errorMessage || e.message || 'Unable to attach client to cart.',
70
+ });
71
+ } finally {
72
+ setLoading(false);
73
+ }
74
+ }
75
+
76
+ const { control, handleSubmit, watch } = useForm({
77
+ defaultValues: {
78
+ emailAddresses: [{
79
+ emailAddress: savedCustomer?.emailAddress || '',
80
+ }],
81
+ name: savedCustomer?.name || '',
82
+ phoneNumbers: [{
83
+ code: savedCustomer?.phoneNumbers?.[0]?.code || 'AU',
84
+ number: savedCustomer?.phoneNumbers?.[0]?.number || '',
85
+ }],
86
+ },
87
+ });
88
+
89
+ async function onSubmit(values: any) {
90
+ if (showUserTermsAndConditions && !acceptConditions) {
91
+ return;
92
+ }
93
+ await actionWhatsappCheckout({ ...values });
94
+ }
95
+
96
+ function validatePhone() {
97
+ const phone = watch('phoneNumbers.0.number');
98
+ if (!phone) return 'Phone number is required for WhatsApp checkout';
99
+ if (isNaN(phone as any)) return 'Phone number must be a number';
100
+ return true;
101
+ }
102
+
103
+ return (
104
+ <form onSubmit={handleSubmit(onSubmit)}>
105
+ <InputText
106
+ control={control}
107
+ label='Full Name'
108
+ name='name'
109
+ placeholder='John Smith'
110
+ rules={{ required: 'Full name is required.' }}
111
+ />
112
+ <InputText
113
+ control={control}
114
+ label='Email'
115
+ name='emailAddresses[0].emailAddress'
116
+ placeholder='john@example.com'
117
+ rules={{
118
+ required: 'Email is required.',
119
+ validate: emailValidation,
120
+ }}
121
+ />
122
+ <div style={{ display: 'flex', gap: '1rem' }}>
123
+ <div style={{ flexGrow: 1 }}>
124
+ <InputSelect
125
+ control={control}
126
+ label='Country Code'
127
+ name='phoneNumbers[0].code'
128
+ options={phoneOptions}
129
+ />
130
+ </div>
131
+ <div style={{ flexGrow: 1 }}>
132
+ <InputText
133
+ control={control}
134
+ label='WhatsApp Number'
135
+ name='phoneNumbers[0].number'
136
+ placeholder='0400 000 000'
137
+ rules={{
138
+ required: 'WhatsApp number is required',
139
+ validate: validatePhone,
140
+ }}
141
+ type='phone'
142
+ />
143
+ </div>
144
+ </div>
145
+ <small className={classNameCartFormGroup}>
146
+ By continuing, you agree to receive order updates via WhatsApp at this
147
+ number.
148
+ </small>
149
+ {showUserTermsAndConditions && (
150
+ <div className={classNameCartFormGroup}>
151
+ <InputAcceptUserTermsAndConditions
152
+ isChecked={acceptConditions}
153
+ setIsChecked={setAcceptConditions}
154
+ />
155
+ {!acceptConditions && (
156
+ <InputError
157
+ error={{
158
+ message:
159
+ 'You must agree to the user profile terms and conditions to proceed.',
160
+ }}
161
+ />
162
+ )}
163
+ </div>
164
+ )}
165
+ <InputError error={error || {}} />
166
+ <div className={classNameCartFormGroupButton}>
167
+ <Button
168
+ className={classNameBtnPrimary}
169
+ disabled={loading}
170
+ type='submit'
171
+ >
172
+ {loading ? 'Loading...' : 'Continue with WhatsApp'}
173
+ </Button>
174
+ </div>
175
+ </form>
176
+ );
177
+ }
178
+
179
+ export default FormWhatsappCustomer;
@@ -3,6 +3,7 @@ import FormReturningCustomer from "./FormReturningCustomer";
3
3
  import FormShipmentAddressAndNotes, { ActiveFormShipmentAddressAndNotes } from "./FormShipmentAddressAndNotes";
4
4
  import FormSquarePayment from "./FormSquarePayment";
5
5
  import FormStripePayment from "./FormStripePayment";
6
+ import FormWhatsappCustomer from "./FormWhatsappCustomer";
6
7
 
7
8
  export {
8
9
  ActiveFormShipmentAddressAndNotes,
@@ -11,4 +12,5 @@ export {
11
12
  FormShipmentAddressAndNotes,
12
13
  FormSquarePayment,
13
14
  FormStripePayment,
15
+ FormWhatsappCustomer,
14
16
  }
@@ -12,9 +12,10 @@ import {
12
12
  } from '../components';
13
13
  import FormNewCustomer from '../forms/FormNewCustomer';
14
14
  import FormReturningCustomer from '../forms/FormReturningCustomer';
15
+ import FormWhatsappCustomer from '../forms/FormWhatsappCustomer';
15
16
  import FormSquarePayment from '../forms/FormSquarePayment';
16
17
  import FormStripePayment from '../forms/FormStripePayment';
17
- import { faCoins, faCreditCard, faUserPlus, faUserTag } from '@fortawesome/free-solid-svg-icons';
18
+ import { faCoins, faCreditCard, faPhone, faUserPlus, faUserTag } from '@fortawesome/free-solid-svg-icons';
18
19
  import { useCartContext } from '../CartProvider';
19
20
  import DiscountInputGroup from '../components/DiscountInputGroup';
20
21
  import CartTotalsListGroup from '../components/CartTotalsListGroup';
@@ -25,6 +26,7 @@ function PanelClientCheckout() {
25
26
  const needsShipping = cartItemsNeedShipment(cart);
26
27
  const { domain } = cart;
27
28
  const company = domain && domain.company;
29
+ const whatsappEnabled = Boolean(domain?.enableWhatsappNotifications);
28
30
  return (
29
31
  <CartTabPanel tabId={tabIdCheckout}>
30
32
  <CartBody style={{ paddingTop: '2rem' }}>
@@ -107,6 +109,17 @@ function PanelClientCheckout() {
107
109
  <FormReturningCustomer />
108
110
  </InnerContainer>
109
111
  </CheckoutContainer>
112
+ {whatsappEnabled && (
113
+ <CheckoutContainer>
114
+ <InnerContainer paddingBottom='0px'>
115
+ <Title
116
+ icon={faPhone}
117
+ title='Checkout with WhatsApp'
118
+ />
119
+ <FormWhatsappCustomer />
120
+ </InnerContainer>
121
+ </CheckoutContainer>
122
+ )}
110
123
  </>
111
124
  }
112
125
  </CartBody>