@everymatrix/general-registration 1.0.69
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/app-globals-3a1e7e63.js +5 -0
- package/dist/cjs/checkbox-group-input_13.cjs.entry.js +39141 -0
- package/dist/cjs/general-registration.cjs.js +25 -0
- package/dist/cjs/index-f6c5854f.js +1331 -0
- package/dist/cjs/index.cjs.js +18 -0
- package/dist/cjs/loader.cjs.js +15 -0
- package/dist/collection/collection-manifest.json +30 -0
- package/dist/collection/components/general-registration/general-registration.css +121 -0
- package/dist/collection/components/general-registration/general-registration.js +781 -0
- package/dist/collection/components/general-registration/index.js +1 -0
- package/dist/collection/index.js +17 -0
- package/dist/collection/utils/locale.utils.js +108 -0
- package/dist/collection/utils/utils.js +3 -0
- package/dist/esm/app-globals-0f993ce5.js +3 -0
- package/dist/esm/checkbox-group-input_13.entry.js +39125 -0
- package/dist/esm/general-registration.js +20 -0
- package/dist/esm/index-8b4a4c93.js +1302 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/loader.js +11 -0
- package/dist/general-registration/general-registration.esm.js +1 -0
- package/dist/general-registration/index.esm.js +1 -0
- package/dist/general-registration/p-35ed5ec5.js +2 -0
- package/dist/general-registration/p-9dd69761.entry.js +5431 -0
- package/dist/general-registration/p-e1255160.js +1 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/stencil.config.dev.js +17 -0
- package/dist/stencil.config.js +17 -0
- package/dist/types/Users/raul.vasile/workspace/everymatrix/widgets-monorepo/packages/stencil/general-registration/.stencil/packages/stencil/general-input/src/utils/types.d.ts +87 -0
- package/dist/types/Users/raul.vasile/workspace/everymatrix/widgets-monorepo/packages/stencil/general-registration/.stencil/packages/stencil/general-registration/stencil.config.d.ts +2 -0
- package/dist/types/Users/raul.vasile/workspace/everymatrix/widgets-monorepo/packages/stencil/general-registration/.stencil/packages/stencil/general-registration/stencil.config.dev.d.ts +2 -0
- package/dist/types/components/general-registration/general-registration.d.ts +95 -0
- package/dist/types/components/general-registration/index.d.ts +1 -0
- package/dist/types/components.d.ts +127 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/stencil-public-runtime.d.ts +1674 -0
- package/dist/types/utils/locale.utils.d.ts +18 -0
- package/dist/types/utils/utils.d.ts +1 -0
- package/loader/cdn.js +1 -0
- package/loader/index.cjs.js +1 -0
- package/loader/index.d.ts +24 -0
- package/loader/index.es2017.js +1 -0
- package/loader/index.js +2 -0
- package/loader/package.json +11 -0
- package/package.json +29 -0
|
@@ -0,0 +1,781 @@
|
|
|
1
|
+
import { h } from "@stencil/core";
|
|
2
|
+
import { getTranslations, translate, TRANSLATIONS, DEFAULT_LANGUAGE } from "../../utils/locale.utils";
|
|
3
|
+
import "../../../../../general-input/dist/types/index";
|
|
4
|
+
export class GeneralRegistration {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.listOfInputValues = [];
|
|
7
|
+
this.listOfInputValidity = [];
|
|
8
|
+
this.listOfActions = [];
|
|
9
|
+
this.listOfInputs = [];
|
|
10
|
+
this.emitValue = false;
|
|
11
|
+
this.backButtonPressed = false;
|
|
12
|
+
this.registerErrors = false;
|
|
13
|
+
this.extraActions = [];
|
|
14
|
+
this.registrationStepsState = {
|
|
15
|
+
regId: null
|
|
16
|
+
};
|
|
17
|
+
this.setClientStyling = () => {
|
|
18
|
+
let sheet = document.createElement('style');
|
|
19
|
+
sheet.innerHTML = this.clientStyling;
|
|
20
|
+
this.host.shadowRoot.prepend(sheet);
|
|
21
|
+
};
|
|
22
|
+
this.setClientStylingURL = () => {
|
|
23
|
+
let url = new URL(this.clientStylingUrl);
|
|
24
|
+
let cssFile = document.createElement('style');
|
|
25
|
+
fetch(url.href)
|
|
26
|
+
.then((res) => res.text())
|
|
27
|
+
.then((data) => {
|
|
28
|
+
cssFile.innerHTML = data;
|
|
29
|
+
this.clientStyling = data;
|
|
30
|
+
setTimeout(() => { this.host.shadowRoot.prepend(cssFile); }, 1);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
this.endpoint = undefined;
|
|
34
|
+
this.language = 'en';
|
|
35
|
+
this.clientStyling = '';
|
|
36
|
+
this.clientStylingUrl = '';
|
|
37
|
+
this.translationUrl = '';
|
|
38
|
+
this.dateFormat = undefined;
|
|
39
|
+
this.buttonInsideForm = undefined;
|
|
40
|
+
this.btag = null;
|
|
41
|
+
this.emitOnClick = false;
|
|
42
|
+
this.errorMessage = undefined;
|
|
43
|
+
this.isFormValid = undefined;
|
|
44
|
+
this.isLoading = true;
|
|
45
|
+
this.isLoadingPOST = undefined;
|
|
46
|
+
this.registrationStep = undefined;
|
|
47
|
+
this.forms = [];
|
|
48
|
+
this.limitStylingAppends = false;
|
|
49
|
+
this.autofilled = false;
|
|
50
|
+
}
|
|
51
|
+
sendStep() {
|
|
52
|
+
this.registrationStepUpdated.emit(this.registrationStep);
|
|
53
|
+
window.postMessage({ type: 'registrationStepUpdated', step: this.registrationStep }, window.location.href);
|
|
54
|
+
}
|
|
55
|
+
handleStylingChange(newValue, oldValue) {
|
|
56
|
+
if (newValue !== oldValue)
|
|
57
|
+
this.setClientStyling();
|
|
58
|
+
}
|
|
59
|
+
handleStylingUrlChange(newValue, oldValue) {
|
|
60
|
+
if (newValue !== oldValue)
|
|
61
|
+
this.setClientStylingURL();
|
|
62
|
+
}
|
|
63
|
+
setFormValidity() {
|
|
64
|
+
this.errorMessage = '';
|
|
65
|
+
if (this.listOfInputValidity) {
|
|
66
|
+
this.isFormValid = !this.getInvalidStatus(this.listOfInputValidity);
|
|
67
|
+
}
|
|
68
|
+
//Check for autofilled.
|
|
69
|
+
if (this.listOfInputs.some(inputs => inputs.autofill)) {
|
|
70
|
+
this.autofilled = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
addBtag() {
|
|
74
|
+
this.addBtagValue();
|
|
75
|
+
}
|
|
76
|
+
checkInputsValidityHandler(event) {
|
|
77
|
+
// Set isValid state of the input in the list.
|
|
78
|
+
this.listOfInputValidity.find(input => input.name == event.detail.name).isValid = event.detail.valid;
|
|
79
|
+
// Check if any one is invalid.
|
|
80
|
+
this.isFormValid = !this.getInvalidStatus(this.listOfInputValidity);
|
|
81
|
+
}
|
|
82
|
+
getInputsValueHandler(event) {
|
|
83
|
+
this.listOfInputValues.find(input => {
|
|
84
|
+
if (input.name == event.detail.name) {
|
|
85
|
+
input.value = event.detail.value;
|
|
86
|
+
input.type = event.detail.type || null;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
this.stepsStateMachine({ event: 'set', type: 'values' });
|
|
90
|
+
}
|
|
91
|
+
componentWillLoad() {
|
|
92
|
+
return this.getRegisterConfig()
|
|
93
|
+
.then((config) => {
|
|
94
|
+
this.formatConfig(config);
|
|
95
|
+
this.isFormValid = !this.getInvalidStatus(this.listOfInputValidity);
|
|
96
|
+
this.stepsStateMachine({ event: 'set', type: 'inputs' });
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
componentDidLoad() {
|
|
100
|
+
this.registrationWidgetLoaded.emit();
|
|
101
|
+
window.postMessage({ type: 'registrationWidgetLoaded' }, window.location.href);
|
|
102
|
+
if (!this.limitStylingAppends && this.host) {
|
|
103
|
+
if (this.clientStyling)
|
|
104
|
+
this.setClientStyling();
|
|
105
|
+
if (this.clientStylingUrl)
|
|
106
|
+
this.setClientStylingURL();
|
|
107
|
+
this.limitStylingAppends = true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
nextHandler(e) {
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
// Trigger events in subwidgets.
|
|
113
|
+
this.emitValue = true;
|
|
114
|
+
this.setRegisterStep();
|
|
115
|
+
}
|
|
116
|
+
backHandler(e) {
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
this.registrationStep = this.stepChange('decrement');
|
|
119
|
+
this.stepsStateMachine({ event: 'get', type: 'inputs' });
|
|
120
|
+
this.stepsStateMachine({ event: 'get', type: 'values' });
|
|
121
|
+
}
|
|
122
|
+
dispatchRegisterCredentialsEvent() {
|
|
123
|
+
const userNameEmail = this.registrationStepsState['Step1']['registerUserData']['Email']['value'];
|
|
124
|
+
const userPassword = this.registrationStepsState['Step1']['registerUserData']['Password']['value'];
|
|
125
|
+
this.registerCredentialsEvent = new CustomEvent('RegisterCredentials', {
|
|
126
|
+
bubbles: true,
|
|
127
|
+
detail: {
|
|
128
|
+
userNameEmail: userNameEmail,
|
|
129
|
+
userPassword: userPassword
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
window.dispatchEvent(this.registerCredentialsEvent);
|
|
133
|
+
}
|
|
134
|
+
stepsStateMachine(state) {
|
|
135
|
+
switch (state.event) {
|
|
136
|
+
case 'set':
|
|
137
|
+
if (state.type == 'inputs') {
|
|
138
|
+
this.registrationStepsState[this.registrationStep].fields = this.listOfInputs;
|
|
139
|
+
this.registrationStepsState[this.registrationStep].actions = this.listOfActions;
|
|
140
|
+
this.registrationStepsState[this.registrationStep].fieldsValidity = this.listOfInputValidity;
|
|
141
|
+
}
|
|
142
|
+
if (state.type == 'values') {
|
|
143
|
+
this.registrationStepsState[this.registrationStep].registerUserData = this.listOfInputValues.reduce((acc, curr) => {
|
|
144
|
+
acc[curr.name] = { value: curr.value, isDuplicate: curr.isDuplicate };
|
|
145
|
+
return acc;
|
|
146
|
+
}, {});
|
|
147
|
+
}
|
|
148
|
+
localStorage.setItem('registrationStepsState', JSON.stringify(this.registrationStepsState));
|
|
149
|
+
break;
|
|
150
|
+
case 'get':
|
|
151
|
+
const savedUserData = JSON.parse(localStorage.getItem('registrationStepsState'));
|
|
152
|
+
if (!savedUserData)
|
|
153
|
+
return;
|
|
154
|
+
if (state.type == 'inputs') {
|
|
155
|
+
this.listOfInputs = this.registrationStepsState[this.registrationStep].fields;
|
|
156
|
+
this.listOfActions = this.registrationStepsState[this.registrationStep].actions;
|
|
157
|
+
this.listOfInputValidity = this.registrationStepsState[this.registrationStep].fieldsValidity;
|
|
158
|
+
}
|
|
159
|
+
if (state.type == 'values') {
|
|
160
|
+
const savedValues = savedUserData[this.registrationStep].registerUserData;
|
|
161
|
+
this.listOfInputValues = Object.keys(savedValues).map(name => {
|
|
162
|
+
return { name, value: savedValues[name].value, isDuplicate: savedValues[name].isDuplicate };
|
|
163
|
+
});
|
|
164
|
+
// Give to each field the user input as the default value.
|
|
165
|
+
this.listOfInputValues.forEach(inputValue => {
|
|
166
|
+
const input = this.listOfInputs.find(input => input.name === inputValue.name);
|
|
167
|
+
if (input) {
|
|
168
|
+
input.defaultValue = inputValue.value;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
this.isFormValid = !this.getInvalidStatus(this.listOfInputValidity);
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
getRegisterConfig(registrationID) {
|
|
177
|
+
const url = new URL(`${this.endpoint}/v1/player/legislation/registration/config`);
|
|
178
|
+
const headers = new Headers();
|
|
179
|
+
headers.append('Content-Type', 'application/json');
|
|
180
|
+
headers.append('Accept', 'application/json');
|
|
181
|
+
if (registrationID) {
|
|
182
|
+
url.searchParams.append('registrationId', registrationID);
|
|
183
|
+
}
|
|
184
|
+
const options = {
|
|
185
|
+
method: 'GET',
|
|
186
|
+
headers
|
|
187
|
+
};
|
|
188
|
+
return new Promise((resolve, reject) => {
|
|
189
|
+
this.isLoading = true;
|
|
190
|
+
fetch(url.href, options)
|
|
191
|
+
.then((res) => res.json())
|
|
192
|
+
.then((config) => {
|
|
193
|
+
this.isLoading = false;
|
|
194
|
+
resolve(config);
|
|
195
|
+
}).catch((err) => {
|
|
196
|
+
this.isLoading = false;
|
|
197
|
+
console.error(err);
|
|
198
|
+
reject(err);
|
|
199
|
+
}).finally(() => {
|
|
200
|
+
this.isLoading = false;
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
setRegisterStep() {
|
|
205
|
+
this.isLoadingPOST = true;
|
|
206
|
+
const url = new URL(`${this.endpoint}/v1/player/legislation/registration/step`);
|
|
207
|
+
const registerStep = {
|
|
208
|
+
registrationId: this.registrationID,
|
|
209
|
+
registerUserDto: this.listOfInputValues
|
|
210
|
+
.filter(input => !input.isDuplicate)
|
|
211
|
+
.reduce((acc, curr) => {
|
|
212
|
+
// Because the API is very robust, some values need to be split as separate entities.
|
|
213
|
+
if (curr.name === 'TypeOfPublicArea') {
|
|
214
|
+
acc[curr.name] = curr.value.toLowerCase();
|
|
215
|
+
}
|
|
216
|
+
else if (curr.type === 'tel') {
|
|
217
|
+
//@ts-ignore
|
|
218
|
+
acc['MobilePrefix'] = curr.value.prefix;
|
|
219
|
+
//@ts-ignore
|
|
220
|
+
acc[curr.name] = curr.value.phone;
|
|
221
|
+
}
|
|
222
|
+
else if (curr.type === 'checkboxgroup') {
|
|
223
|
+
// Skip adding the parent of the checkboxgroup as a key.
|
|
224
|
+
if (curr.value !== null) {
|
|
225
|
+
Object.entries(curr.value).forEach(([key, value]) => {
|
|
226
|
+
acc[key] = value ? 'true' : 'false';
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
acc[curr.name] = curr.value;
|
|
232
|
+
}
|
|
233
|
+
return acc;
|
|
234
|
+
}, {}),
|
|
235
|
+
step: this.registrationStep,
|
|
236
|
+
};
|
|
237
|
+
const headers = new Headers();
|
|
238
|
+
headers.append('Content-Type', 'application/json');
|
|
239
|
+
headers.append('Accept', 'application/json');
|
|
240
|
+
const options = {
|
|
241
|
+
method: 'POST',
|
|
242
|
+
body: JSON.stringify(registerStep),
|
|
243
|
+
headers
|
|
244
|
+
};
|
|
245
|
+
fetch(url.href, options)
|
|
246
|
+
.then((res) => {
|
|
247
|
+
if (!res.ok) {
|
|
248
|
+
return res.json().then(error => {
|
|
249
|
+
this.errorCode = error.thirdPartyResponse.errorCode;
|
|
250
|
+
// Show the idomsoft error if it is the case
|
|
251
|
+
if (this.errorCode == 'GmErr_BadRequest_IdomsoftVerification_ShouldRetry') {
|
|
252
|
+
this.errorMessage = error.thirdPartyResponse.message;
|
|
253
|
+
}
|
|
254
|
+
else if (this.errorCode === 'GmErr_Forbidden_UserAccount_NavExcluded') {
|
|
255
|
+
this.errorMessage = translate(`${this.errorCode}`, this.language);
|
|
256
|
+
}
|
|
257
|
+
else if (this.errorCode == 'GmErr_BadRequest') {
|
|
258
|
+
this.errorMessage = error.thirdPartyResponse.message;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
this.errorMessage = translate(`${this.errorCode}`, this.language) || translate(`generalError`, this.language);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
return res.json();
|
|
266
|
+
})
|
|
267
|
+
.then((data) => {
|
|
268
|
+
this.isLoadingPOST = false;
|
|
269
|
+
this.registrationID = data.registrationId;
|
|
270
|
+
if (this.listOfActions.some(action => action == '/register')) {
|
|
271
|
+
if (this.listOfActions.some(action => action == '/generate-2FA-code/Generate2FACode')) {
|
|
272
|
+
this.extraActions.push('2fa');
|
|
273
|
+
}
|
|
274
|
+
this.setRegister();
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
// After sending the current step, increment and check if the next one is in state.
|
|
278
|
+
this.registrationStep = this.stepChange('increment');
|
|
279
|
+
// If step is present in state do NOT fetch the next config.
|
|
280
|
+
if (Object.keys(this.registrationStepsState).find(key => key == this.registrationStep)) {
|
|
281
|
+
// Use the one from state
|
|
282
|
+
this.stepsStateMachine({ event: 'get', type: 'inputs' });
|
|
283
|
+
this.stepsStateMachine({ event: 'get', type: 'values' });
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
this.getRegisterConfig(this.registrationID).then((config) => {
|
|
287
|
+
// Format the new step config.
|
|
288
|
+
this.formatConfig(config);
|
|
289
|
+
// Set it in local storage.
|
|
290
|
+
this.stepsStateMachine({ event: 'set', type: 'inputs' });
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
})
|
|
295
|
+
.catch((err) => {
|
|
296
|
+
this.isLoadingPOST = false;
|
|
297
|
+
console.error(err);
|
|
298
|
+
}).finally(() => {
|
|
299
|
+
this.isLoadingPOST = false;
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
setRegister() {
|
|
303
|
+
this.isLoading = true;
|
|
304
|
+
this.registerErrors = false;
|
|
305
|
+
const url = new URL(`${this.endpoint}/v1/player/legislation/register`);
|
|
306
|
+
const headers = new Headers();
|
|
307
|
+
headers.append('Content-Type', 'application/json');
|
|
308
|
+
headers.append('Accept', 'application/json');
|
|
309
|
+
const options = {
|
|
310
|
+
method: 'PUT',
|
|
311
|
+
body: JSON.stringify({ registrationId: this.registrationID }),
|
|
312
|
+
headers
|
|
313
|
+
};
|
|
314
|
+
fetch(url.href, options)
|
|
315
|
+
.then((res) => {
|
|
316
|
+
if (!res.ok) {
|
|
317
|
+
this.registerErrors = true;
|
|
318
|
+
return res.json().then(error => {
|
|
319
|
+
this.errorCode = error.thirdPartyResponse.errorCode;
|
|
320
|
+
// Show the idomsoft error if it is the case
|
|
321
|
+
if (this.errorCode == 'GmErr_BadRequest_IdomsoftVerification_ShouldRetry') {
|
|
322
|
+
this.errorMessage = error.thirdPartyResponse.message;
|
|
323
|
+
}
|
|
324
|
+
else if (this.errorCode == 'GmErr_BadRequest') {
|
|
325
|
+
this.errorMessage = error.thirdPartyResponse.message;
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
this.errorMessage = translate(`${this.errorCode}`, this.language) || translate(`generalError`, this.language);
|
|
329
|
+
}
|
|
330
|
+
window.postMessage({ type: 'registrationFailed', errorMessage: error === null || error === void 0 ? void 0 : error.thirdPartyResponse.message }, window.location.href);
|
|
331
|
+
window.postMessage({ type: 'WidgetNotification', data: {
|
|
332
|
+
type: 'error',
|
|
333
|
+
message: this.errorMessage
|
|
334
|
+
} }, window.location.href);
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
return res.json();
|
|
338
|
+
})
|
|
339
|
+
.then((data) => {
|
|
340
|
+
this.isLoading = false;
|
|
341
|
+
if (!this.registerErrors) {
|
|
342
|
+
this.dispatchRegisterCredentialsEvent();
|
|
343
|
+
window.postMessage({ type: 'registrationSuccessful', userId: data === null || data === void 0 ? void 0 : data.userId, extraActions: this.extraActions }, window.location.href);
|
|
344
|
+
window.postMessage({ type: 'WidgetNotification', data: {
|
|
345
|
+
type: 'success',
|
|
346
|
+
message: translate('successMessage', this.language)
|
|
347
|
+
} }, window.location.href);
|
|
348
|
+
}
|
|
349
|
+
})
|
|
350
|
+
.catch((err) => {
|
|
351
|
+
this.isLoading = false;
|
|
352
|
+
console.error(err);
|
|
353
|
+
})
|
|
354
|
+
.finally(() => {
|
|
355
|
+
this.isLoading = false;
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
formatConfig(config) {
|
|
359
|
+
// Populate the list of inputs
|
|
360
|
+
this.listOfInputs = config.content.fields.flatMap((field) => {
|
|
361
|
+
// Special case for inputs that need to be duplicated.
|
|
362
|
+
const duplicateInputRule = field.validate.custom.find(customRule => customRule.rule === 'duplicate-input');
|
|
363
|
+
const inputElement = Object.assign({}, field);
|
|
364
|
+
if (duplicateInputRule) {
|
|
365
|
+
const duplicateInput = Object.assign(Object.assign({}, field), { name: `${field.name}Duplicate`, displayName: duplicateInputRule.displayName, isDuplicateInput: true });
|
|
366
|
+
return [inputElement, duplicateInput];
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
return [inputElement];
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
this.listOfInputValidity = this.listOfInputs.reduce((acc, field) => {
|
|
373
|
+
var _a;
|
|
374
|
+
// If the field is a togglecheckbox, add its subfields
|
|
375
|
+
if (((_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === "togglecheckbox") {
|
|
376
|
+
field.data.subFields.forEach(subfield => {
|
|
377
|
+
acc.push({
|
|
378
|
+
name: subfield.name,
|
|
379
|
+
isValid: this.setInitialValidStatus(subfield)
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
acc.push({
|
|
385
|
+
name: field.name,
|
|
386
|
+
isValid: this.setInitialValidStatus(field)
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
return acc;
|
|
390
|
+
}, []);
|
|
391
|
+
this.listOfInputValues = this.listOfInputs.reduce((acc, field) => {
|
|
392
|
+
var _a, _b, _c;
|
|
393
|
+
// If the field type is a 'togglecheckbox', add its subfields
|
|
394
|
+
if (((_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === "togglecheckbox") {
|
|
395
|
+
field.data.subFields.forEach(subfield => {
|
|
396
|
+
var _a, _b;
|
|
397
|
+
acc.push({
|
|
398
|
+
name: subfield.name,
|
|
399
|
+
value: ((_a = subfield.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) == 'checkbox' ? 'false' : null,
|
|
400
|
+
isDuplicate: subfield.isDuplicateInput || false,
|
|
401
|
+
type: ((_b = field.inputType) === null || _b === void 0 ? void 0 : _b.toLowerCase()) == 'togglecheckbox'
|
|
402
|
+
? 'togglecheckbox'
|
|
403
|
+
: null
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
else {
|
|
408
|
+
acc.push({
|
|
409
|
+
name: field.name,
|
|
410
|
+
value: ((_b = field.inputType) === null || _b === void 0 ? void 0 : _b.toLowerCase()) == 'checkbox' ? 'false' : null,
|
|
411
|
+
isDuplicate: field.isDuplicateInput || false,
|
|
412
|
+
type: ((_c = field.inputType) === null || _c === void 0 ? void 0 : _c.toLowerCase()) == 'checkboxgroup' ? 'checkboxgroup' : null
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
return acc;
|
|
416
|
+
}, []);
|
|
417
|
+
if (this.btag)
|
|
418
|
+
this.addBtagValue();
|
|
419
|
+
// Set the list of actions
|
|
420
|
+
this.listOfActions = config.content.actions.map(action => action);
|
|
421
|
+
this.registrationID = config.content.registrationID;
|
|
422
|
+
this.registrationStep = config.content.step;
|
|
423
|
+
if (this.listOfActions.some(action => action == '/register')) {
|
|
424
|
+
this.lastStep = this.registrationStep;
|
|
425
|
+
}
|
|
426
|
+
;
|
|
427
|
+
// The translations for fields happens here.
|
|
428
|
+
if (this.translationUrl) {
|
|
429
|
+
getTranslations(this.translationUrl).then(() => {
|
|
430
|
+
this.listOfInputs.forEach(field => {
|
|
431
|
+
var _a, _b;
|
|
432
|
+
this.addTranslation(field);
|
|
433
|
+
// Logic for field types that have subfields
|
|
434
|
+
if (((_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'togglecheckbox') {
|
|
435
|
+
field.data.subFields.forEach(subField => this.addTranslation(subField));
|
|
436
|
+
}
|
|
437
|
+
if (((_b = field.inputType) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'checkboxgroup') {
|
|
438
|
+
this.addTranslation(field);
|
|
439
|
+
field.data.subFields.forEach(subField => this.addTranslation(subField));
|
|
440
|
+
}
|
|
441
|
+
return field;
|
|
442
|
+
});
|
|
443
|
+
})
|
|
444
|
+
.catch((error) => {
|
|
445
|
+
console.error('Failed to fetch translations:', error);
|
|
446
|
+
}).finally(() => {
|
|
447
|
+
this.forms = [...this.forms, { [this.registrationStep]: this.listOfInputs }];
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
this.forms = [...this.forms, { [this.registrationStep]: this.listOfInputs }];
|
|
452
|
+
}
|
|
453
|
+
// Add the step to the registrationStepsData
|
|
454
|
+
this.registrationStepsState.regId = this.registrationID;
|
|
455
|
+
if (!this.registrationStepsState[this.registrationStep]) {
|
|
456
|
+
this.registrationStepsState[this.registrationStep] = {
|
|
457
|
+
fields: [],
|
|
458
|
+
fieldsValidity: [],
|
|
459
|
+
registerUserData: {},
|
|
460
|
+
actions: []
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
addBtagValue() {
|
|
465
|
+
const btagField = this.listOfInputs.find(input => input.name.toLowerCase() === 'btag');
|
|
466
|
+
if (btagField) {
|
|
467
|
+
btagField.defaultValue = this.btag;
|
|
468
|
+
}
|
|
469
|
+
const btagValue = this.listOfInputValues.find(input => input.name.toLowerCase() === 'btag');
|
|
470
|
+
if (btagValue) {
|
|
471
|
+
btagValue.value = this.btag;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
addTranslation(field) {
|
|
475
|
+
const lang = TRANSLATIONS[this.language] ? this.language : DEFAULT_LANGUAGE;
|
|
476
|
+
if (TRANSLATIONS[lang][field.name]) {
|
|
477
|
+
Object.keys(TRANSLATIONS[this.language][field.name]).forEach((key) => {
|
|
478
|
+
field[key] = TRANSLATIONS[this.language][field.name][key];
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
setInitialValidStatus(field) {
|
|
483
|
+
var _a, _b;
|
|
484
|
+
// Input type checkbox, with no validation are valid
|
|
485
|
+
if (((_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) == 'checkbox' && ((_b = field.validate) === null || _b === void 0 ? void 0 : _b.mandatory) == false) {
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
488
|
+
//Inputs that have default value are valid.
|
|
489
|
+
if (field.defaultValue !== null) {
|
|
490
|
+
return true;
|
|
491
|
+
}
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
stepChange(action) {
|
|
495
|
+
const stepNum = parseInt(this.registrationStep.replace('Step', ''));
|
|
496
|
+
if (action === 'increment') {
|
|
497
|
+
return 'Step' + (stepNum + 1);
|
|
498
|
+
}
|
|
499
|
+
if (action === 'decrement') {
|
|
500
|
+
return 'Step' + (stepNum - 1);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
getInvalidStatus(listOfInputs) {
|
|
504
|
+
return listOfInputs.filter(input => input.isValid == false).length > 0;
|
|
505
|
+
}
|
|
506
|
+
renderForm() {
|
|
507
|
+
return this.forms.map((form, index) => {
|
|
508
|
+
return h("form", { action: '.', id: `RegistrationForm${this.registrationStep}`, class: `registration__form ${this.registrationStep !== `Step${index + 1}` ? 'hidden' : ''}`, ref: el => this.form = el }, form[this.registrationStep] && form[this.registrationStep].map(input => h("general-input", { type: input.inputType, name: input.name, displayName: input.displayName, validation: input.validate, action: input.action || null, options: input.data
|
|
509
|
+
? (input.inputType.toLowerCase() == 'checkboxgroup' || input.inputType.toLowerCase() == 'togglecheckbox')
|
|
510
|
+
? input.data.subFields
|
|
511
|
+
: input.data.values
|
|
512
|
+
: [], defaultValue: input.defaultValue, autofilled: input.autofill, emitValue: this.emitValue, language: this.language, isDuplicateInput: input.isDuplicateInput, "client-styling": this.clientStyling, tooltip: input.tooltip, placeholder: input.placeholder == null ? '' : input.placeholder, dateFormat: this.dateFormat, "translation-url": this.translationUrl, emitOnClick: this.emitOnClick })), this.buttonInsideForm && this.renderButtons(), h("div", { class: 'registration__wrapper--flex' }, h("p", { class: 'registration__error-message', innerHTML: this.errorMessage })));
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
;
|
|
516
|
+
renderButtons() {
|
|
517
|
+
return (h("div", { class: `registration__buttons-wrapper ${this.autofilled ? 'registration__buttons-wrapper--autofilled' : ''}` }, this.isLoadingPOST
|
|
518
|
+
&& h("slot", { name: 'spinner' })
|
|
519
|
+
&& h("svg", { class: "spinner", viewBox: "0 0 50 50" }, h("circle", { class: "path", cx: "25", cy: "25", r: "20", fill: "none", "stroke-width": "5" })), !this.isLoadingPOST && h("button", { class: `registration__button registration__button--next ${this.isFormValid ? '' : 'registration__button--disabled'}`, type: 'submit', form: `RegistrationForm${this.registrationStep}`, onClick: (e) => this.nextHandler(e), disabled: !this.isFormValid }, this.lastStep === this.registrationStep ? translate('doneButton', this.language) : translate('nextButton', this.language)), h("button", { class: `registration__button registration__button--back ${this.registrationStep == 'Step1' ? 'registration__button--first-step' : ''}`, onClick: (e) => this.backHandler(e) }, translate('backButton', this.language))));
|
|
520
|
+
}
|
|
521
|
+
render() {
|
|
522
|
+
if (this.isLoading) {
|
|
523
|
+
return h("p", null, "Please wait, loading ...");
|
|
524
|
+
}
|
|
525
|
+
return (h("div", { class: `registration registration__${this.registrationStep}` }, this.renderForm(), !this.buttonInsideForm && this.renderButtons()));
|
|
526
|
+
}
|
|
527
|
+
static get is() { return "general-registration"; }
|
|
528
|
+
static get encapsulation() { return "shadow"; }
|
|
529
|
+
static get originalStyleUrls() {
|
|
530
|
+
return {
|
|
531
|
+
"$": ["general-registration.scss"]
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
static get styleUrls() {
|
|
535
|
+
return {
|
|
536
|
+
"$": ["general-registration.css"]
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
static get properties() {
|
|
540
|
+
return {
|
|
541
|
+
"endpoint": {
|
|
542
|
+
"type": "string",
|
|
543
|
+
"mutable": false,
|
|
544
|
+
"complexType": {
|
|
545
|
+
"original": "string",
|
|
546
|
+
"resolved": "string",
|
|
547
|
+
"references": {}
|
|
548
|
+
},
|
|
549
|
+
"required": true,
|
|
550
|
+
"optional": false,
|
|
551
|
+
"docs": {
|
|
552
|
+
"tags": [],
|
|
553
|
+
"text": "NorWAy Endpoint for all the calls."
|
|
554
|
+
},
|
|
555
|
+
"attribute": "endpoint",
|
|
556
|
+
"reflect": true
|
|
557
|
+
},
|
|
558
|
+
"language": {
|
|
559
|
+
"type": "string",
|
|
560
|
+
"mutable": false,
|
|
561
|
+
"complexType": {
|
|
562
|
+
"original": "string",
|
|
563
|
+
"resolved": "string",
|
|
564
|
+
"references": {}
|
|
565
|
+
},
|
|
566
|
+
"required": false,
|
|
567
|
+
"optional": false,
|
|
568
|
+
"docs": {
|
|
569
|
+
"tags": [],
|
|
570
|
+
"text": "Currently selected language"
|
|
571
|
+
},
|
|
572
|
+
"attribute": "language",
|
|
573
|
+
"reflect": true,
|
|
574
|
+
"defaultValue": "'en'"
|
|
575
|
+
},
|
|
576
|
+
"clientStyling": {
|
|
577
|
+
"type": "string",
|
|
578
|
+
"mutable": true,
|
|
579
|
+
"complexType": {
|
|
580
|
+
"original": "string",
|
|
581
|
+
"resolved": "string",
|
|
582
|
+
"references": {}
|
|
583
|
+
},
|
|
584
|
+
"required": false,
|
|
585
|
+
"optional": false,
|
|
586
|
+
"docs": {
|
|
587
|
+
"tags": [],
|
|
588
|
+
"text": "Client custom styling via inline styles"
|
|
589
|
+
},
|
|
590
|
+
"attribute": "client-styling",
|
|
591
|
+
"reflect": true,
|
|
592
|
+
"defaultValue": "''"
|
|
593
|
+
},
|
|
594
|
+
"clientStylingUrl": {
|
|
595
|
+
"type": "string",
|
|
596
|
+
"mutable": false,
|
|
597
|
+
"complexType": {
|
|
598
|
+
"original": "string",
|
|
599
|
+
"resolved": "string",
|
|
600
|
+
"references": {}
|
|
601
|
+
},
|
|
602
|
+
"required": false,
|
|
603
|
+
"optional": false,
|
|
604
|
+
"docs": {
|
|
605
|
+
"tags": [],
|
|
606
|
+
"text": "Client custom styling via url"
|
|
607
|
+
},
|
|
608
|
+
"attribute": "client-styling-url",
|
|
609
|
+
"reflect": true,
|
|
610
|
+
"defaultValue": "''"
|
|
611
|
+
},
|
|
612
|
+
"translationUrl": {
|
|
613
|
+
"type": "string",
|
|
614
|
+
"mutable": false,
|
|
615
|
+
"complexType": {
|
|
616
|
+
"original": "string",
|
|
617
|
+
"resolved": "string",
|
|
618
|
+
"references": {}
|
|
619
|
+
},
|
|
620
|
+
"required": false,
|
|
621
|
+
"optional": false,
|
|
622
|
+
"docs": {
|
|
623
|
+
"tags": [],
|
|
624
|
+
"text": "Translations via URL"
|
|
625
|
+
},
|
|
626
|
+
"attribute": "translation-url",
|
|
627
|
+
"reflect": true,
|
|
628
|
+
"defaultValue": "''"
|
|
629
|
+
},
|
|
630
|
+
"dateFormat": {
|
|
631
|
+
"type": "string",
|
|
632
|
+
"mutable": false,
|
|
633
|
+
"complexType": {
|
|
634
|
+
"original": "string",
|
|
635
|
+
"resolved": "string",
|
|
636
|
+
"references": {}
|
|
637
|
+
},
|
|
638
|
+
"required": false,
|
|
639
|
+
"optional": false,
|
|
640
|
+
"docs": {
|
|
641
|
+
"tags": [],
|
|
642
|
+
"text": "Date format for date picker"
|
|
643
|
+
},
|
|
644
|
+
"attribute": "date-format",
|
|
645
|
+
"reflect": true
|
|
646
|
+
},
|
|
647
|
+
"buttonInsideForm": {
|
|
648
|
+
"type": "boolean",
|
|
649
|
+
"mutable": false,
|
|
650
|
+
"complexType": {
|
|
651
|
+
"original": "boolean",
|
|
652
|
+
"resolved": "boolean",
|
|
653
|
+
"references": {}
|
|
654
|
+
},
|
|
655
|
+
"required": true,
|
|
656
|
+
"optional": false,
|
|
657
|
+
"docs": {
|
|
658
|
+
"tags": [],
|
|
659
|
+
"text": "Boolean that decides the position of the button. e.g. button inside -- true / outside -- false the form."
|
|
660
|
+
},
|
|
661
|
+
"attribute": "button-inside-form",
|
|
662
|
+
"reflect": true
|
|
663
|
+
},
|
|
664
|
+
"btag": {
|
|
665
|
+
"type": "string",
|
|
666
|
+
"mutable": false,
|
|
667
|
+
"complexType": {
|
|
668
|
+
"original": "string",
|
|
669
|
+
"resolved": "string",
|
|
670
|
+
"references": {}
|
|
671
|
+
},
|
|
672
|
+
"required": false,
|
|
673
|
+
"optional": false,
|
|
674
|
+
"docs": {
|
|
675
|
+
"tags": [],
|
|
676
|
+
"text": "Affiliate code to be passed in and sent in the registration."
|
|
677
|
+
},
|
|
678
|
+
"attribute": "btag",
|
|
679
|
+
"reflect": true,
|
|
680
|
+
"defaultValue": "null"
|
|
681
|
+
},
|
|
682
|
+
"emitOnClick": {
|
|
683
|
+
"type": "boolean",
|
|
684
|
+
"mutable": false,
|
|
685
|
+
"complexType": {
|
|
686
|
+
"original": "boolean",
|
|
687
|
+
"resolved": "boolean",
|
|
688
|
+
"references": {}
|
|
689
|
+
},
|
|
690
|
+
"required": false,
|
|
691
|
+
"optional": false,
|
|
692
|
+
"docs": {
|
|
693
|
+
"tags": [],
|
|
694
|
+
"text": "Boolean flag that tells inputs to emit an event on click."
|
|
695
|
+
},
|
|
696
|
+
"attribute": "emit-on-click",
|
|
697
|
+
"reflect": true,
|
|
698
|
+
"defaultValue": "false"
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
static get states() {
|
|
703
|
+
return {
|
|
704
|
+
"errorMessage": {},
|
|
705
|
+
"isFormValid": {},
|
|
706
|
+
"isLoading": {},
|
|
707
|
+
"isLoadingPOST": {},
|
|
708
|
+
"registrationStep": {},
|
|
709
|
+
"forms": {},
|
|
710
|
+
"limitStylingAppends": {},
|
|
711
|
+
"autofilled": {}
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
static get events() {
|
|
715
|
+
return [{
|
|
716
|
+
"method": "registrationWidgetLoaded",
|
|
717
|
+
"name": "registrationWidgetLoaded",
|
|
718
|
+
"bubbles": true,
|
|
719
|
+
"cancelable": true,
|
|
720
|
+
"composed": true,
|
|
721
|
+
"docs": {
|
|
722
|
+
"tags": [],
|
|
723
|
+
"text": ""
|
|
724
|
+
},
|
|
725
|
+
"complexType": {
|
|
726
|
+
"original": "any",
|
|
727
|
+
"resolved": "any",
|
|
728
|
+
"references": {}
|
|
729
|
+
}
|
|
730
|
+
}, {
|
|
731
|
+
"method": "registrationStepUpdated",
|
|
732
|
+
"name": "registrationStepUpdated",
|
|
733
|
+
"bubbles": true,
|
|
734
|
+
"cancelable": true,
|
|
735
|
+
"composed": true,
|
|
736
|
+
"docs": {
|
|
737
|
+
"tags": [],
|
|
738
|
+
"text": ""
|
|
739
|
+
},
|
|
740
|
+
"complexType": {
|
|
741
|
+
"original": "string",
|
|
742
|
+
"resolved": "string",
|
|
743
|
+
"references": {}
|
|
744
|
+
}
|
|
745
|
+
}];
|
|
746
|
+
}
|
|
747
|
+
static get elementRef() { return "host"; }
|
|
748
|
+
static get watchers() {
|
|
749
|
+
return [{
|
|
750
|
+
"propName": "registrationStep",
|
|
751
|
+
"methodName": "sendStep"
|
|
752
|
+
}, {
|
|
753
|
+
"propName": "clientStyling",
|
|
754
|
+
"methodName": "handleStylingChange"
|
|
755
|
+
}, {
|
|
756
|
+
"propName": "clientStylingUrl",
|
|
757
|
+
"methodName": "handleStylingUrlChange"
|
|
758
|
+
}, {
|
|
759
|
+
"propName": "forms",
|
|
760
|
+
"methodName": "setFormValidity"
|
|
761
|
+
}, {
|
|
762
|
+
"propName": "btag",
|
|
763
|
+
"methodName": "addBtag"
|
|
764
|
+
}];
|
|
765
|
+
}
|
|
766
|
+
static get listeners() {
|
|
767
|
+
return [{
|
|
768
|
+
"name": "sendValidityState",
|
|
769
|
+
"method": "checkInputsValidityHandler",
|
|
770
|
+
"target": undefined,
|
|
771
|
+
"capture": false,
|
|
772
|
+
"passive": false
|
|
773
|
+
}, {
|
|
774
|
+
"name": "sendInputValue",
|
|
775
|
+
"method": "getInputsValueHandler",
|
|
776
|
+
"target": undefined,
|
|
777
|
+
"capture": false,
|
|
778
|
+
"passive": false
|
|
779
|
+
}];
|
|
780
|
+
}
|
|
781
|
+
}
|