@everymatrix/general-registration-multistep 1.87.33 → 1.87.34

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.
@@ -14142,7 +14142,8 @@ const CONSTANTS = {
14142
14142
  STEP_THREE: 3,
14143
14143
  REMOVE_WHITESPACE_REGEX: /\s+/g,
14144
14144
  IDENTITY_CARD_NORMALIZED: "identitycard",
14145
- DATE_DASH_SEPARATOR_REGEX: /-/g
14145
+ DATE_DASH_SEPARATOR_REGEX: /-/g,
14146
+ ONLY_DIGITS_REGEX: /\D/g
14146
14147
  };
14147
14148
  const getTranslations = (url) => {
14148
14149
  // fetch url, get the data, replace the TRANSLATIONS content
@@ -14244,6 +14245,7 @@ const GeneralRegistrationMultistep = class {
14244
14245
  this.lastPostalCode = null;
14245
14246
  this.pinAttemptsExceeded = false;
14246
14247
  this.documentIdNineDigits = false;
14248
+ this.isTransitioning = false;
14247
14249
  this.selectedCountry = '';
14248
14250
  this.listOfInputValues = [];
14249
14251
  this.listOfInputValidity = [];
@@ -14367,22 +14369,36 @@ const GeneralRegistrationMultistep = class {
14367
14369
  this.isFormValid = !this.getInvalidStatus(this.listOfInputValidity);
14368
14370
  }
14369
14371
  getInputsValueHandler(event) {
14370
- var _a, _b, _c, _d;
14371
- this.listOfInputValues.find(input => {
14372
- if (input.name == event.detail.name) {
14373
- input.value = event.detail.value;
14374
- input.type = event.detail.type || null;
14375
- }
14376
- });
14372
+ var _a, _b;
14373
+ if (this.isTransitioning) {
14374
+ return;
14375
+ }
14376
+ const { name, value, type } = event.detail;
14377
+ // find the input andd add it if missing
14378
+ let inputItem = this.listOfInputValues.find(input => input.name == name);
14379
+ if (!inputItem) {
14380
+ // If the field (like ValidateSMS) is not in the list because formatConfig didn't clear the old step data
14381
+ // we force-add it so it can be saved and sent to the API
14382
+ inputItem = {
14383
+ name: name,
14384
+ value: value,
14385
+ isDuplicate: false,
14386
+ type: type || null
14387
+ };
14388
+ this.listOfInputValues = [...this.listOfInputValues, inputItem];
14389
+ }
14390
+ else {
14391
+ inputItem.value = value;
14392
+ inputItem.type = type || null;
14393
+ }
14377
14394
  // ---- Document type and document id logic - New custom registration for SA ---- //
14378
- const { name, value } = event.detail;
14379
14395
  // Check SA identity id if valid
14380
14396
  if (name === CONSTANTS.DOCUMENT_TYPE) {
14381
- let type = event.detail.value;
14382
- if ((type || "").replace(CONSTANTS.REMOVE_WHITESPACE_REGEX, "").toLowerCase() === CONSTANTS.IDENTITY_CARD_NORMALIZED) {
14383
- type = CONSTANTS.SOUTH_AFRICAN_ID;
14397
+ let docTypeValue = value;
14398
+ if ((docTypeValue || "").replace(CONSTANTS.REMOVE_WHITESPACE_REGEX, "").toLowerCase() === CONSTANTS.IDENTITY_CARD_NORMALIZED) {
14399
+ docTypeValue = CONSTANTS.SOUTH_AFRICAN_ID;
14384
14400
  }
14385
- window.documentTypeValue = type;
14401
+ window.documentTypeValue = docTypeValue;
14386
14402
  const docField = this.listOfInputValues.find(i => i.name === CONSTANTS.DOCUMENT_NUMBER);
14387
14403
  if (docField)
14388
14404
  docField.value = "";
@@ -14391,11 +14407,12 @@ const GeneralRegistrationMultistep = class {
14391
14407
  docValidity.isValid = false;
14392
14408
  window.dispatchEvent(new CustomEvent("documentNumberUpdatedExternally", { detail: "" }));
14393
14409
  window.dispatchEvent(new CustomEvent("documentNumberResetValidation"));
14410
+ this.stepsStateMachine({ event: 'set', type: 'values' });
14394
14411
  return;
14395
14412
  }
14396
- const docType = window.documentTypeValue;
14413
+ const docTypeContext = window.documentTypeValue;
14397
14414
  // Check if Passport value length and dispatch events to modify the birth date value
14398
- if (name === CONSTANTS.DOCUMENT_NUMBER && docType === CONSTANTS.PASSPORT) {
14415
+ if (name === CONSTANTS.DOCUMENT_NUMBER && docTypeContext === CONSTANTS.PASSPORT) {
14399
14416
  if (value.length === 8 || value.length === 9) {
14400
14417
  const extractedBirthDate = extractBirthDate(value);
14401
14418
  window.dispatchEvent(new CustomEvent('documentIdUpdated', { detail: extractedBirthDate || '' }));
@@ -14410,7 +14427,7 @@ const GeneralRegistrationMultistep = class {
14410
14427
  }
14411
14428
  // If number starts with '0', remove it
14412
14429
  if (name === CONSTANTS.MOBILE) {
14413
- const rawVal = (_b = (_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : {};
14430
+ const rawVal = value !== null && value !== void 0 ? value : {};
14414
14431
  const phoneRaw = typeof rawVal.phone === "string" ? rawVal.phone : "";
14415
14432
  let phone = phoneRaw;
14416
14433
  if (phone.startsWith("0")) {
@@ -14419,14 +14436,13 @@ const GeneralRegistrationMultistep = class {
14419
14436
  const mobileField = this.listOfInputValues.find(i => i.name === CONSTANTS.MOBILE);
14420
14437
  if (mobileField) {
14421
14438
  mobileField.value = {
14422
- prefix: (_c = rawVal.prefix) !== null && _c !== void 0 ? _c : "",
14439
+ prefix: (_a = rawVal.prefix) !== null && _a !== void 0 ? _a : "",
14423
14440
  phone
14424
14441
  };
14425
14442
  }
14426
14443
  }
14427
14444
  // ---- Postal code lookup logic ---- //
14428
14445
  if (this.haspostalcodelookup) {
14429
- const { name, value } = event.detail;
14430
14446
  if (name === 'CountryCode') {
14431
14447
  this.selectedCountry = value;
14432
14448
  if (value === 'GB') {
@@ -14451,7 +14467,7 @@ const GeneralRegistrationMultistep = class {
14451
14467
  this.addresses.length === 0;
14452
14468
  if (shouldFetch) {
14453
14469
  const country = this.selectedCountry ||
14454
- ((_d = this.listOfInputValues.find(i => i.name === 'CountryCode')) === null || _d === void 0 ? void 0 : _d.value) || '';
14470
+ ((_b = this.listOfInputValues.find(i => i.name === 'CountryCode')) === null || _b === void 0 ? void 0 : _b.value) || '';
14455
14471
  if (this.selectedCountry === 'GB' || this.selectedCountry === 'UK') {
14456
14472
  if (this.addrDebounce)
14457
14473
  clearTimeout(this.addrDebounce);
@@ -14469,7 +14485,7 @@ const GeneralRegistrationMultistep = class {
14469
14485
  }
14470
14486
  }
14471
14487
  this.stepsStateMachine({ event: 'set', type: 'values' });
14472
- this.handleConditionalValidation(event.detail.name, event.detail.value);
14488
+ this.handleConditionalValidation(name, value);
14473
14489
  }
14474
14490
  handleAddressSelection(event) {
14475
14491
  const { city, address1, address2 } = event.detail;
@@ -14504,7 +14520,7 @@ const GeneralRegistrationMultistep = class {
14504
14520
  handleCountryCodeUpdateGlobal(event) {
14505
14521
  const { name } = event.detail;
14506
14522
  if (name === 'CountryCode') {
14507
- const savedState = localStorage.getItem('registrationStepsState');
14523
+ const savedState = sessionStorage.getItem('registrationStepsState');
14508
14524
  if (savedState) {
14509
14525
  const parsedState = JSON.parse(savedState);
14510
14526
  Object.keys(parsedState).forEach(stepKey => {
@@ -14516,7 +14532,7 @@ const GeneralRegistrationMultistep = class {
14516
14532
  });
14517
14533
  }
14518
14534
  });
14519
- localStorage.setItem('registrationStepsState', JSON.stringify(parsedState));
14535
+ sessionStorage.setItem('registrationStepsState', JSON.stringify(parsedState));
14520
14536
  }
14521
14537
  }
14522
14538
  }
@@ -14580,6 +14596,10 @@ const GeneralRegistrationMultistep = class {
14580
14596
  }
14581
14597
  async componentWillLoad() {
14582
14598
  await customElements.whenDefined('general-input');
14599
+ const navigationEntries = performance.getEntriesByType('navigation');
14600
+ if (navigationEntries.length > 0 && navigationEntries[0].type === 'reload') {
14601
+ sessionStorage.removeItem('registrationStepsState');
14602
+ }
14583
14603
  const config = await this.getRegisterConfig();
14584
14604
  this.formatConfig(config);
14585
14605
  this.isFormValid = !this.getInvalidStatus(this.listOfInputValidity);
@@ -14684,11 +14704,75 @@ const GeneralRegistrationMultistep = class {
14684
14704
  this.setRegisterStep();
14685
14705
  }
14686
14706
  backHandler(e) {
14707
+ var _a, _b, _c, _d;
14687
14708
  e.preventDefault();
14688
- this.registrationStep = this.stepChange('decrement');
14689
- this.errorMessage = '';
14690
- this.stepsStateMachine({ event: 'get', type: 'inputs' });
14691
- this.stepsStateMachine({ event: 'get', type: 'values' });
14709
+ this.isTransitioning = true;
14710
+ const stepBeforeBack = this.registrationStep;
14711
+ let targetStep = this.stepChange('decrement');
14712
+ if (stepBeforeBack === 'Step3') {
14713
+ targetStep = 'Step1';
14714
+ this.registrationID = null;
14715
+ this.registrationStepsState.regId = null;
14716
+ const savedUserData = JSON.parse(sessionStorage.getItem('registrationStepsState')) || {};
14717
+ const oldPrefix = ((_d = (_c = (_b = (_a = savedUserData === null || savedUserData === void 0 ? void 0 : savedUserData.Step1) === null || _a === void 0 ? void 0 : _a.registerUserData) === null || _b === void 0 ? void 0 : _b.Mobile) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.prefix) || '+27';
14718
+ sessionStorage.removeItem('registrationStepsState');
14719
+ this.registrationStepsState = {
14720
+ regId: null
14721
+ };
14722
+ this.listOfInputValues = [];
14723
+ this.getRegisterConfig().then(config => {
14724
+ this.formatConfig(config);
14725
+ this.registrationID = config.content.registrationID;
14726
+ setTimeout(() => {
14727
+ this.listOfInputValues = this.listOfInputs.map(field => {
14728
+ var _a;
14729
+ if (field.name === 'Mobile') {
14730
+ return { name: field.name, value: { prefix: oldPrefix, phone: '' }, isDuplicate: false, type: 'tel' };
14731
+ }
14732
+ return {
14733
+ name: field.name,
14734
+ value: ((_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'checkbox' ? 'false' : null,
14735
+ isDuplicate: field.isDuplicateInput || false,
14736
+ type: field.inputType
14737
+ };
14738
+ });
14739
+ this.forms = Object.assign({}, this.forms);
14740
+ }, 100);
14741
+ });
14742
+ }
14743
+ this.registrationStep = targetStep;
14744
+ const savedDataAtTarget = JSON.parse(sessionStorage.getItem('registrationStepsState'));
14745
+ if (savedDataAtTarget && savedDataAtTarget[targetStep] && savedDataAtTarget[targetStep].fields) {
14746
+ const stepData = savedDataAtTarget[targetStep];
14747
+ this.listOfInputValidity = [...stepData.fieldsValidity];
14748
+ this.listOfInputs = [...stepData.fields];
14749
+ this.forms = Object.assign(Object.assign({}, this.forms), { [targetStep]: this.listOfInputs.map(input => (Object.assign({}, input))) });
14750
+ const savedValues = stepData.registerUserData || {};
14751
+ this.listOfInputValues = Object.keys(savedValues).length > 0
14752
+ ? Object.keys(savedValues).map(name => ({
14753
+ name,
14754
+ value: savedValues[name].value,
14755
+ isDuplicate: savedValues[name].isDuplicate
14756
+ }))
14757
+ : this.listOfInputs.map(field => {
14758
+ var _a;
14759
+ return ({
14760
+ name: field.name,
14761
+ value: ((_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'checkbox' ? 'false' : null,
14762
+ isDuplicate: field.isDuplicateInput || false
14763
+ });
14764
+ });
14765
+ this.forms[targetStep] = this.forms[targetStep].map(input => {
14766
+ const savedData = this.listOfInputValues.find(v => v.name === input.name);
14767
+ return savedData ? Object.assign(Object.assign({}, input), { defaultValue: savedData.value }) : input;
14768
+ });
14769
+ }
14770
+ else if (stepBeforeBack !== 'Step3') {
14771
+ this.getRegisterConfig(this.registrationID).then(config => this.formatConfig(config));
14772
+ }
14773
+ this.forms = Object.assign({}, this.forms);
14774
+ this.isFormValid = !this.getInvalidStatus(this.listOfInputValidity);
14775
+ setTimeout(() => { this.isTransitioning = false; }, 300);
14692
14776
  }
14693
14777
  dispatchRegisterCredentialsEvent() {
14694
14778
  let userNameEmail = '';
@@ -14719,10 +14803,10 @@ const GeneralRegistrationMultistep = class {
14719
14803
  stepsStateMachine(state) {
14720
14804
  var _a;
14721
14805
  const saveToLocalStorage = () => {
14722
- localStorage.setItem('registrationStepsState', JSON.stringify(this.registrationStepsState));
14806
+ sessionStorage.setItem('registrationStepsState', JSON.stringify(this.registrationStepsState));
14723
14807
  };
14724
14808
  const loadFromLocalStorage = () => {
14725
- return JSON.parse(localStorage.getItem('registrationStepsState'));
14809
+ return JSON.parse(sessionStorage.getItem('registrationStepsState'));
14726
14810
  };
14727
14811
  switch (state.event) {
14728
14812
  case 'set':
@@ -14734,7 +14818,9 @@ const GeneralRegistrationMultistep = class {
14734
14818
  currentStep.fieldsValidity = this.listOfInputValidity;
14735
14819
  }
14736
14820
  if (state.type == 'values') {
14737
- // Map input values into the current step state
14821
+ if (!this.registrationStepsState[this.registrationStep]) {
14822
+ this.registrationStepsState[this.registrationStep] = {};
14823
+ }
14738
14824
  const currentStep = this.registrationStepsState[this.registrationStep];
14739
14825
  currentStep.registerUserData = this.listOfInputValues.reduce((acc, curr) => {
14740
14826
  acc[curr.name] = { value: curr.value, isDuplicate: curr.isDuplicate };
@@ -14745,21 +14831,42 @@ const GeneralRegistrationMultistep = class {
14745
14831
  break;
14746
14832
  case 'get':
14747
14833
  const savedUserData = loadFromLocalStorage();
14748
- if (!savedUserData)
14834
+ if (!savedUserData || !savedUserData[this.registrationStep])
14749
14835
  return;
14750
14836
  if (state.type == 'inputs') {
14751
14837
  // Load input-related data from the saved state
14752
- const currentStep = this.registrationStepsState[this.registrationStep];
14838
+ const currentStep = savedUserData[this.registrationStep];
14753
14839
  this.listOfInputs = currentStep.fields;
14754
14840
  this.listOfActions = currentStep.actions;
14755
14841
  this.listOfInputValidity = currentStep.fieldsValidity;
14842
+ if (!this.registrationStepsState[this.registrationStep]) {
14843
+ this.registrationStepsState[this.registrationStep] = {};
14844
+ }
14845
+ this.registrationStepsState[this.registrationStep].fields = currentStep.fields;
14846
+ this.registrationStepsState[this.registrationStep].fieldsValidity = currentStep.fieldsValidity;
14756
14847
  }
14757
14848
  if (state.type == 'values') {
14758
- const savedValues = savedUserData[this.registrationStep].registerUserData;
14849
+ const stepEntry = savedUserData[this.registrationStep];
14850
+ if (!stepEntry || !stepEntry.registerUserData || Object.keys(stepEntry.registerUserData).length === 0) {
14851
+ return;
14852
+ }
14853
+ const savedValues = stepEntry.registerUserData;
14759
14854
  // Convert saved values to the expected format for inputs
14760
14855
  this.listOfInputValues = Object.keys(savedValues).map(name => {
14761
14856
  return { name, value: savedValues[name].value, isDuplicate: savedValues[name].isDuplicate };
14762
14857
  });
14858
+ // Sync local state object with storage values
14859
+ if (!this.registrationStepsState[this.registrationStep]) {
14860
+ this.registrationStepsState[this.registrationStep] = {};
14861
+ }
14862
+ this.registrationStepsState[this.registrationStep].registerUserData = savedValues;
14863
+ // Sync the forms object to ensure UI rendering
14864
+ if (this.forms[this.registrationStep]) {
14865
+ this.forms[this.registrationStep] = this.forms[this.registrationStep].map(input => {
14866
+ const savedData = this.listOfInputValues.find(v => v.name === input.name);
14867
+ return savedData ? Object.assign(Object.assign({}, input), { defaultValue: savedData.value }) : input;
14868
+ });
14869
+ }
14763
14870
  // Set the right documentTypeValue when the step is loaded
14764
14871
  let docType = (_a = this.listOfInputValues.find(i => i.name === CONSTANTS.DOCUMENT_TYPE)) === null || _a === void 0 ? void 0 : _a.value;
14765
14872
  if (docType === CONSTANTS.IDENTITY_CARD)
@@ -14774,7 +14881,9 @@ const GeneralRegistrationMultistep = class {
14774
14881
  if (input.inputType === 'togglecheckbox') {
14775
14882
  input.data.subFields.forEach((subfield) => {
14776
14883
  const subfieldValue = this.listOfInputValues.find(subfieldValue => subfieldValue.name === subfield.name);
14777
- subfield.defaultValue = subfieldValue.value;
14884
+ if (subfieldValue) {
14885
+ subfield.defaultValue = subfieldValue.value;
14886
+ }
14778
14887
  });
14779
14888
  }
14780
14889
  }
@@ -14837,45 +14946,87 @@ const GeneralRegistrationMultistep = class {
14837
14946
  setRegisterStep() {
14838
14947
  this.isLoadingPOST = true;
14839
14948
  const url = new URL(`${this.endpoint}/v1/player/legislation/registration/step/`);
14949
+ this.stepsStateMachine({ event: 'set', type: 'values' });
14950
+ const currentStepValue = this.registrationStep;
14840
14951
  const registerStep = {
14841
14952
  registrationId: this.registrationID,
14842
14953
  registerUserDto: this.listOfInputValues
14843
- .filter(input => !input.isDuplicate)
14954
+ .filter(input => {
14955
+ if (input.name === 'ValidateSMS')
14956
+ return true;
14957
+ return !input.isDuplicate;
14958
+ })
14844
14959
  .reduce((acc, curr) => {
14845
- // Because the API is very robust, some values need to be split as separate entities.
14846
- if (curr.name === 'TypeOfPublicArea') {
14847
- acc[curr.name] = curr.value.toLowerCase();
14960
+ // Handle SMS Validation field
14961
+ if (curr.name === 'ValidateSMS') {
14962
+ acc[curr.name] = curr.value;
14963
+ }
14964
+ // Handle specific dropdown fields that need lowercase values
14965
+ else if (curr.name === 'TypeOfPublicArea') {
14966
+ acc[curr.name] = curr.value ? curr.value.toLowerCase() : '';
14848
14967
  }
14849
- else if (curr.type === 'tel') {
14850
- //@ts-ignore
14851
- acc['MobilePrefix'] = curr.value.prefix;
14852
- //@ts-ignore
14853
- acc[curr.name] = curr.value.phone;
14968
+ // handlbe mobile number and prefix
14969
+ else if (curr.name === 'Mobile') {
14970
+ const mobileVal = curr.value;
14971
+ let phone = '';
14972
+ let prefix = '';
14973
+ // extract values from object (general-input format) or fallback to string
14974
+ if (typeof mobileVal === 'object' && mobileVal !== null) {
14975
+ phone = mobileVal.phone || '';
14976
+ prefix = mobileVal.prefix || '';
14977
+ }
14978
+ else {
14979
+ phone = mobileVal || '';
14980
+ }
14981
+ // rmove all non-digit characters from the phone string
14982
+ let cleanPhone = phone.toString().replace(CONSTANTS.ONLY_DIGITS_REGEX, '');
14983
+ // get digits from prefix to check for duplication (e.g., "27" from "+27")
14984
+ const prefixDigits = prefix.replace(CONSTANTS.ONLY_DIGITS_REGEX, '');
14985
+ // clear duplicate prefix
14986
+ if (prefixDigits && cleanPhone.startsWith(prefixDigits)) {
14987
+ cleanPhone = cleanPhone.slice(prefixDigits.length);
14988
+ }
14989
+ // remove leading zero if present
14990
+ if (cleanPhone.startsWith('0')) {
14991
+ cleanPhone = cleanPhone.slice(1);
14992
+ }
14993
+ acc['MobilePrefix'] = prefix;
14994
+ acc['Mobile'] = cleanPhone;
14854
14995
  }
14996
+ // Handle Checkbox Groups
14855
14997
  else if (curr.type === 'checkboxgroup') {
14856
- // Skip adding the parent of the checkboxgroup as a key.
14857
14998
  if (curr.value !== null) {
14858
14999
  Object.entries(curr.value).forEach(([key, value]) => {
14859
15000
  acc[key] = value ? 'true' : 'false';
14860
15001
  });
14861
15002
  }
14862
15003
  }
15004
+ // Handle Toggle/Switch inputs
14863
15005
  else if (curr.type === 'toggle') {
14864
15006
  acc[curr.name] = curr.value ? 'true' : 'false';
14865
15007
  }
15008
+ // Default mapping for all other fields
14866
15009
  else {
14867
15010
  acc[curr.name] = curr.value;
14868
15011
  }
14869
15012
  return acc;
14870
15013
  }, {}),
14871
- step: this.registrationStep,
15014
+ step: currentStepValue,
14872
15015
  };
14873
15016
  const headers = new Headers();
14874
15017
  headers.append('Content-Type', 'application/json');
14875
15018
  headers.append('Accept', 'application/json');
15019
+ // new payload to avoid sendind an old registration id
15020
+ const payload = {
15021
+ registerUserDto: registerStep.registerUserDto, // Datele curățate din reduce (fără prefix dublu)
15022
+ step: currentStepValue
15023
+ };
15024
+ if (this.registrationID && this.registrationID !== "null") {
15025
+ payload.registrationId = this.registrationID;
15026
+ }
14876
15027
  const options = {
14877
15028
  method: 'POST',
14878
- body: JSON.stringify(registerStep),
15029
+ body: JSON.stringify(payload),
14879
15030
  headers
14880
15031
  };
14881
15032
  if (this.lastStep === this.registrationStep) {
@@ -14953,8 +15104,8 @@ const GeneralRegistrationMultistep = class {
14953
15104
  if (this.listOfActions.some(action => action == '/generate-2FA-code/Generate2FACode')) {
14954
15105
  this.extraActions.push('2fa');
14955
15106
  }
14956
- if (localStorage.getItem('playerConsents')) {
14957
- localStorage.removeItem("playerConsents");
15107
+ if (sessionStorage.getItem('playerConsents')) {
15108
+ sessionStorage.removeItem("playerConsents");
14958
15109
  }
14959
15110
  this.setRegister();
14960
15111
  }
@@ -14964,9 +15115,11 @@ const GeneralRegistrationMultistep = class {
14964
15115
  }
14965
15116
  // After sending the current step, increment and check if the next one is in state.
14966
15117
  this.registrationStep = this.stepChange('increment');
14967
- // If step is present in state do NOT fetch the next config.
14968
- if (Object.keys(this.registrationStepsState).find(key => key == this.registrationStep)) {
14969
- // Use the one from state
15118
+ const stepData = this.registrationStepsState[this.registrationStep];
15119
+ const isValidStepInMem = stepData && stepData.fields && stepData.fields.length > 0;
15120
+ if (isValidStepInMem) {
15121
+ // Repopulate form
15122
+ this.forms = Object.assign(Object.assign({}, this.forms), { [this.registrationStep]: stepData.fields.map(f => (Object.assign({}, f))) });
14970
15123
  this.stepsStateMachine({ event: 'get', type: 'inputs' });
14971
15124
  this.stepsStateMachine({ event: 'get', type: 'values' });
14972
15125
  }
@@ -14974,6 +15127,10 @@ const GeneralRegistrationMultistep = class {
14974
15127
  this.getRegisterConfig(this.registrationID).then((config) => {
14975
15128
  // Format the new step config.
14976
15129
  this.formatConfig(config);
15130
+ const savedState = JSON.parse(sessionStorage.getItem('registrationStepsState'));
15131
+ if (savedState && savedState[this.registrationStep]) {
15132
+ this.stepsStateMachine({ event: 'get', type: 'values' });
15133
+ }
14977
15134
  // Set it in local storage.
14978
15135
  this.stepsStateMachine({ event: 'set', type: 'inputs' });
14979
15136
  // Setup conditionalValidationMap
@@ -15050,6 +15207,16 @@ const GeneralRegistrationMultistep = class {
15050
15207
  });
15051
15208
  }
15052
15209
  formatConfig(config) {
15210
+ // reset previous state to avoid data leakage between steps
15211
+ this.listOfInputs = [];
15212
+ this.listOfInputValues = [];
15213
+ this.listOfInputValidity = [];
15214
+ this.forms = Object.assign({}, this.forms);
15215
+ // set current context (MUST be done before restoration)
15216
+ this.registrationStep = config.content.step;
15217
+ this.registrationID = config.content.registrationID;
15218
+ this.listOfActions = config.content.actions.map(action => action);
15219
+ // map fields and handle duplicates
15053
15220
  this.listOfInputs = config.content.fields.flatMap((field) => {
15054
15221
  const duplicateInputRule = field.validate.custom.find(customRule => customRule.rule === 'duplicate-input');
15055
15222
  const inputElement = Object.assign({}, field);
@@ -15080,10 +15247,12 @@ const GeneralRegistrationMultistep = class {
15080
15247
  }
15081
15248
  return acc;
15082
15249
  }, []);
15250
+ // initialize values structure (Creating the "containers" for data)
15251
+ // We do this only ONCE using reduce to capture both main fields and subfields
15083
15252
  this.listOfInputValues = this.listOfInputs.reduce((acc, field) => {
15084
15253
  var _a;
15085
15254
  const inputType = (_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase();
15086
- // If the field type is a 'togglecheckbox', add its subfields
15255
+ // If the field type is a 'togglecheckbox', add its subfields first
15087
15256
  if (inputType === 'togglecheckbox') {
15088
15257
  field.data.subFields.forEach(subfield => {
15089
15258
  var _a;
@@ -15091,10 +15260,11 @@ const GeneralRegistrationMultistep = class {
15091
15260
  name: subfield.name,
15092
15261
  value: ((_a = subfield.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) == 'checkbox' ? 'false' : null,
15093
15262
  isDuplicate: subfield.isDuplicateInput || false,
15094
- type: inputType === 'togglecheckbox' ? 'togglecheckbox' : null
15263
+ type: 'togglecheckbox'
15095
15264
  });
15096
15265
  });
15097
15266
  }
15267
+ // Add the main field
15098
15268
  acc.push({
15099
15269
  name: field.name,
15100
15270
  value: inputType === 'checkbox' || inputType === 'togglecheckbox' ? 'false' : null,
@@ -15103,12 +15273,10 @@ const GeneralRegistrationMultistep = class {
15103
15273
  });
15104
15274
  return acc;
15105
15275
  }, []);
15276
+ // restore saved values over the empty structure
15277
+ this.stepsStateMachine({ event: 'get', type: 'values' });
15106
15278
  if (this.btag)
15107
15279
  this.addBtagValue();
15108
- // Set the list of actions
15109
- this.listOfActions = config.content.actions.map(action => action);
15110
- this.registrationID = config.content.registrationID;
15111
- this.registrationStep = config.content.step;
15112
15280
  if (this.listOfActions.some(action => action == '/register')) {
15113
15281
  this.lastStep = this.registrationStep;
15114
15282
  }
@@ -15116,10 +15284,11 @@ const GeneralRegistrationMultistep = class {
15116
15284
  if (this.isConsentReady) {
15117
15285
  this.listOfInputValidity.find((input) => input.name === "Consents").isValid = false;
15118
15286
  this.isFormValid = !this.getInvalidStatus(this.listOfInputValidity);
15119
- return;
15120
15287
  }
15121
- this.listOfInputValidity.push({ name: 'Consents', isValid: false });
15122
- this.isConsentReady = true;
15288
+ else {
15289
+ this.listOfInputValidity.push({ name: 'Consents', isValid: false });
15290
+ this.isConsentReady = true;
15291
+ }
15123
15292
  }
15124
15293
  else {
15125
15294
  this.isConsentReady = false;
@@ -15132,21 +15301,16 @@ const GeneralRegistrationMultistep = class {
15132
15301
  var _a, _b;
15133
15302
  this.addTranslation(field);
15134
15303
  // Logic for field types that have subfields
15135
- if (((_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'togglecheckbox') {
15136
- field.data.subFields.forEach(subField => this.addTranslation(subField));
15137
- }
15138
- if (((_b = field.inputType) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'checkboxgroup') {
15139
- this.addTranslation(field);
15304
+ if (((_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'togglecheckbox' || ((_b = field.inputType) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'checkboxgroup') {
15140
15305
  field.data.subFields.forEach(subField => this.addTranslation(subField));
15141
15306
  }
15142
- return field;
15143
15307
  });
15144
15308
  })
15145
15309
  .catch((error) => {
15146
15310
  console.error('Failed to fetch translations:', error);
15147
15311
  });
15148
15312
  }
15149
- // Add the step to the registrationStepsData
15313
+ // Add the step to the registrationStepsData if not present
15150
15314
  this.registrationStepsState.regId = this.registrationID;
15151
15315
  if (!this.registrationStepsState[this.registrationStep]) {
15152
15316
  this.registrationStepsState[this.registrationStep] = {
@@ -15296,9 +15460,9 @@ const GeneralRegistrationMultistep = class {
15296
15460
  input.inputType.toLowerCase() === 'togglecheckbox'
15297
15461
  ? input.data.subFields
15298
15462
  : input.data.values
15299
- : [], defaultValue: input.defaultValue, autofilled: input.autofill, emitValue: this.emitValue, language: this.language, mbSource: this.mbSource, isDuplicateInput: input.isDuplicateInput, "client-styling": this.clientStyling, tooltip: input.tooltip, placeholder: input.placeholder == null ? '' : input.placeholder, "date-format": this.dateFormat, "twofa-destination": this.twofaDestination, "twofa-resend-interval-seconds": (_a = input.customInfo) === null || _a === void 0 ? void 0 : _a.twofaResendIntervalSeconds, "translation-url": this.translationUrl, emitOnClick: this.emitOnClick, onClick: this.handleInitialClick, haspostalcodelookup: this.haspostalcodelookup, addresses: this.haspostalcodelookup ? this.addresses : null, postalcodelength: this.haspostalcodelookup ? this.postalcodelength : null, "enable-south-african-mode": this.enableSouthAfricanMode, key: ['address1', 'address2', 'City'].includes(input.name)
15300
- ? `${input.name}-${this.addressUpdateKey}`
15301
- : input.name, "ignore-country": this.getIgnoreCountry(input), "pin-attempts-exceeded": this.pinAttemptsExceeded }), ((_b = input.customInfo) === null || _b === void 0 ? void 0 : _b.description) && h("div", { class: "input-description" }, input.customInfo.description)));
15463
+ : [], defaultValue: input.defaultValue, autofilled: input.autofill, emitValue: this.emitValue, language: this.language, mbSource: this.mbSource, isDuplicateInput: input.isDuplicateInput, "client-styling": this.clientStyling, tooltip: input.tooltip, placeholder: input.placeholder == null ? '' : input.placeholder, "date-format": this.dateFormat, "twofa-destination": this.twofaDestination, "twofa-resend-interval-seconds": (_a = input.customInfo) === null || _a === void 0 ? void 0 : _a.twofaResendIntervalSeconds, "translation-url": this.translationUrl, emitOnClick: this.emitOnClick, onClick: this.handleInitialClick, haspostalcodelookup: this.haspostalcodelookup, addresses: this.haspostalcodelookup ? this.addresses : null, postalcodelength: this.haspostalcodelookup ? this.postalcodelength : null, "enable-south-african-mode": this.enableSouthAfricanMode, "ignore-country": this.getIgnoreCountry(input), "pin-attempts-exceeded": this.pinAttemptsExceeded, key: ['address1', 'address2', 'City'].includes(input.name)
15464
+ ? `${input.name}-${this.addressUpdateKey}-${this.registrationStep}`
15465
+ : `${input.name}-${this.registrationStep}` }), ((_b = input.customInfo) === null || _b === void 0 ? void 0 : _b.description) && h("div", { class: "input-description" }, input.customInfo.description)));
15302
15466
  }), this.forms[this.registrationStep] && this.isConsentReady && this.renderConsents(), this.forms[this.registrationStep] && this.buttonInsideForm && this.renderButtons(), h("div", { class: "registration__wrapper--flex" }, h("p", { class: "registration__error-message", innerHTML: this.errorMessage })))));
15303
15467
  }
15304
15468
  renderConsents() {