@everymatrix/player-profile-info 1.43.2 → 1.43.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,111 +1,37 @@
1
1
  <svelte:options tag={null} />
2
2
 
3
3
  <script lang="ts">
4
- import { onMount } from 'svelte';
5
4
  import { getDevice } from 'rvhelper';
6
5
  import { _, addNewMessages, setLocale } from './i18n';
7
6
  import { TRANSLATIONS } from './translations';
8
7
 
9
- export let endpoint:string = '';
8
+ export let userid:string;
9
+ export let sessionid:string;
10
+ export let endpoint:string;
10
11
  export let lang:string = 'en';
11
- export let countrycode:string = 'IR';
12
- export let clientstyling:string = '';
13
- export let clientstylingurl:string = '';
14
- export let translationurl:string = '';
12
+ export let clientstyling:string;
13
+ export let clientstylingurl:string;
14
+ export let translationurl:string;
15
15
  export let custominputtextswitch:string = 'false';
16
16
 
17
17
  let customStylingContainer:HTMLElement;
18
18
  let isLoading:boolean = true;
19
- let userAgent:string = window.navigator.userAgent;
20
- let isMobile:boolean = (getDevice(userAgent) === 'PC') ? false : true;
21
19
  let noPlayerData:boolean = true;
22
-
23
- let playerPostalCode:HTMLElement, playerAddress:HTMLElement, playerCity:HTMLElement;
24
- let giveConsentSMS:boolean = false;
25
- let giveConsentEmail:boolean = false;
26
- let biometricsSelection:boolean = false;
27
- let playerQuestion:string = '';
28
- let playerAnswer:string = '';
29
- let playerPrefix:string = '';
30
- let playerMobileNumber:string = '';
31
- let differencesExist:boolean = false;
32
- let selectedCountry:Object = { Name: 'I.e Ireland'};
33
- let prefixesArray:Array<Object> = [];
34
- let countriesArray:Array<Object> = []
35
-
36
- let profileConsent:Array<Object> = [];
37
- let showEmail:boolean = false;
38
- let showSMS:boolean = false;
39
- let consentArray:any = { items: [] };
40
-
41
- let isValid:boolean = false;
42
-
43
- let invalidCity:string = '';
44
- let invalidPostalCode:string = '';
45
- let invalidAddress:string = '';
46
- let invalidSecurityQuestion:boolean = false;
47
- let invalidSecurityAnswer:boolean = false;
48
- let invalidMobile:boolean;
49
-
50
- let showConfirmSave:boolean = false;
51
-
52
- let regexValidators:any = {
53
- document: /^(?=.*[a-zA-Z0-9])[a-zA-Z0-9\s]+$/
54
- }
55
-
56
- const setTranslationUrl = ():void => {
57
-
58
- let url:string = translationurl;
59
-
60
- fetch(url).then((res:any) => res.json())
61
- .then((res) => {
62
- Object.keys(res).forEach((item:any):void => {
63
- addNewMessages(item, res[item]);
64
- });
65
- }).catch((err:any) => {
66
- console.log(err);
67
- });
68
- }
69
-
70
- Object.keys(TRANSLATIONS).forEach((item:any) => {
71
- addNewMessages(item, TRANSLATIONS[item]);
72
- });
73
-
74
- const mediaQuery = window.matchMedia('(min-width: 768px)');
75
-
76
- // needed to keep track of data changes
77
- let provisionalArray:any = {
78
- address1: '',
79
- address2: '',
80
- city: '',
81
- acceptNewsEmail: false,
82
- acceptSMSOffers : false,
83
- country: '',
84
- mobile: {prefix: '', number: ''},
85
- postalCode: '',
86
- securityAnswer: '',
87
- securityQuestion: '',
88
- }
89
-
90
- // needed to keep track of data changes
91
- let initialValuesArray:any = {
92
- acceptNewsEmail: false,
93
- acceptSMSOffers : false,
94
- address: '',
95
- city: '',
96
- mobileNumber: '',
97
- mobilePrefix: '',
98
- postalCode: '',
99
- securityAnswer: '',
100
- securityQuestion: ''
101
- }
102
-
103
- // placeholder field values
104
- let profileDetails:any = {
20
+ const isMobile:boolean = (getDevice(window.navigator.userAgent) === 'PC') ? false : true;
21
+
22
+ let prefixesArray:Array<Record<string, string>> = null;
23
+ let countriesArray:Array<Record<string, string>> = null;
24
+ let profileInfo:Record<string, any> = null;
25
+ let profileConsent:Array<Record<string, string>> = null;
26
+
27
+ let initialConsentValues:string;
28
+ let initialEditableValues:string;
29
+ const updatedEditableValues:Record<string, any> = {};
30
+ const readOnlyValues:Record<string, string> = {};
31
+ const defaultValues:any = {
105
32
  address1: "i.e.: Glanmire Rd.",
106
33
  birth: '01/01/1990',
107
34
  city: "i.e.: Cork",
108
- country: "i.e.: Ireland",
109
35
  currency: "EUR",
110
36
  iban: "",
111
37
  email: "email@here.com",
@@ -120,68 +46,108 @@
120
46
  username: "Username"
121
47
  };
122
48
 
123
- let {address1, birth, city, country, currency, mobile, email, firstname, userTitles, language, lastname, postalCode, securityAnswer, securityQuestion, username, consents, iban} = profileDetails;
124
-
125
- const messageHandler = (e:any):void => {
126
- if (e.data) {
127
- switch(e.data.type) {
128
- case 'ProfileDetailsData':
129
- noPlayerData = false;
130
- profileDetails = e.data.profileDetails;
131
-
132
- // readonly field values
133
- username = profileDetails.username;
134
- mobile = profileDetails.mobile;
135
- email = profileDetails.email;
136
- firstname = profileDetails.firstname;
137
- lastname = profileDetails.lastname;
138
- language = profileDetails.language;
139
- birth = profileDetails.birth?.day + '/' + profileDetails.birth?.month + '/' + profileDetails.birth?.year;
140
- currency = profileDetails.currency;
141
- iban = profileDetails.iban;
142
- userTitles = profileDetails.title;
143
-
144
- // editable field values used for bindings
145
- playerQuestion = profileDetails.securityQuestion;
146
- playerAnswer = profileDetails.securityAnswer;
147
- playerPrefix = profileDetails.mobile?.prefix;
148
- playerMobileNumber = profileDetails.mobile?.number;
149
-
150
- // set values for the initial editable values object
151
- initialValuesArray.address = profileDetails.address1;
152
- initialValuesArray.city = profileDetails.city;
153
- initialValuesArray.mobilePrefix = mobile?.prefix;
154
- initialValuesArray.mobileNumber = mobile?.number;
155
- initialValuesArray.postalCode = profileDetails.postalCode;
156
- initialValuesArray.securityAnswer = profileDetails.securityAnswer;
157
- initialValuesArray.securityQuestion = profileDetails.securityQuestion;
158
-
159
- break;
49
+ let hasProfileInfoChanged:boolean = false;
50
+ let hasProfileConsentChanged:boolean = false;
51
+ let isValid:boolean = true;
52
+ let isCityValid:boolean = true;
53
+ let isPostalCodeValid:boolean = true;
54
+ let isAddressValid:boolean = true;
55
+ let isSecurityQuestionValid:boolean = true;
56
+ let isSecurityAnswerValid:boolean = true;
57
+ let isMobileValid:boolean = true;
58
+ let showConfirmSave:boolean = false;
160
59
 
161
- case 'ProfileConsentData':
162
- profileConsent = e.data.consent.items;
163
- if (Array.isArray(profileConsent)) {
164
- profileConsent.forEach((item) => {
165
- if (item.tagCode == 'emailmarketing') {
166
- showEmail = true;
167
- giveConsentEmail = item.status == 'Accepted';
168
- initialValuesArray.acceptNewsEmail = giveConsentEmail;
169
- } else if (item.tagCode == 'sms') {
170
- showSMS = true;
171
- giveConsentSMS = item.status == 'Accepted';
172
- initialValuesArray.acceptSMSOffers = giveConsentSMS;
173
- }
174
- });
175
- }
176
- break;
60
+ const regexValidators:any = {
61
+ document: /^(?=.*[a-zA-Z0-9])[a-zA-Z0-9\s]+$/
62
+ }
177
63
 
178
- case 'ConfirmProfileInfoSave':
179
- differencesExist = false;
64
+ const mediaQuery = window.matchMedia('(min-width: 768px)');
180
65
 
181
- showConfirmMessage();
182
- break;
183
- }
66
+ const safeStringify = (obj:Record<string, any>):string => {
67
+ try { return JSON.stringify(obj); } catch { return null; }
68
+ }
69
+
70
+ const initPlayerInfoFields = ():void => {
71
+ readOnlyValues.username = profileInfo.username;
72
+ readOnlyValues.mobile = profileInfo.mobile;
73
+ readOnlyValues.email = profileInfo.email;
74
+ readOnlyValues.firstname = profileInfo.firstname;
75
+ readOnlyValues.lastname = profileInfo.lastname;
76
+ readOnlyValues.language = profileInfo.language;
77
+ readOnlyValues.birth = profileInfo.birth?.day + '/' + profileInfo.birth?.month + '/' + profileInfo.birth?.year;
78
+ readOnlyValues.currency = profileInfo.currency;
79
+ readOnlyValues.iban = profileInfo.iban;
80
+ readOnlyValues.userTitles = profileInfo.title;
81
+ readOnlyValues.countryCode = profileInfo.country;
82
+ readOnlyValues.countryName = countriesArray.find((country:any) => country.Alpha2Code === profileInfo.country).Name || 'I.E. Ireland';
83
+
84
+ updatedEditableValues.address1 = profileInfo.address1;
85
+ updatedEditableValues.city = profileInfo.city;
86
+ updatedEditableValues.mobile = {};
87
+ updatedEditableValues.mobile.prefix = profileInfo.mobile?.prefix;
88
+ updatedEditableValues.mobile.number = profileInfo.mobile?.number;
89
+ updatedEditableValues.postalCode = profileInfo.postalCode;
90
+ updatedEditableValues.securityAnswer = profileInfo.securityAnswer;
91
+ updatedEditableValues.securityQuestion = profileInfo.securityQuestion;
92
+
93
+ if (Array.isArray(profileConsent)) {
94
+ profileConsent.forEach((item) => {
95
+ if (item.tagCode === 'emailmarketing') {
96
+ updatedEditableValues.acceptNewsEmail = item.status === 'Accepted';
97
+ } else if (item.tagCode === 'sms') {
98
+ updatedEditableValues.acceptSMSOffers = item.status === 'Accepted';
99
+ }
100
+ });
184
101
  }
102
+
103
+ initialEditableValues = safeStringify(updatedEditableValues);
104
+ initialConsentValues = safeStringify(new Object({
105
+ acceptNewsEmail: updatedEditableValues.acceptNewsEmail,
106
+ acceptSMSOffers: updatedEditableValues.acceptSMSOffers
107
+ }));
108
+
109
+ noPlayerData = false;
110
+ isLoading = false;
111
+ }
112
+
113
+ const getUserProfileInfo = ():void => {
114
+ const url:URL = new URL(`${endpoint}/v1/player/${userid}/profile`);
115
+ const headers:HeadersInit = new Headers();
116
+
117
+ headers.append('X-SessionID', sessionid);
118
+
119
+ const options:RequestInit = {
120
+ method: "GET",
121
+ headers: headers
122
+ };
123
+
124
+ fetch(url.href, options)
125
+ .then((res:any) => { return res.json(); })
126
+ .then((data:any) => {
127
+ profileInfo = data;
128
+ }, (err:any) => {
129
+ console.error(err);
130
+ });
131
+ }
132
+
133
+ const getUserProfileConsent = ():void => {
134
+ const url:URL = new URL(`${endpoint}/v1/player/${userid}/consent`);
135
+ const headers:HeadersInit = new Headers();
136
+
137
+ headers.append('X-SessionID', sessionid);
138
+
139
+ const options = {
140
+ method: "GET",
141
+ headers: headers
142
+ };
143
+
144
+ fetch(url.href, options)
145
+ .then((res:any) => { return res.json(); })
146
+ .then((data:any) => {
147
+ profileConsent = data.items;
148
+ }, (err:any) => {
149
+ console.error(err);
150
+ });
185
151
  }
186
152
 
187
153
  const getCountriesList = ():void => {
@@ -190,7 +156,6 @@
190
156
  if (res.status >= 300) {
191
157
  return new Error('Error while fetching the countries');
192
158
  }
193
-
194
159
  return res.json();
195
160
  })
196
161
  .then((countryList:any) => {
@@ -198,20 +163,16 @@
198
163
  if (res.status >= 300) {
199
164
  return new Error('Error while fetching the supported countries');
200
165
  }
201
-
202
166
  return res.json();
203
167
  })
204
168
  .then((supportedCountries:any) => {
205
169
  countriesArray = countryList.countries.filter((item:any) => {
206
170
  return supportedCountries.countries.indexOf(item.Alpha2Code) >= 0;
207
171
  });
208
-
209
- selectedCountry = countriesArray.find((country:any) => country.Alpha2Code === countrycode) || { Name: 'I.E. Ireland'};
210
- isLoading = false;
211
172
  });
212
173
  });
213
174
  }
214
-
175
+
215
176
  const getPhoneCodes = ():void => {
216
177
  fetch(`${endpoint}/v1/player/phonecodes`)
217
178
  .then((res:any) => res.json())
@@ -220,182 +181,197 @@
220
181
  });
221
182
  }
222
183
 
223
- const showConfirmMessage = ():void => {
224
- showConfirmSave = true;
225
- setTimeout(() => {showConfirmSave = false;}, 3000);
226
- }
227
-
228
-
229
- const checkIsValid = ():void => {
230
- if (invalidSecurityQuestion || invalidSecurityAnswer || invalidCity || invalidAddress || invalidPostalCode || invalidMobile) {
231
- isValid = false;
232
- }
233
- else {
184
+ const validateAllFields = ():void => {
185
+ isValid = false;
186
+ if (isSecurityQuestionValid && isSecurityAnswerValid && isCityValid && isAddressValid && isPostalCodeValid && isMobileValid) {
234
187
  isValid = true;
235
188
  }
236
189
  }
237
190
 
238
- const checkMobile = ():boolean => {
239
- if(playerMobileNumber && playerMobileNumber.length >= 5 && playerMobileNumber.length <= 12) {
240
- return true;
241
- }
242
-
243
- return false;
191
+ const checkForChanges = ():void => {
192
+ hasProfileInfoChanged = safeStringify(updatedEditableValues) !== initialConsentValues;
244
193
  }
245
194
 
246
- const validateMobile = ():void => {
247
- invalidMobile = !checkMobile();
248
- checkIsValid();
195
+ const checkForConsentChanges = ():void => {
196
+ const c = new Object({
197
+ acceptNewsEmail: updatedEditableValues.acceptNewsEmail,
198
+ acceptSMSOffers: updatedEditableValues.acceptSMSOffers
199
+ });
200
+ hasProfileConsentChanged = safeStringify(c) !== initialConsentValues;
249
201
  }
250
202
 
251
- const checkSecurityQuestion = ():boolean => {
252
- if (securityQuestion)
253
- switch(custominputtextswitch) {
254
- case 'true':
255
- if (regexValidators.document.test(securityQuestion) && securityQuestion.length <= 50) {
256
- return true;
203
+ const validateAndCheckForChanges = (key:string):void => {
204
+ switch (key) {
205
+ case 'mobileNumber':
206
+ isMobileValid = false;
207
+ if(updatedEditableValues.mobile.number && updatedEditableValues.mobile.number.length >= 5 && updatedEditableValues.mobile.number.length <= 12) {
208
+ isMobileValid = true;
257
209
  }
258
210
  break;
259
211
 
260
- case 'false':
261
- if (securityQuestion && securityQuestion.length <= 120) {
262
- return true;
212
+ case 'city':
213
+ isCityValid = false;
214
+ if (updatedEditableValues.city && updatedEditableValues.city.length <= 50) {
215
+ isCityValid = true;
263
216
  }
264
217
  break;
265
- }
266
218
 
267
- return false;
268
- }
269
-
270
- const validateSecurityQuestion = ():void => {
271
- invalidSecurityQuestion = !checkSecurityQuestion();
272
- checkIsValid();
273
- }
274
-
275
- const checkSecurityAnswer = ():boolean => {
276
- if (securityAnswer)
277
- switch(custominputtextswitch) {
278
- case 'true':
279
- if (regexValidators.document.test(securityAnswer) && securityAnswer.length <= 50) {
280
- return true;
219
+ case 'postalCode':
220
+ isPostalCodeValid = false;
221
+ if (updatedEditableValues.postalCode && updatedEditableValues.postalCode.length <= 20) {
222
+ isPostalCodeValid = true;
281
223
  }
282
224
  break;
283
225
 
284
- case 'false':
285
- if (securityAnswer && securityAnswer.length <= 120) {
286
- return true;
226
+ case 'address':
227
+ isAddressValid = false;
228
+ if(updatedEditableValues.address1 && updatedEditableValues.address1.length <= 100) {
229
+ isAddressValid = true;
287
230
  }
288
231
  break;
289
- }
290
-
291
- return false;
292
- }
293
232
 
294
- const validateSecurityAnswer = ():void => {
295
- invalidSecurityAnswer = !checkSecurityAnswer();
296
- checkIsValid();
297
- }
298
-
299
- const checkCity = ():boolean => {
300
- if (playerCity.value && playerCity.value.length <= 50) {
301
- return true;
302
- }
233
+ case 'securityQuestion':
234
+ isSecurityQuestionValid = false;
235
+ if (updatedEditableValues.securityQuestion)
236
+ switch(custominputtextswitch) {
237
+ case 'true':
238
+ if (regexValidators.document.test(updatedEditableValues.securityQuestion) && updatedEditableValues.securityQuestion.length <= 50) {
239
+ isSecurityQuestionValid = true;
240
+ }
241
+ break;
303
242
 
304
- return false;
305
- }
243
+ case 'false':
244
+ if (updatedEditableValues.securityQuestion && updatedEditableValues.securityQuestion.length <= 120) {
245
+ isSecurityQuestionValid = true;
246
+ }
247
+ break;
248
+ }
249
+ break;
306
250
 
307
- const validateCity = ():void => {
308
- invalidCity = !checkCity();
309
- checkIsValid();
310
- }
251
+ case 'securityAnswer':
252
+ isSecurityAnswerValid = false;
253
+ if (updatedEditableValues.securityAnswer)
254
+ switch(custominputtextswitch) {
255
+ case 'true':
256
+ if (regexValidators.document.test(updatedEditableValues.securityAnswer) && updatedEditableValues.securityAnswer.length <= 50) {
257
+ isSecurityAnswerValid = true;
258
+ }
259
+ break;
311
260
 
312
- const checkPostalCode = ():boolean => {
313
- if (playerPostalCode.value && playerPostalCode.value.length <= 20) {
314
- return true;
315
- }
261
+ case 'false':
262
+ if (updatedEditableValues.securityAnswer && updatedEditableValues.securityAnswer.length <= 120) {
263
+ isSecurityAnswerValid = true;
264
+ }
265
+ break;
266
+ }
267
+ break;
316
268
 
317
- return false;
318
- }
269
+ case 'acceptSMSOffers':
270
+ checkForConsentChanges();
271
+ break;
319
272
 
320
- const validatePostalCode = ():void => {
321
- invalidPostalCode = !checkPostalCode();
322
- checkIsValid();
323
- }
273
+ case 'acceptNewsEmail':
274
+ checkForConsentChanges();
275
+ break;
324
276
 
325
- const checkAddress = ():boolean => {
326
- if(playerAddress.value && playerAddress.value.length <= 100) {
327
- return true;
328
277
  }
329
-
330
- return false;
278
+ checkForChanges();
279
+ validateAllFields();
280
+ }
281
+
282
+ const showSuccessMessage = ():void => {
283
+ showConfirmSave = true;
284
+ setTimeout(() => {showConfirmSave = false;}, 3000);
285
+ window.postMessage({ type: 'WidgetNotification', data: {type: 'success', message: $_('profileUpdateSuccess')}}, window.location.href);
331
286
  }
332
287
 
333
- const validateAddress = ():void => {
334
- invalidAddress = !checkAddress();
335
- checkIsValid();
288
+ const showErrorMessage = ():void => {
289
+ window.postMessage({ type: 'WidgetNotification', data: {type: 'error', message: $_('userProfileUpdateError')}}, window.location.href);
336
290
  }
337
291
 
338
- const updatePlayerInfo = (e):void => {
292
+ const updatePlayerInfoAndConsent = (e:any):void => {
339
293
  e.preventDefault();
340
- if (differencesExist == true && isValid == true) {
341
- window.postMessage({ type: 'UpdatePlayerInfo', provisionalArray }, window.location.href);
342
- window.postMessage({ type: 'UpdatePlayerConsent', consentArray }, window.location.href);
294
+
295
+ if (hasProfileInfoChanged && !hasProfileConsentChanged && isValid) {
296
+ updateProfileInfo().then((success:boolean) => {
297
+ if (success) {
298
+ getUserProfileInfo();
299
+ showSuccessMessage();
300
+ }
301
+ });
302
+ return;
303
+ }
304
+ if (hasProfileInfoChanged && hasProfileConsentChanged && isValid) {
305
+ updateProfileInfo();
306
+ updateProfileConsent();
307
+
308
+ Promise.all([updateProfileInfo(), updateProfileConsent()]).then((success:Array<boolean>) => {
309
+ if (success[0] && success[1]) {
310
+ getUserProfileInfo();
311
+ getUserProfileConsent();
312
+ showSuccessMessage();
313
+ hasProfileInfoChanged = false;
314
+ hasProfileConsentChanged = false;
315
+ } else {
316
+ showErrorMessage();
317
+ }
318
+ });
319
+ return;
343
320
  }
344
321
  }
345
322
 
346
- const toggleScreen = ():void => {
347
- window.postMessage({type: 'PlayerAccountMenuActive', isMobile}, window.location.href);
348
- }
323
+ const updateProfileInfo = async ():Promise<boolean> => {
349
324
 
350
- const checkForChanges = ():void => {
351
- provisionalArray = {
352
- acceptNewsEmail: giveConsentEmail,
353
- acceptSMSOffers: giveConsentSMS,
354
- address: playerAddress.value,
355
- city: playerCity.value,
356
- mobileNumber: playerMobileNumber,
357
- mobilePrefix: playerPrefix,
358
- postalCode: playerPostalCode.value,
359
- securityAnswer: playerAnswer,
360
- securityQuestion: playerQuestion,
325
+ const url:URL = new URL(`${endpoint}/v1/player/${userid}/profile`);
326
+ const headers:HeadersInit = new Headers();
327
+
328
+ headers.append('X-SessionID', sessionid);
329
+ headers.append('Content-Type', 'application/json');
330
+ headers.append('Accept', 'application/json');
331
+
332
+ const body = safeStringify(updatedEditableValues);
333
+ if (body === null) {
334
+ return false;
361
335
  }
336
+
337
+ let options:RequestInit = {
338
+ method: "POST",
339
+ headers: headers,
340
+ body: body
341
+ };
362
342
 
363
- checkEquality(provisionalArray, initialValuesArray);
364
- consentData();
365
- checkIsValid();
343
+ return await fetch(url.href, options).then((res:any) => res.status == 200, (err) => {console.error(err); return false});
366
344
  }
367
345
 
368
- const consentData = ():void => {
369
- consentArray = { items: [] };
370
- if (showSMS) {
371
- consentArray.items.push({'tagCode': 'sms', 'status': giveConsentSMS ? 'Accepted' : 'Denied'})
372
- }
346
+ const updateProfileConsent = async ():Promise<boolean> => {
347
+ const updatedProfileConsent = [
348
+ {tagCode: 'sms', status: (updatedEditableValues.acceptSMSOffers ? 'Accepted' : 'Denied')},
349
+ {tagCode: 'emailmarketing', status: (updatedEditableValues.acceptNewsEmail ? 'Accepted' : 'Denied')}
350
+ ];
351
+
352
+ const url:URL = new URL(`${endpoint}/v1/player/${userid}/consent`);
353
+ const headers:HeadersInit = new Headers();
373
354
 
374
- if (showEmail) {
375
- consentArray.items.push({'tagCode': 'emailmarketing', 'status': giveConsentEmail ? 'Accepted' : 'Denied'})
355
+ headers.append('X-SessionID', sessionid);
356
+ headers.append('Content-Type', 'application/json');
357
+ headers.append('Accept', 'application/json');
358
+
359
+ const body = safeStringify({items: updatedProfileConsent});
360
+ if (body === null) {
361
+ return false;
376
362
  }
377
- }
378
363
 
379
- const resetPlayerInfo = ():void => {
380
- playerAddress.value = initialValuesArray.address;
381
- playerCity.value = initialValuesArray.city;
382
- giveConsentEmail = initialValuesArray.acceptNewsEmail;
383
- giveConsentSMS = initialValuesArray.acceptSMSOffers;
384
- playerPrefix = initialValuesArray.mobilePrefix;
385
- playerMobileNumber = initialValuesArray.mobileNumber;
386
- playerPostalCode.value = initialValuesArray.postalCode;
387
- playerAnswer = initialValuesArray.securityAnswer;
388
- playerQuestion = initialValuesArray.securityQuestion;
364
+ const options:RequestInit = {
365
+ method: "POST",
366
+ headers: headers,
367
+ body: body
368
+ };
389
369
 
390
- toggleScreen();
370
+ return await fetch(url.href, options).then((res:any) => res.status == 200, (err) => {console.error(err); return false});
391
371
  }
392
372
 
393
- const checkEquality = (a, b):void => {
394
- if(JSON.stringify(a) === JSON.stringify(b)) {
395
- differencesExist = false;
396
- } else {
397
- differencesExist = true;
398
- }
373
+ const toggleScreen = ():void => {
374
+ window.postMessage({type: 'PlayerAccountMenuActive', isMobile}, window.location.href);
399
375
  }
400
376
 
401
377
  const setActiveLanguage = ():void => {
@@ -421,18 +397,29 @@
421
397
  });
422
398
  }
423
399
 
424
- onMount(() => {
400
+ const setTranslationUrl = ():void => {
401
+ const url:string = translationurl;
425
402
 
426
- window.addEventListener('message', messageHandler, false);
403
+ fetch(url).then((res:any) => res.json())
404
+ .then((res) => {
405
+ Object.keys(res).forEach((item:any):void => {
406
+ addNewMessages(item, res[item]);
407
+ });
408
+ }).catch((err:any) => {
409
+ console.log(err);
410
+ });
411
+ }
427
412
 
428
- return () => {
429
- window.removeEventListener('message', messageHandler);
430
- }
413
+ Object.keys(TRANSLATIONS).forEach((item:any) => {
414
+ addNewMessages(item, TRANSLATIONS[item]);
431
415
  });
432
416
 
433
- $: lang && setActiveLanguage();
434
- $: endpoint && countrycode && getCountriesList();
417
+ $: endpoint && userid && sessionid && getUserProfileInfo();
418
+ $: endpoint && userid && sessionid && getUserProfileConsent();
419
+ $: endpoint && getCountriesList();
435
420
  $: endpoint && getPhoneCodes();
421
+ $: profileInfo && profileConsent && countriesArray && initPlayerInfoFields();
422
+ $: lang && setActiveLanguage();
436
423
  $: clientstylingurl && customStylingContainer && setClientStylingURL();
437
424
  $: clientstyling && customStylingContainer && setClientStyling();
438
425
  $: translationurl && setTranslationUrl();
@@ -445,7 +432,7 @@
445
432
  <form class="PlayerInfoWrapper {isMobile ? 'PlayerInfoWrapperMobile' : ''} {mediaQuery.matches && isMobile ? 'PlayerInfoWrapperTablet' : ''}">
446
433
 
447
434
  {#if isMobile}
448
- <div class="MenuReturnButton" on:click={() => toggleScreen()}>
435
+ <div class="MenuReturnButton" on:click={toggleScreen} on:keyup={null}>
449
436
  <svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 15 15"><defs><style>.aaa{fill:var(--emw--pam-color-primary, var(--emw--color-primary, #22B04E));}</style></defs><g transform="translate(-20 -158)">
450
437
  <g transform="translate(20 158)">
451
438
  <path class="aaa" d="M7.5,0,6.136,1.364,11.3,6.526H0V8.474H11.3L6.136,13.636,7.5,15,15,7.5Z" transform="translate(15 15) rotate(180)"/>
@@ -462,69 +449,69 @@
462
449
  </div>
463
450
  <section class="PlayerDetailsContent">
464
451
  <div class="PlayerInfoBox">
465
- <label>{$_('userName')}</label>
466
- <input type="text" class="FieldDisabled" value={username} readonly />
452
+ <p>{$_('userName')}</p>
453
+ <input type="text" class="FieldDisabled" value={readOnlyValues.username} readonly />
467
454
  </div>
468
- <div class="PlayerInfoBox {invalidMobile ? 'InvalidField' : ''}">
469
- <label>{$_('userPhone')}</label>
455
+ <div class="PlayerInfoBox {isMobileValid ? '' : 'InvalidField'}">
456
+ <p>{$_('userPhone')}</p>
470
457
  <div class="PlayerPhoneNumber">
471
- <select bind:value={playerPrefix} on:change={() => checkForChanges()}>
458
+ <select bind:value={updatedEditableValues.mobile.prefix} on:change={checkForChanges}>
472
459
  {#each prefixesArray as pref}
473
- {#if pref.Prefix === initialValuesArray.mobiePrefix}
460
+ {#if pref.Prefix === updatedEditableValues.mobile.prefix}
474
461
  <option selected>{pref.Prefix}</option>
475
462
  {:else}
476
463
  <option>{pref.Prefix}</option>
477
464
  {/if}
478
465
  {/each}
479
466
  </select>
480
- <input bind:value={playerMobileNumber} on:keyup={validateMobile} type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1');" placeholder={noPlayerData ? mobile.number : ''} on:keyup={() => checkForChanges()}/>
467
+ <input type="text" bind:value={updatedEditableValues.mobile.number} on:keyup={() => validateAndCheckForChanges('mobileNumber')} on:input={updatedEditableValues.mobile.number = updatedEditableValues.mobile.number.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1')} placeholder={defaultValues.mobile.number}/>
481
468
  </div>
482
- {#if invalidMobile}
469
+ {#if !isMobileValid}
483
470
  <p class="InvalidInput">{$_('userPhoneError')}</p>
484
471
  {/if}
485
472
  </div>
486
- <div class="PlayerInfoBox {invalidSecurityQuestion ? 'InvalidField' : ''}">
473
+ <div class="PlayerInfoBox {isSecurityQuestionValid ? '' : 'InvalidField'}">
487
474
  <label for="SecurityQuestion">{custominputtextswitch == 'true' ? $_('profileSecurityQuestion2') : $_('profileSecurityQuestion')}:<span class="FormRequired">*</span></label>
488
- <input type="text" bind:value={playerQuestion} on:keyup={() => checkForChanges()} on:blur={validateSecurityQuestion} placeholder={noPlayerData ? securityQuestion : ''} />
489
- {#if invalidSecurityQuestion}
475
+ <input id="SecurityQuestion" type="text" bind:value={updatedEditableValues.securityQuestion} on:keyup={() => validateAndCheckForChanges('securityQuestion')} placeholder={defaultValues.securityQuestion} />
476
+ {#if !isSecurityQuestionValid}
490
477
  <p class="InvalidInput">{custominputtextswitch == 'true' ? $_('profileSecurityQuestionError2') : $_('profileSecurityQuestionError')}</p>
491
478
  {/if}
492
479
  </div>
493
- <div class="PlayerInfoBox {invalidSecurityAnswer ? 'InvalidField' : ''}">
480
+ <div class="PlayerInfoBox {isSecurityAnswerValid ? '' : 'InvalidField'}">
494
481
  <label for="SecurityAnswer">{custominputtextswitch == 'true' ? $_('profileSecurityAnswer2') : $_('profileSecurityAnswer')}:<span class="FormRequired">*</span></label>
495
- <input type="text" bind:value={playerAnswer} on:keyup={() => checkForChanges()} on:blur={validateSecurityAnswer} placeholder={noPlayerData ? securityAnswer : ''} />
496
- {#if invalidSecurityAnswer}
482
+ <input id="SecurityAnswer" type="text" bind:value={updatedEditableValues.securityAnswer} on:keyup={() => validateAndCheckForChanges('securityAnswer')} placeholder={defaultValues.securityAnswer} />
483
+ {#if !isSecurityAnswerValid}
497
484
  <p class="InvalidInput">{custominputtextswitch == 'true' ? $_('profileSecurityAnswerError2') : $_('profileSecurityAnswerError')}</p>
498
485
  {/if}
499
486
  </div>
500
487
  <div class="PlayerInfoBox">
501
- <label>{$_('userEmail')}</label>
502
- <input type="email" class="FieldDisabled" value={email} readonly />
488
+ <label for="UserEmail">{$_('userEmail')}</label>
489
+ <input id="UserEmail" type="email" class="FieldDisabled" value={readOnlyValues.email} readonly />
503
490
  </div>
504
491
  <div class="PlayerInfoBox">
505
- <label>{$_('dateOfBirth')}</label>
506
- <input type="text" class="FieldDisabled" value={birth} readonly />
492
+ <label for="DateOfBirth">{$_('dateOfBirth')}</label>
493
+ <input id="DateOfBirth" type="text" class="FieldDisabled" value={readOnlyValues.birth} readonly />
507
494
  </div>
508
495
  <div class="PlayerInfoBox">
509
- <label>{$_('firstName')}</label>
510
- <input type="text" class="FieldDisabled" value={firstname} readonly />
496
+ <label for="FirstName">{$_('firstName')}</label>
497
+ <input id="FirstName" type="text" class="FieldDisabled" value={readOnlyValues.firstname} readonly />
511
498
  </div>
512
499
  <div class="PlayerInfoBox">
513
- <label>{$_('lastName')}</label>
514
- <input type="text" class="FieldDisabled" value={lastname} readonly />
500
+ <label for="LastName">{$_('lastName')}</label>
501
+ <input id="LastName" type="text" class="FieldDisabled" value={readOnlyValues.lastname} readonly />
515
502
  </div>
516
503
  <div class="PlayerInfoBox">
517
- <label>{$_('userTitle')}</label>
518
- <input type="text" class="FieldDisabled" value={userTitles} readonly />
504
+ <label for="UserTitle">{$_('userTitle')}</label>
505
+ <input id="UserTitle" type="text" class="FieldDisabled" value={readOnlyValues.userTitles} readonly />
519
506
  </div>
520
507
  <div class="PlayerInfoBox">
521
- <label>{$_('currency')}</label>
522
- <input type="text" class="FieldDisabled" value={currency} readonly />
508
+ <label for="Currrency">{$_('currency')}</label>
509
+ <input id="Currency" type="text" class="FieldDisabled" value={readOnlyValues.currency} readonly />
523
510
  </div>
524
- {#if iban}
511
+ {#if readOnlyValues.iban}
525
512
  <div class="PlayerInfoBox">
526
- <label>{$_('iban')}</label>
527
- <input type="text" class="FieldDisabled" value={iban} readonly />
513
+ <label for="Iban">{$_('iban')}</label>
514
+ <input id="Iban" type="text" class="FieldDisabled" value={readOnlyValues.iban} readonly />
528
515
  </div>
529
516
  {/if}
530
517
  </section>
@@ -534,50 +521,50 @@
534
521
  </div>
535
522
  <section class="PlayerLocationContent">
536
523
  <div class="PlayerInfoBox">
537
- <label>{$_('userCountry')}</label>
538
- <input type="text" class="PlayerCountry FieldDisabled" placeholder={countrycode} value={selectedCountry.Name} readonly />
524
+ <label for="UserCountry">{$_('userCountry')}</label>
525
+ <input id="UserCountry" type="text" class="PlayerCountry FieldDisabled" value={readOnlyValues.countryName} placeholder={readOnlyValues.countryCode} readonly />
539
526
  </div>
540
- <div class="PlayerInfoBox {invalidCity ? 'InvalidField' : ''}">
541
- <label>{$_('userCity')}</label>
542
- <input bind:this={playerCity} type="text" on:blur={validateCity} on:keyup={() => checkForChanges()} placeholder={noPlayerData ? city : ''} value={noPlayerData ? '' : initialValuesArray.city} />
543
- {#if invalidCity}
527
+ <div class="PlayerInfoBox {isCityValid ? '' : 'InvalidField'}">
528
+ <label for="UserCity">{$_('userCity')}</label>
529
+ <input id="UserCity" type="text" bind:value={updatedEditableValues.city} on:keyup={() => validateAndCheckForChanges('city')} placeholder={defaultValues.city}/>
530
+ {#if !isCityValid}
544
531
  <p class="InvalidInput">{$_('userCityError')}</p>
545
532
  {/if}
546
533
  </div>
547
- <div class="PlayerInfoBox {invalidAddress ? 'InvalidField' : ''}">
548
- <label>{$_('userAddress')}</label>
549
- <input bind:this={playerAddress} placeholder={address1} type="text" on:blur={validateAddress} on:keyup={() => checkForChanges()} value={noPlayerData ? '' : initialValuesArray.address} />
550
- {#if invalidAddress}
551
- <p class="InvalidInput">{$_('userAddressError')}</p>
552
- {/if}
534
+ <div class="PlayerInfoBox {isAddressValid ? '' : 'InvalidField'}">
535
+ <label for="UserAdress">{$_('userAddress')}</label>
536
+ <input id="UserAdress" type="text" bind:value={updatedEditableValues.address1} on:keyup={() => validateAndCheckForChanges('address')} placeholder={defaultValues.adress}/>
537
+ {#if !isAddressValid}
538
+ <p class="InvalidInput">{$_('userAddressError')}</p>
539
+ {/if}
553
540
  </div>
554
- <div class="PlayerInfoBox {invalidPostalCode ? 'InvalidField' : ''}">
555
- <label>{$_('userPostalCode')}</label>
556
- <input bind:this={playerPostalCode} type="text" on:blur={validatePostalCode} on:keyup={() => checkForChanges()} placeholder={noPlayerData ? postalCode : ''} value={noPlayerData ? '' : initialValuesArray.postalCode} />
557
- {#if invalidPostalCode}
541
+ <div class="PlayerInfoBox {isPostalCodeValid ? '' : 'InvalidField'}">
542
+ <label for="UserPostalCode">{$_('userPostalCode')}</label>
543
+ <input id="UserPostalCode" type="text" bind:value={updatedEditableValues.postalCode} on:keyup={() => validateAndCheckForChanges('postalCode')} placeholder={defaultValues.postalCode}/>
544
+ {#if !isPostalCodeValid}
558
545
  <p class="InvalidInput">{$_('userPostalCodeError')}</p>
559
546
  {/if}
560
547
  </div>
561
548
  </section>
562
549
 
563
- {#if showEmail || showSMS}
550
+ {#if updatedEditableValues.acceptSMSOffers !== undefined || updatedEditableValues.acceptNewsEmail !== undefined}
564
551
  <div class="PlayerNotificationsHeader">
565
552
  <h3>{$_('userNotifications')}</h3>
566
553
  </div>
567
554
  <section class="PlayerNotificationsCheckboxArea">
568
- {#if showSMS}
555
+ {#if updatedEditableValues.acceptSMSOffers !== undefined}
569
556
  <div class="PlayerNotificationBox">
570
557
  <label for="SMSNotification">
571
- <input bind:checked={giveConsentSMS} on:change={checkForChanges} type="checkbox" id="SMSNotification" name="Enable SMS notifications" />
558
+ <input bind:checked={updatedEditableValues.acceptSMSOffers} on:change={() => validateAndCheckForChanges('acceptSMSOffers')} type="checkbox" id="SMSNotification" name="Enable SMS notifications" />
572
559
  <span class="Checkmark"></span>
573
560
  <span>{$_('userSMSNotification')}</span>
574
561
  </label>
575
562
  </div>
576
563
  {/if}
577
- {#if showEmail}
564
+ {#if updatedEditableValues.acceptNewsEmail !== undefined}
578
565
  <div class="PlayerNotificationBox">
579
566
  <label for="EmailNotification">
580
- <input bind:checked={giveConsentEmail} on:change={checkForChanges} type="checkbox" id="EmailNotification" name="Enable Emails" />
567
+ <input bind:checked={updatedEditableValues.acceptNewsEmail} on:change={() => validateAndCheckForChanges('acceptNewsEmail')} type="checkbox" id="EmailNotification" name="Enable Emails" />
581
568
  <span class="Checkmark"></span>
582
569
  <span>{$_('userEmailNotification')}</span>
583
570
  </label>
@@ -586,7 +573,7 @@
586
573
  </section>
587
574
  {/if}
588
575
  <section class="PlayerDetailsButtonsArea {isMobile ? 'PlayerDetailsButtonsAreaMobile' : ''}" >
589
- <button class="PlayerDetailsSaveButton {differencesExist && isValid ? '' : 'PlayerButtonDisabled'}" on:click={(e) => updatePlayerInfo(e)}>{$_('userProfileSaveChanges')}</button>
576
+ <button class="PlayerDetailsSaveButton {hasProfileInfoChanged && isValid ? '' : 'PlayerButtonDisabled'}" on:click={updatePlayerInfoAndConsent}>{$_('userProfileSaveChanges')}</button>
590
577
  </section>
591
578
  {#if showConfirmSave}
592
579
  <section class="PlayerDetailsConfirmSave">
@@ -599,7 +586,6 @@
599
586
 
600
587
  <style lang="scss">
601
588
 
602
-
603
589
  button {
604
590
  font-family: var(--emw--button-typography);
605
591
  }
@@ -737,6 +723,7 @@
737
723
  /* Firefox */
738
724
  input[type=number] {
739
725
  -moz-appearance: textfield;
726
+ appearance: textfield;
740
727
  }
741
728
  }
742
729