thm-p3-configurator 0.0.401 → 0.0.404

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.
@@ -90,7 +90,7 @@ describe('queryKeyFactory', () => {
90
90
  });
91
91
  it('includes formula in brands and build-years keys', () => {
92
92
  expect((0, _queryKeyFactory.getBrandsQueryKey)('TMG')).toEqual(['brands', 'TMG']);
93
- expect((0, _queryKeyFactory.getBrandsQueryKey)('THCB')).toEqual(['brands', 'THCB']);
93
+ expect((0, _queryKeyFactory.getBrandsQueryKey)('TBE')).toEqual(['brands', 'TBE']);
94
94
  expect((0, _queryKeyFactory.getBuildYearsQueryKey)({
95
95
  brand: 'Volvo',
96
96
  formula: 'TMG'
@@ -33,6 +33,7 @@ var _constants__ = require("../../__constants__");
33
33
  var _AuthSessionContext = require("../../__context__/AuthSessionContext");
34
34
  var _OrderSessionContext = require("../../__context__/OrderSessionContext");
35
35
  var _helpers__ = require("../../__helpers__");
36
+ var _countryOptions = require("../../__helpers__/countryOptions");
36
37
  var _useIsTmg = require("../../__hooks__/useIsTmg");
37
38
  var _AddressLookupService = _interopRequireDefault(require("../../__services__/AddressLookupService"));
38
39
  var _LinkButton = _interopRequireDefault(require("../Buttons/LinkButton"));
@@ -187,14 +188,7 @@ const InternalCustomerDetailsForm = (_ref, ref) => {
187
188
  countries,
188
189
  isLoadingCountries
189
190
  } = (0, _queries.useCountriesQuery)();
190
- const countryOptions = (0, _react.useMemo)(() => {
191
- var _countries$results;
192
- if (!(countries !== null && countries !== void 0 && (_countries$results = countries.results) !== null && _countries$results !== void 0 && _countries$results.length)) return [];
193
- return countries.results.map(country => ({
194
- label: country.title,
195
- value: country.entityId
196
- }));
197
- }, [countries]);
191
+ const countryOptions = (0, _react.useMemo)(() => (0, _countryOptions.buildCountryDropdownOptions)(countries === null || countries === void 0 ? void 0 : countries.results), [countries]);
198
192
  const authSession = (0, _AuthSessionContext.useAuthSession)();
199
193
  const isTmg = (0, _useIsTmg.useIsTmg)();
200
194
  const [companySearchTerm, setCompanySearchTerm] = (0, _react.useState)('');
@@ -510,6 +504,18 @@ const InternalCustomerDetailsForm = (_ref, ref) => {
510
504
 
511
505
  setAddressLookupTimeoutId(newTimeoutId);
512
506
  };
507
+ const handlePostalCodeChange = value => {
508
+ updateCustomerField('zipCode', value);
509
+ const inferredCountry = (0, _helpers__.getCountryOptionForPostalCode)(value, countryOptions);
510
+ if (inferredCountry && inferredCountry.value !== (customer === null || customer === void 0 ? void 0 : customer.countryId)) {
511
+ updateCustomerField('countryId', inferredCountry.value);
512
+ }
513
+
514
+ // Trigger address lookup if house number is also available
515
+ if (customer.houseNumber) {
516
+ handleAddressLookup(value, customer.houseNumber);
517
+ }
518
+ };
513
519
 
514
520
  // Cleanup timeout on unmount
515
521
  (0, _react.useEffect)(() => {
@@ -854,13 +860,7 @@ const InternalCustomerDetailsForm = (_ref, ref) => {
854
860
  placeholder: "",
855
861
  value: customer.zipCode,
856
862
  name: "zipCode",
857
- onChange: value => {
858
- updateCustomerField('zipCode', value);
859
- // Trigger address lookup if house number is also available
860
- if (customer.houseNumber) {
861
- handleAddressLookup(value, customer.houseNumber);
862
- }
863
- },
863
+ onChange: handlePostalCodeChange,
864
864
  isRequired: isDirectDeliveryEnabled,
865
865
  key: "zipCode-".concat(refreshKey),
866
866
  form: form,
@@ -913,6 +913,7 @@ const InternalCustomerDetailsForm = (_ref, ref) => {
913
913
  label: "Stad:".concat(addressLookupLoading ? ' (wordt opgezocht...)' : ''),
914
914
  errorMessage: errors === null || errors === void 0 ? void 0 : errors['city']
915
915
  }), /*#__PURE__*/_react.default.createElement(_DropdownInput.default, {
916
+ key: "country-".concat((customer === null || customer === void 0 ? void 0 : customer.countryId) || 'default'),
916
917
  options: countryOptions,
917
918
  name: "country",
918
919
  label: "Land:",
@@ -2,19 +2,19 @@
2
2
 
3
3
  var _index = require("../index");
4
4
  describe('__constants__/formula helpers', () => {
5
- it('keeps THCB exact when normalizing branch formulas', () => {
6
- expect((0, _index.mapBranchFormulaToConfiguratorFormula)('THCB')).toBe(_index.CONFIGURATOR_FORMULAS.THCB);
7
- expect((0, _index.mapBranchFormulaToConfiguratorFormula)('Trekhaakcentrum Business')).toBe(_index.CONFIGURATOR_FORMULAS.THCB);
5
+ it('keeps TBE exact when normalizing branch formulas', () => {
6
+ expect((0, _index.mapBranchFormulaToConfiguratorFormula)('TBE')).toBe(_index.CONFIGURATOR_FORMULAS.TBE);
7
+ expect((0, _index.mapBranchFormulaToConfiguratorFormula)('Trekhaakcentrum Business')).toBe(_index.CONFIGURATOR_FORMULAS.TBE);
8
8
  });
9
9
  it('normalizes known formula titles and codes without collapsing unknown codes', () => {
10
10
  expect((0, _index.getConfiguratorFormulaCode)('Trekhaakcentrum')).toBe(_index.CONFIGURATOR_FORMULAS.THC);
11
11
  expect((0, _index.getConfiguratorFormulaCode)('TowMotive')).toBe(_index.CONFIGURATOR_FORMULAS.TOW);
12
- expect((0, _index.getConfiguratorFormulaCode)('thcb')).toBe(_index.CONFIGURATOR_FORMULAS.THCB);
12
+ expect((0, _index.getConfiguratorFormulaCode)('tbe')).toBe(_index.CONFIGURATOR_FORMULAS.TBE);
13
13
  expect((0, _index.getConfiguratorFormulaCode)('abc')).toBe('ABC');
14
14
  });
15
- it('treats THCB as THC-family for theme decisions only', () => {
15
+ it('treats TBE as THC-family for theme decisions only', () => {
16
16
  expect((0, _index.isThcFamilyFormula)(_index.CONFIGURATOR_FORMULAS.THC)).toBe(true);
17
- expect((0, _index.isThcFamilyFormula)(_index.CONFIGURATOR_FORMULAS.THCB)).toBe(true);
18
- expect((0, _index.getThemeFormulaForConfiguratorFormula)(_index.CONFIGURATOR_FORMULAS.THCB)).toBe(_index.CONFIGURATOR_FORMULAS.THC);
17
+ expect((0, _index.isThcFamilyFormula)(_index.CONFIGURATOR_FORMULAS.TBE)).toBe(true);
18
+ expect((0, _index.getThemeFormulaForConfiguratorFormula)(_index.CONFIGURATOR_FORMULAS.TBE)).toBe(_index.CONFIGURATOR_FORMULAS.THC);
19
19
  });
20
20
  });
@@ -233,7 +233,7 @@ const ApiStockStatus = exports.ApiStockStatus = {
233
233
  const CONFIGURATOR_FORMULAS = exports.CONFIGURATOR_FORMULAS = {
234
234
  THM: 'THM',
235
235
  THC: 'THC',
236
- THCB: 'THCB',
236
+ TBE: 'TBE',
237
237
  TMG: 'TMG',
238
238
  TOW: 'TOW',
239
239
  TM: 'TOW',
@@ -272,10 +272,10 @@ const getConfiguratorFormulaCode = formula => {
272
272
  case 'thc':
273
273
  case 'trekhaakcentrum':
274
274
  return CONFIGURATOR_FORMULAS.THC;
275
- case 'thcb':
275
+ case 'tbe':
276
276
  case 'trekhaakcentrum belgie':
277
277
  case 'trekhaakcentrum business':
278
- return CONFIGURATOR_FORMULAS.THCB;
278
+ return CONFIGURATOR_FORMULAS.TBE;
279
279
  case 'thm':
280
280
  case 'trekhaakmontage':
281
281
  return CONFIGURATOR_FORMULAS.THM;
@@ -286,7 +286,7 @@ const getConfiguratorFormulaCode = formula => {
286
286
  exports.getConfiguratorFormulaCode = getConfiguratorFormulaCode;
287
287
  const isThcFamilyFormula = formula => {
288
288
  const normalizedFormula = getConfiguratorFormulaCode(formula);
289
- return normalizedFormula === CONFIGURATOR_FORMULAS.THC || normalizedFormula === CONFIGURATOR_FORMULAS.THCB;
289
+ return normalizedFormula === CONFIGURATOR_FORMULAS.THC || normalizedFormula === CONFIGURATOR_FORMULAS.TBE;
290
290
  };
291
291
  exports.isThcFamilyFormula = isThcFamilyFormula;
292
292
  const getThemeFormulaForConfiguratorFormula = formula => {
@@ -312,7 +312,7 @@ const NO_PRODUCTS_CONTACT_DETAILS_BY_FORMULA = exports.NO_PRODUCTS_CONTACT_DETAI
312
312
  companyName: 'Trekhaakcentrum',
313
313
  logoAltText: 'Trekhaakcentrum Logo'
314
314
  },
315
- [CONFIGURATOR_FORMULAS.THCB]: {
315
+ [CONFIGURATOR_FORMULAS.TBE]: {
316
316
  email: 'order@trekhaakcentrum.nl',
317
317
  phoneDisplay: '+31 162 - 490 910',
318
318
  phoneHref: 'tel:+31162490910',
@@ -350,7 +350,7 @@ const EXECUTION_HELP_CONTACT_DETAILS_BY_FORMULA = exports.EXECUTION_HELP_CONTACT
350
350
  phoneDisplay: '+31 85 202 0660',
351
351
  phoneHref: 'tel:+31852020660'
352
352
  },
353
- [CONFIGURATOR_FORMULAS.THCB]: {
353
+ [CONFIGURATOR_FORMULAS.TBE]: {
354
354
  phoneDisplay: '+31 85 202 0660',
355
355
  phoneHref: 'tel:+31852020660'
356
356
  }
@@ -612,11 +612,13 @@ const ProductCartTable = () => {
612
612
  var _p$priceInfo14;
613
613
  return t + Number((p === null || p === void 0 || (_p$priceInfo14 = p.priceInfo) === null || _p$priceInfo14 === void 0 ? void 0 : _p$priceInfo14.salesPrice) || 0);
614
614
  }, 0) : 0;
615
+ const apiMontageSubtotalIncl = (totals === null || totals === void 0 ? void 0 : totals.subtotalMontageInclVat) != null ? Number(totals.subtotalMontageInclVat) : null;
616
+ const mainSubtotalIncl = !isToggled && apiMontageSubtotalIncl !== null && Number.isFinite(apiMontageSubtotalIncl) ? apiMontageSubtotalIncl : mainInclVat + montageInclVat;
615
617
  return {
616
618
  main: {
617
619
  purchase: mainPurchase,
618
620
  margin: mainMargin,
619
- inclVat: mainInclVat + montageInclVat,
621
+ inclVat: mainSubtotalIncl,
620
622
  exclVat: mainExclVat + montageExclVat + marketCorrectionExclVat,
621
623
  tmg: {
622
624
  catalog: tmgCatalog,
@@ -51,6 +51,7 @@ var _AuthSessionContext = require("../../__context__/AuthSessionContext");
51
51
  var _FormulaContext = require("../../__context__/FormulaContext");
52
52
  var _OrderSessionContext = require("../../__context__/OrderSessionContext");
53
53
  var _helpers__ = require("../../__helpers__");
54
+ var _countryOptions = require("../../__helpers__/countryOptions");
54
55
  var _product = require("../../__helpers__/product");
55
56
  var _ui = require("../../__helpers__/ui");
56
57
  var _useIsTmg = require("../../__hooks__/useIsTmg");
@@ -156,6 +157,7 @@ const internalAppointmentFormSchema = (0, _yup.object)({
156
157
  houseNumberAddition: (0, _yup.string)().nullable(),
157
158
  streetName: (0, _yup.string)().required(_constants__.FORM_ERROR_MESSAGES.required),
158
159
  city: (0, _yup.string)().required(_constants__.FORM_ERROR_MESSAGES.required),
160
+ countryId: (0, _yup.string)().required(_constants__.FORM_ERROR_MESSAGES.required),
159
161
  date: (0, _yup.string)().nullable(),
160
162
  time: (0, _yup.string)().nullable(),
161
163
  customerAgreed: (0, _yup.boolean)().required(_constants__.FORM_ERROR_MESSAGES.required).isTrue(_constants__.FORM_ERROR_MESSAGES.required),
@@ -393,14 +395,7 @@ const InternalAppointmentForm = _ref => {
393
395
  countries,
394
396
  isLoadingCountries
395
397
  } = (0, _queries.useCountriesQuery)();
396
- const countryOptions = (0, _react.useMemo)(() => {
397
- var _countries$results;
398
- if (!(countries !== null && countries !== void 0 && (_countries$results = countries.results) !== null && _countries$results !== void 0 && _countries$results.length)) return [];
399
- return countries.results.map(country => ({
400
- label: country.title,
401
- value: country.entityId
402
- }));
403
- }, [countries]);
398
+ const countryOptions = (0, _react.useMemo)(() => (0, _countryOptions.buildCountryDropdownOptions)(countries === null || countries === void 0 ? void 0 : countries.results), [countries]);
404
399
  const branchType = branchTypes === null || branchTypes === void 0 || (_branchTypes$byId$aut = branchTypes.byId[authSession === null || authSession === void 0 || (_authSession$branch = authSession.branch) === null || _authSession$branch === void 0 || (_authSession$branch = _authSession$branch.organisatietype) === null || _authSession$branch === void 0 ? void 0 : _authSession$branch[0]]) === null || _branchTypes$byId$aut === void 0 ? void 0 : _branchTypes$byId$aut.title;
405
400
  const {
406
401
  marketingChannels,
@@ -443,15 +438,10 @@ const InternalAppointmentForm = _ref => {
443
438
  if (!(customer !== null && customer !== void 0 && customer.countryId) && countryOptions !== null && countryOptions !== void 0 && countryOptions.length) {
444
439
  const defaultCountry = countryOptions.find(option => option.label === 'NEDERLAND');
445
440
  if (defaultCountry) {
446
- dispatch({
447
- type: _OrderSessionContext.orderSessionActions.SET_CUSTOMER_COUNTRY_ID,
448
- payload: {
449
- countryId: defaultCountry.value
450
- }
451
- });
441
+ updateCustomerField('countryId', defaultCountry.value);
452
442
  }
453
443
  }
454
- }, [customer === null || customer === void 0 ? void 0 : customer.countryId, countryOptions, dispatch]);
444
+ }, [customer === null || customer === void 0 ? void 0 : customer.countryId, countryOptions, updateCustomerField]);
455
445
  const isBusinessOwnership = activeOwnershipType === _constants__.VEHICLE_OWNERSHIP_TYPE.Zakelijk;
456
446
  const isLeaseOwnership = activeOwnershipType === _constants__.VEHICLE_OWNERSHIP_TYPE.Leasemaatschappij;
457
447
  const isNetherlandsSelected = (0, _react.useMemo)(() => {
@@ -782,6 +772,18 @@ const InternalAppointmentForm = _ref => {
782
772
 
783
773
  setAddressLookupTimeoutId(newTimeoutId);
784
774
  };
775
+ const handlePostalCodeChange = value => {
776
+ updateCustomerField('zipCode', value);
777
+ const inferredCountry = (0, _helpers__.getCountryOptionForPostalCode)(value, countryOptions);
778
+ if (inferredCountry && inferredCountry.value !== (customer === null || customer === void 0 ? void 0 : customer.countryId)) {
779
+ updateCustomerField('countryId', inferredCountry.value);
780
+ }
781
+
782
+ // Trigger address lookup if house number is also available
783
+ if (customer.houseNumber) {
784
+ handleAddressLookup(value, customer.houseNumber);
785
+ }
786
+ };
785
787
 
786
788
  // Cleanup timeout on unmount
787
789
  (0, _react.useEffect)(() => {
@@ -1172,13 +1174,7 @@ const InternalAppointmentForm = _ref => {
1172
1174
  placeholder: "",
1173
1175
  value: customer.zipCode,
1174
1176
  name: "zipCode",
1175
- onChange: value => {
1176
- updateCustomerField('zipCode', value);
1177
- // Trigger address lookup if house number is also available
1178
- if (customer.houseNumber) {
1179
- handleAddressLookup(value, customer.houseNumber);
1180
- }
1181
- },
1177
+ onChange: handlePostalCodeChange,
1182
1178
  key: "zipCode-".concat(refreshKey),
1183
1179
  isRequired: true,
1184
1180
  label: "Postcode:",
@@ -1230,7 +1226,7 @@ const InternalAppointmentForm = _ref => {
1230
1226
  options: countryOptions,
1231
1227
  name: "country",
1232
1228
  label: "Land:",
1233
- isRequired: false,
1229
+ isRequired: true,
1234
1230
  isLoading: isLoadingCountries,
1235
1231
  noOptionsMessage: "Geen landen beschikbaar",
1236
1232
  placeholder: "Selecteer een land",
@@ -1240,12 +1236,7 @@ const InternalAppointmentForm = _ref => {
1240
1236
  let {
1241
1237
  value
1242
1238
  } = _ref6;
1243
- return dispatch({
1244
- type: _OrderSessionContext.orderSessionActions.SET_CUSTOMER_COUNTRY_ID,
1245
- payload: {
1246
- countryId: value
1247
- }
1248
- });
1239
+ return updateCustomerField('countryId', value);
1249
1240
  }
1250
1241
  }), /*#__PURE__*/_react.default.createElement("h6", {
1251
1242
  className: (0, _helpers__.withStyle)('modal-title mb-2 mt-3')
@@ -1281,13 +1272,7 @@ const InternalAppointmentForm = _ref => {
1281
1272
  placeholder: "",
1282
1273
  value: customer.zipCode,
1283
1274
  name: "zipCode",
1284
- onChange: value => {
1285
- updateCustomerField('zipCode', value);
1286
- // Trigger address lookup if house number is also available
1287
- if (customer.houseNumber) {
1288
- handleAddressLookup(value, customer.houseNumber);
1289
- }
1290
- },
1275
+ onChange: handlePostalCodeChange,
1291
1276
  key: "zipCode-".concat(refreshKey),
1292
1277
  isRequired: true,
1293
1278
  label: "Postcode:",
@@ -1339,7 +1324,7 @@ const InternalAppointmentForm = _ref => {
1339
1324
  options: countryOptions,
1340
1325
  name: "country",
1341
1326
  label: "Land:",
1342
- isRequired: false,
1327
+ isRequired: true,
1343
1328
  isLoading: isLoadingCountries,
1344
1329
  noOptionsMessage: "Geen landen beschikbaar",
1345
1330
  placeholder: "Selecteer een land",
@@ -1349,12 +1334,7 @@ const InternalAppointmentForm = _ref => {
1349
1334
  let {
1350
1335
  value
1351
1336
  } = _ref7;
1352
- return dispatch({
1353
- type: _OrderSessionContext.orderSessionActions.SET_CUSTOMER_COUNTRY_ID,
1354
- payload: {
1355
- countryId: value
1356
- }
1357
- });
1337
+ return updateCustomerField('countryId', value);
1358
1338
  }
1359
1339
  })) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_TextInput.default, {
1360
1340
  placeholder: "",
@@ -1369,13 +1349,7 @@ const InternalAppointmentForm = _ref => {
1369
1349
  placeholder: "",
1370
1350
  value: customer.zipCode,
1371
1351
  name: "zipCode",
1372
- onChange: value => {
1373
- updateCustomerField('zipCode', value);
1374
- // Trigger address lookup if house number is also available
1375
- if (customer.houseNumber) {
1376
- handleAddressLookup(value, customer.houseNumber);
1377
- }
1378
- },
1352
+ onChange: handlePostalCodeChange,
1379
1353
  key: "zipCode-".concat(refreshKey),
1380
1354
  isRequired: true,
1381
1355
  label: "Postcode:",
@@ -1427,7 +1401,7 @@ const InternalAppointmentForm = _ref => {
1427
1401
  options: countryOptions,
1428
1402
  name: "country",
1429
1403
  label: "Land:",
1430
- isRequired: false,
1404
+ isRequired: true,
1431
1405
  isLoading: isLoadingCountries,
1432
1406
  noOptionsMessage: "Geen landen beschikbaar",
1433
1407
  placeholder: "Selecteer een land",
@@ -1437,12 +1411,7 @@ const InternalAppointmentForm = _ref => {
1437
1411
  let {
1438
1412
  value
1439
1413
  } = _ref8;
1440
- return dispatch({
1441
- type: _OrderSessionContext.orderSessionActions.SET_CUSTOMER_COUNTRY_ID,
1442
- payload: {
1443
- countryId: value
1444
- }
1445
- });
1414
+ return updateCustomerField('countryId', value);
1446
1415
  }
1447
1416
  })))))), /*#__PURE__*/_react.default.createElement("div", {
1448
1417
  className: (0, _helpers__.withStyle)('col-12 mb-4')
@@ -46,6 +46,7 @@ var _AuthSessionContext = require("../../__context__/AuthSessionContext");
46
46
  var _FormulaContext = require("../../__context__/FormulaContext");
47
47
  var _OrderSessionContext = require("../../__context__/OrderSessionContext");
48
48
  var _helpers__ = require("../../__helpers__");
49
+ var _countryOptions = require("../../__helpers__/countryOptions");
49
50
  var _product = require("../../__helpers__/product");
50
51
  var _ui = require("../../__helpers__/ui");
51
52
  var _useIsTmg = require("../../__hooks__/useIsTmg");
@@ -433,14 +434,7 @@ const InternalQuotationForm = _ref => {
433
434
  return (option === null || option === void 0 || (_option$value = option.value) === null || _option$value === void 0 ? void 0 : _option$value.entityId) === (customer === null || customer === void 0 ? void 0 : customer.leasemaatschappijEntityId);
434
435
  }) || buildLeaseCompanyOption(customer);
435
436
  }, [customer, leaseCompanyOptions]);
436
- const countryOptions = (0, _react.useMemo)(() => {
437
- var _countries$results;
438
- if (!(countries !== null && countries !== void 0 && (_countries$results = countries.results) !== null && _countries$results !== void 0 && _countries$results.length)) return [];
439
- return countries.results.map(country => ({
440
- label: country.title,
441
- value: country.entityId
442
- }));
443
- }, [countries]);
437
+ const countryOptions = (0, _react.useMemo)(() => (0, _countryOptions.buildCountryDropdownOptions)(countries === null || countries === void 0 ? void 0 : countries.results), [countries]);
444
438
  const initialCountry = (0, _react.useMemo)(() => {
445
439
  if (!(countryOptions !== null && countryOptions !== void 0 && countryOptions.length)) return null;
446
440
 
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.array.sort.js");
4
+ require("core-js/modules/es.string.trim.js");
5
+ require("core-js/modules/esnext.iterator.constructor.js");
6
+ require("core-js/modules/esnext.iterator.filter.js");
7
+ require("core-js/modules/esnext.iterator.map.js");
8
+ Object.defineProperty(exports, "__esModule", {
9
+ value: true
10
+ });
11
+ exports.buildCountryDropdownOptions = void 0;
12
+ require("core-js/modules/es.array.sort.js");
13
+ require("core-js/modules/es.string.trim.js");
14
+ require("core-js/modules/esnext.iterator.constructor.js");
15
+ require("core-js/modules/esnext.iterator.filter.js");
16
+ require("core-js/modules/esnext.iterator.map.js");
17
+ var _constants__ = require("../__constants__");
18
+ const PRIORITY_COUNTRY_LABELS = [_constants__.COUNTRY_NAMES.NETHERLANDS, _constants__.COUNTRY_NAMES.BELGIUM, _constants__.COUNTRY_NAMES.BELGIUM_FALLBACK];
19
+ const normalizeCountryLabel = label => (label || '').trim().toUpperCase();
20
+ const getCountrySortPriority = label => {
21
+ const normalized = normalizeCountryLabel(label);
22
+ const index = PRIORITY_COUNTRY_LABELS.findIndex(priorityLabel => normalizeCountryLabel(priorityLabel) === normalized);
23
+ return index === -1 ? PRIORITY_COUNTRY_LABELS.length : index;
24
+ };
25
+
26
+ /**
27
+ * @description Maps Hyper countries to dropdown options: Nederland and België first, then A–Z.
28
+ */
29
+ const buildCountryDropdownOptions = exports.buildCountryDropdownOptions = function buildCountryDropdownOptions() {
30
+ let countries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
31
+ if (!(countries !== null && countries !== void 0 && countries.length)) return [];
32
+ return countries.filter(country => country.title && country.entityId).map(country => ({
33
+ label: country.title,
34
+ value: country.entityId
35
+ })).sort((a, b) => {
36
+ const priorityDiff = getCountrySortPriority(a.label) - getCountrySortPriority(b.label);
37
+ if (priorityDiff !== 0) return priorityDiff;
38
+ return (a.label || '').localeCompare(b.label || '', 'nl', {
39
+ sensitivity: 'base'
40
+ });
41
+ });
42
+ };
@@ -3,12 +3,14 @@
3
3
  require("core-js/modules/es.array.reduce.js");
4
4
  require("core-js/modules/es.object.from-entries.js");
5
5
  require("core-js/modules/es.regexp.exec.js");
6
+ require("core-js/modules/es.regexp.test.js");
6
7
  require("core-js/modules/es.regexp.to-string.js");
7
8
  require("core-js/modules/es.string.ends-with.js");
8
9
  require("core-js/modules/es.string.replace.js");
9
10
  require("core-js/modules/es.string.trim.js");
10
11
  require("core-js/modules/esnext.iterator.constructor.js");
11
12
  require("core-js/modules/esnext.iterator.filter.js");
13
+ require("core-js/modules/esnext.iterator.find.js");
12
14
  require("core-js/modules/esnext.iterator.for-each.js");
13
15
  require("core-js/modules/esnext.iterator.map.js");
14
16
  require("core-js/modules/esnext.iterator.reduce.js");
@@ -32,21 +34,26 @@ var _exportNames = {
32
34
  truncateAtPipe: true,
33
35
  parseJson: true,
34
36
  isBelgianDomain: true,
37
+ isDutchPostalCode: true,
38
+ isBelgianPostalCode: true,
39
+ getCountryOptionForPostalCode: true,
35
40
  removeNullishProps: true,
36
41
  createSlug: true,
37
42
  getProxyApiErrorMessage: true,
38
43
  formatMontageTime: true
39
44
  };
40
- exports.withStyle = exports.truncateAtPipe = exports.removeNullishProps = exports.reduceYupErrorsToObject = exports.pushToDataLayer = exports.parseJson = exports.parseDateAndTimeToTimestamp = exports.parseArrayToInputOptions = exports.normalizeArray = exports.isBelgianDomain = exports.groupByKey = exports.getProxyApiErrorMessage = exports.getConfiguratorThemeClassByFormula = exports.getConfiguratorThemeClass = exports.getConfiguratorButtonVariant = exports.formatPrice = exports.formatMontageTime = exports.createSlug = void 0;
45
+ exports.withStyle = exports.truncateAtPipe = exports.removeNullishProps = exports.reduceYupErrorsToObject = exports.pushToDataLayer = exports.parseJson = exports.parseDateAndTimeToTimestamp = exports.parseArrayToInputOptions = exports.normalizeArray = exports.isDutchPostalCode = exports.isBelgianPostalCode = exports.isBelgianDomain = exports.groupByKey = exports.getProxyApiErrorMessage = exports.getCountryOptionForPostalCode = exports.getConfiguratorThemeClassByFormula = exports.getConfiguratorThemeClass = exports.getConfiguratorButtonVariant = exports.formatPrice = exports.formatMontageTime = exports.createSlug = void 0;
41
46
  require("core-js/modules/es.array.reduce.js");
42
47
  require("core-js/modules/es.object.from-entries.js");
43
48
  require("core-js/modules/es.regexp.exec.js");
49
+ require("core-js/modules/es.regexp.test.js");
44
50
  require("core-js/modules/es.regexp.to-string.js");
45
51
  require("core-js/modules/es.string.ends-with.js");
46
52
  require("core-js/modules/es.string.replace.js");
47
53
  require("core-js/modules/es.string.trim.js");
48
54
  require("core-js/modules/esnext.iterator.constructor.js");
49
55
  require("core-js/modules/esnext.iterator.filter.js");
56
+ require("core-js/modules/esnext.iterator.find.js");
50
57
  require("core-js/modules/esnext.iterator.map.js");
51
58
  require("core-js/modules/esnext.iterator.reduce.js");
52
59
  require("core-js/modules/web.dom-collections.iterator.js");
@@ -292,11 +299,33 @@ const isBelgianDomain = () => {
292
299
  const hostname = (_window$location = window.location) === null || _window$location === void 0 || (_window$location = _window$location.hostname) === null || _window$location === void 0 ? void 0 : _window$location.toLowerCase();
293
300
  return Boolean(hostname && (hostname === 'be' || hostname.endsWith('.be')));
294
301
  };
302
+ exports.isBelgianDomain = isBelgianDomain;
303
+ const isDutchPostalCode = postalCode => {
304
+ if (!postalCode) return false;
305
+ const cleanedPostalCode = postalCode.replace(/\s/g, '');
306
+ return /^[1-9][0-9]{3}[A-Z]{2}$/i.test(cleanedPostalCode);
307
+ };
308
+ exports.isDutchPostalCode = isDutchPostalCode;
309
+ const isBelgianPostalCode = postalCode => {
310
+ if (!postalCode) return false;
311
+ const cleanedPostalCode = postalCode.replace(/\s/g, '');
312
+ return /^[1-9][0-9]{3}$/.test(cleanedPostalCode);
313
+ };
314
+ exports.isBelgianPostalCode = isBelgianPostalCode;
315
+ const normalizeCountryLabel = function normalizeCountryLabel() {
316
+ let label = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
317
+ return label.normalize('NFD').replace(/[\u0300-\u036f]/g, '').toUpperCase();
318
+ };
319
+ const getCountryOptionForPostalCode = exports.getCountryOptionForPostalCode = function getCountryOptionForPostalCode(postalCode) {
320
+ let countryOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
321
+ const countryName = isDutchPostalCode(postalCode) ? 'NEDERLAND' : isBelgianPostalCode(postalCode) ? 'BELGIE' : null;
322
+ if (!countryName) return null;
323
+ return countryOptions.find(option => normalizeCountryLabel(option === null || option === void 0 ? void 0 : option.label) === countryName) || null;
324
+ };
295
325
 
296
326
  /**
297
327
  * @description Removes nullish properties from a passed object
298
328
  */
299
- exports.isBelgianDomain = isBelgianDomain;
300
329
  const removeNullishProps = exports.removeNullishProps = function removeNullishProps() {
301
330
  let object = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
302
331
  return Object.fromEntries(Object.entries(object).filter(_ref3 => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thm-p3-configurator",
3
- "version": "0.0.401",
3
+ "version": "0.0.404",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "EnoRm.",