thm-p3-configurator 0.0.437 → 0.0.441

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.
@@ -813,7 +813,8 @@ const useBranchesByType = _ref4 => {
813
813
  }
814
814
  return response.data;
815
815
  },
816
- enabled: enabled && (allowEmptySearch || !!normalizedSearchTerm && normalizedSearchTerm.length >= 3)
816
+ enabled: enabled && (allowEmptySearch || !!normalizedSearchTerm && normalizedSearchTerm.length >= 3),
817
+ keepPreviousData: true
817
818
  });
818
819
  return {
819
820
  isLoadingBranchesByType: branchesByTypeQuery.isLoading,
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ require("core-js/modules/es.array.includes.js");
4
+ require("core-js/modules/es.string.includes.js");
3
5
  require("core-js/modules/es.weak-map.js");
4
6
  require("core-js/modules/esnext.iterator.constructor.js");
5
7
  require("core-js/modules/esnext.iterator.filter.js");
@@ -13,6 +15,8 @@ Object.defineProperty(exports, "__esModule", {
13
15
  value: true
14
16
  });
15
17
  exports.default = void 0;
18
+ require("core-js/modules/es.array.includes.js");
19
+ require("core-js/modules/es.string.includes.js");
16
20
  require("core-js/modules/esnext.iterator.constructor.js");
17
21
  require("core-js/modules/esnext.iterator.find.js");
18
22
  require("core-js/modules/web.dom-collections.iterator.js");
@@ -96,6 +100,11 @@ function _toPrimitive(t, r) {
96
100
  }
97
101
  const DEFAULT_MENU_MAX_HEIGHT = 320;
98
102
  const SCROLLABLE_OPTIONS_THRESHOLD = 7;
103
+ const filterByLabel = (option, input) => {
104
+ if (!input) return true;
105
+ const label = String((option === null || option === void 0 ? void 0 : option.label) || '');
106
+ return label.toLowerCase().includes(input.toLowerCase());
107
+ };
99
108
  const DropdownInput = _ref => {
100
109
  let {
101
110
  options = [],
@@ -106,6 +115,7 @@ const DropdownInput = _ref => {
106
115
  noOptionsMessage: _noOptionsMessage = 'Geen opties beschikbaar',
107
116
  placeholder = 'Maak een keuze',
108
117
  onChange,
118
+ onInputChange: _onInputChange = () => {},
109
119
  onMenuOpen = () => {},
110
120
  onMenuClose = () => {},
111
121
  className,
@@ -179,8 +189,12 @@ const DropdownInput = _ref => {
179
189
  noOptionsMessage: () => _noOptionsMessage,
180
190
  classNamePrefix: (0, _helpers__.withStyle)('form-select'),
181
191
  onChange: option => handleChange(option),
192
+ onInputChange: (inputValue, actionMeta) => {
193
+ _onInputChange(inputValue, actionMeta);
194
+ },
182
195
  onMenuOpen: handleMenuOpen,
183
196
  onMenuClose: handleMenuClose,
197
+ filterOption: filterByLabel,
184
198
  isLoading: isLoading,
185
199
  isDisabled: isDisabled,
186
200
  isSearchable: true,
@@ -18,7 +18,6 @@ require("core-js/modules/esnext.iterator.for-each.js");
18
18
  require("core-js/modules/web.dom-collections.iterator.js");
19
19
  var _react = _interopRequireWildcard(require("react"));
20
20
  var _reactRouter = require("react-router");
21
- var _yup = require("yup");
22
21
  var _mutations = require("../__api__/mutations");
23
22
  var _NavigationButton = _interopRequireDefault(require("../__components__/Buttons/NavigationButton"));
24
23
  var _PrimaryButton = _interopRequireDefault(require("../__components__/Buttons/PrimaryButton"));
@@ -32,12 +31,14 @@ var _constants__ = require("../__constants__");
32
31
  var _FormulaContext = require("../__context__/FormulaContext");
33
32
  var _OrderSessionContext = require("../__context__/OrderSessionContext");
34
33
  var _helpers__ = require("../__helpers__");
35
- var _prospectTracking = require("../__helpers__/prospectTracking");
36
- var _Datalayer = require("../__services__/Datalayer");
37
- var _useDebouncedPush = _interopRequireDefault(require("../__hooks__/useDebouncedPush"));
38
34
  var _product = require("../__helpers__/product");
39
- var _useIsTowmotive = require("../__hooks__/useIsTowmotive");
35
+ var _quotationFormSchema = require("../__helpers__/quotationFormSchema");
36
+ var _prospectTracking = require("../__helpers__/prospectTracking");
40
37
  var _ui = require("../__helpers__/ui");
38
+ var _useAddressLookup = _interopRequireDefault(require("../__hooks__/useAddressLookup"));
39
+ var _useIsTowmotive = require("../__hooks__/useIsTowmotive");
40
+ var _useDebouncedPush = _interopRequireDefault(require("../__hooks__/useDebouncedPush"));
41
+ var _Datalayer = require("../__services__/Datalayer");
41
42
  function _interopRequireDefault(e) {
42
43
  return e && e.__esModule ? e : {
43
44
  default: e
@@ -119,20 +120,6 @@ const trackFormField = (fieldName, action, value) => (0, _Datalayer.pushToDataLa
119
120
  action,
120
121
  action_value: value !== null && value !== void 0 ? value : ''
121
122
  });
122
- const quotationFormSchema = (0, _yup.object)({
123
- firstName: (0, _yup.string)().required(_constants__.FORM_ERROR_MESSAGES.required),
124
- infix: (0, _yup.string)().nullable(),
125
- lastName: (0, _yup.string)().required(_constants__.FORM_ERROR_MESSAGES.required),
126
- email: (0, _yup.string)().email(_constants__.FORM_ERROR_MESSAGES.email).required(_constants__.FORM_ERROR_MESSAGES.required),
127
- phoneNumber: (0, _yup.string)().required(_constants__.FORM_ERROR_MESSAGES.required),
128
- ownershipType: (0, _yup.string)().required(_constants__.FORM_ERROR_MESSAGES.required),
129
- companyName: (0, _yup.string)().when('ownershipType', {
130
- is: _constants__.VEHICLE_OWNERSHIP_TYPE.Zakelijk,
131
- then: schema => schema.required(_constants__.FORM_ERROR_MESSAGES.required),
132
- otherwise: schema => schema.nullable()
133
- }),
134
- termsAndConditions: (0, _yup.boolean)().isTrue(_constants__.FORM_ERROR_MESSAGES.required).required(_constants__.FORM_ERROR_MESSAGES.required)
135
- });
136
123
  const QuotationForm = () => {
137
124
  const [{
138
125
  customer,
@@ -162,6 +149,31 @@ const QuotationForm = () => {
162
149
  const hasTrackedValidSubmitRef = (0, _react.useRef)(false);
163
150
  const prospectIdRef = (0, _react.useRef)(null);
164
151
  const trackInput = (0, _useDebouncedPush.default)();
152
+ const updateCustomerField = (field, value) => {
153
+ const actionByField = {
154
+ zipCode: _OrderSessionContext.orderSessionActions.SET_CUSTOMER_ZIP_CODE,
155
+ houseNumber: _OrderSessionContext.orderSessionActions.SET_CUSTOMER_HOUSE_NUMBER,
156
+ houseNumberAddition: _OrderSessionContext.orderSessionActions.SET_CUSTOMER_HOUSE_NUMBER_ADDITION,
157
+ streetName: _OrderSessionContext.orderSessionActions.SET_CUSTOMER_STREET_NAME,
158
+ city: _OrderSessionContext.orderSessionActions.SET_CUSTOMER_CITY
159
+ };
160
+ dispatch({
161
+ type: actionByField[field],
162
+ payload: {
163
+ [field]: value
164
+ }
165
+ });
166
+ };
167
+ const {
168
+ isLoading: addressLookupLoading,
169
+ lookup: handleAddressLookup
170
+ } = (0, _useAddressLookup.default)({
171
+ onResult: address => {
172
+ var _address$street, _address$city;
173
+ updateCustomerField('streetName', (_address$street = address === null || address === void 0 ? void 0 : address.street) !== null && _address$street !== void 0 ? _address$street : '');
174
+ updateCustomerField('city', (_address$city = address === null || address === void 0 ? void 0 : address.city) !== null && _address$city !== void 0 ? _address$city : '');
175
+ }
176
+ });
165
177
  const {
166
178
  createQuotation,
167
179
  isCreateQuotationSuccess,
@@ -189,7 +201,7 @@ const QuotationForm = () => {
189
201
  });
190
202
  try {
191
203
  setErrors(null);
192
- quotationFormSchema.validateSync(_objectSpread(_objectSpread({}, customer), {}, {
204
+ _quotationFormSchema.quotationFormSchema.validateSync(_objectSpread(_objectSpread({}, customer), {}, {
193
205
  ownershipType: vehicle === null || vehicle === void 0 ? void 0 : vehicle.ownershipType,
194
206
  termsAndConditions: isTermsAccepted
195
207
  }), {
@@ -425,9 +437,7 @@ const QuotationForm = () => {
425
437
  form: "quotation",
426
438
  label: "Telefoonnummer:",
427
439
  errorMessage: errors === null || errors === void 0 ? void 0 : errors['phoneNumber']
428
- })), /*#__PURE__*/_react.default.createElement("div", {
429
- className: (0, _helpers__.withStyle)('col-12 col-md-6')
430
- }, (vehicle === null || vehicle === void 0 ? void 0 : vehicle.ownershipType) === _constants__.VEHICLE_OWNERSHIP_TYPE.Zakelijk && /*#__PURE__*/_react.default.createElement("div", {
440
+ }), (vehicle === null || vehicle === void 0 ? void 0 : vehicle.ownershipType) === _constants__.VEHICLE_OWNERSHIP_TYPE.Zakelijk && /*#__PURE__*/_react.default.createElement("div", {
431
441
  className: (0, _helpers__.withStyle)('mb-3')
432
442
  }, /*#__PURE__*/_react.default.createElement("h6", {
433
443
  className: (0, _helpers__.withStyle)('mb-2')
@@ -455,7 +465,114 @@ const QuotationForm = () => {
455
465
  form: "quotation",
456
466
  label: "Bedrijfsnaam:",
457
467
  errorMessage: errors === null || errors === void 0 ? void 0 : errors['companyName']
458
- })), /*#__PURE__*/_react.default.createElement(_TextAreaInput.default, {
468
+ }))), /*#__PURE__*/_react.default.createElement("div", {
469
+ className: (0, _helpers__.withStyle)('col-12 col-md-6')
470
+ }, /*#__PURE__*/_react.default.createElement("div", {
471
+ className: (0, _helpers__.withStyle)('row')
472
+ }, /*#__PURE__*/_react.default.createElement("div", {
473
+ className: (0, _helpers__.withStyle)('col-12 col-sm-4')
474
+ }, /*#__PURE__*/_react.default.createElement(_TextInput.default, {
475
+ placeholder: "",
476
+ value: customer.zipCode,
477
+ name: "zipCode",
478
+ onFocus: () => trackFormField('postcode', 'focus'),
479
+ onChange: value => {
480
+ trackInput({
481
+ event: 'form',
482
+ component: 'offerte',
483
+ element: 'text_field',
484
+ field: 'postcode',
485
+ action: 'input'
486
+ });
487
+ updateCustomerField('zipCode', value);
488
+ handleAddressLookup(value, customer.houseNumber);
489
+ },
490
+ isRequired: false,
491
+ form: "quotation",
492
+ label: "Postcode:",
493
+ errorMessage: errors === null || errors === void 0 ? void 0 : errors['zipCode']
494
+ })), /*#__PURE__*/_react.default.createElement("div", {
495
+ className: (0, _helpers__.withStyle)('col-12 col-sm-4')
496
+ }, /*#__PURE__*/_react.default.createElement(_TextInput.default, {
497
+ placeholder: "",
498
+ value: customer.houseNumber,
499
+ name: "houseNumber",
500
+ onFocus: () => trackFormField('huisnummer', 'focus'),
501
+ onChange: value => {
502
+ trackInput({
503
+ event: 'form',
504
+ component: 'offerte',
505
+ element: 'text_field',
506
+ field: 'huisnummer',
507
+ action: 'input'
508
+ });
509
+ updateCustomerField('houseNumber', value);
510
+ handleAddressLookup(customer.zipCode, value);
511
+ },
512
+ isRequired: false,
513
+ form: "quotation",
514
+ label: "Huisnummer:",
515
+ errorMessage: errors === null || errors === void 0 ? void 0 : errors['houseNumber']
516
+ })), /*#__PURE__*/_react.default.createElement("div", {
517
+ className: (0, _helpers__.withStyle)('col-12 col-sm-4')
518
+ }, /*#__PURE__*/_react.default.createElement(_TextInput.default, {
519
+ placeholder: "",
520
+ value: customer.houseNumberAddition,
521
+ name: "houseNumberAddition",
522
+ onFocus: () => trackFormField('toevoeging', 'focus'),
523
+ onChange: value => {
524
+ trackInput({
525
+ event: 'form',
526
+ component: 'offerte',
527
+ element: 'text_field',
528
+ field: 'toevoeging',
529
+ action: 'input'
530
+ });
531
+ updateCustomerField('houseNumberAddition', value);
532
+ },
533
+ isRequired: false,
534
+ form: "quotation",
535
+ label: "Toevoeging:",
536
+ errorMessage: errors === null || errors === void 0 ? void 0 : errors['houseNumberAddition']
537
+ }))), /*#__PURE__*/_react.default.createElement(_TextInput.default, {
538
+ placeholder: addressLookupLoading ? 'Adres wordt opgezocht...' : '',
539
+ value: customer.streetName,
540
+ name: "streetName",
541
+ onFocus: () => trackFormField('straat', 'focus'),
542
+ onChange: value => {
543
+ trackInput({
544
+ event: 'form',
545
+ component: 'offerte',
546
+ element: 'text_field',
547
+ field: 'straat',
548
+ action: 'input'
549
+ });
550
+ updateCustomerField('streetName', value);
551
+ },
552
+ isRequired: false,
553
+ form: "quotation",
554
+ label: "Straat:".concat(addressLookupLoading ? ' (wordt opgezocht...)' : ''),
555
+ errorMessage: errors === null || errors === void 0 ? void 0 : errors['streetName']
556
+ }), /*#__PURE__*/_react.default.createElement(_TextInput.default, {
557
+ placeholder: addressLookupLoading ? 'Stad wordt opgezocht...' : '',
558
+ value: customer.city,
559
+ name: "city",
560
+ onFocus: () => trackFormField('plaats', 'focus'),
561
+ onChange: value => {
562
+ trackInput({
563
+ event: 'form',
564
+ component: 'offerte',
565
+ element: 'text_field',
566
+ field: 'plaats',
567
+ action: 'input'
568
+ });
569
+ updateCustomerField('city', value);
570
+ },
571
+ isRequired: false,
572
+ form: "quotation",
573
+ label: "Plaats:".concat(addressLookupLoading ? ' (wordt opgezocht...)' : ''),
574
+ errorMessage: errors === null || errors === void 0 ? void 0 : errors['city']
575
+ }), /*#__PURE__*/_react.default.createElement(_TextAreaInput.default, {
459
576
  placeholder: "",
460
577
  initialValue: customer.note,
461
578
  name: "note",
@@ -14,7 +14,6 @@ require("core-js/modules/esnext.iterator.for-each.js");
14
14
  require("core-js/modules/esnext.iterator.map.js");
15
15
  require("core-js/modules/web.dom-collections.iterator.js");
16
16
  require("core-js/modules/es.weak-map.js");
17
- require("core-js/modules/esnext.iterator.filter.js");
18
17
  Object.defineProperty(exports, "__esModule", {
19
18
  value: true
20
19
  });
@@ -26,6 +25,7 @@ require("core-js/modules/es.string.includes.js");
26
25
  require("core-js/modules/es.string.replace.js");
27
26
  require("core-js/modules/es.string.trim.js");
28
27
  require("core-js/modules/esnext.iterator.constructor.js");
28
+ require("core-js/modules/esnext.iterator.filter.js");
29
29
  require("core-js/modules/esnext.iterator.find.js");
30
30
  require("core-js/modules/esnext.iterator.for-each.js");
31
31
  require("core-js/modules/esnext.iterator.map.js");
@@ -212,6 +212,10 @@ const getEmptyCustomerState = () => ({
212
212
  zakeiljkContactFactuuradres: '',
213
213
  zakelijkContactEMailadres: ''
214
214
  });
215
+ const getLeaseCompanyLabel = function getLeaseCompanyLabel() {
216
+ let branch = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
217
+ return (branch === null || branch === void 0 ? void 0 : branch.name) || (branch === null || branch === void 0 ? void 0 : branch.naamVestiging) || '';
218
+ };
215
219
  const buildLeaseCompanyOption = function buildLeaseCompanyOption() {
216
220
  let customer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
217
221
  const label = (customer === null || customer === void 0 ? void 0 : customer.leasemaatschappijBedrijfsnaam) || (customer === null || customer === void 0 ? void 0 : customer.companyName) || '';
@@ -243,9 +247,17 @@ const InternalAppointmentForm = _ref => {
243
247
  const [order, dispatch] = (0, _OrderSessionContext.useOrderSession)();
244
248
  const [refreshKey, setRefreshKey] = (0, _react.useState)(Date.now());
245
249
  const [companySearchTerm, setCompanySearchTerm] = (0, _react.useState)('');
250
+ const [leaseSearchTerm, setLeaseSearchTerm] = (0, _react.useState)('');
251
+ const [debouncedLeaseSearchTerm, setDebouncedLeaseSearchTerm] = (0, _react.useState)('');
246
252
  const [isCompanyInputFocused, setIsCompanyInputFocused] = (0, _react.useState)(false);
247
253
  const [addressLookupLoading, setAddressLookupLoading] = (0, _react.useState)(false);
248
254
  const [addressLookupTimeoutId, setAddressLookupTimeoutId] = (0, _react.useState)(null);
255
+ (0, _react.useEffect)(() => {
256
+ const timeoutId = setTimeout(() => {
257
+ setDebouncedLeaseSearchTerm(leaseSearchTerm);
258
+ }, 300);
259
+ return () => clearTimeout(timeoutId);
260
+ }, [leaseSearchTerm]);
249
261
  const {
250
262
  customerAgreed,
251
263
  customer: contextCustomer,
@@ -750,7 +762,7 @@ const InternalAppointmentForm = _ref => {
750
762
  } = (0, _queries.useBranchesByType)({
751
763
  isTmg,
752
764
  isTowCenterBranch,
753
- searchTerm: '',
765
+ searchTerm: debouncedLeaseSearchTerm,
754
766
  formula,
755
767
  ownershipType: activeOwnershipType,
756
768
  organisationType: branchType,
@@ -766,9 +778,9 @@ const InternalAppointmentForm = _ref => {
766
778
  enabled: isBusinessOwnership
767
779
  });
768
780
  const leaseCompanyOptions = (0, _react.useMemo)(() => (branchesByType || []).map(branch => ({
769
- label: branch === null || branch === void 0 ? void 0 : branch.name,
781
+ label: getLeaseCompanyLabel(branch),
770
782
  value: branch
771
- })), [branchesByType]);
783
+ })).filter(option => option.label), [branchesByType]);
772
784
  const selectedLeaseCompanyOption = (0, _react.useMemo)(() => {
773
785
  if (!(customer !== null && customer !== void 0 && customer.leasemaatschappijEntityId) && !(customer !== null && customer !== void 0 && customer.companyName)) {
774
786
  return null;
@@ -933,6 +945,8 @@ const InternalAppointmentForm = _ref => {
933
945
  initialValue: activeOwnershipType,
934
946
  onChange: val => {
935
947
  setCompanySearchTerm('');
948
+ setLeaseSearchTerm('');
949
+ setDebouncedLeaseSearchTerm('');
936
950
  setIsCompanyInputFocused(false);
937
951
  setActiveOwnershipType(val);
938
952
  },
@@ -950,11 +964,20 @@ const InternalAppointmentForm = _ref => {
950
964
  errorMessage: errors === null || errors === void 0 ? void 0 : errors['companyName'],
951
965
  initialValue: selectedLeaseCompanyOption,
952
966
  isClearable: true,
967
+ onInputChange: (inputValue, actionMeta) => {
968
+ if ((actionMeta === null || actionMeta === void 0 ? void 0 : actionMeta.action) === 'input-change') {
969
+ setLeaseSearchTerm(inputValue);
970
+ }
971
+ if ((actionMeta === null || actionMeta === void 0 ? void 0 : actionMeta.action) === 'set-value') {
972
+ setLeaseSearchTerm('');
973
+ }
974
+ },
953
975
  onChange: option => {
954
976
  const branch = option === null || option === void 0 ? void 0 : option.value;
955
- updateCustomerField('companyName', (branch === null || branch === void 0 ? void 0 : branch.name) || '');
977
+ const companyName = getLeaseCompanyLabel(branch);
978
+ updateCustomerField('companyName', companyName);
956
979
  updateCustomerField('leasemaatschappijEntityId', (branch === null || branch === void 0 ? void 0 : branch.entityId) || '');
957
- updateCustomerField('leasemaatschappijBedrijfsnaam', (branch === null || branch === void 0 ? void 0 : branch.name) || '');
980
+ updateCustomerField('leasemaatschappijBedrijfsnaam', companyName);
958
981
  }
959
982
  }), existingDossierId && existingDossierType === _constants__.DOSSIER_TYPES.PlannedAppointment && (branchById === null || branchById === void 0 ? void 0 : branchById.towCenterVestiging) === true && /*#__PURE__*/_react.default.createElement(_CheckboxInput.default, {
960
983
  name: "invoicePaymentByLeaseCompany",
@@ -13,7 +13,6 @@ require("core-js/modules/esnext.iterator.for-each.js");
13
13
  require("core-js/modules/esnext.iterator.map.js");
14
14
  require("core-js/modules/web.dom-collections.iterator.js");
15
15
  require("core-js/modules/es.weak-map.js");
16
- require("core-js/modules/esnext.iterator.filter.js");
17
16
  Object.defineProperty(exports, "__esModule", {
18
17
  value: true
19
18
  });
@@ -24,6 +23,7 @@ require("core-js/modules/es.regexp.exec.js");
24
23
  require("core-js/modules/es.string.includes.js");
25
24
  require("core-js/modules/es.string.replace.js");
26
25
  require("core-js/modules/esnext.iterator.constructor.js");
26
+ require("core-js/modules/esnext.iterator.filter.js");
27
27
  require("core-js/modules/esnext.iterator.find.js");
28
28
  require("core-js/modules/esnext.iterator.for-each.js");
29
29
  require("core-js/modules/esnext.iterator.map.js");
@@ -156,6 +156,10 @@ const getEmptyCustomerState = () => ({
156
156
  zakeiljkContactFactuuradres: '',
157
157
  zakelijkContactEMailadres: ''
158
158
  });
159
+ const getLeaseCompanyLabel = function getLeaseCompanyLabel() {
160
+ let branch = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
161
+ return (branch === null || branch === void 0 ? void 0 : branch.name) || (branch === null || branch === void 0 ? void 0 : branch.naamVestiging) || '';
162
+ };
159
163
  const buildLeaseCompanyOption = function buildLeaseCompanyOption() {
160
164
  let customer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
161
165
  const label = (customer === null || customer === void 0 ? void 0 : customer.leasemaatschappijBedrijfsnaam) || (customer === null || customer === void 0 ? void 0 : customer.companyName) || '';
@@ -252,8 +256,16 @@ const InternalQuotationForm = _ref => {
252
256
  }, dispatch] = (0, _OrderSessionContext.useOrderSession)();
253
257
  const [errors, setErrors] = (0, _react.useState)({});
254
258
  const [companySearchTerm, setCompanySearchTerm] = (0, _react.useState)('');
259
+ const [leaseSearchTerm, setLeaseSearchTerm] = (0, _react.useState)('');
260
+ const [debouncedLeaseSearchTerm, setDebouncedLeaseSearchTerm] = (0, _react.useState)('');
255
261
  const [isCompanyInputFocused, setIsCompanyInputFocused] = (0, _react.useState)(false);
256
262
  const [refreshKey, setRefreshKey] = (0, _react.useState)(Date.now());
263
+ (0, _react.useEffect)(() => {
264
+ const timeoutId = setTimeout(() => {
265
+ setDebouncedLeaseSearchTerm(leaseSearchTerm);
266
+ }, 300);
267
+ return () => clearTimeout(timeoutId);
268
+ }, [leaseSearchTerm]);
257
269
 
258
270
  // Track the original ownership type from context
259
271
  const [originalOwnershipType] = (0, _react.useState)(() => (vehicle === null || vehicle === void 0 ? void 0 : vehicle.ownershipType) || _constants__.VEHICLE_OWNERSHIP_TYPE.Particulier);
@@ -417,7 +429,7 @@ const InternalQuotationForm = _ref => {
417
429
  } = (0, _queries.useBranchesByType)({
418
430
  isTmg,
419
431
  isTowCenterBranch,
420
- searchTerm: '',
432
+ searchTerm: debouncedLeaseSearchTerm,
421
433
  formula,
422
434
  ownershipType: activeOwnershipType,
423
435
  organisationType: branchType,
@@ -433,9 +445,9 @@ const InternalQuotationForm = _ref => {
433
445
  enabled: isBusinessOwnership
434
446
  });
435
447
  const leaseCompanyOptions = (0, _react.useMemo)(() => (branchesByType || []).map(branch => ({
436
- label: branch === null || branch === void 0 ? void 0 : branch.name,
448
+ label: getLeaseCompanyLabel(branch),
437
449
  value: branch
438
- })), [branchesByType]);
450
+ })).filter(option => option.label), [branchesByType]);
439
451
  const selectedLeaseCompanyOption = (0, _react.useMemo)(() => {
440
452
  if (!(customer !== null && customer !== void 0 && customer.leasemaatschappijEntityId) && !(customer !== null && customer !== void 0 && customer.companyName)) {
441
453
  return null;
@@ -710,6 +722,8 @@ const InternalQuotationForm = _ref => {
710
722
  initialValue: activeOwnershipType,
711
723
  onChange: val => {
712
724
  setCompanySearchTerm('');
725
+ setLeaseSearchTerm('');
726
+ setDebouncedLeaseSearchTerm('');
713
727
  setIsCompanyInputFocused(false);
714
728
  setActiveOwnershipType(val);
715
729
  },
@@ -871,11 +885,20 @@ const InternalQuotationForm = _ref => {
871
885
  errorMessage: errors === null || errors === void 0 ? void 0 : errors['companyName'],
872
886
  initialValue: selectedLeaseCompanyOption,
873
887
  isClearable: true,
888
+ onInputChange: (inputValue, actionMeta) => {
889
+ if ((actionMeta === null || actionMeta === void 0 ? void 0 : actionMeta.action) === 'input-change') {
890
+ setLeaseSearchTerm(inputValue);
891
+ }
892
+ if ((actionMeta === null || actionMeta === void 0 ? void 0 : actionMeta.action) === 'set-value') {
893
+ setLeaseSearchTerm('');
894
+ }
895
+ },
874
896
  onChange: option => {
875
897
  const branch = option === null || option === void 0 ? void 0 : option.value;
876
- updateCustomerField('companyName', (branch === null || branch === void 0 ? void 0 : branch.name) || '');
898
+ const companyName = getLeaseCompanyLabel(branch);
899
+ updateCustomerField('companyName', companyName);
877
900
  updateCustomerField('leasemaatschappijEntityId', (branch === null || branch === void 0 ? void 0 : branch.entityId) || '');
878
- updateCustomerField('leasemaatschappijBedrijfsnaam', (branch === null || branch === void 0 ? void 0 : branch.name) || '');
901
+ updateCustomerField('leasemaatschappijBedrijfsnaam', companyName);
879
902
  }
880
903
  }), activeOwnershipType === _constants__.VEHICLE_OWNERSHIP_TYPE.Leasemaatschappij && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("h6", {
881
904
  className: (0, _helpers__.withStyle)('modal-title mb-2 mt-3')
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.promise.js");
4
+ require("core-js/modules/esnext.iterator.constructor.js");
5
+ require("core-js/modules/esnext.iterator.filter.js");
6
+ require("core-js/modules/esnext.iterator.for-each.js");
7
+ require("core-js/modules/esnext.iterator.constructor.js");
8
+ require("core-js/modules/esnext.iterator.filter.js");
9
+ require("core-js/modules/esnext.iterator.for-each.js");
10
+ require("core-js/modules/es.promise.js");
11
+ var _quotationFormSchema = require("../quotationFormSchema");
12
+ var _constants__ = require("../../__constants__");
13
+ function ownKeys(e, r) {
14
+ var t = Object.keys(e);
15
+ if (Object.getOwnPropertySymbols) {
16
+ var o = Object.getOwnPropertySymbols(e);
17
+ r && (o = o.filter(function (r) {
18
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
19
+ })), t.push.apply(t, o);
20
+ }
21
+ return t;
22
+ }
23
+ function _objectSpread(e) {
24
+ for (var r = 1; r < arguments.length; r++) {
25
+ var t = null != arguments[r] ? arguments[r] : {};
26
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
27
+ _defineProperty(e, r, t[r]);
28
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
29
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
30
+ });
31
+ }
32
+ return e;
33
+ }
34
+ function _defineProperty(e, r, t) {
35
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
36
+ value: t,
37
+ enumerable: !0,
38
+ configurable: !0,
39
+ writable: !0
40
+ }) : e[r] = t, e;
41
+ }
42
+ function _toPropertyKey(t) {
43
+ var i = _toPrimitive(t, "string");
44
+ return "symbol" == typeof i ? i : i + "";
45
+ }
46
+ function _toPrimitive(t, r) {
47
+ if ("object" != typeof t || !t) return t;
48
+ var e = t[Symbol.toPrimitive];
49
+ if (void 0 !== e) {
50
+ var i = e.call(t, r || "default");
51
+ if ("object" != typeof i) return i;
52
+ throw new TypeError("@@toPrimitive must return a primitive value.");
53
+ }
54
+ return ("string" === r ? String : Number)(t);
55
+ }
56
+ const baseValid = {
57
+ firstName: 'Jan',
58
+ infix: null,
59
+ lastName: 'Jansen',
60
+ email: 'jan@example.com',
61
+ phoneNumber: '0612345678',
62
+ ownershipType: _constants__.VEHICLE_OWNERSHIP_TYPE.Particulier,
63
+ companyName: null,
64
+ termsAndConditions: true
65
+ };
66
+ describe('quotationFormSchema', () => {
67
+ it('accepts a valid form without address fields', async () => {
68
+ await expect(_quotationFormSchema.quotationFormSchema.validate(baseValid)).resolves.toBeTruthy();
69
+ });
70
+ it('rejects an invalid postcode when zipCode is filled', async () => {
71
+ await expect(_quotationFormSchema.quotationFormSchema.validate(_objectSpread(_objectSpread({}, baseValid), {}, {
72
+ zipCode: '123'
73
+ }))).rejects.toMatchObject({
74
+ path: 'zipCode'
75
+ });
76
+ });
77
+ it('accepts a valid Dutch postcode with optional spaces', async () => {
78
+ await expect(_quotationFormSchema.quotationFormSchema.validate(_objectSpread(_objectSpread({}, baseValid), {}, {
79
+ zipCode: '1234 AB'
80
+ }))).resolves.toBeTruthy();
81
+ });
82
+ it('accepts a partial address without requiring street/city', async () => {
83
+ await expect(_quotationFormSchema.quotationFormSchema.validate(_objectSpread(_objectSpread({}, baseValid), {}, {
84
+ zipCode: '1234AB',
85
+ houseNumber: '12'
86
+ }))).resolves.toBeTruthy();
87
+ });
88
+ });
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.regexp.exec.js");
4
+ require("core-js/modules/es.regexp.test.js");
5
+ require("core-js/modules/es.string.trim.js");
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.quotationFormSchema = void 0;
10
+ require("core-js/modules/es.regexp.exec.js");
11
+ require("core-js/modules/es.regexp.test.js");
12
+ require("core-js/modules/es.string.trim.js");
13
+ var _yup = require("yup");
14
+ var _constants__ = require("../__constants__");
15
+ const DUTCH_POSTCODE = /^[1-9][0-9]{3}\s?[A-Za-z]{2}$/;
16
+ const quotationFormSchema = exports.quotationFormSchema = (0, _yup.object)({
17
+ firstName: (0, _yup.string)().required(_constants__.FORM_ERROR_MESSAGES.required),
18
+ infix: (0, _yup.string)().nullable(),
19
+ lastName: (0, _yup.string)().required(_constants__.FORM_ERROR_MESSAGES.required),
20
+ email: (0, _yup.string)().email(_constants__.FORM_ERROR_MESSAGES.email).required(_constants__.FORM_ERROR_MESSAGES.required),
21
+ phoneNumber: (0, _yup.string)().required(_constants__.FORM_ERROR_MESSAGES.required),
22
+ ownershipType: (0, _yup.string)().required(_constants__.FORM_ERROR_MESSAGES.required),
23
+ companyName: (0, _yup.string)().when('ownershipType', {
24
+ is: _constants__.VEHICLE_OWNERSHIP_TYPE.Zakelijk,
25
+ then: schema => schema.required(_constants__.FORM_ERROR_MESSAGES.required),
26
+ otherwise: schema => schema.nullable()
27
+ }),
28
+ termsAndConditions: (0, _yup.boolean)().isTrue(_constants__.FORM_ERROR_MESSAGES.required).required(_constants__.FORM_ERROR_MESSAGES.required),
29
+ zipCode: (0, _yup.string)().nullable().test('dutch-postcode', _constants__.FORM_ERROR_MESSAGES.postCode, value => {
30
+ const trimmed = value == null ? '' : String(value).trim();
31
+ return trimmed === '' || DUTCH_POSTCODE.test(trimmed);
32
+ })
33
+ });
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.promise.js");
4
+ require("core-js/modules/web.dom-collections.iterator.js");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+ require("core-js/modules/es.promise.js");
10
+ require("core-js/modules/web.dom-collections.iterator.js");
11
+ var _react = require("react");
12
+ var _AddressLookupService = _interopRequireDefault(require("../__services__/AddressLookupService"));
13
+ function _interopRequireDefault(e) {
14
+ return e && e.__esModule ? e : {
15
+ default: e
16
+ };
17
+ }
18
+ const addressLookupService = new _AddressLookupService.default();
19
+ const useAddressLookup = function useAddressLookup() {
20
+ let {
21
+ onResult,
22
+ debounceMs = 800
23
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
24
+ const [isLoading, setIsLoading] = (0, _react.useState)(false);
25
+ const timeoutRef = (0, _react.useRef)(null);
26
+ const requestIdRef = (0, _react.useRef)(0);
27
+ const onResultRef = (0, _react.useRef)(onResult);
28
+ onResultRef.current = onResult;
29
+ (0, _react.useEffect)(() => () => {
30
+ clearTimeout(timeoutRef.current);
31
+ requestIdRef.current += 1;
32
+ }, []);
33
+ const lookup = (0, _react.useCallback)((postcode, houseNumber) => {
34
+ var _onResultRef$current;
35
+ clearTimeout(timeoutRef.current);
36
+ requestIdRef.current += 1;
37
+ (_onResultRef$current = onResultRef.current) === null || _onResultRef$current === void 0 || _onResultRef$current.call(onResultRef, null);
38
+ if (!postcode || !houseNumber) {
39
+ setIsLoading(false);
40
+ return;
41
+ }
42
+ const requestId = requestIdRef.current;
43
+ timeoutRef.current = setTimeout(async () => {
44
+ setIsLoading(true);
45
+ try {
46
+ var _onResultRef$current2;
47
+ const addressInfo = await addressLookupService.lookup(postcode, houseNumber);
48
+ if (requestId !== requestIdRef.current) return;
49
+ (_onResultRef$current2 = onResultRef.current) === null || _onResultRef$current2 === void 0 || _onResultRef$current2.call(onResultRef, addressInfo !== null && addressInfo !== void 0 && addressInfo.street && addressInfo !== null && addressInfo !== void 0 && addressInfo.city ? addressInfo : null);
50
+ } finally {
51
+ if (requestId === requestIdRef.current) {
52
+ setIsLoading(false);
53
+ }
54
+ }
55
+ }, debounceMs);
56
+ }, [debounceMs]);
57
+ return {
58
+ isLoading,
59
+ lookup
60
+ };
61
+ };
62
+ var _default = exports.default = useAddressLookup;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thm-p3-configurator",
3
- "version": "0.0.437",
3
+ "version": "0.0.441",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "EnoRm.",