ProductPresentPackage.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _react = _interopRequireDefault(require("react"));
  7. var _modularityFront = _interopRequireDefault(require("modularity-front"));
  8. var _reactMaterialize = require("react-materialize");
  9. var _Pagination = _interopRequireDefault(require("../../Modules/Pagination"));
  10. var _Card = _interopRequireDefault(require("../../Modules/Card"));
  11. var _Repository = _interopRequireDefault(require("../../Services/Repository"));
  12. var _FilterModule = _interopRequireDefault(require("../../Modules/FilterModule"));
  13. var _Present = _interopRequireDefault(require("../../Modules/Product/Present"));
  14. var _Done = _interopRequireDefault(require("@material-ui/icons/Done"));
  15. var _searchbar = _interopRequireDefault(require("../../Modules/searchbar"));
  16. var _Chip = _interopRequireDefault(require("../../Modules/Chip"));
  17. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  18. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  19. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  20. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  21. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  22. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  23. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  24. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  25. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  26. function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
  27. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  28. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  29. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  30. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  31. var Module = _modularityFront.default.Module;
  32. var ProductPresentPackage =
  33. /*#__PURE__*/
  34. function (_Modularity$Module) {
  35. _inherits(ProductPresentPackage, _Modularity$Module);
  36. function ProductPresentPackage(props) {
  37. var _this;
  38. _classCallCheck(this, ProductPresentPackage);
  39. _this = _possibleConstructorReturn(this, _getPrototypeOf(ProductPresentPackage).call(this, props));
  40. _this.state = {
  41. product: {}
  42. };
  43. _this.repo = new _Repository.default('products');
  44. _this.RoutingSystem.onRouteChange("ProductPresentPackage", function () {
  45. _this.reload();
  46. }, 'product\/[0-9]+');
  47. _this.reload();
  48. return _this;
  49. }
  50. _createClass(ProductPresentPackage, [{
  51. key: "reload",
  52. value: function reload() {
  53. var _this2 = this;
  54. this.productId = this.RoutingSystem.getRoute().params.productId;
  55. if (!this.productId) return;
  56. this.repo.get(this.productId).then(function (product) {
  57. return _this2.setState({
  58. product: product
  59. });
  60. }).catch(function (e) {
  61. return alert("NOT FOUND");
  62. });
  63. }
  64. }, {
  65. key: "render",
  66. value: function render() {
  67. var _this3 = this;
  68. return _react.default.createElement("div", {
  69. className: "ProductPresentPackage"
  70. }, _react.default.createElement("div", null, _react.default.createElement(_Present.default, {
  71. Product: _objectSpread({}, this.state.product, {
  72. image: this.state.product.image || "/logo.png"
  73. }),
  74. addToCart: function addToCart(q) {
  75. return _this3.AddToCart.set({
  76. id: _this3.state.product.id,
  77. name: _this3.state.product.name,
  78. price: _this3.state.product.price,
  79. quantity: q
  80. });
  81. }
  82. })), _get(_getPrototypeOf(ProductPresentPackage.prototype), "render", this).call(this));
  83. }
  84. }]);
  85. return ProductPresentPackage;
  86. }(_modularityFront.default.Module);
  87. ProductPresentPackage.EditPosition = "center";
  88. ProductPresentPackage.Inputs = {};
  89. ProductPresentPackage.Outputs = {
  90. AddToCart: {}
  91. };
  92. ProductPresentPackage.Category = "NikatlasPackages";
  93. var _default = ProductPresentPackage;
  94. exports.default = _default;