thm-p3-configurator 0.0.281 → 0.0.282

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.
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "__esModule", {
11
11
  exports.useUpdatePrivateQuotationByIdMutation = exports.useUpdatePrivateAppointmentRequestByIdMutation = exports.useUpdatePrivateAppointmentByIdMutation = exports.useCreateSingleOrderMutation = exports.useCreateShopifyOrderMutation = exports.useCreateQuotationMutation = exports.useCreatePrivateQuotationMutation = exports.useCreatePrivateAppointmentRequestMutation = exports.useCreatePrivateAppointmentMutation = exports.useCreateAppointmentRequestMutation = void 0;
12
12
  require("core-js/modules/es.promise.js");
13
13
  var _reactQuery = require("react-query");
14
+ var _montageRate = require("../__helpers__/montageRate");
14
15
  var _authenticatedProxyApi = require("./authenticatedProxyApi");
15
16
  var _publicProxyApi = require("./publicProxyApi");
16
17
  const _excluded = ["linkToExistingCustomerId"],
@@ -230,6 +231,7 @@ const useCreatePrivateQuotationMutation = () => {
230
231
  linkToExistingCustomerId
231
232
  } = _ref6,
232
233
  restCustomer = _objectWithoutProperties(_ref6, _excluded);
234
+ const apiMontageRate = (0, _montageRate.toApiMontageRate)(montageRate);
233
235
  const createQuotation = () => _authenticatedProxyApi.authenticatedProxyApi.postQuotation({
234
236
  isExitIntent,
235
237
  model,
@@ -244,7 +246,7 @@ const useCreatePrivateQuotationMutation = () => {
244
246
  selectBoardComputerUpdate,
245
247
  customer: restCustomer,
246
248
  branchId,
247
- montageRate
249
+ montageRate: apiMontageRate
248
250
  });
249
251
  if (linkToExistingCustomerId) {
250
252
  return _authenticatedProxyApi.authenticatedProxyApi.postQuotation({
@@ -261,7 +263,7 @@ const useCreatePrivateQuotationMutation = () => {
261
263
  selectBoardComputerUpdate,
262
264
  customer: restCustomer,
263
265
  branchId,
264
- montageRate
266
+ montageRate: apiMontageRate
265
267
  }).then(async res => {
266
268
  var _res$data;
267
269
  const entityId = (_res$data = res.data) === null || _res$data === void 0 || (_res$data = _res$data.data) === null || _res$data === void 0 ? void 0 : _res$data.entityId;
@@ -319,6 +321,7 @@ const useCreatePrivateAppointmentMutation = () => {
319
321
  linkToExistingCustomerId
320
322
  } = _ref8,
321
323
  restCustomer = _objectWithoutProperties(_ref8, _excluded2);
324
+ const apiMontageRate = (0, _montageRate.toApiMontageRate)(montageRate);
322
325
  const response = await _authenticatedProxyApi.authenticatedProxyApi.postAppointment({
323
326
  appointment,
324
327
  model,
@@ -335,7 +338,7 @@ const useCreatePrivateAppointmentMutation = () => {
335
338
  branchId,
336
339
  customerAgreed,
337
340
  invoicePaymentByLeaseCompany,
338
- montageRate
341
+ montageRate: apiMontageRate
339
342
  });
340
343
  const entityId = (_response$data = response.data) === null || _response$data === void 0 || (_response$data = _response$data.data) === null || _response$data === void 0 ? void 0 : _response$data.entityId;
341
344
  if (linkToExistingCustomerId && entityId) {
@@ -388,6 +391,7 @@ const useCreatePrivateAppointmentRequestMutation = () => {
388
391
  linkToExistingCustomerId
389
392
  } = _ref10,
390
393
  restCustomer = _objectWithoutProperties(_ref10, _excluded3);
394
+ const apiMontageRate = (0, _montageRate.toApiMontageRate)(montageRate);
391
395
  const response = await _authenticatedProxyApi.authenticatedProxyApi.postAppointmentRequest({
392
396
  appointment,
393
397
  model,
@@ -403,7 +407,7 @@ const useCreatePrivateAppointmentRequestMutation = () => {
403
407
  customer: restCustomer,
404
408
  branchId,
405
409
  customerAgreed,
406
- montageRate
410
+ montageRate: apiMontageRate
407
411
  });
408
412
  const entityId = (_response$data2 = response.data) === null || _response$data2 === void 0 || (_response$data2 = _response$data2.data) === null || _response$data2 === void 0 ? void 0 : _response$data2.entityId;
409
413
  if (linkToExistingCustomerId && entityId) {
@@ -448,7 +452,8 @@ const useUpdatePrivateAppointmentRequestByIdMutation = id => {
448
452
  formula,
449
453
  discount,
450
454
  priceCalculationDate,
451
- customerAgreed
455
+ customerAgreed,
456
+ montageRate
452
457
  } = _ref11;
453
458
  const _ref12 = customer || {},
454
459
  {
@@ -463,6 +468,7 @@ const useUpdatePrivateAppointmentRequestByIdMutation = id => {
463
468
  }
464
469
  });
465
470
  }
471
+ const apiMontageRate = (0, _montageRate.toApiMontageRate)(montageRate);
466
472
  return _authenticatedProxyApi.authenticatedProxyApi.putAppointmentRequestById({
467
473
  id,
468
474
  payload: {
@@ -480,7 +486,8 @@ const useUpdatePrivateAppointmentRequestByIdMutation = id => {
480
486
  customer: restCustomer,
481
487
  branchId,
482
488
  priceCalculationDate,
483
- customerAgreed
489
+ customerAgreed,
490
+ montageRate: apiMontageRate
484
491
  }
485
492
  });
486
493
  });
@@ -513,7 +520,8 @@ const useUpdatePrivateQuotationByIdMutation = id => {
513
520
  branchId,
514
521
  formula,
515
522
  discount,
516
- priceCalculationDate
523
+ priceCalculationDate,
524
+ montageRate
517
525
  } = _ref13;
518
526
  const _ref14 = customer || {},
519
527
  {
@@ -528,6 +536,7 @@ const useUpdatePrivateQuotationByIdMutation = id => {
528
536
  }
529
537
  });
530
538
  }
539
+ const apiMontageRate = (0, _montageRate.toApiMontageRate)(montageRate);
531
540
  return _authenticatedProxyApi.authenticatedProxyApi.putQuotationById({
532
541
  id,
533
542
  payload: {
@@ -542,7 +551,8 @@ const useUpdatePrivateQuotationByIdMutation = id => {
542
551
  selectBoardComputerUpdate,
543
552
  customer: restCustomer,
544
553
  branchId,
545
- priceCalculationDate
554
+ priceCalculationDate,
555
+ montageRate: apiMontageRate
546
556
  }
547
557
  });
548
558
  });
@@ -578,7 +588,8 @@ const useUpdatePrivateAppointmentByIdMutation = id => {
578
588
  formula,
579
589
  discount,
580
590
  priceCalculationDate,
581
- customerAgreed
591
+ customerAgreed,
592
+ montageRate
582
593
  } = _ref15;
583
594
  const _ref16 = customer || {},
584
595
  {
@@ -593,6 +604,7 @@ const useUpdatePrivateAppointmentByIdMutation = id => {
593
604
  }
594
605
  });
595
606
  }
607
+ const apiMontageRate = (0, _montageRate.toApiMontageRate)(montageRate);
596
608
  return _authenticatedProxyApi.authenticatedProxyApi.putAppointmentById({
597
609
  id,
598
610
  payload: {
@@ -610,7 +622,8 @@ const useUpdatePrivateAppointmentByIdMutation = id => {
610
622
  customer: restCustomer,
611
623
  branchId,
612
624
  priceCalculationDate,
613
- customerAgreed
625
+ customerAgreed,
626
+ montageRate: apiMontageRate
614
627
  }
615
628
  });
616
629
  });
@@ -42,6 +42,7 @@ var _FormulaContext = require("../__context__/FormulaContext");
42
42
  var _OrderSessionContext = require("../__context__/OrderSessionContext");
43
43
  var _helpers__ = require("../__helpers__");
44
44
  var _image = require("../__helpers__/image");
45
+ var _montageRate = require("../__helpers__/montageRate");
45
46
  var _product = require("../__helpers__/product");
46
47
  var _useIsTowmotive = require("../__hooks__/useIsTowmotive");
47
48
  function _interopRequireDefault(e) {
@@ -126,7 +127,7 @@ const ProductCartSide = () => {
126
127
  branchId: isToggled ? selectedBranch : undefined,
127
128
  discountAmount,
128
129
  discountPercentage,
129
- montageRate: montageRate !== null && montageRate !== void 0 ? montageRate : undefined
130
+ montageRate: (0, _montageRate.toApiMontageRate)(montageRate)
130
131
  });
131
132
  const marketCorrection = cart === null || cart === void 0 ? void 0 : cart.find(item => item.articleNumber === 'MC');
132
133
  let mainProducts = [];
@@ -61,6 +61,7 @@ var _OrderSessionContext = require("../__context__/OrderSessionContext");
61
61
  var _helpers__ = require("../__helpers__");
62
62
  var _cartTable2 = require("../__helpers__/cartTable");
63
63
  var _image = require("../__helpers__/image");
64
+ var _montageRate = require("../__helpers__/montageRate");
64
65
  var _product = require("../__helpers__/product");
65
66
  var _useIsTmg = require("../__hooks__/useIsTmg");
66
67
  var _useIsTowmotive = require("../__hooks__/useIsTowmotive");
@@ -276,7 +277,7 @@ const ProductCartTable = () => {
276
277
  discountAmount,
277
278
  discountPercentage,
278
279
  formula,
279
- montageRate: montageRate !== null && montageRate !== undefined ? montageRate / 100 : undefined
280
+ montageRate: (0, _montageRate.toApiMontageRate)(montageRate)
280
281
  });
281
282
  const montageHours = Number(totals === null || totals === void 0 ? void 0 : totals.montageTime) || 0;
282
283
  const montageTotalExcl = Number((totals === null || totals === void 0 ? void 0 : totals.totalMontageExclVat) || 0);
@@ -297,14 +298,13 @@ const ProductCartTable = () => {
297
298
  }, [cart, consumerDiscounts, dispatch, isToggled]);
298
299
  (0, _react.useEffect)(() => {
299
300
  const rateFromApi = totals === null || totals === void 0 ? void 0 : totals.montageRate;
300
- if (rateFromApi === undefined || rateFromApi === null) return;
301
- const numericRate = Number(rateFromApi);
302
- if (Number.isNaN(numericRate)) return;
301
+ const uiRate = (0, _montageRate.toUiMontageRate)(rateFromApi);
302
+ if (uiRate === null) return;
303
303
  if (montageRate === null || montageRate === undefined) {
304
304
  dispatch({
305
305
  type: _OrderSessionContext.orderSessionActions.SET_MONTAGE_RATE,
306
306
  payload: {
307
- montageRate: numericRate * 100
307
+ montageRate: uiRate
308
308
  }
309
309
  });
310
310
  }
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  require("core-js/modules/es.array.includes.js");
4
- require("core-js/modules/es.number.parse-float.js");
5
4
  require("core-js/modules/es.promise.js");
6
5
  require("core-js/modules/es.regexp.exec.js");
7
- require("core-js/modules/es.regexp.to-string.js");
8
6
  require("core-js/modules/es.string.includes.js");
9
7
  require("core-js/modules/es.string.replace.js");
10
8
  require("core-js/modules/es.string.trim.js");
@@ -22,10 +20,8 @@ Object.defineProperty(exports, "__esModule", {
22
20
  });
23
21
  exports.default = void 0;
24
22
  require("core-js/modules/es.array.includes.js");
25
- require("core-js/modules/es.number.parse-float.js");
26
23
  require("core-js/modules/es.promise.js");
27
24
  require("core-js/modules/es.regexp.exec.js");
28
- require("core-js/modules/es.regexp.to-string.js");
29
25
  require("core-js/modules/es.string.includes.js");
30
26
  require("core-js/modules/es.string.replace.js");
31
27
  require("core-js/modules/es.string.trim.js");
@@ -401,7 +397,6 @@ const InternalAppointmentForm = _ref => {
401
397
  isTmg: isTmg
402
398
  }
403
399
  });
404
- const parsedMontageRate = montageRate === null || montageRate === undefined ? undefined : Number.parseFloat(montageRate.toString().replace(',', '.'));
405
400
  const payload = (0, _helpers__.removeNullishProps)(_objectSpread(_objectSpread({
406
401
  vehicle,
407
402
  customer: (0, _helpers__.removeNullishProps)(_objectSpread(_objectSpread({}, customer), {}, {
@@ -456,9 +451,9 @@ const InternalAppointmentForm = _ref => {
456
451
  isTowmotiveFormula: isTowmotive,
457
452
  vehicleCodingDiscountPercentage,
458
453
  consumerDiscounts
459
- })
454
+ }),
455
+ montageRate: montageRate !== null && montageRate !== void 0 ? montageRate : undefined
460
456
  }));
461
- payload.montageRate = Number.isNaN(parsedMontageRate) ? undefined : parsedMontageRate;
462
457
  await onSubmit(payload);
463
458
  } catch (ex) {
464
459
  console.error("handleSubmit(): ".concat(ex));
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
 
3
- require("core-js/modules/es.number.parse-float.js");
4
3
  require("core-js/modules/es.promise.js");
5
4
  require("core-js/modules/es.regexp.exec.js");
6
- require("core-js/modules/es.regexp.to-string.js");
7
5
  require("core-js/modules/es.string.replace.js");
8
6
  require("core-js/modules/es.weak-map.js");
9
7
  require("core-js/modules/esnext.iterator.constructor.js");
@@ -18,10 +16,8 @@ Object.defineProperty(exports, "__esModule", {
18
16
  value: true
19
17
  });
20
18
  exports.default = void 0;
21
- require("core-js/modules/es.number.parse-float.js");
22
19
  require("core-js/modules/es.promise.js");
23
20
  require("core-js/modules/es.regexp.exec.js");
24
- require("core-js/modules/es.regexp.to-string.js");
25
21
  require("core-js/modules/es.string.replace.js");
26
22
  require("core-js/modules/esnext.iterator.constructor.js");
27
23
  require("core-js/modules/esnext.iterator.find.js");
@@ -348,7 +344,6 @@ const InternalQuotationForm = _ref => {
348
344
  isTmg
349
345
  }
350
346
  });
351
- const parsedMontageRate = montageRate === null || montageRate === undefined ? undefined : Number.parseFloat(montageRate.toString().replace(',', '.'));
352
347
  const payload = (0, _helpers__.removeNullishProps)(_objectSpread(_objectSpread({
353
348
  vehicle,
354
349
  customer: (0, _helpers__.removeNullishProps)(_objectSpread(_objectSpread({}, customer), {}, {
@@ -397,9 +392,9 @@ const InternalQuotationForm = _ref => {
397
392
  isTowmotiveFormula: isTowmotive,
398
393
  vehicleCodingDiscountPercentage,
399
394
  consumerDiscounts
400
- })
395
+ }),
396
+ montageRate: montageRate !== null && montageRate !== void 0 ? montageRate : undefined
401
397
  }));
402
- payload.montageRate = Number.isNaN(parsedMontageRate) ? undefined : parsedMontageRate;
403
398
  await onSubmit(payload);
404
399
  } catch (ex) {
405
400
  console.error("handleSubmit(): ".concat(ex));
@@ -25,6 +25,7 @@ require("core-js/modules/esnext.iterator.reduce.js");
25
25
  require("core-js/modules/esnext.iterator.some.js");
26
26
  require("core-js/modules/web.dom-collections.iterator.js");
27
27
  var _constants__ = require("../__constants__");
28
+ var _montageRate = require("./montageRate");
28
29
  function ownKeys(e, r) {
29
30
  var t = Object.keys(e);
30
31
  if (Object.getOwnPropertySymbols) {
@@ -119,6 +120,7 @@ const parseDossierToOrderSession = exports.parseDossierToOrderSession = function
119
120
  },
120
121
  discountPercentage: dossier === null || dossier === void 0 ? void 0 : dossier.kortingspercentage,
121
122
  discountAmount: (dossier === null || dossier === void 0 ? void 0 : dossier.kortingsbedragInclBtw) || null,
123
+ montageRate: (0, _montageRate.toUiMontageRate)((dossier === null || dossier === void 0 ? void 0 : dossier.montageRate) || (dossier === null || dossier === void 0 ? void 0 : dossier.montageTarief)),
122
124
  appointment: {
123
125
  date: dossier !== null && dossier !== void 0 && dossier.geplandeTijd ? new Date().setTime(dossier === null || dossier === void 0 ? void 0 : dossier.geplandeTijd) : dossier !== null && dossier !== void 0 && dossier.voorkeurstijd ? new Date().setTime(dossier === null || dossier === void 0 ? void 0 : dossier.voorkeurstijd) : null,
124
126
  time: dossier !== null && dossier !== void 0 && dossier.geplandeTijd ? new Date().setTime(dossier === null || dossier === void 0 ? void 0 : dossier.geplandeTijd) : dossier !== null && dossier !== void 0 && dossier.voorkeurstijd ? new Date().setTime(dossier === null || dossier === void 0 ? void 0 : dossier.voorkeurstijd) : null,
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.number.parse-float.js");
4
+ require("core-js/modules/es.regexp.exec.js");
5
+ require("core-js/modules/es.regexp.to-string.js");
6
+ require("core-js/modules/es.string.replace.js");
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.toUiMontageRate = exports.toApiMontageRate = void 0;
11
+ require("core-js/modules/es.number.parse-float.js");
12
+ require("core-js/modules/es.regexp.exec.js");
13
+ require("core-js/modules/es.regexp.to-string.js");
14
+ require("core-js/modules/es.string.replace.js");
15
+ /**
16
+ * @description Conversion helpers for montageRate unit normalization
17
+ * - UI / OrderSession: percent (e.g. 85 means 85%)
18
+ * - Backend + pricing API: fraction (e.g. 0.85)
19
+ */
20
+
21
+ /**
22
+ * Converts UI percent value to API fraction
23
+ * @param {number | string | null | undefined} uiPercent - The montage rate in percent (UI format)
24
+ * @returns {number | undefined} The montage rate as fraction (API format), or undefined if nullish/invalid
25
+ */
26
+ const toApiMontageRate = uiPercent => {
27
+ if (uiPercent === null || uiPercent === undefined) {
28
+ return undefined;
29
+ }
30
+
31
+ // Handle string input (e.g., "85" or "85,5")
32
+ const sanitized = typeof uiPercent === 'string' ? uiPercent.toString().replace(/[^0-9.,-]/g, '').replace(',', '.') : uiPercent.toString().replace(',', '.');
33
+
34
+ // Allow empty string or "0." / "0," while typing
35
+ if (sanitized === '' || sanitized === '0.' || sanitized === '0,') {
36
+ return undefined;
37
+ }
38
+ const parsed = Number.parseFloat(sanitized);
39
+ if (parsed === null || Number.isNaN(parsed)) {
40
+ return undefined;
41
+ }
42
+
43
+ // Clamp to >= 0 and convert percent to fraction
44
+ const clamped = Math.max(0, parsed);
45
+ return clamped / 100;
46
+ };
47
+
48
+ /**
49
+ * Converts API value to UI percent (with backward compatibility heuristic)
50
+ * @param {number | string | null | undefined} apiValue - The montage rate from API
51
+ * @returns {number | null} The montage rate in percent (UI format), or null if nullish/invalid
52
+ */
53
+ exports.toApiMontageRate = toApiMontageRate;
54
+ const toUiMontageRate = apiValue => {
55
+ if (apiValue === null || apiValue === undefined) {
56
+ return null;
57
+ }
58
+ const numericValue = Number(apiValue);
59
+ if (Number.isNaN(numericValue)) {
60
+ return null;
61
+ }
62
+
63
+ // Lenient heuristic for backward compatibility:
64
+ // - If value <= 3, assume it's a fraction and convert to percent
65
+ // - Otherwise, assume it's already in percent format
66
+ if (numericValue <= 3) {
67
+ return numericValue * 100;
68
+ }
69
+ return numericValue;
70
+ };
71
+ exports.toUiMontageRate = toUiMontageRate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thm-p3-configurator",
3
- "version": "0.0.281",
3
+ "version": "0.0.282",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "EnoRm.",