thm-p3-configurator 0.0.356 → 0.0.357

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.
@@ -51,6 +51,8 @@ const DecimalInput = _ref => {
51
51
  value,
52
52
  name,
53
53
  onClick = () => {},
54
+ onBlur = () => {},
55
+ onKeyDown = () => {},
54
56
  isDisabled = false,
55
57
  onChange = () => {},
56
58
  isRequired = true,
@@ -93,6 +95,8 @@ const DecimalInput = _ref => {
93
95
  value: displayValue,
94
96
  disabled: isDisabled,
95
97
  onChange: e => handleChange(e.target.value),
98
+ onBlur: onBlur,
99
+ onKeyDown: onKeyDown,
96
100
  required: isRequired,
97
101
  className: "".concat((0, _helpers__.withStyle)('form-control'), " ").concat(errorMessage ? (0, _helpers__.withStyle)('is-invalid') : '')
98
102
  }), errorMessage && /*#__PURE__*/_react.default.createElement(_ErrorMessage.default, {
@@ -158,6 +158,7 @@ const parseDiscountValue = value => {
158
158
  return Math.min(100, Math.max(0, parseInt(sanitized, 10)));
159
159
  };
160
160
  const formatDiscountDraft = value => value === null || value === undefined ? '' : value.toString();
161
+ const formatMontageRateDraft = value => value === null || value === undefined ? '' : value.toString();
161
162
  const DeferredDiscountInput = _ref => {
162
163
  let {
163
164
  articleNumber,
@@ -201,6 +202,44 @@ const DeferredDiscountInput = _ref => {
201
202
  }
202
203
  }));
203
204
  };
205
+ const DeferredMontageRateInput = _ref2 => {
206
+ let {
207
+ value,
208
+ isDisabled = false,
209
+ onCommit
210
+ } = _ref2;
211
+ const [draftValue, setDraftValue] = (0, _react.useState)(formatMontageRateDraft(value));
212
+ const isEditingRef = (0, _react.useRef)(false);
213
+ (0, _react.useEffect)(() => {
214
+ if (!isEditingRef.current) {
215
+ setDraftValue(formatMontageRateDraft(value));
216
+ }
217
+ }, [value]);
218
+ return /*#__PURE__*/_react.default.createElement(_DecimalInput.default, {
219
+ label: "Montage tarief",
220
+ className: "mb-0",
221
+ name: "montage-rate",
222
+ placeholder: "0.0",
223
+ value: draftValue,
224
+ min: 0,
225
+ step: "0.1",
226
+ isRequired: false,
227
+ isDisabled: isDisabled,
228
+ onChange: nextValue => {
229
+ isEditingRef.current = true;
230
+ setDraftValue(nextValue);
231
+ },
232
+ onBlur: () => {
233
+ isEditingRef.current = false;
234
+ onCommit(draftValue);
235
+ },
236
+ onKeyDown: event => {
237
+ if (event.key === 'Enter') {
238
+ event.currentTarget.blur();
239
+ }
240
+ }
241
+ });
242
+ };
204
243
 
205
244
  // ============================================================================
206
245
  // MAIN COMPONENT
@@ -263,7 +302,7 @@ const ProductCartTable = () => {
263
302
  });
264
303
  }
265
304
  };
266
- const handleMontageRateChange = value => {
305
+ const handleMontageRateCommit = value => {
267
306
  if (value === null || value === undefined) {
268
307
  dispatch({
269
308
  type: _OrderSessionContext.orderSessionActions.SET_MONTAGE_RATE,
@@ -276,9 +315,7 @@ const ProductCartTable = () => {
276
315
 
277
316
  // Permit typing both comma and dot decimals
278
317
  const sanitized = value.toString().replace(/[^0-9.,-]/g, '').replace(',', '.');
279
-
280
- // Allow a lone "0." or "0," while typing
281
- if (sanitized === '' || sanitized === '0.' || sanitized === '0,') {
318
+ if (sanitized === '' || sanitized === '-' || sanitized === '.' || sanitized === ',') {
282
319
  dispatch({
283
320
  type: _OrderSessionContext.orderSessionActions.SET_MONTAGE_RATE,
284
321
  payload: {
@@ -617,17 +654,10 @@ const ProductCartTable = () => {
617
654
  }));
618
655
  const renderMontageRateInput = () => isThc ? null : /*#__PURE__*/_react.default.createElement("div", {
619
656
  className: (0, _helpers__.withStyle)('d-flex flex-column align-items-end justify-content-end gap-1')
620
- }, /*#__PURE__*/_react.default.createElement(_DecimalInput.default, {
621
- label: "Montage tarief",
622
- className: "mb-0",
623
- name: "montage-rate",
624
- placeholder: "0.0",
625
- value: montageRate === null || montageRate === undefined ? '' : montageRate.toString(),
626
- min: 0,
627
- step: "0.1",
628
- isRequired: false,
657
+ }, /*#__PURE__*/_react.default.createElement(DeferredMontageRateInput, {
658
+ value: montageRate,
629
659
  isDisabled: isMontageTariffFixed,
630
- onChange: handleMontageRateChange
660
+ onCommit: handleMontageRateCommit
631
661
  }), montageHourlyExcl !== null && /*#__PURE__*/_react.default.createElement("span", {
632
662
  className: (0, _helpers__.withStyle)('small text-muted')
633
663
  }, "Uurprijs: ", (0, _helpers__.formatPrice)(montageHourlyExcl)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thm-p3-configurator",
3
- "version": "0.0.356",
3
+ "version": "0.0.357",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "EnoRm.",