makerspace-react-rails 0.3.0 → 0.4.0

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.
@@ -176793,16 +176793,12 @@ var App = /** @class */ (function (_super) {
176793
176793
  return App;
176794
176794
  }(React.Component));
176795
176795
  var mapStateToProps = function (state, _ownProps) {
176796
- var _a = state.auth, currentUser = _a.currentUser, permissions = _a.permissions, isSigningIn = _a.isRequesting, invoices = state.checkout.invoices;
176797
- var _b = state.checkout, isCheckingOut = _b.isRequesting, checkoutError = _b.error;
176796
+ var _a = state.auth, currentUser = _a.currentUser, permissions = _a.permissions, isSigningIn = _a.isRequesting;
176798
176797
  return {
176799
176798
  currentUserId: currentUser.id,
176800
176799
  isAdmin: currentUser.isAdmin,
176801
- stagedInvoices: invoices,
176802
176800
  permissions: permissions,
176803
176801
  isSigningIn: isSigningIn,
176804
- isCheckingOut: isCheckingOut,
176805
- checkoutError: checkoutError
176806
176802
  };
176807
176803
  };
176808
176804
  var mapDispatchToProps = function (dispatch) {
@@ -176833,7 +176829,7 @@ var MembersList_1 = __webpack_require__(/*! ui/members/MembersList */ "./src/ui/
176833
176829
  var RentalsList_1 = __webpack_require__(/*! ui/rentals/RentalsList */ "./src/ui/rentals/RentalsList.tsx");
176834
176830
  var EarnedMembershipsList_1 = __webpack_require__(/*! ui/earnedMemberships/EarnedMembershipsList */ "./src/ui/earnedMemberships/EarnedMembershipsList.tsx");
176835
176831
  var MemberDetail_1 = __webpack_require__(/*! ui/member/MemberDetail */ "./src/ui/member/MemberDetail.tsx");
176836
- var CheckoutContainer_1 = __webpack_require__(/*! ui/checkout/CheckoutContainer */ "./src/ui/checkout/CheckoutContainer.tsx");
176832
+ var CheckoutPage_1 = __webpack_require__(/*! ui/checkout/CheckoutPage */ "./src/ui/checkout/CheckoutPage.tsx");
176837
176833
  var BillingContainer_1 = __webpack_require__(/*! ui/billing/BillingContainer */ "./src/ui/billing/BillingContainer.tsx");
176838
176834
  var Settings_1 = __webpack_require__(/*! ui/member/Settings */ "./src/ui/member/Settings.tsx");
176839
176835
  var BillingContextContainer_1 = __webpack_require__(/*! ui/billing/BillingContextContainer */ "./src/ui/billing/BillingContextContainer.tsx");
@@ -176853,7 +176849,7 @@ var PrivateRouting = function (_a) {
176853
176849
  React.createElement(react_router_dom_1.Route, { exact: true, path: constants_1.Routing.Rentals, component: RentalsList_1.default }),
176854
176850
  billingEnabled && React.createElement(react_router_dom_1.Route, { exact: true, path: constants_1.Routing.Billing + "/" + constants_1.Routing.PathPlaceholder.Resource + constants_1.Routing.PathPlaceholder.Optional, component: BillingContainer_1.default }),
176855
176851
  billingEnabled && React.createElement(react_router_dom_1.Route, { exact: true, path: constants_1.Routing.Receipt, component: Receipt_1.default }),
176856
- billingEnabled && React.createElement(react_router_dom_1.Route, { path: constants_1.Routing.Checkout, component: CheckoutContainer_1.default }),
176852
+ billingEnabled && React.createElement(react_router_dom_1.Route, { path: constants_1.Routing.Checkout, component: CheckoutPage_1.default }),
176857
176853
  React.createElement(react_router_dom_1.Route, { exact: true, path: constants_1.Routing.SendRegistration, component: SendRegistrationComponent_1.default }),
176858
176854
  earnedMembershipEnabled && React.createElement(react_router_dom_1.Route, { exact: true, path: constants_1.Routing.EarnedMemberships, component: EarnedMembershipsList_1.default }),
176859
176855
  React.createElement(react_router_dom_1.Redirect, { to: constants_1.Routing.Members + "/" + currentUserId }),
@@ -176879,14 +176875,14 @@ var react_router_dom_1 = __webpack_require__(/*! react-router-dom */ "./node_mod
176879
176875
  var constants_1 = __webpack_require__(/*! app/constants */ "./src/app/constants.ts");
176880
176876
  var LandingPage_1 = __webpack_require__(/*! ui/auth/LandingPage */ "./src/ui/auth/LandingPage.tsx");
176881
176877
  var PasswordReset_1 = __webpack_require__(/*! ui/auth/PasswordReset */ "./src/ui/auth/PasswordReset.tsx");
176882
- var SignUpContainer_1 = __webpack_require__(/*! ui/auth/SignUpContainer */ "./src/ui/auth/SignUpContainer.tsx");
176878
+ var SignUpForm_1 = __webpack_require__(/*! ui/auth/SignUpForm */ "./src/ui/auth/SignUpForm.tsx");
176883
176879
  var LoginPage_1 = __webpack_require__(/*! ui/auth/LoginPage */ "./src/ui/auth/LoginPage.tsx");
176884
176880
  var PublicRouting = function () {
176885
176881
  // Redirect to root if not authed and somewhere else
176886
176882
  return (React.createElement(react_router_dom_1.Switch, null,
176887
176883
  React.createElement(react_router_dom_1.Route, { exact: true, path: constants_1.Routing.PasswordReset + "/:token", component: PasswordReset_1.default }),
176888
176884
  React.createElement(react_router_dom_1.Route, { exact: true, path: constants_1.Routing.Login, component: LoginPage_1.default }),
176889
- React.createElement(react_router_dom_1.Route, { exact: true, path: constants_1.Routing.SignUp, component: SignUpContainer_1.default }),
176885
+ React.createElement(react_router_dom_1.Route, { exact: true, path: constants_1.Routing.SignUp, component: SignUpForm_1.default }),
176890
176886
  React.createElement(react_router_dom_1.Route, { exact: true, path: constants_1.Routing.Root, component: LandingPage_1.default }),
176891
176887
  React.createElement(react_router_dom_1.Redirect, { to: "/" })));
176892
176888
  };
@@ -177003,7 +176999,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
177003
176999
  exports.isMemberInvoice = function (item) {
177004
177000
  return item && !!item.member && !item.rental;
177005
177001
  };
177006
- exports.isInvoiceOptionSelection = function (item) { return !!item.invoiceOptionId; };
177007
177002
  var InvoiceOperation;
177008
177003
  (function (InvoiceOperation) {
177009
177004
  InvoiceOperation["Renew"] = "renew";
@@ -177297,7 +177292,6 @@ var AccessCardForm = function (_a) {
177297
177292
  createCard({
177298
177293
  memberId: member.id,
177299
177294
  uid: rejectionCard.uid,
177300
- cardLocation: undefined // TODO: this should be optional
177301
177295
  });
177302
177296
  }, [rejectionCard, createCard, setError, member.id]);
177303
177297
  return (React.createElement(React.Fragment, null,
@@ -177342,6 +177336,17 @@ exports.default = AccessCardForm;
177342
177336
 
177343
177337
  "use strict";
177344
177338
 
177339
+ var __assign = (this && this.__assign) || function () {
177340
+ __assign = Object.assign || function(t) {
177341
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
177342
+ s = arguments[i];
177343
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
177344
+ t[p] = s[p];
177345
+ }
177346
+ return t;
177347
+ };
177348
+ return __assign.apply(this, arguments);
177349
+ };
177345
177350
  Object.defineProperty(exports, "__esModule", { value: true });
177346
177351
  var React = __webpack_require__(/*! react */ "./node_modules/react/index.js");
177347
177352
  var use_react_router_1 = __webpack_require__(/*! use-react-router */ "./node_modules/use-react-router/use-react-router.js");
@@ -177354,8 +177359,15 @@ var FilledLaserableLogo_svg_1 = __webpack_require__(/*! -!react-svg-loader!asset
177354
177359
  var constants_1 = __webpack_require__(/*! app/constants */ "./src/app/constants.ts");
177355
177360
  var MembershipSelectForm_1 = __webpack_require__(/*! ui/membership/MembershipSelectForm */ "./src/ui/membership/MembershipSelectForm.tsx");
177356
177361
  var LandingPage = function () {
177357
- var history = use_react_router_1.default().history;
177358
- var goToSignup = React.useCallback(function () { return history.push(constants_1.Routing.SignUp); }, []);
177362
+ var _a = use_react_router_1.default(), history = _a.history, search = _a.location.search;
177363
+ var goToSignup = React.useCallback(function (option, discountId) {
177364
+ var searchParams = new URLSearchParams(search);
177365
+ if (option !== undefined) {
177366
+ searchParams.set(MembershipSelectForm_1.invoiceOptionParam, option.id);
177367
+ discountId && searchParams.set(MembershipSelectForm_1.discountParam, discountId);
177368
+ }
177369
+ history.push(__assign(__assign({}, option && { search: searchParams.toString() }), { pathname: constants_1.Routing.SignUp }));
177370
+ }, [history, search]);
177359
177371
  return (React.createElement(Grid_1.default, { container: true, spacing: 24, justify: "center" },
177360
177372
  React.createElement(Grid_1.default, { item: true, xs: 10 },
177361
177373
  React.createElement(Card_1.default, { style: { minWidth: 275 } },
@@ -177368,10 +177380,10 @@ var LandingPage = function () {
177368
177380
  React.createElement(Grid_1.default, { container: true, spacing: 24, justify: "center" },
177369
177381
  constants_1.billingEnabled && React.createElement(Grid_1.default, { item: true, xs: 12 },
177370
177382
  React.createElement(Typography_1.default, { variant: "h5" }, "To get started, first select a membership option."),
177371
- React.createElement(MembershipSelectForm_1.default, { onSelect: goToSignup, subscriptionOnly: true })),
177383
+ React.createElement(MembershipSelectForm_1.default, { onSelect: goToSignup, allowNone: true })),
177372
177384
  !constants_1.billingEnabled && React.createElement(Grid_1.default, { item: true, md: 6, xs: 12 },
177373
177385
  React.createElement(Typography_1.default, { variant: "subtitle1", align: "center" }, "Please take a moment to register with our online portal."),
177374
- React.createElement(Button_1.default, { id: "register", variant: "outlined", color: "secondary", fullWidth: true, onClick: goToSignup }, "Register"))))))));
177386
+ React.createElement(Button_1.default, { id: "register", variant: "outlined", color: "secondary", fullWidth: true, onClick: function () { return goToSignup(); } }, "Register"))))))));
177375
177387
  };
177376
177388
  exports.default = LandingPage;
177377
177389
 
@@ -177876,39 +177888,15 @@ exports.default = SendRegistrationComponent;
177876
177888
 
177877
177889
  /***/ }),
177878
177890
 
177879
- /***/ "./src/ui/auth/SignUpContainer.tsx":
177880
- /*!*****************************************!*\
177881
- !*** ./src/ui/auth/SignUpContainer.tsx ***!
177882
- \*****************************************/
177891
+ /***/ "./src/ui/auth/SignUpForm.tsx":
177892
+ /*!************************************!*\
177893
+ !*** ./src/ui/auth/SignUpForm.tsx ***!
177894
+ \************************************/
177883
177895
  /*! no static exports found */
177884
177896
  /***/ (function(module, exports, __webpack_require__) {
177885
177897
 
177886
177898
  "use strict";
177887
177899
 
177888
- var __extends = (this && this.__extends) || (function () {
177889
- var extendStatics = function (d, b) {
177890
- extendStatics = Object.setPrototypeOf ||
177891
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
177892
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
177893
- return extendStatics(d, b);
177894
- };
177895
- return function (d, b) {
177896
- extendStatics(d, b);
177897
- function __() { this.constructor = d; }
177898
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
177899
- };
177900
- })();
177901
- var __assign = (this && this.__assign) || function () {
177902
- __assign = Object.assign || function(t) {
177903
- for (var s, i = 1, n = arguments.length; i < n; i++) {
177904
- s = arguments[i];
177905
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
177906
- t[p] = s[p];
177907
- }
177908
- return t;
177909
- };
177910
- return __assign.apply(this, arguments);
177911
- };
177912
177900
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
177913
177901
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
177914
177902
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -177949,230 +177937,100 @@ Object.defineProperty(exports, "__esModule", { value: true });
177949
177937
  var React = __webpack_require__(/*! react */ "./node_modules/react/index.js");
177950
177938
  var react_redux_1 = __webpack_require__(/*! react-redux */ "./node_modules/react-redux/es/index.js");
177951
177939
  var use_react_router_1 = __webpack_require__(/*! use-react-router */ "./node_modules/use-react-router/use-react-router.js");
177940
+ var TextField_1 = __webpack_require__(/*! @material-ui/core/TextField */ "./node_modules/@material-ui/core/TextField/index.js");
177952
177941
  var Grid_1 = __webpack_require__(/*! @material-ui/core/Grid */ "./node_modules/@material-ui/core/Grid/index.js");
177953
- var Card_1 = __webpack_require__(/*! @material-ui/core/Card */ "./node_modules/@material-ui/core/Card/index.js");
177954
177942
  var Button_1 = __webpack_require__(/*! @material-ui/core/Button */ "./node_modules/@material-ui/core/Button/index.js");
177943
+ var Card_1 = __webpack_require__(/*! @material-ui/core/Card */ "./node_modules/@material-ui/core/Card/index.js");
177955
177944
  var CardContent_1 = __webpack_require__(/*! @material-ui/core/CardContent */ "./node_modules/@material-ui/core/CardContent/index.js");
177945
+ var InputAdornment_1 = __webpack_require__(/*! @material-ui/core/InputAdornment */ "./node_modules/@material-ui/core/InputAdornment/index.js");
177946
+ var RemoveRedEye_1 = __webpack_require__(/*! @material-ui/icons/RemoveRedEye */ "./node_modules/@material-ui/icons/RemoveRedEye.js");
177956
177947
  var makerspace_ts_api_client_1 = __webpack_require__(/*! makerspace-ts-api-client */ "./node_modules/makerspace-ts-api-client/dist/apiClient.js");
177957
- var constants_1 = __webpack_require__(/*! app/constants */ "./src/app/constants.ts");
177958
- var SignUpForm_1 = __webpack_require__(/*! ui/auth/SignUpForm */ "./src/ui/auth/SignUpForm.tsx");
177959
- var actions_1 = __webpack_require__(/*! ui/auth/actions */ "./src/ui/auth/actions.ts");
177948
+ var constants_1 = __webpack_require__(/*! ui/auth/constants */ "./src/ui/auth/constants.ts");
177949
+ var ErrorMessage_1 = __webpack_require__(/*! ui/common/ErrorMessage */ "./src/ui/common/ErrorMessage.tsx");
177950
+ var Form_1 = __webpack_require__(/*! ui/common/Form */ "./src/ui/common/Form.tsx");
177951
+ var useModal_1 = __webpack_require__(/*! ../hooks/useModal */ "./src/ui/hooks/useModal.ts");
177952
+ var FormModal_1 = __webpack_require__(/*! ../common/FormModal */ "./src/ui/common/FormModal.tsx");
177960
177953
  var constants_2 = __webpack_require__(/*! app/constants */ "./src/app/constants.ts");
177961
- var connected_react_router_1 = __webpack_require__(/*! connected-react-router */ "./node_modules/connected-react-router/esm/index.js");
177954
+ var actions_1 = __webpack_require__(/*! ./actions */ "./src/ui/auth/actions.ts");
177955
+ var constants_3 = __webpack_require__(/*! ui/auth/constants */ "./src/ui/auth/constants.ts");
177962
177956
  var hooks_1 = __webpack_require__(/*! ../reducer/hooks */ "./src/ui/reducer/hooks.ts");
177957
+ var constants_4 = __webpack_require__(/*! app/constants */ "./src/app/constants.ts");
177963
177958
  var useWriteTransaction_1 = __webpack_require__(/*! ../hooks/useWriteTransaction */ "./src/ui/hooks/useWriteTransaction.ts");
177964
- var SignUpWrapper = function (_a) {
177965
- var goToLogin = _a.goToLogin, submitSignUp = _a.submitSignUp;
177966
- var selectedOption = hooks_1.useBillingState()[0].selectedOption;
177967
- var _b = hooks_1.useAuthState(), isRequesting = _b.isRequesting, error = _b.error;
177968
- var location = use_react_router_1.default().location;
177969
- var call = useWriteTransaction_1.default(makerspace_ts_api_client_1.createInvoice).call;
177970
- var onSubmit = React.useCallback(function (validSignUp) { return __awaiter(void 0, void 0, void 0, function () {
177959
+ var MembershipSelectForm_1 = __webpack_require__(/*! ui/membership/MembershipSelectForm */ "./src/ui/membership/MembershipSelectForm.tsx");
177960
+ var SignUpForm = function () {
177961
+ var _a = useModal_1.default(), emailNoteOpen = _a.isOpen, openEmailNote = _a.openModal, closeEmailNote = _a.closeModal;
177962
+ var _b = use_react_router_1.default(), history = _b.history, search = _b.location.search;
177963
+ var goToLogin = React.useCallback(function () { return history.push(constants_2.Routing.Login); }, [history]);
177964
+ var dispatch = react_redux_1.useDispatch();
177965
+ var _c = hooks_1.useAuthState(), isRequesting = _c.isRequesting, error = _c.error;
177966
+ var searchParams = new URLSearchParams(search);
177967
+ var _d = React.useState({
177968
+ id: searchParams.get(MembershipSelectForm_1.invoiceOptionParam),
177969
+ discountId: searchParams.get(MembershipSelectForm_1.discountParam),
177970
+ }), option = _d[0], setOption = _d[1];
177971
+ var buildInvoice = useWriteTransaction_1.default(makerspace_ts_api_client_1.createInvoice).call;
177972
+ var _e = React.useState(true), mask = _e[0], setMask = _e[1];
177973
+ var toggleMask = React.useCallback(function () { return setMask(function (curr) { return !curr; }); }, [setMask]);
177974
+ var submit = React.useCallback(function (form) { return __awaiter(void 0, void 0, void 0, function () {
177975
+ var validSignUp;
177971
177976
  return __generator(this, function (_a) {
177972
177977
  switch (_a.label) {
177973
- case 0: return [4 /*yield*/, submitSignUp(validSignUp)];
177978
+ case 0: return [4 /*yield*/, form.simpleValidate(constants_1.SignUpFields)];
177974
177979
  case 1:
177975
- _a.sent();
177976
- if (!selectedOption) return [3 /*break*/, 3];
177977
- return [4 /*yield*/, call(selectedOption)];
177980
+ validSignUp = _a.sent();
177981
+ if (!form.isValid())
177982
+ return [2 /*return*/];
177983
+ return [4 /*yield*/, dispatch(actions_1.submitSignUpAction(validSignUp))];
177978
177984
  case 2:
177979
177985
  _a.sent();
177980
- _a.label = 3;
177981
- case 3: return [2 /*return*/];
177986
+ if (!option) return [3 /*break*/, 4];
177987
+ return [4 /*yield*/, buildInvoice(option)];
177988
+ case 3:
177989
+ _a.sent();
177990
+ _a.label = 4;
177991
+ case 4: return [2 /*return*/];
177982
177992
  }
177983
177993
  });
177984
- }); }, [call, submitSignUp, selectedOption]);
177985
- return (React.createElement(Grid_1.default, { container: true, justify: "center", spacing: 16 },
177986
- React.createElement(Grid_1.default, { item: true, md: 10, xs: 12 },
177987
- React.createElement(Grid_1.default, { container: true, justify: "center", spacing: 16 },
177988
- React.createElement(Grid_1.default, { item: true, xs: 12 },
177989
- React.createElement(Card_1.default, { style: { minWidth: 275 } },
177990
- React.createElement(CardContent_1.default, null,
177991
- React.createElement(SignUpForm_1.default, { goToLogin: goToLogin, onSubmit: onSubmit, isRequesting: isRequesting, error: error, renderMembershipOptions: constants_2.billingEnabled, selectedOption: selectedOption, location: location })))),
177992
- React.createElement(Grid_1.default, { item: true, xs: 12 },
177993
- React.createElement(Button_1.default, { id: "auth-toggle", variant: "outlined", color: "secondary", fullWidth: true, onClick: goToLogin }, "Already a Member? Login"))))));
177994
- };
177995
- var SignUpContainer = /** @class */ (function (_super) {
177996
- __extends(SignUpContainer, _super);
177997
- function SignUpContainer() {
177998
- return _super !== null && _super.apply(this, arguments) || this;
177999
- }
178000
- SignUpContainer.prototype.render = function () {
178001
- return React.createElement(SignUpWrapper, __assign({}, this.props));
178002
- };
178003
- return SignUpContainer;
178004
- }(React.Component));
178005
- var mapDispatchToProps = function (dispatch) {
178006
- return {
178007
- submitSignUp: function (signUpForm) { return dispatch(actions_1.submitSignUpAction(signUpForm)); },
178008
- goToLogin: function () { return dispatch(connected_react_router_1.push(constants_1.Routing.Login)); },
178009
- };
178010
- };
178011
- exports.default = react_redux_1.connect(null, mapDispatchToProps)(SignUpContainer);
178012
-
178013
-
178014
- /***/ }),
178015
-
178016
- /***/ "./src/ui/auth/SignUpForm.tsx":
178017
- /*!************************************!*\
178018
- !*** ./src/ui/auth/SignUpForm.tsx ***!
178019
- \************************************/
178020
- /*! no static exports found */
178021
- /***/ (function(module, exports, __webpack_require__) {
178022
-
178023
- "use strict";
178024
-
178025
- var __extends = (this && this.__extends) || (function () {
178026
- var extendStatics = function (d, b) {
178027
- extendStatics = Object.setPrototypeOf ||
178028
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
178029
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
178030
- return extendStatics(d, b);
178031
- };
178032
- return function (d, b) {
178033
- extendStatics(d, b);
178034
- function __() { this.constructor = d; }
178035
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
178036
- };
178037
- })();
178038
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
178039
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
178040
- return new (P || (P = Promise))(function (resolve, reject) {
178041
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
178042
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
178043
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
178044
- step((generator = generator.apply(thisArg, _arguments || [])).next());
178045
- });
178046
- };
178047
- var __generator = (this && this.__generator) || function (thisArg, body) {
178048
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
178049
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
178050
- function verb(n) { return function (v) { return step([n, v]); }; }
178051
- function step(op) {
178052
- if (f) throw new TypeError("Generator is already executing.");
178053
- while (_) try {
178054
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
178055
- if (y = 0, t) op = [op[0] & 2, t.value];
178056
- switch (op[0]) {
178057
- case 0: case 1: t = op; break;
178058
- case 4: _.label++; return { value: op[1], done: false };
178059
- case 5: _.label++; y = op[1]; op = [0]; continue;
178060
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
178061
- default:
178062
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
178063
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
178064
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
178065
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
178066
- if (t[2]) _.ops.pop();
178067
- _.trys.pop(); continue;
178068
- }
178069
- op = body.call(thisArg, _);
178070
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
178071
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
178072
- }
178073
- };
178074
- Object.defineProperty(exports, "__esModule", { value: true });
178075
- var React = __webpack_require__(/*! react */ "./node_modules/react/index.js");
178076
- var TextField_1 = __webpack_require__(/*! @material-ui/core/TextField */ "./node_modules/@material-ui/core/TextField/index.js");
178077
- var Grid_1 = __webpack_require__(/*! @material-ui/core/Grid */ "./node_modules/@material-ui/core/Grid/index.js");
178078
- var InputAdornment_1 = __webpack_require__(/*! @material-ui/core/InputAdornment */ "./node_modules/@material-ui/core/InputAdornment/index.js");
178079
- var Card_1 = __webpack_require__(/*! @material-ui/core/Card */ "./node_modules/@material-ui/core/Card/index.js");
178080
- var CardContent_1 = __webpack_require__(/*! @material-ui/core/CardContent */ "./node_modules/@material-ui/core/CardContent/index.js");
178081
- var RemoveRedEye_1 = __webpack_require__(/*! @material-ui/icons/RemoveRedEye */ "./node_modules/@material-ui/icons/RemoveRedEye.js");
178082
- var MembershipSelectForm_1 = __webpack_require__(/*! ui/membership/MembershipSelectForm */ "./src/ui/membership/MembershipSelectForm.tsx");
178083
- var constants_1 = __webpack_require__(/*! ui/auth/constants */ "./src/ui/auth/constants.ts");
178084
- var ErrorMessage_1 = __webpack_require__(/*! ui/common/ErrorMessage */ "./src/ui/common/ErrorMessage.tsx");
178085
- var Form_1 = __webpack_require__(/*! ui/common/Form */ "./src/ui/common/Form.tsx");
178086
- var SignUpFormComponent = /** @class */ (function (_super) {
178087
- __extends(SignUpFormComponent, _super);
178088
- function SignUpFormComponent(props) {
178089
- var _this = _super.call(this, props) || this;
178090
- _this.setFormRef = function (ref) { return _this.formRef = ref; };
178091
- _this.togglePasswordMask = function () {
178092
- _this.setState(function (state) { return ({ passwordMask: !state.passwordMask }); });
178093
- };
178094
- _this.renderPasswordInput = function () {
178095
- var passwordMask = _this.state.passwordMask;
178096
- return (React.createElement(Grid_1.default, { item: true, xs: 12 },
178097
- React.createElement(TextField_1.default, { fullWidth: true, required: true, label: constants_1.SignUpFields.password.label, name: constants_1.SignUpFields.password.name, id: constants_1.SignUpFields.password.name, placeholder: constants_1.SignUpFields.password.placeholder, type: passwordMask ? 'password' : 'text', InputProps: {
178098
- endAdornment: (React.createElement(InputAdornment_1.default, { position: "end" },
178099
- React.createElement(RemoveRedEye_1.default, { style: { cursor: 'pointer' }, onClick: _this.togglePasswordMask }))),
178100
- } })));
178101
- };
178102
- _this.submit = function (form) { return __awaiter(_this, void 0, void 0, function () {
178103
- var validSignUp;
178104
- return __generator(this, function (_a) {
178105
- switch (_a.label) {
178106
- case 0: return [4 /*yield*/, form.simpleValidate(constants_1.SignUpFields)];
178107
- case 1:
178108
- validSignUp = _a.sent();
178109
- if (!form.isValid())
178110
- return [2 /*return*/];
178111
- if (this.props.renderMembershipOptions && !this.state.membershipSelectionId) {
178112
- this.setState({ membershipSelectionError: constants_1.SignUpFields.membershipSelectionId.error });
178113
- return [2 /*return*/];
178114
- }
178115
- return [4 /*yield*/, this.props.onSubmit(validSignUp)];
178116
- case 2:
178117
- _a.sent();
178118
- return [2 /*return*/];
178119
- }
178120
- });
178121
- }); };
178122
- _this.closeNotification = function () {
178123
- _this.setState({ emailExists: false });
178124
- };
178125
- _this.renderEmailNotification = function () {
178126
- var goToLogin = _this.props.goToLogin;
178127
- return (React.createElement(Card_1.default, { style: { minWidth: 275 } },
178128
- React.createElement(CardContent_1.default, null,
178129
- React.createElement(Form_1.default, { id: "email-exists", title: "Email already exists", onSubmit: goToLogin, submitText: "Login", onCancel: _this.closeNotification, cancelText: "Cancel" }, "An account with this email already exists. Please login to continue."))));
178130
- };
178131
- _this.updateMembershipSelection = function (membershipSelectionId) {
178132
- _this.setState({ membershipSelectionId: membershipSelectionId });
178133
- };
178134
- _this.state = {
178135
- passwordMask: true,
178136
- emailExists: false,
178137
- membershipSelectionError: "",
178138
- membershipSelectionId: props.selectedOption && props.selectedOption.id,
178139
- discountId: props.selectedOption && props.selectedOption.discountId,
178140
- };
178141
- return _this;
178142
- }
178143
- SignUpFormComponent.prototype.componentDidUpdate = function (prevProps, prevState) {
178144
- var wasRequesting = prevProps.isRequesting;
178145
- var _a = this.props, isRequesting = _a.isRequesting, error = _a.error;
178146
- if (wasRequesting && !isRequesting) {
178147
- if (error === constants_1.EmailExistsError) {
178148
- this.setState({ emailExists: true });
178149
- }
178150
- }
178151
- if (this.state.membershipSelectionId !== prevState.membershipSelectionId) {
178152
- this.setState({ membershipSelectionError: "" });
177994
+ }); }, []);
177995
+ React.useEffect(function () {
177996
+ if (!isRequesting && error && error.match(new RegExp(constants_1.EmailExistsError))) {
177997
+ dispatch({ type: constants_3.Action.LogoutSuccess }); // Clear error & redirect
177998
+ openEmailNote();
178153
177999
  }
178154
- };
178155
- SignUpFormComponent.prototype.render = function () {
178156
- var _a = this.props, isRequesting = _a.isRequesting, error = _a.error;
178157
- var _b = this.state, emailExists = _b.emailExists, membershipSelectionError = _b.membershipSelectionError;
178158
- return (React.createElement(Form_1.default, { ref: this.setFormRef, id: constants_1.signUpPrefix, loading: isRequesting, title: "Create an Account", onSubmit: this.submit, submitText: "Sign Up" },
178159
- React.createElement(Grid_1.default, { container: true, spacing: 16 },
178160
- React.createElement(Grid_1.default, { item: true, xs: 6 },
178161
- React.createElement(TextField_1.default, { fullWidth: true, required: true, label: constants_1.SignUpFields.firstname.label, name: constants_1.SignUpFields.firstname.name, id: constants_1.SignUpFields.firstname.name, placeholder: constants_1.SignUpFields.firstname.placeholder })),
178162
- React.createElement(Grid_1.default, { item: true, xs: 6 },
178163
- React.createElement(TextField_1.default, { fullWidth: true, required: true, label: constants_1.SignUpFields.lastname.label, name: constants_1.SignUpFields.lastname.name, id: constants_1.SignUpFields.lastname.name, placeholder: constants_1.SignUpFields.lastname.placeholder })),
178164
- React.createElement(Grid_1.default, { item: true, xs: 12 },
178165
- React.createElement(TextField_1.default, { fullWidth: true, required: true, label: constants_1.SignUpFields.email.label, name: constants_1.SignUpFields.email.name, id: constants_1.SignUpFields.email.name, placeholder: constants_1.SignUpFields.email.placeholder, type: "email" })),
178166
- React.createElement(Grid_1.default, { item: true, xs: 12 }, this.renderPasswordInput()),
178167
- this.props.renderMembershipOptions && (React.createElement(Grid_1.default, { item: true, xs: 12 },
178168
- React.createElement(MembershipSelectForm_1.default, { onSelect: this.updateMembershipSelection, subscriptionOnly: true }),
178169
- membershipSelectionError && React.createElement(ErrorMessage_1.default, { error: membershipSelectionError }))),
178170
- !isRequesting && error && React.createElement(ErrorMessage_1.default, { id: constants_1.signUpPrefix + "-error", error: error })),
178171
- emailExists && this.renderEmailNotification()));
178172
- };
178173
- return SignUpFormComponent;
178174
- }(React.Component));
178175
- exports.default = SignUpFormComponent;
178000
+ }, [openEmailNote, isRequesting, error]);
178001
+ var selectMembership = React.useCallback(function (option, discountId) {
178002
+ setOption({ discountId: discountId, id: option.id });
178003
+ }, [setOption]);
178004
+ return (React.createElement(React.Fragment, null,
178005
+ React.createElement(Grid_1.default, { container: true, justify: "center", spacing: 16 },
178006
+ React.createElement(Grid_1.default, { item: true, md: 10, xs: 12 },
178007
+ React.createElement(Grid_1.default, { container: true, justify: "center", spacing: 16 },
178008
+ React.createElement(Grid_1.default, { item: true, xs: 12 },
178009
+ React.createElement(Card_1.default, { style: { minWidth: 275 } },
178010
+ React.createElement(CardContent_1.default, null,
178011
+ React.createElement(Form_1.default, { id: constants_1.signUpPrefix, loading: isRequesting, title: "Create an Account", onSubmit: submit, submitText: "Sign Up" },
178012
+ React.createElement(Grid_1.default, { container: true, spacing: 16 },
178013
+ React.createElement(Grid_1.default, { item: true, xs: 6 },
178014
+ React.createElement(TextField_1.default, { fullWidth: true, required: true, label: constants_1.SignUpFields.firstname.label, name: constants_1.SignUpFields.firstname.name, id: constants_1.SignUpFields.firstname.name, placeholder: constants_1.SignUpFields.firstname.placeholder })),
178015
+ React.createElement(Grid_1.default, { item: true, xs: 6 },
178016
+ React.createElement(TextField_1.default, { fullWidth: true, required: true, label: constants_1.SignUpFields.lastname.label, name: constants_1.SignUpFields.lastname.name, id: constants_1.SignUpFields.lastname.name, placeholder: constants_1.SignUpFields.lastname.placeholder })),
178017
+ React.createElement(Grid_1.default, { item: true, xs: 12 },
178018
+ React.createElement(TextField_1.default, { fullWidth: true, required: true, label: constants_1.SignUpFields.email.label, name: constants_1.SignUpFields.email.name, id: constants_1.SignUpFields.email.name, placeholder: constants_1.SignUpFields.email.placeholder, type: "email" })),
178019
+ React.createElement(Grid_1.default, { item: true, xs: 12 },
178020
+ React.createElement(TextField_1.default, { fullWidth: true, required: true, label: constants_1.SignUpFields.password.label, name: constants_1.SignUpFields.password.name, id: constants_1.SignUpFields.password.name, placeholder: constants_1.SignUpFields.password.placeholder, type: mask ? 'password' : 'text', InputProps: {
178021
+ endAdornment: (React.createElement(InputAdornment_1.default, { position: "end" },
178022
+ React.createElement(RemoveRedEye_1.default, { style: { cursor: 'pointer' }, onClick: toggleMask }))),
178023
+ } })),
178024
+ constants_4.billingEnabled && (React.createElement(Grid_1.default, { item: true, xs: 12 },
178025
+ React.createElement(MembershipSelectForm_1.default, { onSelect: selectMembership, allowNone: true }))),
178026
+ !isRequesting && error && React.createElement(ErrorMessage_1.default, { id: constants_1.signUpPrefix + "-error", error: error })))))),
178027
+ React.createElement(Grid_1.default, { item: true, xs: 12 },
178028
+ React.createElement(Button_1.default, { id: "auth-toggle", variant: "outlined", color: "secondary", fullWidth: true, onClick: goToLogin }, "Already a Member? Login"))))),
178029
+ emailNoteOpen && (React.createElement(FormModal_1.default, { isOpen: true, id: "email-exists", title: "Email already exists", onSubmit: goToLogin, submitText: "Login", closeHandler: closeEmailNote },
178030
+ React.createElement(Card_1.default, { style: { minWidth: 275 } },
178031
+ React.createElement(CardContent_1.default, null, "An account with this email already exists. Please login to continue."))))));
178032
+ };
178033
+ exports.default = SignUpForm;
178176
178034
 
178177
178035
 
178178
178036
  /***/ }),
@@ -178235,7 +178093,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
178235
178093
  };
178236
178094
  Object.defineProperty(exports, "__esModule", { value: true });
178237
178095
  var constants_1 = __webpack_require__(/*! ui/auth/constants */ "./src/ui/auth/constants.ts");
178238
- var constants_2 = __webpack_require__(/*! ui/checkout/constants */ "./src/ui/checkout/constants.ts");
178239
178096
  var utils_1 = __webpack_require__(/*! ui/member/utils */ "./src/ui/member/utils.ts");
178240
178097
  var makerspace_ts_api_client_1 = __webpack_require__(/*! makerspace-ts-api-client */ "./node_modules/makerspace-ts-api-client/dist/apiClient.js");
178241
178098
  var handleAuthWithPermissions = function (response, dispatch, ignoreError) {
@@ -178330,7 +178187,6 @@ exports.submitSignUpAction = function (signUpForm) { return function (dispatch)
178330
178187
  switch (_a.label) {
178331
178188
  case 0:
178332
178189
  dispatch({ type: constants_1.Action.StartAuthRequest });
178333
- dispatch({ type: constants_2.Action.ResetStagedInvoices });
178334
178190
  return [4 /*yield*/, makerspace_ts_api_client_1.registerMember(signUpForm)];
178335
178191
  case 1:
178336
178192
  response = _a.sent();
@@ -178393,10 +178249,8 @@ var Action;
178393
178249
  Action["AuthUserSuccess"] = "AUTH/LOGIN_SUCCESS";
178394
178250
  Action["AuthUserFailure"] = "AUTH/LOGIN_FAILURE";
178395
178251
  Action["LogoutSuccess"] = "AUTH/LOGOUT";
178396
- Action["StageSignUp"] = "AUTH/STAGE_SIGN_UP";
178397
- Action["ClearStagedSignUp"] = "AUTH/CLEAR_STAGED_SIGN_UP";
178398
178252
  })(Action = exports.Action || (exports.Action = {}));
178399
- exports.EmailExistsError = "Email already exists";
178253
+ exports.EmailExistsError = "Email is already taken";
178400
178254
  exports.loginPrefix = "login-modal";
178401
178255
  exports.LoginFields = {
178402
178256
  email: {
@@ -179595,7 +179449,6 @@ exports.deleteBillingAction = function (invoiceOptionId) { return function (disp
179595
179449
  }); }; };
179596
179450
  var defaultState = {
179597
179451
  entities: {},
179598
- selectedOption: undefined,
179599
179452
  read: {
179600
179453
  isRequesting: false,
179601
179454
  error: "",
@@ -179653,11 +179506,6 @@ exports.billingReducer = function (state, action) {
179653
179506
  case constants_1.Action.DeleteOptionFailure:
179654
179507
  var deleteError = action.error;
179655
179508
  return __assign(__assign({}, state), { delete: __assign(__assign({}, state.delete), { isRequesting: false, error: deleteError }) });
179656
- case constants_1.Action.SelectOption:
179657
- var selectedOption = action.data;
179658
- return __assign(__assign({}, state), { selectedOption: __assign({}, selectedOption) });
179659
- case constants_1.Action.ClearSelection:
179660
- return __assign(__assign({}, state), { selectedOption: undefined });
179661
179509
  default:
179662
179510
  return state;
179663
179511
  }
@@ -179692,8 +179540,6 @@ var Action;
179692
179540
  Action["StartDeleteRequest"] = "BILLING/START_DELETE_REQUEST";
179693
179541
  Action["DeleteOptionSuccess"] = "BILLING/DELETE_OPTION_SUCCESS";
179694
179542
  Action["DeleteOptionFailure"] = "BILLING/DELETE_OPTION_FAILURE";
179695
- Action["SelectOption"] = "BILLING/SELECT_OPTION";
179696
- Action["ClearSelection"] = "BILLING/CLEAR_SELECTION";
179697
179543
  })(Action = exports.Action || (exports.Action = {}));
179698
179544
  var formPrefix = "invoice-option-form";
179699
179545
  exports.fields = (_a = {},
@@ -179755,122 +179601,144 @@ exports.fields = (_a = {},
179755
179601
 
179756
179602
  /***/ }),
179757
179603
 
179758
- /***/ "./src/ui/checkout/CheckoutContainer.tsx":
179759
- /*!***********************************************!*\
179760
- !*** ./src/ui/checkout/CheckoutContainer.tsx ***!
179761
- \***********************************************/
179604
+ /***/ "./src/ui/checkout/CartList.tsx":
179605
+ /*!**************************************!*\
179606
+ !*** ./src/ui/checkout/CartList.tsx ***!
179607
+ \**************************************/
179762
179608
  /*! no static exports found */
179763
179609
  /***/ (function(module, exports, __webpack_require__) {
179764
179610
 
179765
179611
  "use strict";
179766
179612
 
179767
- var __extends = (this && this.__extends) || (function () {
179768
- var extendStatics = function (d, b) {
179769
- extendStatics = Object.setPrototypeOf ||
179770
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
179771
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
179772
- return extendStatics(d, b);
179773
- };
179774
- return function (d, b) {
179775
- extendStatics(d, b);
179776
- function __() { this.constructor = d; }
179777
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
179613
+ var __assign = (this && this.__assign) || function () {
179614
+ __assign = Object.assign || function(t) {
179615
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
179616
+ s = arguments[i];
179617
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
179618
+ t[p] = s[p];
179619
+ }
179620
+ return t;
179778
179621
  };
179779
- })();
179622
+ return __assign.apply(this, arguments);
179623
+ };
179624
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
179625
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
179626
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
179627
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
179628
+ r[k] = a[j];
179629
+ return r;
179630
+ };
179780
179631
  Object.defineProperty(exports, "__esModule", { value: true });
179781
179632
  var React = __webpack_require__(/*! react */ "./node_modules/react/index.js");
179782
- var react_redux_1 = __webpack_require__(/*! react-redux */ "./node_modules/react-redux/es/index.js");
179783
- var connected_react_router_1 = __webpack_require__(/*! connected-react-router */ "./node_modules/connected-react-router/esm/index.js");
179784
- var isEmpty_1 = __webpack_require__(/*! lodash-es/isEmpty */ "./node_modules/lodash-es/isEmpty.js");
179785
- var constants_1 = __webpack_require__(/*! app/constants */ "./src/app/constants.ts");
179786
- var actions_1 = __webpack_require__(/*! ui/checkout/actions */ "./src/ui/checkout/actions.ts");
179787
- var CheckoutPage_1 = __webpack_require__(/*! ui/checkout/CheckoutPage */ "./src/ui/checkout/CheckoutPage.tsx");
179788
- var utils_1 = __webpack_require__(/*! ui/member/utils */ "./src/ui/member/utils.ts");
179789
- var constants_2 = __webpack_require__(/*! ui/checkout/constants */ "./src/ui/checkout/constants.ts");
179790
- var CheckoutContainer = /** @class */ (function (_super) {
179791
- __extends(CheckoutContainer, _super);
179792
- function CheckoutContainer(props) {
179793
- var _this = _super.call(this, props) || this;
179794
- _this.submitPayment = function (paymentMethodId) {
179795
- var invoices = _this.props.invoices;
179796
- if (!paymentMethodId) {
179797
- return;
179798
- }
179799
- _this.props.submitCheckout(Object.values(invoices), paymentMethodId);
179800
- };
179801
- _this.state = {
179802
- transactionsComplete: false
179803
- };
179804
- return _this;
179805
- }
179806
- CheckoutContainer.prototype.componentDidMount = function () {
179807
- // Redirect if there are no invoices to checkout
179808
- var _a = this.props, userId = _a.userId, invoices = _a.invoices;
179809
- var redirectPath = userId ? utils_1.buildProfileRouting(userId) : constants_1.Routing.Login;
179810
- var redirect = invoices && isEmpty_1.default(invoices) ? redirectPath : undefined;
179811
- if (redirect) {
179812
- console.warn("Illegal transition to checkout detected. Transitioning");
179813
- this.props.pushLocation(redirectPath);
179814
- }
179815
- };
179816
- CheckoutContainer.prototype.componentDidUpdate = function (prevProps) {
179817
- var _this = this;
179818
- var _a = this.props, isRequesting = _a.isRequesting, error = _a.error, invoices = _a.invoices, transactions = _a.transactions, userId = _a.userId, transactionsLoading = _a.transactionsLoading, transactionsError = _a.transactionsError;
179819
- var wasRequesting = prevProps.isRequesting, wasTransacting = prevProps.transactionsLoading;
179820
- if (wasRequesting && !isRequesting && !error) {
179821
- // If there are no invoices, redirect to profile since there's nothing to do here
179822
- if (isEmpty_1.default(invoices)) {
179823
- this.props.pushLocation(utils_1.buildProfileRouting(userId));
179824
- return;
179825
- }
179826
- }
179827
- if (wasTransacting && !transactionsLoading && isEmpty_1.default(transactionsError) && !isEmpty_1.default(transactions)) {
179828
- var invoice_1 = Object.values(invoices)[0];
179829
- // Update state so component unmounts correctly
179830
- this.setState({ transactionsComplete: true }, function () { return _this.props.pushLocation(constants_1.Routing.Receipt.replace(constants_1.Routing.PathPlaceholder.InvoiceId, invoice_1.id)); });
179831
- }
179832
- };
179833
- CheckoutContainer.prototype.componentWillUnmount = function () {
179834
- if (!this.state.transactionsComplete) {
179835
- this.props.resetCheckoutState();
179836
- }
179837
- };
179838
- CheckoutContainer.prototype.render = function () {
179839
- var _a = this.props, isRequesting = _a.isRequesting, error = _a.error, invoices = _a.invoices, transactionsError = _a.transactionsError;
179840
- return (React.createElement(CheckoutPage_1.default, { onSubmit: this.submitPayment, isRequesting: isRequesting, error: error || transactionsError, invoices: invoices }));
179841
- };
179842
- return CheckoutContainer;
179843
- }(React.Component));
179844
- var mapStateToProps = function (state, _ownProps) {
179845
- var _a = state.checkout, invoices = _a.invoices, transactions = _a.transactions, isRequesting = _a.isRequesting, error = _a.error;
179846
- var userId = state.auth.currentUser.id;
179847
- var transactionsLoading = Object.values(transactions).some(function (transaction) { return transaction.isRequesting; });
179848
- var transactionsError = Object.entries(transactions).reduce(function (list, _a) {
179849
- var key = _a[0], error = _a[1].error;
179850
- if (error) {
179851
- list[key] = error;
179633
+ var use_react_router_1 = __webpack_require__(/*! use-react-router */ "./node_modules/use-react-router/use-react-router.js");
179634
+ var Grid_1 = __webpack_require__(/*! @material-ui/core/Grid */ "./node_modules/@material-ui/core/Grid/index.js");
179635
+ var Card_1 = __webpack_require__(/*! @material-ui/core/Card */ "./node_modules/@material-ui/core/Card/index.js");
179636
+ var Button_1 = __webpack_require__(/*! @material-ui/core/Button */ "./node_modules/@material-ui/core/Button/index.js");
179637
+ var CardContent_1 = __webpack_require__(/*! @material-ui/core/CardContent */ "./node_modules/@material-ui/core/CardContent/index.js");
179638
+ var Typography_1 = __webpack_require__(/*! @material-ui/core/Typography */ "./node_modules/@material-ui/core/Typography/index.js");
179639
+ var TableContainer_1 = __webpack_require__(/*! ui/common/table/TableContainer */ "./src/ui/common/table/TableContainer.tsx");
179640
+ var Table_1 = __webpack_require__(/*! ui/common/table/Table */ "./src/ui/common/table/Table.tsx");
179641
+ var numberAsCurrency_1 = __webpack_require__(/*! ui/utils/numberAsCurrency */ "./src/ui/utils/numberAsCurrency.ts");
179642
+ var ErrorMessage_1 = __webpack_require__(/*! ui/common/ErrorMessage */ "./src/ui/common/ErrorMessage.tsx");
179643
+ var LoadingOverlay_1 = __webpack_require__(/*! ui/common/LoadingOverlay */ "./src/ui/common/LoadingOverlay.tsx");
179644
+ var BillingContextContainer_1 = __webpack_require__(/*! ui/billing/BillingContextContainer */ "./src/ui/billing/BillingContextContainer.tsx");
179645
+ var FormModal_1 = __webpack_require__(/*! ui/common/FormModal */ "./src/ui/common/FormModal.tsx");
179646
+ var cart_1 = __webpack_require__(/*! ./cart */ "./src/ui/checkout/cart.ts");
179647
+ var useModal_1 = __webpack_require__(/*! ../hooks/useModal */ "./src/ui/hooks/useModal.ts");
179648
+ var utils_1 = __webpack_require__(/*! ../member/utils */ "./src/ui/member/utils.ts");
179649
+ var hooks_1 = __webpack_require__(/*! ../reducer/hooks */ "./src/ui/reducer/hooks.ts");
179650
+ var constants_1 = __webpack_require__(/*! app/constants */ "./src/app/constants.ts");
179651
+ var useWriteTransaction_1 = __webpack_require__(/*! ../hooks/useWriteTransaction */ "./src/ui/hooks/useWriteTransaction.ts");
179652
+ var makerspace_ts_api_client_1 = __webpack_require__(/*! makerspace-ts-api-client */ "./node_modules/makerspace-ts-api-client/dist/apiClient.js");
179653
+ var getCartId = function (item) { return item.id; };
179654
+ var CartList = function (_a) {
179655
+ var paymentMethodId = _a.paymentMethodId;
179656
+ var item = cart_1.useCartState().item;
179657
+ var history = use_react_router_1.default().history;
179658
+ var currentUserId = hooks_1.useAuthState().currentUser.id;
179659
+ var emptyCart = cart_1.useEmptyCart();
179660
+ // Redirect to profile if theres nothing in the cart
179661
+ React.useEffect(function () {
179662
+ !item && history.push(utils_1.buildProfileRouting(currentUserId));
179663
+ return emptyCart;
179664
+ }, []);
179665
+ var discounts = React.useContext(BillingContextContainer_1.BillingContext).discounts;
179666
+ var onSuccess = React.useCallback(function (_a) {
179667
+ var invoiceId = _a.invoiceId;
179668
+ history.push("" + constants_1.Routing.Receipt.replace(constants_1.Routing.PathPlaceholder.InvoiceId, invoiceId));
179669
+ }, [history]);
179670
+ var _b = useWriteTransaction_1.default(makerspace_ts_api_client_1.createTransaction, onSuccess), call = _b.call, isRequesting = _b.isRequesting, error = _b.error, reset = _b.reset;
179671
+ var _c = useModal_1.default(), errorIsOpen = _c.isOpen, openModal = _c.openModal, closeModal = _c.closeModal;
179672
+ var closeErrModal = React.useCallback(function () {
179673
+ reset();
179674
+ closeModal();
179675
+ }, [reset, closeModal]);
179676
+ // Open error modal on error
179677
+ React.useEffect(function () {
179678
+ !isRequesting && error && openModal();
179679
+ }, [isRequesting, error, openModal]);
179680
+ var getFields = React.useCallback(function (withError) { return __spreadArrays([
179681
+ {
179682
+ id: "name",
179683
+ label: "Name",
179684
+ cell: function (row) { return row.name; },
179685
+ }
179686
+ ], withError ? [] : [{
179687
+ id: "description",
179688
+ label: "Description",
179689
+ cell: function (row) {
179690
+ var discount = discounts && (discounts.data || []).find(function (discount) { return discount.id === row.discountId; });
179691
+ return (React.createElement(React.Fragment, null,
179692
+ React.createElement("div", null, row.description),
179693
+ discount && (React.createElement(React.Fragment, null,
179694
+ React.createElement("hr", null),
179695
+ React.createElement("div", { id: "discount" }, discount.description)))));
179696
+ },
179697
+ }], [
179698
+ {
179699
+ id: "amount",
179700
+ label: "Amount",
179701
+ cell: function (row) { return numberAsCurrency_1.numberAsCurrency(row.amount); },
179702
+ }
179703
+ ], withError ? [{
179704
+ id: "error",
179705
+ label: "Error",
179706
+ cell: function (row) {
179707
+ return React.createElement(ErrorMessage_1.default, { error: error });
179708
+ },
179709
+ }] : []); }, [error]);
179710
+ var submitPayment = React.useCallback(function () {
179711
+ if (!paymentMethodId) {
179712
+ return;
179852
179713
  }
179853
- return list;
179854
- }, {});
179855
- return {
179856
- invoices: invoices,
179857
- transactions: transactions,
179858
- userId: userId,
179859
- isRequesting: isRequesting,
179860
- error: error,
179861
- transactionsLoading: transactionsLoading,
179862
- // Only set error on this page if all transactions errored out
179863
- transactionsError: Object.keys(transactionsError).length === Object.keys(transactions).length && transactionsError
179864
- };
179865
- };
179866
- var mapDispatchToProps = function (dispatch) {
179867
- return {
179868
- submitCheckout: function (invoices, paymentMethodId) { return dispatch(actions_1.submitPaymentAction(paymentMethodId, invoices)); },
179869
- pushLocation: function (location) { return dispatch(connected_react_router_1.push(location)); },
179870
- resetCheckoutState: function () { return dispatch({ type: constants_2.Action.ResetStagedInvoices }); },
179871
- };
179714
+ call(__assign(__assign({}, cart_1.isInvoiceSelection(item) ? {
179715
+ invoiceId: item.id
179716
+ } : __assign({ invoiceOptionId: item.id }, item.discountId && { discountId: item.discountId })), { paymentMethodId: paymentMethodId }));
179717
+ }, [call, item, paymentMethodId]);
179718
+ if (!item) {
179719
+ return null;
179720
+ }
179721
+ return (React.createElement(React.Fragment, null,
179722
+ React.createElement(Card_1.default, { style: { height: "100%" } },
179723
+ React.createElement(CardContent_1.default, null,
179724
+ React.createElement(Grid_1.default, { container: true, spacing: 16 },
179725
+ React.createElement(Grid_1.default, { item: true, xs: 12 },
179726
+ React.createElement(TableContainer_1.default, { id: "checkout-invoices-table", title: "Review Items Before Purchase", data: item ? [item] : [], columns: getFields(false), rowId: getCartId })),
179727
+ React.createElement(Grid_1.default, { item: true, xs: 12, style: { textAlign: "right" } },
179728
+ React.createElement(Typography_1.default, { id: "total", variant: "h6", color: "inherit" },
179729
+ "Total ",
179730
+ numberAsCurrency_1.numberAsCurrency(item.amount))),
179731
+ React.createElement(Grid_1.default, { item: true, xs: 12, style: { textAlign: "left" } },
179732
+ React.createElement(Button_1.default, { id: "submit-payment-button", variant: "contained", disabled: !paymentMethodId, onClick: submitPayment }, "Submit Payment"))),
179733
+ isRequesting && React.createElement(LoadingOverlay_1.default, { id: "checkout-submitting-overlay" }))),
179734
+ errorIsOpen && (React.createElement(FormModal_1.default, { id: "payment-error-modal", title: "Error processing transactions", isOpen: true, onSubmit: closeErrModal, submitText: "Okay" },
179735
+ React.createElement(Grid_1.default, { container: true, spacing: 16 },
179736
+ React.createElement(Grid_1.default, { item: true, xs: 12 },
179737
+ React.createElement(Typography_1.default, { variant: "body1" }, "There was an error processing one or more transactions. Please review these errors and try again")),
179738
+ React.createElement(Grid_1.default, { item: true, xs: 12 },
179739
+ React.createElement(Table_1.default, { id: "payment-invoices-table", data: item ? [item] : [], columns: getFields(true), rowId: getCartId })))))));
179872
179740
  };
179873
- exports.default = react_redux_1.connect(mapStateToProps, mapDispatchToProps)(CheckoutContainer);
179741
+ exports.default = CartList;
179874
179742
 
179875
179743
 
179876
179744
  /***/ }),
@@ -179884,182 +179752,27 @@ exports.default = react_redux_1.connect(mapStateToProps, mapDispatchToProps)(Che
179884
179752
 
179885
179753
  "use strict";
179886
179754
 
179887
- var __extends = (this && this.__extends) || (function () {
179888
- var extendStatics = function (d, b) {
179889
- extendStatics = Object.setPrototypeOf ||
179890
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
179891
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
179892
- return extendStatics(d, b);
179893
- };
179894
- return function (d, b) {
179895
- extendStatics(d, b);
179896
- function __() { this.constructor = d; }
179897
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
179898
- };
179899
- })();
179900
- var __assign = (this && this.__assign) || function () {
179901
- __assign = Object.assign || function(t) {
179902
- for (var s, i = 1, n = arguments.length; i < n; i++) {
179903
- s = arguments[i];
179904
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
179905
- t[p] = s[p];
179906
- }
179907
- return t;
179908
- };
179909
- return __assign.apply(this, arguments);
179910
- };
179911
- var __spreadArrays = (this && this.__spreadArrays) || function () {
179912
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
179913
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
179914
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
179915
- r[k] = a[j];
179916
- return r;
179917
- };
179918
179755
  Object.defineProperty(exports, "__esModule", { value: true });
179919
179756
  var React = __webpack_require__(/*! react */ "./node_modules/react/index.js");
179920
179757
  var Grid_1 = __webpack_require__(/*! @material-ui/core/Grid */ "./node_modules/@material-ui/core/Grid/index.js");
179921
- var Dialog_1 = __webpack_require__(/*! @material-ui/core/Dialog */ "./node_modules/@material-ui/core/Dialog/index.js");
179922
179758
  var Card_1 = __webpack_require__(/*! @material-ui/core/Card */ "./node_modules/@material-ui/core/Card/index.js");
179923
- var Button_1 = __webpack_require__(/*! @material-ui/core/Button */ "./node_modules/@material-ui/core/Button/index.js");
179924
179759
  var CardContent_1 = __webpack_require__(/*! @material-ui/core/CardContent */ "./node_modules/@material-ui/core/CardContent/index.js");
179925
- var Typography_1 = __webpack_require__(/*! @material-ui/core/Typography */ "./node_modules/@material-ui/core/Typography/index.js");
179926
- var TableContainer_1 = __webpack_require__(/*! ui/common/table/TableContainer */ "./src/ui/common/table/TableContainer.tsx");
179927
- var Table_1 = __webpack_require__(/*! ui/common/table/Table */ "./src/ui/common/table/Table.tsx");
179928
- var numberAsCurrency_1 = __webpack_require__(/*! ui/utils/numberAsCurrency */ "./src/ui/utils/numberAsCurrency.ts");
179929
179760
  var PaymentMethodsContainer_1 = __webpack_require__(/*! ui/checkout/PaymentMethodsContainer */ "./src/ui/checkout/PaymentMethodsContainer.tsx");
179930
- var ErrorMessage_1 = __webpack_require__(/*! ui/common/ErrorMessage */ "./src/ui/common/ErrorMessage.tsx");
179931
- var LoadingOverlay_1 = __webpack_require__(/*! ui/common/LoadingOverlay */ "./src/ui/common/LoadingOverlay.tsx");
179932
- var LoginForm_1 = __webpack_require__(/*! ui/auth/LoginForm */ "./src/ui/auth/LoginForm.tsx");
179933
- var BillingContextContainer_1 = __webpack_require__(/*! ui/billing/BillingContextContainer */ "./src/ui/billing/BillingContextContainer.tsx");
179934
- var FormModal_1 = __webpack_require__(/*! ui/common/FormModal */ "./src/ui/common/FormModal.tsx");
179935
- var CheckoutPage = /** @class */ (function (_super) {
179936
- __extends(CheckoutPage, _super);
179937
- function CheckoutPage(props) {
179938
- var _this = _super.call(this, props) || this;
179939
- _this.setFormRef = function (ref) { return _this.formRef = ref; };
179940
- _this.getFields = function (errorState) {
179941
- if (errorState === void 0) { errorState = false; }
179942
- return __spreadArrays([
179943
- {
179944
- id: "name",
179945
- label: "Name",
179946
- cell: function (row) { return row.name; },
179947
- }
179948
- ], errorState ? [] : [{
179949
- id: "description",
179950
- label: "Description",
179951
- cell: function (row) {
179952
- var discounts = row.discountId && _this.props.context.discounts.data;
179953
- var discount = discounts && discounts.find(function (discount) { return discount.id === row.discountId; });
179954
- return (React.createElement(React.Fragment, null,
179955
- React.createElement("div", null, row.description),
179956
- discount && (React.createElement(React.Fragment, null,
179957
- React.createElement("hr", null),
179958
- React.createElement("div", { id: "discount" }, discount.description)))));
179959
- },
179960
- }], [
179961
- {
179962
- id: "amount",
179963
- label: "Amount",
179964
- cell: function (row) { return numberAsCurrency_1.numberAsCurrency(row.amount); },
179965
- }
179966
- ], errorState ? [{
179967
- id: "error",
179968
- label: "Error",
179969
- cell: function (row) {
179970
- var error = typeof _this.props.error === 'object' ?
179971
- _this.props.error[row.id]
179972
- : _this.props.error;
179973
- return React.createElement(ErrorMessage_1.default, { error: error });
179974
- },
179975
- }] : []);
179976
- };
179977
- _this.closeErrorModal = function () { return _this.setState({ openTransactionErrorModal: false }); };
179978
- _this.renderErrorModal = function () {
179979
- var _a = _this.props, invoices = _a.invoices, error = _a.error;
179980
- return (React.createElement(FormModal_1.default, { formRef: _this.setFormRef, id: "payment-error-modal", title: "Error processing transactions", isOpen: _this.state.openTransactionErrorModal, onSubmit: _this.closeErrorModal, submitText: "Okay" },
179981
- React.createElement(Grid_1.default, { container: true, spacing: 16 },
179982
- React.createElement(Grid_1.default, { item: true, xs: 12 },
179983
- React.createElement(Typography_1.default, { variant: "body1" }, "There was an error processing one or more transactions. Please review these errors and try again")),
179984
- React.createElement(Grid_1.default, { item: true, xs: 12 },
179985
- React.createElement(Table_1.default, { id: "payment-invoices-table", error: typeof error === 'string' && error, data: Object.values(invoices), columns: _this.getFields(true), rowId: _this.rowId })))));
179986
- };
179987
- _this.renderTotal = function () {
179988
- var invoices = _this.props.invoices;
179989
- var _a = _this.state, total = _a.total, paymentMethodId = _a.paymentMethodId;
179990
- return (React.createElement(Card_1.default, { style: { height: "100%" } },
179991
- React.createElement(CardContent_1.default, null,
179992
- React.createElement(Grid_1.default, { container: true, spacing: 16 },
179993
- React.createElement(Grid_1.default, { item: true, xs: 12 },
179994
- React.createElement(TableContainer_1.default, { id: "checkout-invoices-table", title: "Review Items Before Purchase", data: Object.values(invoices), totalItems: Object.values(invoices).length, columns: _this.getFields(), rowId: _this.rowId })),
179995
- React.createElement(Grid_1.default, { item: true, xs: 12, style: { textAlign: "right" } },
179996
- React.createElement(Typography_1.default, { id: "total", variant: "h6", color: "inherit" },
179997
- "Total ",
179998
- numberAsCurrency_1.numberAsCurrency(total))),
179999
- React.createElement(Grid_1.default, { item: true, xs: 12, style: { textAlign: "left" } },
180000
- React.createElement(Button_1.default, { id: "submit-payment-button", variant: "contained", disabled: !paymentMethodId, onClick: _this.submitPayment }, "Submit Payment"))))));
180001
- };
180002
- _this.submitPayment = function () {
180003
- var paymentMethodId = _this.state.paymentMethodId;
180004
- _this.props.onSubmit(paymentMethodId);
180005
- };
180006
- _this.selectPaymentMethod = function (paymentMethodId) {
180007
- _this.setState({ paymentMethodId: paymentMethodId });
180008
- };
180009
- _this.openLoginModal = function () {
180010
- _this.setState({ openLoginModal: true });
180011
- };
180012
- _this.closeLoginModal = function () {
180013
- _this.setState({ openLoginModal: false });
180014
- };
180015
- _this.renderLoginModal = function () {
180016
- return (React.createElement(Dialog_1.default, { fullWidth: true, open: _this.state.openLoginModal, onClose: _this.closeLoginModal, disableBackdropClick: true },
180017
- React.createElement(LoginForm_1.default, null)));
180018
- };
180019
- _this.rowId = function (row) { return row.id; };
180020
- // Redirect if there are no invoices to checkout
180021
- var invoices = props.invoices;
180022
- _this.state = ({
180023
- total: invoices && Object.values(invoices).reduce(function (a, b) { return a + Number(b.amount); }, 0),
180024
- error: false,
180025
- paymentMethodId: undefined,
180026
- openLoginModal: false,
180027
- openTransactionErrorModal: false,
180028
- });
180029
- return _this;
180030
- }
180031
- CheckoutPage.prototype.componentDidUpdate = function (prevProps) {
180032
- var _a = this.props, isRequesting = _a.isRequesting, error = _a.error;
180033
- var wasRequesting = prevProps.isRequesting;
180034
- var paymentMethodId = this.state.paymentMethodId;
180035
- if (wasRequesting && !isRequesting) {
180036
- // Open error modal if error exists after submitting payment
180037
- if (error && paymentMethodId) {
180038
- this.setState({ error: !!error, openTransactionErrorModal: true });
180039
- return;
180040
- }
180041
- }
180042
- };
180043
- CheckoutPage.prototype.render = function () {
180044
- var _a = this.props, isRequesting = _a.isRequesting, error = _a.error;
180045
- return (React.createElement(Grid_1.default, { container: true, spacing: 16 },
180046
- isRequesting && React.createElement(LoadingOverlay_1.default, { id: "checkout-submitting-overlay" }),
180047
- React.createElement(Grid_1.default, { item: true, sm: 5, xs: 12 },
180048
- React.createElement(Grid_1.default, { container: true, spacing: 16 },
180049
- React.createElement(Grid_1.default, { item: true, xs: 12 },
180050
- React.createElement(Card_1.default, null,
180051
- React.createElement(CardContent_1.default, null,
180052
- React.createElement(PaymentMethodsContainer_1.default, { onPaymentMethodChange: this.selectPaymentMethod }),
180053
- React.createElement("p", null, "*The payment method used when creating a subscription will be the default payment method used for subscription payments unless changed through Settings.")))))),
180054
- React.createElement(Grid_1.default, { item: true, sm: 7, xs: 12 },
180055
- this.renderTotal(),
180056
- !isRequesting && error && React.createElement(ErrorMessage_1.default, { id: "checkout-submitting-error", error: typeof error === 'string' && error })),
180057
- this.renderLoginModal(),
180058
- this.renderErrorModal()));
180059
- };
180060
- return CheckoutPage;
180061
- }(React.Component));
180062
- exports.default = (function (props) { return (React.createElement(BillingContextContainer_1.BillingContext.Consumer, null, function (context) { return React.createElement(CheckoutPage, __assign({}, props, { context: context })); })); });
179761
+ var CartList_1 = __webpack_require__(/*! ./CartList */ "./src/ui/checkout/CartList.tsx");
179762
+ var CheckoutPage = function () {
179763
+ var _a = React.useState(), paymentMethodId = _a[0], setPaymentMethodId = _a[1];
179764
+ return (React.createElement(Grid_1.default, { container: true, spacing: 16 },
179765
+ React.createElement(Grid_1.default, { item: true, sm: 5, xs: 12 },
179766
+ React.createElement(Grid_1.default, { container: true, spacing: 16 },
179767
+ React.createElement(Grid_1.default, { item: true, xs: 12 },
179768
+ React.createElement(Card_1.default, null,
179769
+ React.createElement(CardContent_1.default, null,
179770
+ React.createElement(PaymentMethodsContainer_1.default, { onPaymentMethodChange: setPaymentMethodId }),
179771
+ React.createElement("p", null, "*The payment method used when creating a subscription will be the default payment method used for subscription payments unless changed through Settings.")))))),
179772
+ React.createElement(Grid_1.default, { item: true, sm: 7, xs: 12 },
179773
+ React.createElement(CartList_1.default, { paymentMethodId: paymentMethodId }))));
179774
+ };
179775
+ exports.default = CheckoutPage;
180063
179776
 
180064
179777
 
180065
179778
  /***/ }),
@@ -180140,10 +179853,33 @@ var Grid_1 = __webpack_require__(/*! @material-ui/core/Grid */ "./node_modules/@
180140
179853
  //@ts-ignore
180141
179854
  var Braintree = __webpack_require__(/*! braintree-web */ "./node_modules/braintree-web/dist/browser/index.js");
180142
179855
  var Form_1 = __webpack_require__(/*! ui/common/Form */ "./src/ui/common/Form.tsx");
180143
- var constants_1 = __webpack_require__(/*! ui/checkout/constants */ "./src/ui/checkout/constants.ts");
180144
179856
  var ErrorMessage_1 = __webpack_require__(/*! ui/common/ErrorMessage */ "./src/ui/common/ErrorMessage.tsx");
180145
179857
  var HostedInput_1 = __webpack_require__(/*! ui/checkout/HostedInput */ "./src/ui/checkout/HostedInput.tsx");
180146
179858
  var makerspace_ts_api_client_1 = __webpack_require__(/*! makerspace-ts-api-client */ "./node_modules/makerspace-ts-api-client/dist/apiClient.js");
179859
+ var formPrefix = "credit-card-form";
179860
+ var CreditCardFields = {
179861
+ number: {
179862
+ label: "Credit or debit card number",
179863
+ name: formPrefix + "-cardNumber",
179864
+ placeholder: "4111 1111 1111 1111",
179865
+ validate: function (val) { return !!val; }
179866
+ },
179867
+ cvv: {
179868
+ label: "Security code",
179869
+ name: formPrefix + "-csv",
179870
+ placeholder: "123"
179871
+ },
179872
+ expirationDate: {
179873
+ label: "Expiration date",
179874
+ name: formPrefix + "-expirationDate",
179875
+ placeholder: "MM/YYYY"
179876
+ },
179877
+ postalCode: {
179878
+ label: "Zipcode",
179879
+ name: formPrefix + "-zipcode",
179880
+ placeholder: "90210"
179881
+ }
179882
+ };
180147
179883
  var CreditCardForm = /** @class */ (function (_super) {
180148
179884
  __extends(CreditCardForm, _super);
180149
179885
  function CreditCardForm(props) {
@@ -180183,7 +179919,7 @@ var CreditCardForm = /** @class */ (function (_super) {
180183
179919
  return [4 /*yield*/, Braintree.hostedFields.create({
180184
179920
  client: braintreeInstance,
180185
179921
  styles: {},
180186
- fields: Object.entries(constants_1.CreditCardFields).reduce(function (fields, _a) {
179922
+ fields: Object.entries(CreditCardFields).reduce(function (fields, _a) {
180187
179923
  var key = _a[0], field = _a[1];
180188
179924
  fields[key] = {
180189
179925
  selector: "#" + field.name,
@@ -180272,21 +180008,21 @@ var CreditCardForm = /** @class */ (function (_super) {
180272
180008
  React.createElement(Form_1.default, { ref: this.setFormRef, onSubmit: this.requestPaymentMethod, onCancel: this.props.closeHandler, id: "credit-card-form", title: "Enter your credit or debit card information" },
180273
180009
  React.createElement(Grid_1.default, { container: true, spacing: 8 },
180274
180010
  React.createElement(Grid_1.default, { item: true, xs: 12 },
180275
- React.createElement(HostedInput_1.default, { label: constants_1.CreditCardFields.number.label, id: constants_1.CreditCardFields.number.name }),
180011
+ React.createElement(HostedInput_1.default, { label: CreditCardFields.number.label, id: CreditCardFields.number.name }),
180276
180012
  inputErrors["number"] &&
180277
180013
  React.createElement(ErrorMessage_1.default, { error: inputErrors["number"] }))),
180278
180014
  React.createElement(Grid_1.default, { container: true, spacing: 8 },
180279
180015
  React.createElement(Grid_1.default, { item: true, xs: 6 },
180280
- React.createElement(HostedInput_1.default, { label: constants_1.CreditCardFields.expirationDate.label, id: constants_1.CreditCardFields.expirationDate.name }),
180016
+ React.createElement(HostedInput_1.default, { label: CreditCardFields.expirationDate.label, id: CreditCardFields.expirationDate.name }),
180281
180017
  inputErrors["expirationDate"] &&
180282
180018
  React.createElement(ErrorMessage_1.default, { error: inputErrors["expirationDate"] })),
180283
180019
  React.createElement(Grid_1.default, { item: true, xs: 6 },
180284
- React.createElement(HostedInput_1.default, { label: constants_1.CreditCardFields.cvv.label, id: constants_1.CreditCardFields.cvv.name }),
180020
+ React.createElement(HostedInput_1.default, { label: CreditCardFields.cvv.label, id: CreditCardFields.cvv.name }),
180285
180021
  inputErrors["cvv"] &&
180286
180022
  React.createElement(ErrorMessage_1.default, { error: inputErrors["cvv"] }))),
180287
180023
  React.createElement(Grid_1.default, { container: true, spacing: 8 },
180288
180024
  React.createElement(Grid_1.default, { item: true, xs: 12 },
180289
- React.createElement(HostedInput_1.default, { label: constants_1.CreditCardFields.postalCode.label, id: constants_1.CreditCardFields.postalCode.name }),
180025
+ React.createElement(HostedInput_1.default, { label: CreditCardFields.postalCode.label, id: CreditCardFields.postalCode.name }),
180290
180026
  inputErrors["postalCode"] &&
180291
180027
  React.createElement(ErrorMessage_1.default, { error: inputErrors["postalCode"] }))),
180292
180028
  error && React.createElement(ErrorMessage_1.default, { error: error, id: "credit-card-error" }))));
@@ -180965,250 +180701,135 @@ exports.default = PaypalButton;
180965
180701
  /*!*************************************!*\
180966
180702
  !*** ./src/ui/checkout/Receipt.tsx ***!
180967
180703
  \*************************************/
180968
- /*! no static exports found */
180969
- /***/ (function(module, exports, __webpack_require__) {
180970
-
180971
- "use strict";
180972
-
180973
- Object.defineProperty(exports, "__esModule", { value: true });
180974
- var React = __webpack_require__(/*! react */ "./node_modules/react/index.js");
180975
- var use_react_router_1 = __webpack_require__(/*! use-react-router */ "./node_modules/use-react-router/use-react-router.js");
180976
- var Grid_1 = __webpack_require__(/*! @material-ui/core/Grid */ "./node_modules/@material-ui/core/Grid/index.js");
180977
- var Card_1 = __webpack_require__(/*! @material-ui/core/Card */ "./node_modules/@material-ui/core/Card/index.js");
180978
- var CardContent_1 = __webpack_require__(/*! @material-ui/core/CardContent */ "./node_modules/@material-ui/core/CardContent/index.js");
180979
- var Typography_1 = __webpack_require__(/*! @material-ui/core/Typography */ "./node_modules/@material-ui/core/Typography/index.js");
180980
- var utils_1 = __webpack_require__(/*! ui/member/utils */ "./src/ui/member/utils.ts");
180981
- var hooks_1 = __webpack_require__(/*! ../reducer/hooks */ "./src/ui/reducer/hooks.ts");
180982
- var ButtonRow_1 = __webpack_require__(/*! ../common/ButtonRow */ "./src/ui/common/ButtonRow.tsx");
180983
- var LoadingOverlay_1 = __webpack_require__(/*! ../common/LoadingOverlay */ "./src/ui/common/LoadingOverlay.tsx");
180984
- var buildReceiptUrl = function (id) { return ( false || "") + "/api/billing/receipts/" + id; };
180985
- var receiptContainerId = "receipt-container";
180986
- var Receipt = function () {
180987
- var userId = hooks_1.useAuthState().currentUser.id;
180988
- var _a = use_react_router_1.default(), history = _a.history, invoiceId = _a.match.params.invoiceId;
180989
- var goToProfile = React.useCallback(function () { return history.push(utils_1.buildProfileRouting(userId)); }, [history, userId]);
180990
- var printReceipt = React.useCallback(function () {
180991
- window.frames[receiptContainerId].focus();
180992
- window.frames[receiptContainerId].print();
180993
- }, [window.frames]);
180994
- var _b = React.useState(true), loading = _b[0], setLoading = _b[1];
180995
- return (React.createElement(React.Fragment, null,
180996
- React.createElement(Grid_1.default, { container: true, spacing: 16 },
180997
- React.createElement(Grid_1.default, { item: true, sm: 6, xs: 12 },
180998
- React.createElement(Typography_1.default, { variant: "h4" }, "Thank you for your purchase!"),
180999
- React.createElement(Typography_1.default, { variant: "subheading" }, "Details regarding your purchase can be found below.")),
181000
- React.createElement(Grid_1.default, { item: true, sm: 6, xs: 12 },
181001
- React.createElement(ButtonRow_1.ActionButton, { id: "return-to-profile", variant: "outlined", style: { float: "right" }, color: "primary", label: "Return to profile", onClick: goToProfile }),
181002
- React.createElement(ButtonRow_1.ActionButton, { label: "Print Receipt", style: { float: "right" }, color: "primary", variant: "contained", onClick: printReceipt }))),
181003
- React.createElement(Card_1.default, { style: { height: "75vh" } },
181004
- React.createElement(CardContent_1.default, { style: { height: "100%" } },
181005
- React.createElement(Grid_1.default, { container: true, spacing: 16, style: { height: "100%" } },
181006
- React.createElement(Grid_1.default, { item: true, xs: 12, style: { height: "100%" } },
181007
- loading && React.createElement(LoadingOverlay_1.default, { id: "receipt-loading" }),
181008
- React.createElement("iframe", { id: receiptContainerId, name: receiptContainerId, src: buildReceiptUrl(invoiceId), style: { height: "100%", width: "100%" }, onLoad: function () { return setLoading(false); }, frameBorder: 0 })))))));
181009
- };
181010
- exports.default = Receipt;
181011
-
181012
-
181013
- /***/ }),
181014
-
181015
- /***/ "./src/ui/checkout/actions.ts":
181016
- /*!************************************!*\
181017
- !*** ./src/ui/checkout/actions.ts ***!
181018
- \************************************/
181019
- /*! no static exports found */
181020
- /***/ (function(module, exports, __webpack_require__) {
181021
-
181022
- "use strict";
181023
-
181024
- var __assign = (this && this.__assign) || function () {
181025
- __assign = Object.assign || function(t) {
181026
- for (var s, i = 1, n = arguments.length; i < n; i++) {
181027
- s = arguments[i];
181028
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
181029
- t[p] = s[p];
181030
- }
181031
- return t;
181032
- };
181033
- return __assign.apply(this, arguments);
181034
- };
181035
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
181036
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
181037
- return new (P || (P = Promise))(function (resolve, reject) {
181038
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
181039
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
181040
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
181041
- step((generator = generator.apply(thisArg, _arguments || [])).next());
181042
- });
181043
- };
181044
- var __generator = (this && this.__generator) || function (thisArg, body) {
181045
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
181046
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
181047
- function verb(n) { return function (v) { return step([n, v]); }; }
181048
- function step(op) {
181049
- if (f) throw new TypeError("Generator is already executing.");
181050
- while (_) try {
181051
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
181052
- if (y = 0, t) op = [op[0] & 2, t.value];
181053
- switch (op[0]) {
181054
- case 0: case 1: t = op; break;
181055
- case 4: _.label++; return { value: op[1], done: false };
181056
- case 5: _.label++; y = op[1]; op = [0]; continue;
181057
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
181058
- default:
181059
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
181060
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
181061
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
181062
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
181063
- if (t[2]) _.ops.pop();
181064
- _.trys.pop(); continue;
181065
- }
181066
- op = body.call(thisArg, _);
181067
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
181068
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
181069
- }
181070
- };
181071
- Object.defineProperty(exports, "__esModule", { value: true });
181072
- var omit_1 = __webpack_require__(/*! lodash-es/omit */ "./node_modules/lodash-es/omit.js");
181073
- var makerspace_ts_api_client_1 = __webpack_require__(/*! makerspace-ts-api-client */ "./node_modules/makerspace-ts-api-client/dist/apiClient.js");
181074
- var isObject_1 = __webpack_require__(/*! ui/utils/isObject */ "./src/ui/utils/isObject.ts");
181075
- var constants_1 = __webpack_require__(/*! ui/checkout/constants */ "./src/ui/checkout/constants.ts");
181076
- exports.submitPaymentAction = function (paymentMethodId, invoices) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
181077
- return __generator(this, function (_a) {
181078
- switch (_a.label) {
181079
- case 0:
181080
- dispatch({ type: constants_1.Action.StartAsyncRequest });
181081
- return [4 /*yield*/, Promise.all(invoices.map(function (invoice) { return __awaiter(void 0, void 0, void 0, function () {
181082
- var invoiceId, result;
181083
- return __generator(this, function (_a) {
181084
- switch (_a.label) {
181085
- case 0:
181086
- invoiceId = invoice.id;
181087
- dispatch({ type: constants_1.Action.StartTransactionRequest, data: invoiceId });
181088
- return [4 /*yield*/, makerspace_ts_api_client_1.createTransaction({ paymentMethodId: paymentMethodId, invoiceId: invoiceId })];
181089
- case 1:
181090
- result = _a.sent();
181091
- if (makerspace_ts_api_client_1.isApiErrorResponse(result)) {
181092
- dispatch({
181093
- type: constants_1.Action.FinishTransactionFailure,
181094
- error: result.error.message,
181095
- id: invoiceId
181096
- });
181097
- }
181098
- else {
181099
- dispatch({
181100
- type: constants_1.Action.FinishTransactionSuccess, data: __assign(__assign({}, result.data), { invoice: invoice })
181101
- });
181102
- }
181103
- return [2 /*return*/];
181104
- }
181105
- });
181106
- }); }))];
181107
- case 1:
181108
- _a.sent();
181109
- dispatch({ type: constants_1.Action.StopAsyncRequest });
181110
- return [2 /*return*/];
181111
- }
181112
- });
181113
- }); }; };
181114
- var defaultState = {
181115
- invoices: {},
181116
- transactions: {},
181117
- isRequesting: false,
181118
- error: ""
181119
- };
181120
- exports.checkoutReducer = function (state, action) {
181121
- var _a, _b, _c;
181122
- if (state === void 0) { state = defaultState; }
181123
- var invoiceId;
181124
- switch (action.type) {
181125
- case constants_1.Action.StartAsyncRequest:
181126
- return __assign(__assign({}, state), { isRequesting: true });
181127
- case constants_1.Action.StopAsyncRequest:
181128
- return __assign(__assign({}, state), { isRequesting: false });
181129
- case constants_1.Action.StageInvoicesForPayment:
181130
- var invoices = action.data;
181131
- // Can accept array or collection of invoices to stage
181132
- if (Array.isArray(invoices)) {
181133
- var newInvoices_1 = {};
181134
- invoices.forEach(function (invoice) {
181135
- newInvoices_1[invoice.id] = invoice;
181136
- });
181137
- return __assign(__assign({}, state), { invoices: __assign(__assign({}, state.invoices), newInvoices_1) });
181138
- }
181139
- else if (isObject_1.default(invoices)) {
181140
- return __assign(__assign({}, state), { invoices: __assign(__assign({}, state.invoices), invoices) });
181141
- }
181142
- case constants_1.Action.ResetStagedInvoice:
181143
- invoiceId = action.data;
181144
- return __assign(__assign({}, state), { invoices: omit_1.default(state.invoices, invoiceId) });
181145
- case constants_1.Action.ResetStagedInvoices:
181146
- return __assign(__assign({}, state), { invoices: defaultState.invoices, transactions: defaultState.transactions });
181147
- case constants_1.Action.StartTransactionRequest:
181148
- invoiceId = action.data;
181149
- return __assign(__assign({}, state), { transactions: __assign(__assign({}, state.transactions), (_a = {}, _a[invoiceId] = __assign(__assign({}, state.transactions[invoiceId]), { isRequesting: true }), _a)) });
181150
- case constants_1.Action.FinishTransactionSuccess:
181151
- var transaction = action.data;
181152
- return __assign(__assign({}, state), { transactions: __assign(__assign({}, state.transactions), (_b = {}, _b[transaction.invoice.id] = __assign(__assign({}, transaction), { isRequesting: false, error: "" }), _b)) });
181153
- case constants_1.Action.FinishTransactionFailure:
181154
- var id = action.id, error = action.error;
181155
- return __assign(__assign({}, state), { transactions: __assign(__assign({}, state.transactions), (_c = {}, _c[id] = {
181156
- isRequesting: false,
181157
- error: error,
181158
- }, _c)) });
181159
- default:
181160
- return state;
181161
- }
180704
+ /*! no static exports found */
180705
+ /***/ (function(module, exports, __webpack_require__) {
180706
+
180707
+ "use strict";
180708
+
180709
+ Object.defineProperty(exports, "__esModule", { value: true });
180710
+ var React = __webpack_require__(/*! react */ "./node_modules/react/index.js");
180711
+ var use_react_router_1 = __webpack_require__(/*! use-react-router */ "./node_modules/use-react-router/use-react-router.js");
180712
+ var Grid_1 = __webpack_require__(/*! @material-ui/core/Grid */ "./node_modules/@material-ui/core/Grid/index.js");
180713
+ var Card_1 = __webpack_require__(/*! @material-ui/core/Card */ "./node_modules/@material-ui/core/Card/index.js");
180714
+ var CardContent_1 = __webpack_require__(/*! @material-ui/core/CardContent */ "./node_modules/@material-ui/core/CardContent/index.js");
180715
+ var Typography_1 = __webpack_require__(/*! @material-ui/core/Typography */ "./node_modules/@material-ui/core/Typography/index.js");
180716
+ var utils_1 = __webpack_require__(/*! ui/member/utils */ "./src/ui/member/utils.ts");
180717
+ var hooks_1 = __webpack_require__(/*! ../reducer/hooks */ "./src/ui/reducer/hooks.ts");
180718
+ var ButtonRow_1 = __webpack_require__(/*! ../common/ButtonRow */ "./src/ui/common/ButtonRow.tsx");
180719
+ var LoadingOverlay_1 = __webpack_require__(/*! ../common/LoadingOverlay */ "./src/ui/common/LoadingOverlay.tsx");
180720
+ var buildReceiptUrl = function (id) { return ( false || "") + "/api/billing/receipts/" + id; };
180721
+ var receiptContainerId = "receipt-container";
180722
+ var Receipt = function () {
180723
+ var userId = hooks_1.useAuthState().currentUser.id;
180724
+ var _a = use_react_router_1.default(), history = _a.history, invoiceId = _a.match.params.invoiceId;
180725
+ var goToProfile = React.useCallback(function () { return history.push(utils_1.buildProfileRouting(userId)); }, [history, userId]);
180726
+ var printReceipt = React.useCallback(function () {
180727
+ window.frames[receiptContainerId].focus();
180728
+ window.frames[receiptContainerId].print();
180729
+ }, [window.frames]);
180730
+ var _b = React.useState(true), loading = _b[0], setLoading = _b[1];
180731
+ return (React.createElement(React.Fragment, null,
180732
+ React.createElement(Grid_1.default, { container: true, spacing: 16 },
180733
+ React.createElement(Grid_1.default, { item: true, sm: 6, xs: 12 },
180734
+ React.createElement(Typography_1.default, { variant: "h4" }, "Thank you for your purchase!"),
180735
+ React.createElement(Typography_1.default, { variant: "subheading" }, "Details regarding your purchase can be found below.")),
180736
+ React.createElement(Grid_1.default, { item: true, sm: 6, xs: 12 },
180737
+ React.createElement(ButtonRow_1.ActionButton, { id: "return-to-profile", variant: "outlined", style: { float: "right" }, color: "primary", label: "Return to profile", onClick: goToProfile }),
180738
+ React.createElement(ButtonRow_1.ActionButton, { label: "Print Receipt", style: { float: "right" }, color: "primary", variant: "contained", onClick: printReceipt }))),
180739
+ React.createElement(Card_1.default, { style: { height: "75vh" } },
180740
+ React.createElement(CardContent_1.default, { style: { height: "100%" } },
180741
+ React.createElement(Grid_1.default, { container: true, spacing: 16, style: { height: "100%" } },
180742
+ React.createElement(Grid_1.default, { item: true, xs: 12, style: { height: "100%" } },
180743
+ loading && React.createElement(LoadingOverlay_1.default, { id: "receipt-loading" }),
180744
+ React.createElement("iframe", { id: receiptContainerId, name: receiptContainerId, src: buildReceiptUrl(invoiceId), style: { height: "100%", width: "100%" }, onLoad: function () { return setLoading(false); }, frameBorder: 0 })))))));
181162
180745
  };
180746
+ exports.default = Receipt;
181163
180747
 
181164
180748
 
181165
180749
  /***/ }),
181166
180750
 
181167
- /***/ "./src/ui/checkout/constants.ts":
181168
- /*!**************************************!*\
181169
- !*** ./src/ui/checkout/constants.ts ***!
181170
- \**************************************/
180751
+ /***/ "./src/ui/checkout/cart.ts":
180752
+ /*!*********************************!*\
180753
+ !*** ./src/ui/checkout/cart.ts ***!
180754
+ \*********************************/
181171
180755
  /*! no static exports found */
181172
180756
  /***/ (function(module, exports, __webpack_require__) {
181173
180757
 
181174
180758
  "use strict";
181175
180759
 
180760
+ var __assign = (this && this.__assign) || function () {
180761
+ __assign = Object.assign || function(t) {
180762
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
180763
+ s = arguments[i];
180764
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
180765
+ t[p] = s[p];
180766
+ }
180767
+ return t;
180768
+ };
180769
+ return __assign.apply(this, arguments);
180770
+ };
181176
180771
  Object.defineProperty(exports, "__esModule", { value: true });
181177
- var Action;
181178
- (function (Action) {
181179
- Action["StartAsyncRequest"] = "CHECKOUT/START_ASYNC_REQUEST";
181180
- Action["StopAsyncRequest"] = "CHECKOUT/STOP_ASYNC_REQUEST";
181181
- Action["GetClientTokenSuccess"] = "CHECKOUT/GET_CLIENT_TOKEN_SUCCESS";
181182
- Action["GetClientTokenFailure"] = "CHECKOUT/GET_CLIENT_TOKEN_FAILURE";
181183
- Action["StartTransactionRequest"] = "CHECKOUT/START_TRANSACTION";
181184
- Action["FinishTransactionFailure"] = "CHECKOUT/FINISH_TRANSACTION_FAILURE";
181185
- Action["FinishTransactionSuccess"] = "CHECKOUT/FINISH_TRANSACTION_SUCCESS";
181186
- Action["StageInvoicesForPayment"] = "CHECKOUT/STAGE_INVOICES_PAYMENT";
181187
- Action["ResetStagedInvoices"] = "CHECKOUT/RESET_STAGED_INVOICES";
181188
- Action["ResetStagedInvoice"] = "CHECKOUT/RESET_STAGED_INVOICE";
181189
- })(Action = exports.Action || (exports.Action = {}));
181190
- var formPrefix = "credit-card-form";
181191
- exports.CreditCardFields = {
181192
- number: {
181193
- label: "Credit or debit card number",
181194
- name: formPrefix + "-cardNumber",
181195
- placeholder: "4111 1111 1111 1111",
181196
- validate: function (val) { return !!val; }
181197
- },
181198
- cvv: {
181199
- label: "Security code",
181200
- name: formPrefix + "-csv",
181201
- placeholder: "123"
181202
- },
181203
- expirationDate: {
181204
- label: "Expiration date",
181205
- name: formPrefix + "-expirationDate",
181206
- placeholder: "MM/YYYY"
181207
- },
181208
- postalCode: {
181209
- label: "Zipcode",
181210
- name: formPrefix + "-zipcode",
181211
- placeholder: "90210"
180772
+ var React = __webpack_require__(/*! react */ "./node_modules/react/index.js");
180773
+ var react_redux_1 = __webpack_require__(/*! react-redux */ "./node_modules/react-redux/es/index.js");
180774
+ var CartAction;
180775
+ (function (CartAction) {
180776
+ CartAction["AddToCart"] = "CART/ADD";
180777
+ CartAction["RemoveFromCart"] = "CART/REMOVE";
180778
+ CartAction["EmptyCart"] = "CART/EMPTY";
180779
+ })(CartAction = exports.CartAction || (exports.CartAction = {}));
180780
+ exports.isInvoiceSelection = function (item) { return item.hasOwnProperty("dueDate"); };
180781
+ var defaultState = {
180782
+ item: undefined
180783
+ };
180784
+ var dispatchAction = function (dispatch) { return function (type, data) {
180785
+ dispatch({ type: type, data: data });
180786
+ }; };
180787
+ exports.useEmptyCart = function () {
180788
+ var dispatch = react_redux_1.useDispatch();
180789
+ return function () { return dispatchAction(dispatch)(CartAction.EmptyCart); };
180790
+ };
180791
+ exports.useAddToCart = function () {
180792
+ var dispatch = react_redux_1.useDispatch();
180793
+ return function (item) { return dispatchAction(dispatch)(CartAction.AddToCart, item); };
180794
+ };
180795
+ exports.useRemoveFromCart = function () {
180796
+ var dispatch = react_redux_1.useDispatch();
180797
+ return function (item) { return dispatchAction(dispatch)(CartAction.RemoveFromCart, item); };
180798
+ };
180799
+ exports.useCartState = function () {
180800
+ var getState = React.useCallback(function (state) { return state.cart; }, []);
180801
+ return react_redux_1.useSelector(getState, react_redux_1.shallowEqual);
180802
+ };
180803
+ exports.cartReducer = function (state, action) {
180804
+ if (state === void 0) { state = defaultState; }
180805
+ switch (action.type) {
180806
+ case CartAction.AddToCart:
180807
+ return {
180808
+ item: action.data
180809
+ };
180810
+ case CartAction.RemoveFromCart:
180811
+ return {
180812
+ item: {}
180813
+ };
180814
+ // TODO: Handle multiple itmes
180815
+ // case CartAction.AddToCart:
180816
+ // return {
180817
+ // items: [...state.items, action.data]
180818
+ // };
180819
+ // case CartAction.RemoveFromCart:
180820
+ // const identifer = action.data;
180821
+ // const newItems = state.items.filter(item => {
180822
+ // if (typeof identifer === "string") {
180823
+ // return item.id === identifer;
180824
+ // } else {
180825
+ // return item === identifer;
180826
+ // }
180827
+ // });
180828
+ // return { items: newItems };
180829
+ case CartAction.EmptyCart:
180830
+ return __assign({}, defaultState);
180831
+ default:
180832
+ return state;
181212
180833
  }
181213
180834
  };
181214
180835
 
@@ -182466,9 +182087,9 @@ var StatefulTable = function (_a) {
182466
182087
  }, [pageNum, setOrder, setOrderBy]);
182467
182088
  var onPageChange = React.useCallback(function (newPage) { return setPageNum(newPage); }, [setPageNum]);
182468
182089
  var onSelect = React.useCallback(function (id, selected) {
182469
- setSelectedIds(function (currentIds) {
182470
- var updatedIds = currentIds.slice();
182471
- var existingIndex = currentIds.indexOf(id);
182090
+ if (Array.isArray(selectedIds)) {
182091
+ var updatedIds = selectedIds.slice();
182092
+ var existingIndex = selectedIds.indexOf(id);
182472
182093
  var alreadySelected = existingIndex > -1;
182473
182094
  if (selected && alreadySelected) {
182474
182095
  return;
@@ -182479,25 +182100,29 @@ var StatefulTable = function (_a) {
182479
182100
  else {
182480
182101
  updatedIds.push(id);
182481
182102
  }
182482
- return updatedIds;
182483
- });
182484
- }, [setSelectedIds]);
182103
+ return setSelectedIds(updatedIds);
182104
+ }
182105
+ else {
182106
+ return setSelectedIds(selected ? id : undefined);
182107
+ }
182108
+ }, [setSelectedIds, selectedIds]);
182109
+ // SelectAll only works with lists of IDs
182485
182110
  var onSelectAll = React.useCallback(function () {
182486
- setSelectedIds(function (currIds) {
182111
+ if (Array.isArray(selectedIds)) {
182487
182112
  var allIds = data.map(rowId);
182488
- if (currIds.length === allIds.length) {
182489
- return [];
182113
+ if (selectedIds.length === allIds.length) {
182114
+ setSelectedIds([]);
182490
182115
  }
182491
182116
  else {
182492
- return allIds;
182117
+ setSelectedIds(allIds);
182493
182118
  }
182494
- });
182119
+ }
182495
182120
  }, [setSelectedIds, data]);
182496
182121
  var onSearchEnter = React.useCallback(function (searchTerm) {
182497
182122
  setSearch(searchTerm);
182498
182123
  setPageNum(0);
182499
182124
  }, [setSearch, setPageNum]);
182500
- return (React.createElement(TableContainer_1.default, { id: id, title: title, loading: loading, data: data, error: error, totalItems: totalItems, selectedIds: selectedIds, pageNum: pageNum, columns: columns, order: order, orderBy: orderBy, onSort: onSort, rowId: rowId, onPageChange: onPageChange, onSelect: setSelectedIds && onSelect, onSelectAll: setSelectedIds && onSelectAll, onSearchEnter: renderSearch && onSearchEnter }));
182125
+ return (React.createElement(TableContainer_1.default, { id: id, title: title, loading: loading, data: data, error: error, totalItems: totalItems, selectedIds: Array.isArray(selectedIds) ? selectedIds : [selectedIds], pageNum: pageNum, columns: columns, order: order, orderBy: orderBy, onSort: onSort, rowId: rowId, onPageChange: onPageChange, onSelect: setSelectedIds && onSelect, onSelectAll: Array.isArray(selectedIds) && setSelectedIds && onSelectAll, onSearchEnter: renderSearch && onSearchEnter }));
182501
182126
  };
182502
182127
  function default_1(props) {
182503
182128
  return React.createElement(StatefulTable, __assign({}, props));
@@ -184636,60 +184261,24 @@ exports.default = InvoiceForm;
184636
184261
 
184637
184262
  "use strict";
184638
184263
 
184639
- var __extends = (this && this.__extends) || (function () {
184640
- var extendStatics = function (d, b) {
184641
- extendStatics = Object.setPrototypeOf ||
184642
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
184643
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
184644
- return extendStatics(d, b);
184645
- };
184646
- return function (d, b) {
184647
- extendStatics(d, b);
184648
- function __() { this.constructor = d; }
184649
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
184650
- };
184651
- })();
184652
184264
  Object.defineProperty(exports, "__esModule", { value: true });
184653
184265
  var React = __webpack_require__(/*! react */ "./node_modules/react/index.js");
184654
- var react_redux_1 = __webpack_require__(/*! react-redux */ "./node_modules/react-redux/es/index.js");
184655
- var connected_react_router_1 = __webpack_require__(/*! connected-react-router */ "./node_modules/connected-react-router/esm/index.js");
184266
+ var use_react_router_1 = __webpack_require__(/*! use-react-router */ "./node_modules/use-react-router/use-react-router.js");
184656
184267
  var constants_1 = __webpack_require__(/*! app/constants */ "./src/app/constants.ts");
184657
- var constants_2 = __webpack_require__(/*! ui/checkout/constants */ "./src/ui/checkout/constants.ts");
184268
+ var cart_1 = __webpack_require__(/*! ui/checkout/cart */ "./src/ui/checkout/cart.ts");
184658
184269
  var InvoicesTable_1 = __webpack_require__(/*! ./InvoicesTable */ "./src/ui/invoice/InvoicesTable.tsx");
184659
- var InvoicesListComponent = /** @class */ (function (_super) {
184660
- __extends(InvoicesListComponent, _super);
184661
- function InvoicesListComponent() {
184662
- var _this = _super !== null && _super.apply(this, arguments) || this;
184663
- _this.goToCheckout = function (selectedInvoices) {
184664
- var _a = _this.props, resetStagedInvoices = _a.resetStagedInvoices, stageInvoices = _a.stageInvoices, goToCheckout = _a.goToCheckout;
184665
- var mappedInvoices = selectedInvoices.reduce(function (mapped, invoice) {
184666
- mapped[invoice.id] = invoice;
184667
- return mapped;
184668
- }, {});
184669
- resetStagedInvoices();
184670
- stageInvoices(mappedInvoices);
184671
- goToCheckout();
184672
- };
184673
- return _this;
184674
- }
184675
- InvoicesListComponent.prototype.render = function () {
184676
- return (React.createElement(InvoicesTable_1.default, { stageInvoices: this.goToCheckout }));
184677
- };
184678
- return InvoicesListComponent;
184679
- }(React.Component));
184680
- var mapDispatchToProps = function (dispatch) {
184681
- return {
184682
- resetStagedInvoices: function () { return dispatch({
184683
- type: constants_2.Action.ResetStagedInvoices
184684
- }); },
184685
- stageInvoices: function (invoices) { return dispatch({
184686
- type: constants_2.Action.StageInvoicesForPayment,
184687
- data: invoices
184688
- }); },
184689
- goToCheckout: function () { return dispatch(connected_react_router_1.push(constants_1.Routing.Checkout)); },
184690
- };
184270
+ var InvoicesList = function () {
184271
+ var history = use_react_router_1.default().history;
184272
+ var resetCart = cart_1.useEmptyCart();
184273
+ var addToCart = cart_1.useAddToCart();
184274
+ var goToCheckout = React.useCallback(function (selectedInvoice) {
184275
+ resetCart();
184276
+ addToCart(selectedInvoice);
184277
+ history.push(constants_1.Routing.Checkout);
184278
+ }, [resetCart, addToCart, history]);
184279
+ return React.createElement(InvoicesTable_1.default, { stageInvoice: goToCheckout });
184691
184280
  };
184692
- exports.default = react_redux_1.connect(null, mapDispatchToProps)(InvoicesListComponent);
184281
+ exports.default = InvoicesList;
184693
184282
 
184694
184283
 
184695
184284
  /***/ }),
@@ -184801,46 +184390,37 @@ var getFields = function (memberId, isAdmin, onSuccess) { return __spreadArrays(
184801
184390
  }
184802
184391
  ]); };
184803
184392
  var InvoicesTable = function (_a) {
184804
- var stageInvoices = _a.stageInvoices;
184393
+ var stageInvoice = _a.stageInvoice;
184805
184394
  var memberId = use_react_router_1.default().match.params.memberId;
184806
184395
  var _b = hooks_1.useAuthState().currentUser, isAdmin = _b.isAdmin, currentUserId = _b.id;
184807
184396
  var _c = StatefulTable_1.useQueryState(), queryParams = _c[0], setQueryState = _c[1];
184808
- var _d = React.useState([]), selectedIds = _d[0], setSelectedIds = _d[1];
184397
+ var _d = React.useState(), selectedInvoice = _d[0], setSelectedInvoice = _d[1];
184809
184398
  var refreshMember = useReadTransaction_1.default(makerspace_ts_api_client_1.getMember, memberId).refresh;
184810
184399
  var _e = useReadTransaction_1.default(isAdmin ? makerspace_ts_api_client_1.adminListInvoices : makerspace_ts_api_client_1.listInvoices, __assign({ resourceId: memberId }, queryParams)), isRequesting = _e.isRequesting, error = _e.error, _f = _e.data, data = _f === void 0 ? [] : _f, response = _e.response, refresh = _e.refresh;
184811
184400
  React.useEffect(function () {
184812
184401
  if (Array.isArray(data) && data.length) {
184813
- setSelectedIds(data.reduce(function (selected, invoice) {
184814
- if (invoice.memberId === currentUserId && utils_1.isInvoicePayable(invoice)) {
184815
- selected.push(invoice.id);
184816
- }
184817
- return selected;
184818
- }, []));
184402
+ var newSelection = data.find(function (invoice) { return (invoice.memberId === currentUserId && utils_1.isInvoicePayable(invoice)); });
184403
+ setSelectedInvoice(newSelection);
184819
184404
  }
184820
- }, [JSON.stringify(data), setSelectedIds]);
184405
+ }, [JSON.stringify(data), setSelectedInvoice]);
184406
+ var setSelected = React.useCallback(function (id) {
184407
+ setSelectedInvoice(data.find(function (invoice) { return invoice.id === id; }));
184408
+ }, [setSelectedInvoice, data]);
184821
184409
  var onSuccess = React.useCallback(function () {
184822
184410
  refreshMember();
184823
184411
  refresh();
184824
184412
  }, [refresh, refreshMember]);
184825
184413
  var rowId = React.useCallback(function (invoice) { return invoice.id; }, []);
184826
184414
  var fields = getFields(memberId, isAdmin, onSuccess);
184827
- var selectedInvoices = React.useMemo(function () {
184828
- return data.reduce(function (selectedInvoice, invoice) {
184829
- if (selectedIds.includes(invoice.id)) {
184830
- selectedInvoice.push(invoice);
184831
- }
184832
- return selectedInvoice;
184833
- }, []);
184834
- }, [data, selectedIds]);
184835
184415
  var viewingOwnInvoices = memberId === currentUserId;
184836
- var payNow = viewingOwnInvoices && selectedInvoices.length && selectedInvoices.every(function (invoice) { return utils_1.isInvoicePayable(invoice); });
184837
- var goToCheckout = React.useCallback(function () { return stageInvoices(selectedInvoices); }, [selectedInvoices, stageInvoices]);
184416
+ var payNow = viewingOwnInvoices && utils_1.isInvoicePayable(selectedInvoice);
184417
+ var goToCheckout = React.useCallback(function () { return stageInvoice(selectedInvoice); }, [selectedInvoice, stageInvoice]);
184838
184418
  return (React.createElement(React.Fragment, null,
184839
184419
  isAdmin && (React.createElement(React.Fragment, null,
184840
184420
  React.createElement(CreateInvoiceModal_1.default, { memberId: memberId, onSuccess: onSuccess }),
184841
- React.createElement(DeleteInvoiceModal_1.default, { invoice: selectedInvoices.length === 1 && selectedInvoices[0], onSuccess: onSuccess }))),
184421
+ React.createElement(DeleteInvoiceModal_1.default, { invoice: selectedInvoice, onSuccess: onSuccess }))),
184842
184422
  viewingOwnInvoices && (React.createElement(ButtonRow_1.ActionButton, { id: "invoices-list-payNow", style: { float: "right" }, variant: "contained", color: "primary", disabled: !payNow, onClick: goToCheckout, label: "Pay Selected Dues" })),
184843
- React.createElement(StatefulTable_1.default, { id: "invoices-table", title: "Dues", loading: isRequesting, data: data, error: error, queryParams: queryParams, setQuery: setQueryState, columns: fields, rowId: rowId, totalItems: extractTotalItems_1.default(response), selectedIds: selectedIds, setSelectedIds: setSelectedIds })));
184423
+ React.createElement(StatefulTable_1.default, { id: "invoices-table", title: "Dues", loading: isRequesting, data: data, error: error, queryParams: queryParams, setQuery: setQueryState, columns: fields, rowId: rowId, totalItems: extractTotalItems_1.default(response), selectedIds: selectedInvoice && selectedInvoice.id, setSelectedIds: setSelected })));
184844
184424
  };
184845
184425
  exports.default = InvoicesTable;
184846
184426
 
@@ -186702,6 +186282,54 @@ var ChangePaymentMethodModal = function (_a) {
186702
186282
  exports.default = ChangePaymentMethodModal;
186703
186283
 
186704
186284
 
186285
+ /***/ }),
186286
+
186287
+ /***/ "./src/ui/membership/DuplicateInvoiceModal.tsx":
186288
+ /*!*****************************************************!*\
186289
+ !*** ./src/ui/membership/DuplicateInvoiceModal.tsx ***!
186290
+ \*****************************************************/
186291
+ /*! no static exports found */
186292
+ /***/ (function(module, exports, __webpack_require__) {
186293
+
186294
+ "use strict";
186295
+
186296
+ Object.defineProperty(exports, "__esModule", { value: true });
186297
+ var React = __webpack_require__(/*! react */ "./node_modules/react/index.js");
186298
+ var use_react_router_1 = __webpack_require__(/*! use-react-router */ "./node_modules/use-react-router/use-react-router.js");
186299
+ var Grid_1 = __webpack_require__(/*! @material-ui/core/Grid */ "./node_modules/@material-ui/core/Grid/index.js");
186300
+ var makerspace_ts_api_client_1 = __webpack_require__(/*! makerspace-ts-api-client */ "./node_modules/makerspace-ts-api-client/dist/apiClient.js");
186301
+ var useReadTransaction_1 = __webpack_require__(/*! ../hooks/useReadTransaction */ "./src/ui/hooks/useReadTransaction.ts");
186302
+ var utils_1 = __webpack_require__(/*! ../invoice/utils */ "./src/ui/invoice/utils.ts");
186303
+ var FormModal_1 = __webpack_require__(/*! ../common/FormModal */ "./src/ui/common/FormModal.tsx");
186304
+ var utils_2 = __webpack_require__(/*! ../member/utils */ "./src/ui/member/utils.ts");
186305
+ var hooks_1 = __webpack_require__(/*! ../reducer/hooks */ "./src/ui/reducer/hooks.ts");
186306
+ var DuplicateInvoiceModal = function (_a) {
186307
+ var type = _a.type;
186308
+ var _b = useReadTransaction_1.default(makerspace_ts_api_client_1.listInvoices).data, invoices = _b === void 0 ? [] : _b;
186309
+ var currentUserId = hooks_1.useAuthState().currentUser.id;
186310
+ var _c = React.useState(), outstandingInvoice = _c[0], setOutstandingInvoice = _c[1];
186311
+ var history = use_react_router_1.default().history;
186312
+ var goToProfile = React.useCallback(function () { return history.push(utils_2.buildProfileRouting(currentUserId)); }, [history, currentUserId]);
186313
+ React.useEffect(function () {
186314
+ var outstandingInvoiceOfType = invoices.find(function (invoice) { return utils_1.isInvoicePayable(invoice) && invoice.resourceClass === type; });
186315
+ setOutstandingInvoice(outstandingInvoiceOfType);
186316
+ }, [invoices, setOutstandingInvoice, type]);
186317
+ if (!outstandingInvoice) {
186318
+ return null;
186319
+ }
186320
+ return (React.createElement(FormModal_1.default, { id: "outstanding-invoice", onSubmit: goToProfile, closeHandler: function () { return setOutstandingInvoice(undefined); }, cancelText: "Ignore", submitText: "View Dues", title: "Existing Dues Found", isOpen: true },
186321
+ React.createElement(Grid_1.default, { container: true, spacing: 16 },
186322
+ React.createElement(Grid_1.default, { item: true, xs: 12 }, "We found existing outstanding dues matching your selection category. \
186323
+ This may cause issues trying to purchase additional items of this type. \
186324
+ Would you like to view your outstanding dues?"),
186325
+ React.createElement(Grid_1.default, { item: true, xs: 12 },
186326
+ "If you're having trouble with your dues, please don't hesitate to ",
186327
+ React.createElement("a", { href: "mailto:contact@manchestermakerspace.org" }, "contact us"),
186328
+ "."))));
186329
+ };
186330
+ exports.default = DuplicateInvoiceModal;
186331
+
186332
+
186705
186333
  /***/ }),
186706
186334
 
186707
186335
  /***/ "./src/ui/membership/MembershipSelectForm.tsx":
@@ -186713,139 +186341,114 @@ exports.default = ChangePaymentMethodModal;
186713
186341
 
186714
186342
  "use strict";
186715
186343
 
186716
- var __extends = (this && this.__extends) || (function () {
186717
- var extendStatics = function (d, b) {
186718
- extendStatics = Object.setPrototypeOf ||
186719
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
186720
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
186721
- return extendStatics(d, b);
186722
- };
186723
- return function (d, b) {
186724
- extendStatics(d, b);
186725
- function __() { this.constructor = d; }
186726
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
186727
- };
186728
- })();
186729
186344
  Object.defineProperty(exports, "__esModule", { value: true });
186730
186345
  var React = __webpack_require__(/*! react */ "./node_modules/react/index.js");
186731
- var react_redux_1 = __webpack_require__(/*! react-redux */ "./node_modules/react-redux/es/index.js");
186732
- var isUndefined_1 = __webpack_require__(/*! lodash-es/isUndefined */ "./node_modules/lodash-es/isUndefined.js");
186346
+ var use_react_router_1 = __webpack_require__(/*! use-react-router */ "./node_modules/use-react-router/use-react-router.js");
186733
186347
  var Button_1 = __webpack_require__(/*! @material-ui/core/Button */ "./node_modules/@material-ui/core/Button/index.js");
186734
186348
  var FormControlLabel_1 = __webpack_require__(/*! @material-ui/core/FormControlLabel */ "./node_modules/@material-ui/core/FormControlLabel/index.js");
186735
186349
  var Checkbox_1 = __webpack_require__(/*! @material-ui/core/Checkbox */ "./node_modules/@material-ui/core/Checkbox/index.js");
186350
+ var makerspace_ts_api_client_1 = __webpack_require__(/*! makerspace-ts-api-client */ "./node_modules/makerspace-ts-api-client/dist/apiClient.js");
186736
186351
  var invoice_1 = __webpack_require__(/*! app/entities/invoice */ "./src/app/entities/invoice.ts");
186737
186352
  var ErrorMessage_1 = __webpack_require__(/*! ui/common/ErrorMessage */ "./src/ui/common/ErrorMessage.tsx");
186738
186353
  var TableContainer_1 = __webpack_require__(/*! ui/common/table/TableContainer */ "./src/ui/common/table/TableContainer.tsx");
186739
186354
  var numberAsCurrency_1 = __webpack_require__(/*! ui/utils/numberAsCurrency */ "./src/ui/utils/numberAsCurrency.ts");
186740
- var actions_1 = __webpack_require__(/*! ui/billing/actions */ "./src/ui/billing/actions.ts");
186741
- var constants_1 = __webpack_require__(/*! ui/billing/constants */ "./src/ui/billing/constants.ts");
186742
- var MembershipSelectComponent = /** @class */ (function (_super) {
186743
- __extends(MembershipSelectComponent, _super);
186744
- function MembershipSelectComponent() {
186745
- var _this = _super !== null && _super.apply(this, arguments) || this;
186746
- _this.selectMembershipOption = function (event) {
186747
- var discountId = _this.props.discountId;
186748
- var optionId = event.currentTarget.id;
186749
- var option = _this.getOption(optionId);
186750
- var optionDiscount;
186751
- if (discountId) {
186752
- // Only want to update discount if already selected
186753
- optionDiscount = option.discountId;
186754
- }
186755
- _this.props.selectMembershipOption(optionId, optionDiscount);
186756
- _this.props.onSelect && _this.props.onSelect(optionId, optionDiscount);
186757
- };
186758
- _this.getOption = function (id) { return _this.props.membershipOptions[id]; };
186759
- _this.rowId = function (row) { return row.id; };
186760
- _this.membershipColumns = [
186761
- {
186762
- id: "name",
186763
- label: "Name",
186764
- cell: function (row) { return row.name; }
186765
- },
186766
- {
186767
- id: "description",
186768
- label: "Description",
186769
- cell: function (row) { return row.description; }
186770
- },
186771
- {
186772
- id: "amount",
186773
- label: "Amount",
186774
- cell: function (row) { return numberAsCurrency_1.numberAsCurrency(row.amount); }
186775
- },
186776
- {
186777
- id: "select",
186778
- label: "",
186779
- cell: function (row) {
186780
- var selected = _this.props.membershipOptionId === row.id;
186781
- var variant = selected ? "contained" : "outlined";
186782
- var label = selected ? "Selected" : "Select";
186783
- return (React.createElement(Button_1.default, { id: row.id, variant: variant, color: "primary", onClick: _this.selectMembershipOption }, label));
186784
- }
186785
- }
186786
- ];
186787
- _this.toggleDiscount = function (_event, checked) {
186788
- var _a = _this.props, membershipOptionId = _a.membershipOptionId, membershipOptions = _a.membershipOptions, selectMembershipOption = _a.selectMembershipOption;
186789
- var discountId;
186790
- if (checked) {
186791
- // Apply discount
186792
- if (membershipOptionId) {
186793
- // If option is already selected, find related discount and apply
186794
- var membershipOption = membershipOptions[membershipOptionId];
186795
- discountId = membershipOption.discountId;
186796
- }
186797
- else {
186798
- // Otherwise just make it truthy to be updated when membership is actually selected
186799
- discountId = "apply";
186800
- }
186801
- }
186802
- selectMembershipOption(membershipOptionId, discountId);
186803
- };
186804
- _this.byAmount = function (a, b) { return Number(a.amount) - Number(b.amount); };
186805
- return _this;
186806
- }
186807
- MembershipSelectComponent.prototype.componentDidMount = function () {
186808
- this.props.getMembershipOptions();
186809
- };
186810
- MembershipSelectComponent.prototype.render = function () {
186811
- var _a = this.props, membershipOptions = _a.membershipOptions, invoiceOptionsError = _a.invoiceOptionsError, invoiceOptionsLoading = _a.invoiceOptionsLoading, discountId = _a.discountId;
186812
- var normalizedError = (invoiceOptionsError && (React.createElement(React.Fragment, null,
186813
- "Error reading membership options: ",
186814
- invoiceOptionsError,
186815
- ". Email",
186816
- " ",
186817
- React.createElement("a", { href: "mailto: contact@manchestermakerspace.org" }, "contact@manchestermakerspace.org"),
186818
- " if your desired membership option is not present")));
186819
- return (React.createElement(React.Fragment, null,
186820
- React.createElement(TableContainer_1.default, { id: "membership-select-table", title: isUndefined_1.default(this.props.title) && "Select a Membership", data: Object.values(membershipOptions).sort(this.byAmount), columns: this.membershipColumns, rowId: this.rowId, loading: invoiceOptionsLoading }),
186821
- React.createElement(FormControlLabel_1.default, { control: React.createElement(Checkbox_1.default, { name: "discount-select", value: "discount-select", checked: !!discountId, onChange: this.toggleDiscount, color: "default" }), label: "Apply 10% Discount for all student, senior (+65) and military. Proof of applicable affiliation may be required during orientation." }),
186822
- React.createElement(ErrorMessage_1.default, { error: normalizedError })));
186823
- };
186824
- return MembershipSelectComponent;
186825
- }(React.Component));
186826
- var mapStateToProps = function (state, _ownProps) {
186827
- var _a = state.billing, membershipOptions = _a.entities, selectedOption = _a.selectedOption, _b = _a.read, invoiceOptionsLoading = _b.isRequesting, invoiceOptionsError = _b.error;
186828
- var discountId = selectedOption && selectedOption.discountId;
186829
- var membershipOptionId = selectedOption && selectedOption.id;
186830
- return {
186831
- membershipOptions: membershipOptions,
186832
- invoiceOptionsLoading: invoiceOptionsLoading,
186833
- invoiceOptionsError: invoiceOptionsError,
186834
- membershipOptionId: membershipOptionId,
186835
- discountId: discountId,
186836
- };
186837
- };
186838
- var mapDispatchToProps = function (dispatch, ownProps) {
186839
- var subscriptionOnly = ownProps.subscriptionOnly;
186840
- return {
186841
- getMembershipOptions: function () { return dispatch(actions_1.readOptionsAction({ subscriptionOnly: subscriptionOnly, types: [invoice_1.InvoiceableResource.Membership] })); },
186842
- selectMembershipOption: function (membershipOptionId, discountId) { return dispatch({
186843
- type: constants_1.Action.SelectOption,
186844
- data: { id: membershipOptionId, discountId: discountId }
186845
- }); }
186846
- };
186355
+ var useReadTransaction_1 = __webpack_require__(/*! ../hooks/useReadTransaction */ "./src/ui/hooks/useReadTransaction.ts");
186356
+ var DuplicateInvoiceModal_1 = __webpack_require__(/*! ./DuplicateInvoiceModal */ "./src/ui/membership/DuplicateInvoiceModal.tsx");
186357
+ exports.invoiceOptionParam = "optionId";
186358
+ exports.discountParam = "discountId";
186359
+ var byAmount = function (a, b) { return Number(a.amount) - Number(b.amount); };
186360
+ var MembershipSelect = function (_a) {
186361
+ var onSelect = _a.onSelect, allowNone = _a.allowNone, title = _a.title;
186362
+ var _b = use_react_router_1.default(), history = _b.history, search = _b.location.search;
186363
+ var _c = React.useState(), selectedOption = _c[0], setSelectedOption = _c[1];
186364
+ var searchParams = React.useMemo(function () { return new URLSearchParams(search); }, [search]);
186365
+ var _d = React.useMemo(function () {
186366
+ var membershipOptionId = searchParams.get(exports.invoiceOptionParam);
186367
+ var discountId = searchParams.get(exports.discountParam);
186368
+ return { membershipOptionId: membershipOptionId, discountId: discountId };
186369
+ }, [search, searchParams]), membershipOptionId = _d.membershipOptionId, discountId = _d.discountId;
186370
+ var _e = useReadTransaction_1.default(makerspace_ts_api_client_1.listInvoiceOptions, { types: [invoice_1.InvoiceableResource.Membership] }), isRequesting = _e.isRequesting, error = _e.error, _f = _e.data, options = _f === void 0 ? [] : _f;
186371
+ // Select bookmarked option on load
186372
+ React.useEffect(function () {
186373
+ if (options.length) {
186374
+ var option = (options || []).find(function (option) { return option.id === membershipOptionId; });
186375
+ setSelectedOption(option);
186376
+ }
186377
+ }, [membershipOptionId, setSelectedOption, options]);
186378
+ var allOptions = React.useMemo(function () {
186379
+ return options.sort(byAmount)
186380
+ .concat(allowNone ? [{
186381
+ id: "none",
186382
+ name: "None",
186383
+ description: "Paid with cash or select an option later",
186384
+ amount: "0",
186385
+ resourceClass: undefined,
186386
+ quantity: 0,
186387
+ disabled: false,
186388
+ operation: undefined,
186389
+ }] : []);
186390
+ }, [allowNone, options]);
186391
+ var updateSelection = React.useCallback(function (optionId, discountId) {
186392
+ var option = (options || []).find(function (option) { return option.id === optionId; });
186393
+ setSelectedOption(option);
186394
+ optionId ? searchParams.set(exports.invoiceOptionParam, optionId) : searchParams.delete(exports.invoiceOptionParam);
186395
+ discountId ? searchParams.set(exports.discountParam, discountId) : searchParams.delete(exports.discountParam);
186396
+ history.push({
186397
+ search: searchParams.toString()
186398
+ });
186399
+ onSelect && onSelect(option, discountId);
186400
+ }, [onSelect, options, history, searchParams]);
186401
+ // Add option and discount IDs to query params
186402
+ var selectMembershipOption = React.useCallback(function (event) {
186403
+ var optionId = event.currentTarget.id;
186404
+ var option = (options || []).find(function (option) { return option.id === optionId; });
186405
+ updateSelection(optionId, discountId ? option.discountId : undefined);
186406
+ }, [updateSelection, discountId, options]);
186407
+ // Add or remove discount ID from query params
186408
+ var toggleDiscount = React.useCallback(function (_event, checked) {
186409
+ updateSelection(membershipOptionId, checked ? (membershipOptionId || "apply") : undefined);
186410
+ }, [updateSelection, membershipOptionId]);
186411
+ var fields = React.useMemo(function () { return [
186412
+ {
186413
+ id: "name",
186414
+ label: "Name",
186415
+ cell: function (row) { return row.name; }
186416
+ },
186417
+ {
186418
+ id: "description",
186419
+ label: "Description",
186420
+ cell: function (row) { return row.description; }
186421
+ },
186422
+ {
186423
+ id: "amount",
186424
+ label: "Amount",
186425
+ cell: function (row) { return numberAsCurrency_1.numberAsCurrency(row.amount); }
186426
+ },
186427
+ {
186428
+ id: "select",
186429
+ label: "",
186430
+ cell: function (row) {
186431
+ var selected = membershipOptionId === row.id;
186432
+ var variant = selected ? "contained" : "outlined";
186433
+ var label = selected ? "Selected" : "Select";
186434
+ return (React.createElement(Button_1.default, { id: row.id, variant: variant, color: "primary", onClick: selectMembershipOption }, label));
186435
+ }
186436
+ }
186437
+ ]; }, [selectMembershipOption, membershipOptionId]);
186438
+ var normalizedError = (error && (React.createElement(React.Fragment, null,
186439
+ "Error reading membership options: ",
186440
+ error,
186441
+ ". Email",
186442
+ " ",
186443
+ React.createElement("a", { href: "mailto: contact@manchestermakerspace.org" }, "contact@manchestermakerspace.org"),
186444
+ " if your desired membership option is not present")));
186445
+ return (React.createElement(React.Fragment, null,
186446
+ React.createElement(DuplicateInvoiceModal_1.default, { type: selectedOption && selectedOption.resourceClass }),
186447
+ React.createElement(TableContainer_1.default, { id: "membership-select-table", title: typeof title === undefined && "Select a Membership", data: allOptions, columns: fields, rowId: function (row) { return row.id; }, loading: isRequesting }),
186448
+ React.createElement(FormControlLabel_1.default, { control: React.createElement(Checkbox_1.default, { name: "discount-select", value: "discount-select", checked: !!discountId, onChange: toggleDiscount, color: "default" }), label: "Apply 10% Discount for all student, senior (+65) and military. Proof of applicable affiliation may be required during orientation." }),
186449
+ React.createElement(ErrorMessage_1.default, { error: normalizedError })));
186847
186450
  };
186848
- exports.default = react_redux_1.connect(mapStateToProps, mapDispatchToProps)(MembershipSelectComponent);
186451
+ exports.default = MembershipSelect;
186849
186452
 
186850
186453
 
186851
186454
  /***/ }),
@@ -186859,6 +186462,17 @@ exports.default = react_redux_1.connect(mapStateToProps, mapDispatchToProps)(Mem
186859
186462
 
186860
186463
  "use strict";
186861
186464
 
186465
+ var __assign = (this && this.__assign) || function () {
186466
+ __assign = Object.assign || function(t) {
186467
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
186468
+ s = arguments[i];
186469
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
186470
+ t[p] = s[p];
186471
+ }
186472
+ return t;
186473
+ };
186474
+ return __assign.apply(this, arguments);
186475
+ };
186862
186476
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
186863
186477
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
186864
186478
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -186908,42 +186522,40 @@ var MemberStatusLabel_1 = __webpack_require__(/*! ui/member/MemberStatusLabel */
186908
186522
  var constants_1 = __webpack_require__(/*! ui/membership/constants */ "./src/ui/membership/constants.ts");
186909
186523
  var constants_2 = __webpack_require__(/*! app/constants */ "./src/app/constants.ts");
186910
186524
  var FormModal_1 = __webpack_require__(/*! ui/common/FormModal */ "./src/ui/common/FormModal.tsx");
186911
- var makerspace_ts_api_client_1 = __webpack_require__(/*! makerspace-ts-api-client */ "./node_modules/makerspace-ts-api-client/dist/apiClient.js");
186912
186525
  var useModal_1 = __webpack_require__(/*! ../hooks/useModal */ "./src/ui/hooks/useModal.ts");
186913
- var hooks_1 = __webpack_require__(/*! ../reducer/hooks */ "./src/ui/reducer/hooks.ts");
186914
- var useWriteTransaction_1 = __webpack_require__(/*! ../hooks/useWriteTransaction */ "./src/ui/hooks/useWriteTransaction.ts");
186915
- var constants_3 = __webpack_require__(/*! ../checkout/constants */ "./src/ui/checkout/constants.ts");
186526
+ var cart_1 = __webpack_require__(/*! ui/checkout/cart */ "./src/ui/checkout/cart.ts");
186916
186527
  /**
186917
186528
  * Component for when a member is viewing membership details but they don't have a subscription yet
186918
186529
  */
186919
186530
  var NoSubscriptionDetails = function (_a) {
186920
186531
  var member = _a.member;
186921
186532
  var _b = useModal_1.default(), isOpen = _b.isOpen, openModal = _b.openModal, closeModal = _b.closeModal;
186922
- var selectedOption = hooks_1.useBillingState()[0].selectedOption;
186923
- var _c = React.useState(selectedOption), option = _c[0], setOption = _c[1];
186924
- var _d = hooks_1.useCheckoutState(), _ = _d[0], dispatch = _d[1];
186533
+ var _c = React.useState(), option = _c[0], setOption = _c[1];
186534
+ var _d = React.useState(), error = _d[0], setError = _d[1];
186925
186535
  var history = use_react_router_1.default().history;
186926
- var _e = useWriteTransaction_1.default(makerspace_ts_api_client_1.createInvoice, function (_a) {
186927
- var response = _a.response;
186928
- dispatch({
186929
- type: constants_3.Action.StageInvoicesForPayment,
186930
- data: [response.data]
186931
- });
186932
- history.push(constants_2.Routing.Checkout);
186933
- }), call = _e.call, isRequesting = _e.isRequesting, error = _e.error;
186934
- var onSelect = React.useCallback(function (id, discountId) {
186935
- setOption({ id: id, discountId: discountId });
186536
+ var resetCart = cart_1.useEmptyCart();
186537
+ var addToCart = cart_1.useAddToCart();
186538
+ var onSelect = React.useCallback(function (option, discountId) {
186539
+ setOption(__assign(__assign({}, option), discountId && { discountId: discountId }));
186540
+ setError("");
186936
186541
  }, [setOption]);
186937
186542
  var onSubmit = React.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
186938
186543
  return __generator(this, function (_a) {
186939
- call(option);
186544
+ if (option) {
186545
+ resetCart();
186546
+ addToCart(option);
186547
+ history.push(constants_2.Routing.Checkout);
186548
+ }
186549
+ else {
186550
+ setError("Select an option to continue");
186551
+ }
186940
186552
  return [2 /*return*/];
186941
186553
  });
186942
- }); }, [option, call]);
186554
+ }); }, [option]);
186943
186555
  var details = constants_1.getDetailsForMember(member);
186944
186556
  return (React.createElement(React.Fragment, null,
186945
- isOpen && (React.createElement(FormModal_1.default, { id: "select-membership", fullScreen: true, isOpen: isOpen, closeHandler: closeModal, onSubmit: onSubmit, loading: isRequesting, error: error },
186946
- React.createElement(MembershipSelectForm_1.default, { subscriptionOnly: true, onSelect: onSelect }))),
186557
+ isOpen && (React.createElement(FormModal_1.default, { id: "select-membership", fullScreen: true, isOpen: isOpen, closeHandler: closeModal, onSubmit: onSubmit, error: error },
186558
+ React.createElement(MembershipSelectForm_1.default, { allowNone: false, onSelect: onSelect }))),
186947
186559
  React.createElement(Grid_1.default, { container: true, spacing: 16 },
186948
186560
  React.createElement(Grid_1.default, { item: true, xs: 12 },
186949
186561
  React.createElement(KeyValueItem_1.default, { label: "Membership Expiration" },
@@ -187142,27 +186754,28 @@ var actions_3 = __webpack_require__(/*! ui/rentals/actions */ "./src/ui/rentals/
187142
186754
  var actions_4 = __webpack_require__(/*! ui/billing/actions */ "./src/ui/billing/actions.ts");
187143
186755
  var actions_5 = __webpack_require__(/*! ui/subscriptions/actions */ "./src/ui/subscriptions/actions.ts");
187144
186756
  var actions_6 = __webpack_require__(/*! ui/member/actions */ "./src/ui/member/actions.ts");
187145
- var actions_7 = __webpack_require__(/*! ui/checkout/actions */ "./src/ui/checkout/actions.ts");
187146
- var actions_8 = __webpack_require__(/*! ui/earnedMemberships/actions */ "./src/ui/earnedMemberships/actions.ts");
187147
- var actions_9 = __webpack_require__(/*! ui/transactions/actions */ "./src/ui/transactions/actions.ts");
186757
+ var actions_7 = __webpack_require__(/*! ui/earnedMemberships/actions */ "./src/ui/earnedMemberships/actions.ts");
186758
+ var actions_8 = __webpack_require__(/*! ui/transactions/actions */ "./src/ui/transactions/actions.ts");
186759
+ var cart_1 = __webpack_require__(/*! ./checkout/cart */ "./src/ui/checkout/cart.ts");
187148
186760
  exports.getRootReducer = function (history) { return redux_1.combineReducers({
187149
186761
  router: connected_react_router_1.connectRouter(history),
187150
186762
  base: baseReducer,
187151
186763
  auth: actions_1.authReducer,
186764
+ cart: cart_1.cartReducer,
187152
186765
  members: actions_2.membersReducer,
187153
186766
  member: actions_6.memberReducer,
187154
186767
  rentals: actions_3.rentalsReducer,
187155
186768
  billing: actions_4.billingReducer,
187156
186769
  subscriptions: actions_5.subscriptionsReducer,
187157
- checkout: actions_7.checkoutReducer,
187158
- earnedMemberships: actions_8.earnedMembershipsReducer,
187159
- transactions: actions_9.transactionsReducer,
186770
+ earnedMemberships: actions_7.earnedMembershipsReducer,
186771
+ transactions: actions_8.transactionsReducer,
187160
186772
  }); };
187161
186773
  var TransactionAction;
187162
186774
  (function (TransactionAction) {
187163
186775
  TransactionAction["Start"] = "start";
187164
186776
  TransactionAction["Success"] = "success";
187165
186777
  TransactionAction["Failure"] = "failure";
186778
+ TransactionAction["Reset"] = "reset";
187166
186779
  })(TransactionAction = exports.TransactionAction || (exports.TransactionAction = {}));
187167
186780
  var baseReducer = function (state, action) {
187168
186781
  var _a, _b, _c;
@@ -187181,6 +186794,8 @@ var baseReducer = function (state, action) {
187181
186794
  var error = action.error;
187182
186795
  key = action.key;
187183
186796
  return __assign(__assign({}, state), (_c = {}, _c[key] = __assign(__assign({}, state[key]), { error: error, isRequesting: false }), _c));
186797
+ case TransactionAction.Reset:
186798
+ return __assign({}, state);
187184
186799
  default:
187185
186800
  return state;
187186
186801
  }
@@ -187245,16 +186860,6 @@ exports.useAuthState = function () {
187245
186860
  var getState = React.useCallback(function (state) { return state.auth; }, []);
187246
186861
  return react_redux_1.useSelector(getState, react_redux_1.shallowEqual);
187247
186862
  };
187248
- exports.useBillingState = function () {
187249
- var dispatch = react_redux_1.useDispatch();
187250
- var getState = React.useCallback(function (state) { return state.billing; }, []);
187251
- return [react_redux_1.useSelector(getState, react_redux_1.shallowEqual), dispatch];
187252
- };
187253
- exports.useCheckoutState = function () {
187254
- var dispatch = react_redux_1.useDispatch();
187255
- var getState = React.useCallback(function (state) { return state.checkout; }, []);
187256
- return [react_redux_1.useSelector(getState, react_redux_1.shallowEqual), dispatch];
187257
- };
187258
186863
  exports.useApiState = function (reducerKey) {
187259
186864
  var dispatch = react_redux_1.useDispatch();
187260
186865
  var dispatchApi = React.useCallback(function (action) {