OrderPackage.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. require("./CartPage.css");
  10. var _API = _interopRequireDefault(require("../../Services/API"));
  11. var _Repository = _interopRequireDefault(require("../../Services/Repository"));
  12. var _UserService = _interopRequireDefault(require("../../Services/UserService"));
  13. var _Step = _interopRequireDefault(require("@material-ui/core/Step"));
  14. var _StepLabel = _interopRequireDefault(require("@material-ui/core/StepLabel"));
  15. var _Button = _interopRequireDefault(require("@material-ui/core/Button"));
  16. var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));
  17. var _CustomTable = _interopRequireDefault(require("../../Modules/CustomTable"));
  18. var _ViewOrder = _interopRequireDefault(require("../../HigherModules/ViewOrder"));
  19. var _TonersalesInfo = _interopRequireDefault(require("../../Inputs/TonersalesInfo"));
  20. require("./OrderPackage.css");
  21. var _CircularProgress = _interopRequireDefault(require("@material-ui/core/CircularProgress"));
  22. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  23. 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); }
  24. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  25. 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); } }
  26. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  27. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  28. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  29. 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); }
  30. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  31. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  32. 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); }
  33. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  34. var Module = _modularityFront.default.Module;
  35. var OrderPackage =
  36. /*#__PURE__*/
  37. function (_Modularity$Module) {
  38. _inherits(OrderPackage, _Modularity$Module);
  39. function OrderPackage(props) {
  40. var _this;
  41. _classCallCheck(this, OrderPackage);
  42. _this = _possibleConstructorReturn(this, _getPrototypeOf(OrderPackage).call(this, props));
  43. _this.state = {};
  44. _this.api = new _API.default('/orders', _this.Token.value);
  45. _this.addressRepo = new _Repository.default('addresses', _this.Token.value);
  46. _this.accountRepo = new _Repository.default('accounts', _this.Token.value);
  47. _this.OrdersRepo = new _Repository.default('orders', _this.Token.value);
  48. _this.userRepo = new _UserService.default({
  49. Token: function Token(t) {}
  50. });
  51. _this.Token.onUpdate(function (token) {
  52. return _this.handleToken(token);
  53. });
  54. console.log("hhh");
  55. _this.handleToken();
  56. return _this;
  57. }
  58. _createClass(OrderPackage, [{
  59. key: "getOrder",
  60. value: function getOrder() {
  61. var _this2 = this;
  62. var url = this.RoutingSystem.getRoute().url;
  63. var id = url.split('/order/')[1];
  64. this.OrdersRepo.setToken(this.Token.value);
  65. this.OrdersRepo.get(id).then(function (data) {
  66. _this2.setState({
  67. order: data
  68. });
  69. _this2.forceUpdate();
  70. });
  71. }
  72. }, {
  73. key: "routeMatch",
  74. value: function routeMatch() {
  75. return this.RoutingSystem.getRoute().url.startsWith(this.baseURL.value);
  76. }
  77. }, {
  78. key: "handleToken",
  79. value: function handleToken() {
  80. if (this.Token.value === "missing" && this.RoutingSystem.getRoute().url !== "/login" && this.routeMatch()) {
  81. this.CoreSystem.go('/login', {
  82. ref: this.RoutingSystem.getRoute().url
  83. }, true);
  84. }
  85. if (!this.Token.value) {
  86. return; // this.requestClientToken(this.Token.value);
  87. }
  88. this.api.setToken(this.Token.value);
  89. this.accountRepo.setToken(this.Token.value);
  90. this.addressRepo.setToken(this.Token.value);
  91. this.getOrder();
  92. }
  93. }, {
  94. key: "render",
  95. value: function render() {
  96. if (!this.state.order) return _react.default.createElement("div", {
  97. className: "loadin_container"
  98. }, _react.default.createElement(_reactMaterialize.Row, {
  99. className: "card"
  100. }, _react.default.createElement(_reactMaterialize.Col, {
  101. s: 12,
  102. className: "card-content"
  103. }, _react.default.createElement("div", {
  104. className: "loader"
  105. }, _react.default.createElement(_CircularProgress.default, null))), _get(_getPrototypeOf(OrderPackage.prototype), "render", this).call(this)));
  106. return _react.default.createElement("div", {
  107. className: "order_container"
  108. }, _react.default.createElement(_ViewOrder.default, {
  109. Order: this.state.order
  110. }), _get(_getPrototypeOf(OrderPackage.prototype), "render", this).call(this));
  111. }
  112. }]);
  113. return OrderPackage;
  114. }(_modularityFront.default.Module);
  115. OrderPackage.EditPosition = "center";
  116. OrderPackage.Inputs = {
  117. Order: {
  118. type: Module.Types.Object
  119. },
  120. Token: {
  121. type: Module.Types.Text
  122. },
  123. baseURL: {
  124. type: Module.Types.Text,
  125. defaultValue: "/orders/:id"
  126. }
  127. };
  128. OrderPackage.Outputs = {};
  129. OrderPackage.Category = "Sxoinas Packages";
  130. var _default = OrderPackage;
  131. exports.default = _default;