thm-p3-configurator 0.0.288 → 0.0.289

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.
@@ -168,6 +168,7 @@ const ProductCartTable = () => {
168
168
  selectedBranch,
169
169
  vehicleCodingDiscountPercentage,
170
170
  consumerDiscounts,
171
+ touchedConsumerDiscounts,
171
172
  montageRate,
172
173
  isMontageTariffFixed
173
174
  }, dispatch] = (0, _OrderSessionContext.useOrderSession)();
@@ -207,7 +208,8 @@ const ProductCartTable = () => {
207
208
  type: _OrderSessionContext.orderSessionActions.SET_CONSUMER_DISCOUNT_PERCENTAGE,
208
209
  payload: {
209
210
  articleNumber,
210
- percentage: parsed
211
+ percentage: parsed,
212
+ userModified: true
211
213
  }
212
214
  });
213
215
  if (isVehicleCoding) {
@@ -287,7 +289,8 @@ const ProductCartTable = () => {
287
289
  (0, _react.useEffect)(() => {
288
290
  if (!isToggled || !(cart !== null && cart !== void 0 && cart.length)) return;
289
291
  cart.forEach(item => {
290
- if ((item === null || item === void 0 ? void 0 : item.consumerDiscountPercentage) !== undefined && (consumerDiscounts === null || consumerDiscounts === void 0 ? void 0 : consumerDiscounts[item.articleNumber]) === undefined) {
292
+ // Only sync non-zero values from cart; let product default be used for 0
293
+ if ((item === null || item === void 0 ? void 0 : item.consumerDiscountPercentage) > 0 && (consumerDiscounts === null || consumerDiscounts === void 0 ? void 0 : consumerDiscounts[item.articleNumber]) === undefined) {
291
294
  dispatch({
292
295
  type: _OrderSessionContext.orderSessionActions.SET_CONSUMER_DISCOUNT_PERCENTAGE,
293
296
  payload: {
@@ -428,10 +431,17 @@ const ProductCartTable = () => {
428
431
  const extras = Object.keys(selectedExtras);
429
432
  const rawAccessoireProducts = extras.length > 0 ? ((_products$Extras = products.Extras) === null || _products$Extras === void 0 ? void 0 : _products$Extras.filter(p => extras.includes(p.articleNumber.toString()))) || [] : [];
430
433
  const enhanceProduct = product => {
431
- var _ref3, _consumerDiscounts$pr;
434
+ var _cartItem$consumerDis, _product$consumerPric5, _product$consumerPric6;
432
435
  const cartItem = cartLookup === null || cartLookup === void 0 ? void 0 : cartLookup[product.articleNumber];
433
436
  const priceInfo = getItemPrices(cartItem, product);
434
- const consumerDiscountPercentage = (_ref3 = (_consumerDiscounts$pr = consumerDiscounts === null || consumerDiscounts === void 0 ? void 0 : consumerDiscounts[product.articleNumber]) !== null && _consumerDiscounts$pr !== void 0 ? _consumerDiscounts$pr : cartItem === null || cartItem === void 0 ? void 0 : cartItem.consumerDiscountPercentage) !== null && _ref3 !== void 0 ? _ref3 : null;
437
+ const storedDiscount = consumerDiscounts === null || consumerDiscounts === void 0 ? void 0 : consumerDiscounts[product.articleNumber];
438
+ const isTouched = (touchedConsumerDiscounts === null || touchedConsumerDiscounts === void 0 ? void 0 : touchedConsumerDiscounts[product.articleNumber]) === true;
439
+ const cartDiscount = (_cartItem$consumerDis = cartItem === null || cartItem === void 0 ? void 0 : cartItem.consumerDiscountPercentage) !== null && _cartItem$consumerDis !== void 0 ? _cartItem$consumerDis : 0;
440
+ const productDefault = (_product$consumerPric5 = product === null || product === void 0 || (_product$consumerPric6 = product.consumerPrices) === null || _product$consumerPric6 === void 0 ? void 0 : _product$consumerPric6.discountPercentage) !== null && _product$consumerPric5 !== void 0 ? _product$consumerPric5 : 0;
441
+
442
+ // If user explicitly modified this discount, use stored value (even if 0)
443
+ // Otherwise use cart value if non-zero, else product default
444
+ const consumerDiscountPercentage = isTouched ? storedDiscount !== null && storedDiscount !== void 0 ? storedDiscount : 0 : cartDiscount || productDefault || 0;
435
445
  return _objectSpread(_objectSpread({}, product), {}, {
436
446
  priceInfo,
437
447
  consumerDiscountPercentage
@@ -441,7 +451,7 @@ const ProductCartTable = () => {
441
451
  mainProducts: rawMainProducts.map(enhanceProduct),
442
452
  accessoireProducts: rawAccessoireProducts.map(enhanceProduct)
443
453
  };
444
- }, [products, selectedTowbar, selectedCombiset, selectedCableset, selectedBoardComputer, selectedExtras, cartLookup, consumerDiscounts, useTmgDisplayMode, isToggled]);
454
+ }, [products, selectedTowbar, selectedCombiset, selectedCableset, selectedBoardComputer, selectedExtras, cartLookup, consumerDiscounts, touchedConsumerDiscounts, useTmgDisplayMode, isToggled]);
445
455
 
446
456
  // Calculate subtotals
447
457
  const subtotals = (0, _react.useMemo)(() => {
@@ -136,6 +136,7 @@ const INITIAL_ORDER_SESSION_STATE = {
136
136
  customerAgreed: undefined,
137
137
  vehicleCodingDiscountPercentage: null,
138
138
  consumerDiscounts: {},
139
+ touchedConsumerDiscounts: {},
139
140
  montageRate: null,
140
141
  isMontageTariffFixed: false,
141
142
  vehicle: {
@@ -841,12 +842,16 @@ const orderSessionReducer = (state, action) => {
841
842
  {
842
843
  const {
843
844
  articleNumber,
844
- percentage
845
+ percentage,
846
+ userModified = false
845
847
  } = action.payload;
846
848
  return _objectSpread(_objectSpread({}, state), {}, {
847
849
  consumerDiscounts: _objectSpread(_objectSpread({}, state.consumerDiscounts), {}, {
848
850
  [articleNumber]: percentage
849
851
  }),
852
+ touchedConsumerDiscounts: userModified ? _objectSpread(_objectSpread({}, state.touchedConsumerDiscounts), {}, {
853
+ [articleNumber]: true
854
+ }) : state.touchedConsumerDiscounts,
850
855
  isTouched: true
851
856
  });
852
857
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thm-p3-configurator",
3
- "version": "0.0.288",
3
+ "version": "0.0.289",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "EnoRm.",