@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.
- package/dist/cjs/checkbox-group-input_15.cjs.entry.js +233 -69
- package/dist/collection/components/general-registration-multisteps/general-registration-multistep.js +231 -68
- package/dist/collection/utils/locale.utils.js +2 -1
- package/dist/esm/checkbox-group-input_15.entry.js +233 -69
- package/dist/general-registration-multistep/checkbox-group-input_15.entry.js +78 -78
- package/dist/types/components/general-registration-multisteps/general-registration-multistep.d.ts +1 -0
- package/dist/types/utils/locale.utils.d.ts +1 -0
- package/package.json +1 -1
package/dist/collection/components/general-registration-multisteps/general-registration-multistep.js
CHANGED
|
@@ -10,6 +10,7 @@ export class GeneralRegistrationMultistep {
|
|
|
10
10
|
this.lastPostalCode = null;
|
|
11
11
|
this.pinAttemptsExceeded = false;
|
|
12
12
|
this.documentIdNineDigits = false;
|
|
13
|
+
this.isTransitioning = false;
|
|
13
14
|
this.selectedCountry = '';
|
|
14
15
|
this.listOfInputValues = [];
|
|
15
16
|
this.listOfInputValidity = [];
|
|
@@ -133,22 +134,36 @@ export class GeneralRegistrationMultistep {
|
|
|
133
134
|
this.isFormValid = !this.getInvalidStatus(this.listOfInputValidity);
|
|
134
135
|
}
|
|
135
136
|
getInputsValueHandler(event) {
|
|
136
|
-
var _a, _b
|
|
137
|
-
this.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
137
|
+
var _a, _b;
|
|
138
|
+
if (this.isTransitioning) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const { name, value, type } = event.detail;
|
|
142
|
+
// find the input andd add it if missing
|
|
143
|
+
let inputItem = this.listOfInputValues.find(input => input.name == name);
|
|
144
|
+
if (!inputItem) {
|
|
145
|
+
// If the field (like ValidateSMS) is not in the list because formatConfig didn't clear the old step data
|
|
146
|
+
// we force-add it so it can be saved and sent to the API
|
|
147
|
+
inputItem = {
|
|
148
|
+
name: name,
|
|
149
|
+
value: value,
|
|
150
|
+
isDuplicate: false,
|
|
151
|
+
type: type || null
|
|
152
|
+
};
|
|
153
|
+
this.listOfInputValues = [...this.listOfInputValues, inputItem];
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
inputItem.value = value;
|
|
157
|
+
inputItem.type = type || null;
|
|
158
|
+
}
|
|
143
159
|
// ---- Document type and document id logic - New custom registration for SA ---- //
|
|
144
|
-
const { name, value } = event.detail;
|
|
145
160
|
// Check SA identity id if valid
|
|
146
161
|
if (name === CONSTANTS.DOCUMENT_TYPE) {
|
|
147
|
-
let
|
|
148
|
-
if ((
|
|
149
|
-
|
|
162
|
+
let docTypeValue = value;
|
|
163
|
+
if ((docTypeValue || "").replace(CONSTANTS.REMOVE_WHITESPACE_REGEX, "").toLowerCase() === CONSTANTS.IDENTITY_CARD_NORMALIZED) {
|
|
164
|
+
docTypeValue = CONSTANTS.SOUTH_AFRICAN_ID;
|
|
150
165
|
}
|
|
151
|
-
window.documentTypeValue =
|
|
166
|
+
window.documentTypeValue = docTypeValue;
|
|
152
167
|
const docField = this.listOfInputValues.find(i => i.name === CONSTANTS.DOCUMENT_NUMBER);
|
|
153
168
|
if (docField)
|
|
154
169
|
docField.value = "";
|
|
@@ -157,11 +172,12 @@ export class GeneralRegistrationMultistep {
|
|
|
157
172
|
docValidity.isValid = false;
|
|
158
173
|
window.dispatchEvent(new CustomEvent("documentNumberUpdatedExternally", { detail: "" }));
|
|
159
174
|
window.dispatchEvent(new CustomEvent("documentNumberResetValidation"));
|
|
175
|
+
this.stepsStateMachine({ event: 'set', type: 'values' });
|
|
160
176
|
return;
|
|
161
177
|
}
|
|
162
|
-
const
|
|
178
|
+
const docTypeContext = window.documentTypeValue;
|
|
163
179
|
// Check if Passport value length and dispatch events to modify the birth date value
|
|
164
|
-
if (name === CONSTANTS.DOCUMENT_NUMBER &&
|
|
180
|
+
if (name === CONSTANTS.DOCUMENT_NUMBER && docTypeContext === CONSTANTS.PASSPORT) {
|
|
165
181
|
if (value.length === 8 || value.length === 9) {
|
|
166
182
|
const extractedBirthDate = extractBirthDate(value);
|
|
167
183
|
window.dispatchEvent(new CustomEvent('documentIdUpdated', { detail: extractedBirthDate || '' }));
|
|
@@ -176,7 +192,7 @@ export class GeneralRegistrationMultistep {
|
|
|
176
192
|
}
|
|
177
193
|
// If number starts with '0', remove it
|
|
178
194
|
if (name === CONSTANTS.MOBILE) {
|
|
179
|
-
const rawVal =
|
|
195
|
+
const rawVal = value !== null && value !== void 0 ? value : {};
|
|
180
196
|
const phoneRaw = typeof rawVal.phone === "string" ? rawVal.phone : "";
|
|
181
197
|
let phone = phoneRaw;
|
|
182
198
|
if (phone.startsWith("0")) {
|
|
@@ -185,14 +201,13 @@ export class GeneralRegistrationMultistep {
|
|
|
185
201
|
const mobileField = this.listOfInputValues.find(i => i.name === CONSTANTS.MOBILE);
|
|
186
202
|
if (mobileField) {
|
|
187
203
|
mobileField.value = {
|
|
188
|
-
prefix: (
|
|
204
|
+
prefix: (_a = rawVal.prefix) !== null && _a !== void 0 ? _a : "",
|
|
189
205
|
phone
|
|
190
206
|
};
|
|
191
207
|
}
|
|
192
208
|
}
|
|
193
209
|
// ---- Postal code lookup logic ---- //
|
|
194
210
|
if (this.haspostalcodelookup) {
|
|
195
|
-
const { name, value } = event.detail;
|
|
196
211
|
if (name === 'CountryCode') {
|
|
197
212
|
this.selectedCountry = value;
|
|
198
213
|
if (value === 'GB') {
|
|
@@ -217,7 +232,7 @@ export class GeneralRegistrationMultistep {
|
|
|
217
232
|
this.addresses.length === 0;
|
|
218
233
|
if (shouldFetch) {
|
|
219
234
|
const country = this.selectedCountry ||
|
|
220
|
-
((
|
|
235
|
+
((_b = this.listOfInputValues.find(i => i.name === 'CountryCode')) === null || _b === void 0 ? void 0 : _b.value) || '';
|
|
221
236
|
if (this.selectedCountry === 'GB' || this.selectedCountry === 'UK') {
|
|
222
237
|
if (this.addrDebounce)
|
|
223
238
|
clearTimeout(this.addrDebounce);
|
|
@@ -235,7 +250,7 @@ export class GeneralRegistrationMultistep {
|
|
|
235
250
|
}
|
|
236
251
|
}
|
|
237
252
|
this.stepsStateMachine({ event: 'set', type: 'values' });
|
|
238
|
-
this.handleConditionalValidation(
|
|
253
|
+
this.handleConditionalValidation(name, value);
|
|
239
254
|
}
|
|
240
255
|
handleAddressSelection(event) {
|
|
241
256
|
const { city, address1, address2 } = event.detail;
|
|
@@ -270,7 +285,7 @@ export class GeneralRegistrationMultistep {
|
|
|
270
285
|
handleCountryCodeUpdateGlobal(event) {
|
|
271
286
|
const { name } = event.detail;
|
|
272
287
|
if (name === 'CountryCode') {
|
|
273
|
-
const savedState =
|
|
288
|
+
const savedState = sessionStorage.getItem('registrationStepsState');
|
|
274
289
|
if (savedState) {
|
|
275
290
|
const parsedState = JSON.parse(savedState);
|
|
276
291
|
Object.keys(parsedState).forEach(stepKey => {
|
|
@@ -282,7 +297,7 @@ export class GeneralRegistrationMultistep {
|
|
|
282
297
|
});
|
|
283
298
|
}
|
|
284
299
|
});
|
|
285
|
-
|
|
300
|
+
sessionStorage.setItem('registrationStepsState', JSON.stringify(parsedState));
|
|
286
301
|
}
|
|
287
302
|
}
|
|
288
303
|
}
|
|
@@ -346,6 +361,10 @@ export class GeneralRegistrationMultistep {
|
|
|
346
361
|
}
|
|
347
362
|
async componentWillLoad() {
|
|
348
363
|
await customElements.whenDefined('general-input');
|
|
364
|
+
const navigationEntries = performance.getEntriesByType('navigation');
|
|
365
|
+
if (navigationEntries.length > 0 && navigationEntries[0].type === 'reload') {
|
|
366
|
+
sessionStorage.removeItem('registrationStepsState');
|
|
367
|
+
}
|
|
349
368
|
const config = await this.getRegisterConfig();
|
|
350
369
|
this.formatConfig(config);
|
|
351
370
|
this.isFormValid = !this.getInvalidStatus(this.listOfInputValidity);
|
|
@@ -450,11 +469,75 @@ export class GeneralRegistrationMultistep {
|
|
|
450
469
|
this.setRegisterStep();
|
|
451
470
|
}
|
|
452
471
|
backHandler(e) {
|
|
472
|
+
var _a, _b, _c, _d;
|
|
453
473
|
e.preventDefault();
|
|
454
|
-
this.
|
|
455
|
-
|
|
456
|
-
this.
|
|
457
|
-
|
|
474
|
+
this.isTransitioning = true;
|
|
475
|
+
const stepBeforeBack = this.registrationStep;
|
|
476
|
+
let targetStep = this.stepChange('decrement');
|
|
477
|
+
if (stepBeforeBack === 'Step3') {
|
|
478
|
+
targetStep = 'Step1';
|
|
479
|
+
this.registrationID = null;
|
|
480
|
+
this.registrationStepsState.regId = null;
|
|
481
|
+
const savedUserData = JSON.parse(sessionStorage.getItem('registrationStepsState')) || {};
|
|
482
|
+
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';
|
|
483
|
+
sessionStorage.removeItem('registrationStepsState');
|
|
484
|
+
this.registrationStepsState = {
|
|
485
|
+
regId: null
|
|
486
|
+
};
|
|
487
|
+
this.listOfInputValues = [];
|
|
488
|
+
this.getRegisterConfig().then(config => {
|
|
489
|
+
this.formatConfig(config);
|
|
490
|
+
this.registrationID = config.content.registrationID;
|
|
491
|
+
setTimeout(() => {
|
|
492
|
+
this.listOfInputValues = this.listOfInputs.map(field => {
|
|
493
|
+
var _a;
|
|
494
|
+
if (field.name === 'Mobile') {
|
|
495
|
+
return { name: field.name, value: { prefix: oldPrefix, phone: '' }, isDuplicate: false, type: 'tel' };
|
|
496
|
+
}
|
|
497
|
+
return {
|
|
498
|
+
name: field.name,
|
|
499
|
+
value: ((_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'checkbox' ? 'false' : null,
|
|
500
|
+
isDuplicate: field.isDuplicateInput || false,
|
|
501
|
+
type: field.inputType
|
|
502
|
+
};
|
|
503
|
+
});
|
|
504
|
+
this.forms = Object.assign({}, this.forms);
|
|
505
|
+
}, 100);
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
this.registrationStep = targetStep;
|
|
509
|
+
const savedDataAtTarget = JSON.parse(sessionStorage.getItem('registrationStepsState'));
|
|
510
|
+
if (savedDataAtTarget && savedDataAtTarget[targetStep] && savedDataAtTarget[targetStep].fields) {
|
|
511
|
+
const stepData = savedDataAtTarget[targetStep];
|
|
512
|
+
this.listOfInputValidity = [...stepData.fieldsValidity];
|
|
513
|
+
this.listOfInputs = [...stepData.fields];
|
|
514
|
+
this.forms = Object.assign(Object.assign({}, this.forms), { [targetStep]: this.listOfInputs.map(input => (Object.assign({}, input))) });
|
|
515
|
+
const savedValues = stepData.registerUserData || {};
|
|
516
|
+
this.listOfInputValues = Object.keys(savedValues).length > 0
|
|
517
|
+
? Object.keys(savedValues).map(name => ({
|
|
518
|
+
name,
|
|
519
|
+
value: savedValues[name].value,
|
|
520
|
+
isDuplicate: savedValues[name].isDuplicate
|
|
521
|
+
}))
|
|
522
|
+
: this.listOfInputs.map(field => {
|
|
523
|
+
var _a;
|
|
524
|
+
return ({
|
|
525
|
+
name: field.name,
|
|
526
|
+
value: ((_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'checkbox' ? 'false' : null,
|
|
527
|
+
isDuplicate: field.isDuplicateInput || false
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
this.forms[targetStep] = this.forms[targetStep].map(input => {
|
|
531
|
+
const savedData = this.listOfInputValues.find(v => v.name === input.name);
|
|
532
|
+
return savedData ? Object.assign(Object.assign({}, input), { defaultValue: savedData.value }) : input;
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
else if (stepBeforeBack !== 'Step3') {
|
|
536
|
+
this.getRegisterConfig(this.registrationID).then(config => this.formatConfig(config));
|
|
537
|
+
}
|
|
538
|
+
this.forms = Object.assign({}, this.forms);
|
|
539
|
+
this.isFormValid = !this.getInvalidStatus(this.listOfInputValidity);
|
|
540
|
+
setTimeout(() => { this.isTransitioning = false; }, 300);
|
|
458
541
|
}
|
|
459
542
|
dispatchRegisterCredentialsEvent() {
|
|
460
543
|
let userNameEmail = '';
|
|
@@ -485,10 +568,10 @@ export class GeneralRegistrationMultistep {
|
|
|
485
568
|
stepsStateMachine(state) {
|
|
486
569
|
var _a;
|
|
487
570
|
const saveToLocalStorage = () => {
|
|
488
|
-
|
|
571
|
+
sessionStorage.setItem('registrationStepsState', JSON.stringify(this.registrationStepsState));
|
|
489
572
|
};
|
|
490
573
|
const loadFromLocalStorage = () => {
|
|
491
|
-
return JSON.parse(
|
|
574
|
+
return JSON.parse(sessionStorage.getItem('registrationStepsState'));
|
|
492
575
|
};
|
|
493
576
|
switch (state.event) {
|
|
494
577
|
case 'set':
|
|
@@ -500,7 +583,9 @@ export class GeneralRegistrationMultistep {
|
|
|
500
583
|
currentStep.fieldsValidity = this.listOfInputValidity;
|
|
501
584
|
}
|
|
502
585
|
if (state.type == 'values') {
|
|
503
|
-
|
|
586
|
+
if (!this.registrationStepsState[this.registrationStep]) {
|
|
587
|
+
this.registrationStepsState[this.registrationStep] = {};
|
|
588
|
+
}
|
|
504
589
|
const currentStep = this.registrationStepsState[this.registrationStep];
|
|
505
590
|
currentStep.registerUserData = this.listOfInputValues.reduce((acc, curr) => {
|
|
506
591
|
acc[curr.name] = { value: curr.value, isDuplicate: curr.isDuplicate };
|
|
@@ -511,21 +596,42 @@ export class GeneralRegistrationMultistep {
|
|
|
511
596
|
break;
|
|
512
597
|
case 'get':
|
|
513
598
|
const savedUserData = loadFromLocalStorage();
|
|
514
|
-
if (!savedUserData)
|
|
599
|
+
if (!savedUserData || !savedUserData[this.registrationStep])
|
|
515
600
|
return;
|
|
516
601
|
if (state.type == 'inputs') {
|
|
517
602
|
// Load input-related data from the saved state
|
|
518
|
-
const currentStep =
|
|
603
|
+
const currentStep = savedUserData[this.registrationStep];
|
|
519
604
|
this.listOfInputs = currentStep.fields;
|
|
520
605
|
this.listOfActions = currentStep.actions;
|
|
521
606
|
this.listOfInputValidity = currentStep.fieldsValidity;
|
|
607
|
+
if (!this.registrationStepsState[this.registrationStep]) {
|
|
608
|
+
this.registrationStepsState[this.registrationStep] = {};
|
|
609
|
+
}
|
|
610
|
+
this.registrationStepsState[this.registrationStep].fields = currentStep.fields;
|
|
611
|
+
this.registrationStepsState[this.registrationStep].fieldsValidity = currentStep.fieldsValidity;
|
|
522
612
|
}
|
|
523
613
|
if (state.type == 'values') {
|
|
524
|
-
const
|
|
614
|
+
const stepEntry = savedUserData[this.registrationStep];
|
|
615
|
+
if (!stepEntry || !stepEntry.registerUserData || Object.keys(stepEntry.registerUserData).length === 0) {
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
const savedValues = stepEntry.registerUserData;
|
|
525
619
|
// Convert saved values to the expected format for inputs
|
|
526
620
|
this.listOfInputValues = Object.keys(savedValues).map(name => {
|
|
527
621
|
return { name, value: savedValues[name].value, isDuplicate: savedValues[name].isDuplicate };
|
|
528
622
|
});
|
|
623
|
+
// Sync local state object with storage values
|
|
624
|
+
if (!this.registrationStepsState[this.registrationStep]) {
|
|
625
|
+
this.registrationStepsState[this.registrationStep] = {};
|
|
626
|
+
}
|
|
627
|
+
this.registrationStepsState[this.registrationStep].registerUserData = savedValues;
|
|
628
|
+
// Sync the forms object to ensure UI rendering
|
|
629
|
+
if (this.forms[this.registrationStep]) {
|
|
630
|
+
this.forms[this.registrationStep] = this.forms[this.registrationStep].map(input => {
|
|
631
|
+
const savedData = this.listOfInputValues.find(v => v.name === input.name);
|
|
632
|
+
return savedData ? Object.assign(Object.assign({}, input), { defaultValue: savedData.value }) : input;
|
|
633
|
+
});
|
|
634
|
+
}
|
|
529
635
|
// Set the right documentTypeValue when the step is loaded
|
|
530
636
|
let docType = (_a = this.listOfInputValues.find(i => i.name === CONSTANTS.DOCUMENT_TYPE)) === null || _a === void 0 ? void 0 : _a.value;
|
|
531
637
|
if (docType === CONSTANTS.IDENTITY_CARD)
|
|
@@ -540,7 +646,9 @@ export class GeneralRegistrationMultistep {
|
|
|
540
646
|
if (input.inputType === 'togglecheckbox') {
|
|
541
647
|
input.data.subFields.forEach((subfield) => {
|
|
542
648
|
const subfieldValue = this.listOfInputValues.find(subfieldValue => subfieldValue.name === subfield.name);
|
|
543
|
-
|
|
649
|
+
if (subfieldValue) {
|
|
650
|
+
subfield.defaultValue = subfieldValue.value;
|
|
651
|
+
}
|
|
544
652
|
});
|
|
545
653
|
}
|
|
546
654
|
}
|
|
@@ -603,45 +711,87 @@ export class GeneralRegistrationMultistep {
|
|
|
603
711
|
setRegisterStep() {
|
|
604
712
|
this.isLoadingPOST = true;
|
|
605
713
|
const url = new URL(`${this.endpoint}/v1/player/legislation/registration/step/`);
|
|
714
|
+
this.stepsStateMachine({ event: 'set', type: 'values' });
|
|
715
|
+
const currentStepValue = this.registrationStep;
|
|
606
716
|
const registerStep = {
|
|
607
717
|
registrationId: this.registrationID,
|
|
608
718
|
registerUserDto: this.listOfInputValues
|
|
609
|
-
.filter(input =>
|
|
719
|
+
.filter(input => {
|
|
720
|
+
if (input.name === 'ValidateSMS')
|
|
721
|
+
return true;
|
|
722
|
+
return !input.isDuplicate;
|
|
723
|
+
})
|
|
610
724
|
.reduce((acc, curr) => {
|
|
611
|
-
//
|
|
612
|
-
if (curr.name === '
|
|
613
|
-
acc[curr.name] = curr.value
|
|
725
|
+
// Handle SMS Validation field
|
|
726
|
+
if (curr.name === 'ValidateSMS') {
|
|
727
|
+
acc[curr.name] = curr.value;
|
|
614
728
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
acc[
|
|
618
|
-
|
|
619
|
-
|
|
729
|
+
// Handle specific dropdown fields that need lowercase values
|
|
730
|
+
else if (curr.name === 'TypeOfPublicArea') {
|
|
731
|
+
acc[curr.name] = curr.value ? curr.value.toLowerCase() : '';
|
|
732
|
+
}
|
|
733
|
+
// handlbe mobile number and prefix
|
|
734
|
+
else if (curr.name === 'Mobile') {
|
|
735
|
+
const mobileVal = curr.value;
|
|
736
|
+
let phone = '';
|
|
737
|
+
let prefix = '';
|
|
738
|
+
// extract values from object (general-input format) or fallback to string
|
|
739
|
+
if (typeof mobileVal === 'object' && mobileVal !== null) {
|
|
740
|
+
phone = mobileVal.phone || '';
|
|
741
|
+
prefix = mobileVal.prefix || '';
|
|
742
|
+
}
|
|
743
|
+
else {
|
|
744
|
+
phone = mobileVal || '';
|
|
745
|
+
}
|
|
746
|
+
// rmove all non-digit characters from the phone string
|
|
747
|
+
let cleanPhone = phone.toString().replace(CONSTANTS.ONLY_DIGITS_REGEX, '');
|
|
748
|
+
// get digits from prefix to check for duplication (e.g., "27" from "+27")
|
|
749
|
+
const prefixDigits = prefix.replace(CONSTANTS.ONLY_DIGITS_REGEX, '');
|
|
750
|
+
// clear duplicate prefix
|
|
751
|
+
if (prefixDigits && cleanPhone.startsWith(prefixDigits)) {
|
|
752
|
+
cleanPhone = cleanPhone.slice(prefixDigits.length);
|
|
753
|
+
}
|
|
754
|
+
// remove leading zero if present
|
|
755
|
+
if (cleanPhone.startsWith('0')) {
|
|
756
|
+
cleanPhone = cleanPhone.slice(1);
|
|
757
|
+
}
|
|
758
|
+
acc['MobilePrefix'] = prefix;
|
|
759
|
+
acc['Mobile'] = cleanPhone;
|
|
620
760
|
}
|
|
761
|
+
// Handle Checkbox Groups
|
|
621
762
|
else if (curr.type === 'checkboxgroup') {
|
|
622
|
-
// Skip adding the parent of the checkboxgroup as a key.
|
|
623
763
|
if (curr.value !== null) {
|
|
624
764
|
Object.entries(curr.value).forEach(([key, value]) => {
|
|
625
765
|
acc[key] = value ? 'true' : 'false';
|
|
626
766
|
});
|
|
627
767
|
}
|
|
628
768
|
}
|
|
769
|
+
// Handle Toggle/Switch inputs
|
|
629
770
|
else if (curr.type === 'toggle') {
|
|
630
771
|
acc[curr.name] = curr.value ? 'true' : 'false';
|
|
631
772
|
}
|
|
773
|
+
// Default mapping for all other fields
|
|
632
774
|
else {
|
|
633
775
|
acc[curr.name] = curr.value;
|
|
634
776
|
}
|
|
635
777
|
return acc;
|
|
636
778
|
}, {}),
|
|
637
|
-
step:
|
|
779
|
+
step: currentStepValue,
|
|
638
780
|
};
|
|
639
781
|
const headers = new Headers();
|
|
640
782
|
headers.append('Content-Type', 'application/json');
|
|
641
783
|
headers.append('Accept', 'application/json');
|
|
784
|
+
// new payload to avoid sendind an old registration id
|
|
785
|
+
const payload = {
|
|
786
|
+
registerUserDto: registerStep.registerUserDto, // Datele curățate din reduce (fără prefix dublu)
|
|
787
|
+
step: currentStepValue
|
|
788
|
+
};
|
|
789
|
+
if (this.registrationID && this.registrationID !== "null") {
|
|
790
|
+
payload.registrationId = this.registrationID;
|
|
791
|
+
}
|
|
642
792
|
const options = {
|
|
643
793
|
method: 'POST',
|
|
644
|
-
body: JSON.stringify(
|
|
794
|
+
body: JSON.stringify(payload),
|
|
645
795
|
headers
|
|
646
796
|
};
|
|
647
797
|
if (this.lastStep === this.registrationStep) {
|
|
@@ -719,8 +869,8 @@ export class GeneralRegistrationMultistep {
|
|
|
719
869
|
if (this.listOfActions.some(action => action == '/generate-2FA-code/Generate2FACode')) {
|
|
720
870
|
this.extraActions.push('2fa');
|
|
721
871
|
}
|
|
722
|
-
if (
|
|
723
|
-
|
|
872
|
+
if (sessionStorage.getItem('playerConsents')) {
|
|
873
|
+
sessionStorage.removeItem("playerConsents");
|
|
724
874
|
}
|
|
725
875
|
this.setRegister();
|
|
726
876
|
}
|
|
@@ -730,9 +880,11 @@ export class GeneralRegistrationMultistep {
|
|
|
730
880
|
}
|
|
731
881
|
// After sending the current step, increment and check if the next one is in state.
|
|
732
882
|
this.registrationStep = this.stepChange('increment');
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
883
|
+
const stepData = this.registrationStepsState[this.registrationStep];
|
|
884
|
+
const isValidStepInMem = stepData && stepData.fields && stepData.fields.length > 0;
|
|
885
|
+
if (isValidStepInMem) {
|
|
886
|
+
// Repopulate form
|
|
887
|
+
this.forms = Object.assign(Object.assign({}, this.forms), { [this.registrationStep]: stepData.fields.map(f => (Object.assign({}, f))) });
|
|
736
888
|
this.stepsStateMachine({ event: 'get', type: 'inputs' });
|
|
737
889
|
this.stepsStateMachine({ event: 'get', type: 'values' });
|
|
738
890
|
}
|
|
@@ -740,6 +892,10 @@ export class GeneralRegistrationMultistep {
|
|
|
740
892
|
this.getRegisterConfig(this.registrationID).then((config) => {
|
|
741
893
|
// Format the new step config.
|
|
742
894
|
this.formatConfig(config);
|
|
895
|
+
const savedState = JSON.parse(sessionStorage.getItem('registrationStepsState'));
|
|
896
|
+
if (savedState && savedState[this.registrationStep]) {
|
|
897
|
+
this.stepsStateMachine({ event: 'get', type: 'values' });
|
|
898
|
+
}
|
|
743
899
|
// Set it in local storage.
|
|
744
900
|
this.stepsStateMachine({ event: 'set', type: 'inputs' });
|
|
745
901
|
// Setup conditionalValidationMap
|
|
@@ -816,6 +972,16 @@ export class GeneralRegistrationMultistep {
|
|
|
816
972
|
});
|
|
817
973
|
}
|
|
818
974
|
formatConfig(config) {
|
|
975
|
+
// reset previous state to avoid data leakage between steps
|
|
976
|
+
this.listOfInputs = [];
|
|
977
|
+
this.listOfInputValues = [];
|
|
978
|
+
this.listOfInputValidity = [];
|
|
979
|
+
this.forms = Object.assign({}, this.forms);
|
|
980
|
+
// set current context (MUST be done before restoration)
|
|
981
|
+
this.registrationStep = config.content.step;
|
|
982
|
+
this.registrationID = config.content.registrationID;
|
|
983
|
+
this.listOfActions = config.content.actions.map(action => action);
|
|
984
|
+
// map fields and handle duplicates
|
|
819
985
|
this.listOfInputs = config.content.fields.flatMap((field) => {
|
|
820
986
|
const duplicateInputRule = field.validate.custom.find(customRule => customRule.rule === 'duplicate-input');
|
|
821
987
|
const inputElement = Object.assign({}, field);
|
|
@@ -846,10 +1012,12 @@ export class GeneralRegistrationMultistep {
|
|
|
846
1012
|
}
|
|
847
1013
|
return acc;
|
|
848
1014
|
}, []);
|
|
1015
|
+
// initialize values structure (Creating the "containers" for data)
|
|
1016
|
+
// We do this only ONCE using reduce to capture both main fields and subfields
|
|
849
1017
|
this.listOfInputValues = this.listOfInputs.reduce((acc, field) => {
|
|
850
1018
|
var _a;
|
|
851
1019
|
const inputType = (_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
852
|
-
// If the field type is a 'togglecheckbox', add its subfields
|
|
1020
|
+
// If the field type is a 'togglecheckbox', add its subfields first
|
|
853
1021
|
if (inputType === 'togglecheckbox') {
|
|
854
1022
|
field.data.subFields.forEach(subfield => {
|
|
855
1023
|
var _a;
|
|
@@ -857,10 +1025,11 @@ export class GeneralRegistrationMultistep {
|
|
|
857
1025
|
name: subfield.name,
|
|
858
1026
|
value: ((_a = subfield.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) == 'checkbox' ? 'false' : null,
|
|
859
1027
|
isDuplicate: subfield.isDuplicateInput || false,
|
|
860
|
-
type:
|
|
1028
|
+
type: 'togglecheckbox'
|
|
861
1029
|
});
|
|
862
1030
|
});
|
|
863
1031
|
}
|
|
1032
|
+
// Add the main field
|
|
864
1033
|
acc.push({
|
|
865
1034
|
name: field.name,
|
|
866
1035
|
value: inputType === 'checkbox' || inputType === 'togglecheckbox' ? 'false' : null,
|
|
@@ -869,12 +1038,10 @@ export class GeneralRegistrationMultistep {
|
|
|
869
1038
|
});
|
|
870
1039
|
return acc;
|
|
871
1040
|
}, []);
|
|
1041
|
+
// restore saved values over the empty structure
|
|
1042
|
+
this.stepsStateMachine({ event: 'get', type: 'values' });
|
|
872
1043
|
if (this.btag)
|
|
873
1044
|
this.addBtagValue();
|
|
874
|
-
// Set the list of actions
|
|
875
|
-
this.listOfActions = config.content.actions.map(action => action);
|
|
876
|
-
this.registrationID = config.content.registrationID;
|
|
877
|
-
this.registrationStep = config.content.step;
|
|
878
1045
|
if (this.listOfActions.some(action => action == '/register')) {
|
|
879
1046
|
this.lastStep = this.registrationStep;
|
|
880
1047
|
}
|
|
@@ -883,10 +1050,11 @@ export class GeneralRegistrationMultistep {
|
|
|
883
1050
|
if (this.isConsentReady) {
|
|
884
1051
|
this.listOfInputValidity.find((input) => input.name === "Consents").isValid = false;
|
|
885
1052
|
this.isFormValid = !this.getInvalidStatus(this.listOfInputValidity);
|
|
886
|
-
return;
|
|
887
1053
|
}
|
|
888
|
-
|
|
889
|
-
|
|
1054
|
+
else {
|
|
1055
|
+
this.listOfInputValidity.push({ name: 'Consents', isValid: false });
|
|
1056
|
+
this.isConsentReady = true;
|
|
1057
|
+
}
|
|
890
1058
|
}
|
|
891
1059
|
else {
|
|
892
1060
|
this.isConsentReady = false;
|
|
@@ -899,21 +1067,16 @@ export class GeneralRegistrationMultistep {
|
|
|
899
1067
|
var _a, _b;
|
|
900
1068
|
this.addTranslation(field);
|
|
901
1069
|
// Logic for field types that have subfields
|
|
902
|
-
if (((_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'togglecheckbox') {
|
|
903
|
-
field.data.subFields.forEach(subField => this.addTranslation(subField));
|
|
904
|
-
}
|
|
905
|
-
if (((_b = field.inputType) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'checkboxgroup') {
|
|
906
|
-
this.addTranslation(field);
|
|
1070
|
+
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') {
|
|
907
1071
|
field.data.subFields.forEach(subField => this.addTranslation(subField));
|
|
908
1072
|
}
|
|
909
|
-
return field;
|
|
910
1073
|
});
|
|
911
1074
|
})
|
|
912
1075
|
.catch((error) => {
|
|
913
1076
|
console.error('Failed to fetch translations:', error);
|
|
914
1077
|
});
|
|
915
1078
|
}
|
|
916
|
-
// Add the step to the registrationStepsData
|
|
1079
|
+
// Add the step to the registrationStepsData if not present
|
|
917
1080
|
this.registrationStepsState.regId = this.registrationID;
|
|
918
1081
|
if (!this.registrationStepsState[this.registrationStep]) {
|
|
919
1082
|
this.registrationStepsState[this.registrationStep] = {
|
|
@@ -1063,9 +1226,9 @@ export class GeneralRegistrationMultistep {
|
|
|
1063
1226
|
input.inputType.toLowerCase() === 'togglecheckbox'
|
|
1064
1227
|
? input.data.subFields
|
|
1065
1228
|
: input.data.values
|
|
1066
|
-
: [], 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)
|
|
1067
|
-
? `${input.name}-${this.addressUpdateKey}`
|
|
1068
|
-
: input.name
|
|
1229
|
+
: [], 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)
|
|
1230
|
+
? `${input.name}-${this.addressUpdateKey}-${this.registrationStep}`
|
|
1231
|
+
: `${input.name}-${this.registrationStep}` }), ((_b = input.customInfo) === null || _b === void 0 ? void 0 : _b.description) && h("div", { class: "input-description" }, input.customInfo.description)));
|
|
1069
1232
|
}), 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 })))));
|
|
1070
1233
|
}
|
|
1071
1234
|
renderConsents() {
|
|
@@ -1060,7 +1060,8 @@ export const CONSTANTS = {
|
|
|
1060
1060
|
STEP_THREE: 3,
|
|
1061
1061
|
REMOVE_WHITESPACE_REGEX: /\s+/g,
|
|
1062
1062
|
IDENTITY_CARD_NORMALIZED: "identitycard",
|
|
1063
|
-
DATE_DASH_SEPARATOR_REGEX: /-/g
|
|
1063
|
+
DATE_DASH_SEPARATOR_REGEX: /-/g,
|
|
1064
|
+
ONLY_DIGITS_REGEX: /\D/g
|
|
1064
1065
|
};
|
|
1065
1066
|
export const getTranslations = (url) => {
|
|
1066
1067
|
// fetch url, get the data, replace the TRANSLATIONS content
|