thm-p3-configurator 0.0.45 → 0.0.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1 +1,49 @@
1
- # thm-configurator-app
1
+ # thm-configurator-app
2
+
3
+ ## Local Testing of Internal Pages
4
+
5
+ To set up and test internal pages locally:
6
+
7
+ 1. Enable internal routes:
8
+
9
+ - Open `src/shared/App.jsx`
10
+ - Uncomment the following code:
11
+ ```javascript
12
+ {
13
+ APP_CONFIG.nodeEnv === 'development' && APP_CONFIG.internal === true && (
14
+ <TEST_ONLY_INTERNAL_ROUTES />
15
+ );
16
+ }
17
+ ```
18
+ - Add this import at the top of the file:
19
+ ```javascript
20
+ import TEST_ONLY_INTERNAL_ROUTES from './__pages__/internal/__TEST_ONLY_INTERNAL_ROUTES';
21
+ ```
22
+ - Run `yarn watch`
23
+
24
+ 2. Set up authentication:
25
+ - Run the trekhaak-partner-app using `yarn watch`
26
+ - Log in to the partner app
27
+ - Open browser developer tools (F12)
28
+ - Navigate to Application > Local Storage
29
+ - Copy the `__authSession` value from trekhaak-partner-app
30
+ - Go to thm-configurator-app on localhost
31
+ - Open developer tools
32
+ - Navigate to Application > Local Storage
33
+ - Paste the copied value as `__authSession`
34
+ - Refresh the page
35
+
36
+ You should now be able to access the internal pages locally, you can test this by navigating to one of the internal pages in your code editor, change some text and see if it updates.
37
+
38
+ 3. Reauthenticating (Optional)
39
+
40
+ - If you receive 401 or 403 errors, your auth session might have expired, you can reauthenticate by following the steps above.
41
+
42
+ ## Important Note
43
+
44
+ - **Do not deploy with the internal routes uncommented.**
45
+ - **Only use this for testing purposes.**
46
+
47
+ ## Production context
48
+
49
+ On production the internal routes are embedded via the `thm-p3-configurator` package. it automatically will share the auth session in production.
@@ -63,6 +63,7 @@ _reactNumericInput.default.style.plus.background = MAIN_THEME;
63
63
  _reactNumericInput.default.style.minus.background = MAIN_THEME;
64
64
  const NumericInput = _ref => {
65
65
  let {
66
+ value: propValue,
66
67
  defaultValue,
67
68
  onChange,
68
69
  min = 1,
@@ -73,11 +74,14 @@ const NumericInput = _ref => {
73
74
  name,
74
75
  label
75
76
  } = _ref;
76
- const [value, setValue] = (0, _react.useState)(defaultValue);
77
+ const [internalValue, setInternalValue] = (0, _react.useState)(defaultValue);
77
78
  const inputRef = (0, _react.useRef)();
78
- const handleChange = value => {
79
- setValue(value);
80
- onChange(value);
79
+ const value = propValue !== undefined ? propValue : internalValue;
80
+ const handleChange = newValue => {
81
+ if (propValue === undefined) {
82
+ setInternalValue(newValue);
83
+ }
84
+ onChange(newValue);
81
85
  };
82
86
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, label && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, ' ', /*#__PURE__*/_react.default.createElement("label", {
83
87
  htmlFor: name,
@@ -94,10 +98,7 @@ const NumericInput = _ref => {
94
98
  maxLength: 4,
95
99
  required: isRequired,
96
100
  onChange: handleChange,
97
- disabled: isDisabled
98
- // Inline styling to override libray
99
- ,
100
-
101
+ disabled: isDisabled,
101
102
  style: {
102
103
  wrap: {
103
104
  width: '6.5rem',
@@ -1,18 +1,22 @@
1
1
  "use strict";
2
2
 
3
+ require("core-js/modules/es.weak-map.js");
3
4
  require("core-js/modules/esnext.iterator.constructor.js");
4
5
  require("core-js/modules/esnext.iterator.find.js");
6
+ require("core-js/modules/esnext.iterator.for-each.js");
5
7
  require("core-js/modules/esnext.iterator.map.js");
6
8
  require("core-js/modules/web.dom-collections.iterator.js");
9
+ require("core-js/modules/es.weak-map.js");
7
10
  Object.defineProperty(exports, "__esModule", {
8
11
  value: true
9
12
  });
10
13
  exports.default = void 0;
11
14
  require("core-js/modules/esnext.iterator.constructor.js");
12
15
  require("core-js/modules/esnext.iterator.find.js");
16
+ require("core-js/modules/esnext.iterator.for-each.js");
13
17
  require("core-js/modules/esnext.iterator.map.js");
14
18
  require("core-js/modules/web.dom-collections.iterator.js");
15
- var _react = _interopRequireDefault(require("react"));
19
+ var _react = _interopRequireWildcard(require("react"));
16
20
  var _queries = require("../__api__/queries");
17
21
  var _NumericInput = _interopRequireDefault(require("../__components__/Form/NumericInput"));
18
22
  var _FormulaContext = require("../__context__/FormulaContext");
@@ -23,6 +27,31 @@ function _interopRequireDefault(e) {
23
27
  default: e
24
28
  };
25
29
  }
30
+ function _getRequireWildcardCache(e) {
31
+ if ("function" != typeof WeakMap) return null;
32
+ var r = new WeakMap(),
33
+ t = new WeakMap();
34
+ return (_getRequireWildcardCache = function _getRequireWildcardCache(e) {
35
+ return e ? t : r;
36
+ })(e);
37
+ }
38
+ function _interopRequireWildcard(e, r) {
39
+ if (!r && e && e.__esModule) return e;
40
+ if (null === e || "object" != typeof e && "function" != typeof e) return {
41
+ default: e
42
+ };
43
+ var t = _getRequireWildcardCache(r);
44
+ if (t && t.has(e)) return t.get(e);
45
+ var n = {
46
+ __proto__: null
47
+ },
48
+ a = Object.defineProperty && Object.getOwnPropertyDescriptor;
49
+ for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
50
+ var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
51
+ i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
52
+ }
53
+ return n.default = e, t && t.set(e, n), n;
54
+ }
26
55
  const DiscountProductsSelector = () => {
27
56
  const [{
28
57
  licensePlate,
@@ -32,7 +61,8 @@ const DiscountProductsSelector = () => {
32
61
  executionAnswer2,
33
62
  priceCalculationDate,
34
63
  discountCode,
35
- selectedDiscountedProducts
64
+ selectedDiscountedProducts,
65
+ discountsInitialized
36
66
  }, dispatch] = (0, _OrderSessionContext.useOrderSession)();
37
67
  const formula = (0, _FormulaContext.useFormula)();
38
68
  const {
@@ -47,6 +77,22 @@ const DiscountProductsSelector = () => {
47
77
  priceCalculationDate,
48
78
  discountCode
49
79
  });
80
+ (0, _react.useEffect)(() => {
81
+ if (!discountsInitialized && (discountProducts === null || discountProducts === void 0 ? void 0 : discountProducts.length) > 0) {
82
+ discountProducts.forEach(product => {
83
+ dispatch({
84
+ type: _OrderSessionContext.orderSessionActions.ADD_DISCOUNTED_PRODUCT,
85
+ payload: {
86
+ articleNumber: product === null || product === void 0 ? void 0 : product.articleNumber,
87
+ quantity: 1
88
+ }
89
+ });
90
+ });
91
+ dispatch({
92
+ type: _OrderSessionContext.orderSessionActions.DISCOUNTS_INITIALIZED
93
+ });
94
+ }
95
+ }, [discountProducts, discountsInitialized, dispatch]);
50
96
  const handleProductUpdated = _ref => {
51
97
  let {
52
98
  articleNumber,
@@ -79,7 +125,7 @@ const DiscountProductsSelector = () => {
79
125
  }, /*#__PURE__*/_react.default.createElement("div", {
80
126
  className: (0, _helpers__.withStyle)('d-flex justify-content-between align-items-center mb-1')
81
127
  }, ' ', product === null || product === void 0 ? void 0 : product.name, " (", !(product !== null && product !== void 0 && product.price) ? 'Gratis' : (0, _helpers__.formatPrice)(product.price), ")", /*#__PURE__*/_react.default.createElement(_NumericInput.default, {
82
- defaultValue: (selectedProductAmount === null || selectedProductAmount === void 0 ? void 0 : selectedProductAmount.quantity) || 0,
128
+ value: (selectedProductAmount === null || selectedProductAmount === void 0 ? void 0 : selectedProductAmount.quantity) || 0,
83
129
  isDisabled: false,
84
130
  onChange: quantity => handleProductUpdated({
85
131
  quantity,
@@ -48,6 +48,11 @@ const InternalDiscountCodeSelector = () => {
48
48
  discountCode: codeOption === null || codeOption === void 0 ? void 0 : codeOption.value
49
49
  }
50
50
  });
51
+ if (!codeOption) {
52
+ dispatch({
53
+ type: _OrderSessionContext.orderSessionActions.DISCOUNTS_REMOVED
54
+ });
55
+ }
51
56
  };
52
57
  if (isLoadingDiscounts || !Array.isArray(discounts)) return null;
53
58
  const selectedDiscountCode = discounts.find(discount => (discount === null || discount === void 0 ? void 0 : discount.code) === discountCode);
@@ -95,8 +95,8 @@ const OrderSessionContext = /*#__PURE__*/(0, _react.createContext)();
95
95
  OrderSessionContext.displayName = 'OrderSessionContext';
96
96
  const INITIAL_ORDER_SESSION_STATE = {
97
97
  isTouched: false,
98
- isEditMode: false,
99
98
  existingDossierId: null,
99
+ existingDossierType: null,
100
100
  licensePlate: null,
101
101
  buildYear: null,
102
102
  model: null,
@@ -114,6 +114,7 @@ const INITIAL_ORDER_SESSION_STATE = {
114
114
  selectedCableset: null,
115
115
  selectedCombiset: null,
116
116
  selectedDiscountedProducts: [],
117
+ discountsInitialized: false,
117
118
  selectedBoardComputer: null,
118
119
  isBoardComputerDeselected: false,
119
120
  selectedBranch: null,
@@ -164,6 +165,8 @@ const orderSessionActions = exports.orderSessionActions = {
164
165
  SET_SELECTED_CABLESET: 'SET_SELECTED_CABLESET',
165
166
  SET_SELECTED_COMBISET: 'SET_SELECTED_COMBISET',
166
167
  ADD_DISCOUNTED_PRODUCT: 'ADD_DISCOUNTED_PRODUCT',
168
+ DISCOUNTS_INITIALIZED: 'DISCOUNTS_INITIALIZED',
169
+ DISCOUNTS_REMOVED: 'DISCOUNTS_REMOVED',
167
170
  REMOVE_DISCOUNTED_PRODUCT: 'REMOVE_DISCOUNTED_PRODUCT',
168
171
  ADD_EXTRA: 'ADD_EXTRA',
169
172
  REMOVE_EXTRA: 'REMOVE_EXTRA',
@@ -694,6 +697,18 @@ const orderSessionReducer = (state, action) => {
694
697
  selectedDiscountedProducts: ((_state$selectedDiscou = state === null || state === void 0 ? void 0 : state.selectedDiscountedProducts) !== null && _state$selectedDiscou !== void 0 ? _state$selectedDiscou : []).filter(product => (product === null || product === void 0 ? void 0 : product.articleNumber) !== articleNumber)
695
698
  });
696
699
  }
700
+ case orderSessionActions.DISCOUNTS_INITIALIZED:
701
+ {
702
+ return _objectSpread(_objectSpread({}, state), {}, {
703
+ discountsInitialized: true
704
+ });
705
+ }
706
+ case orderSessionActions.DISCOUNTS_REMOVED:
707
+ {
708
+ return _objectSpread(_objectSpread({}, state), {}, {
709
+ discountsInitialized: false
710
+ });
711
+ }
697
712
  case orderSessionActions.ADD_DISCOUNTED_PRODUCT:
698
713
  {
699
714
  var _state$selectedDiscou3;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thm-p3-configurator",
3
- "version": "0.0.45",
3
+ "version": "0.0.47",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "EnoRm.",