@klauswuestefeld/jux-web 2024.2.8 → 2024.3.28
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/api-client.d.ts +11 -11
- package/dist/captcha/google-captcha.d.ts +1 -1
- package/dist/contact-us/contact-field.d.ts +1 -1
- package/dist/contact-us/contact-us-modal.d.ts +1 -1
- package/dist/jux/jux-event.d.ts +12 -10
- package/dist/jux/language.d.ts +4 -4
- package/dist/jux-modal.d.ts +1 -1
- package/dist/jux-web.js +1227 -1180
- package/dist/login/auth.d.ts +2 -2
- package/dist/login/base-page.d.ts +1 -1
- package/dist/login/login-button.d.ts +1 -1
- package/dist/login/login-page.d.ts +1 -1
- package/dist/login/magic-email-field.d.ts +2 -2
- package/dist/login/magic-link-modal.d.ts +1 -1
- package/dist/login/magic-link-requested-page.d.ts +1 -1
- package/dist/login/session.d.ts +6 -6
- package/dist/login/social-login.d.ts +1 -1
- package/dist/login/unauthorized-magic-link-request-page.d.ts +1 -1
- package/dist/login/utils/constants.d.ts +1 -1
- package/dist/login/utils/cookies.d.ts +1 -1
- package/dist/login/utils/layout-changes.d.ts +2 -2
- package/dist/login/utils/string.d.ts +1 -1
- package/dist/login/utils/token.d.ts +1 -1
- package/dist/main.d.ts +12 -12
- package/dist/main.esm.js +1227 -1180
- package/dist/main.js +1227 -1180
- package/dist/style-constants.d.ts +6 -6
- package/package.json +2 -2
package/dist/main.esm.js
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
1
|
import * as msal from '@azure/msal-browser';
|
|
2
2
|
|
|
3
|
-
const getBrowserLanguage = () => {
|
|
4
|
-
const result = (navigator.languages && navigator.languages.length)
|
|
5
|
-
? navigator.languages[0]
|
|
6
|
-
: navigator.userLanguage || navigator.language || navigator.browserLanguage || 'en';
|
|
7
|
-
return result.substring(0, 2);
|
|
8
|
-
};
|
|
9
|
-
const OVERRIDE_KEY = 'jux.language.override';
|
|
10
|
-
let translations = {};
|
|
11
|
-
const chosenLanguage = localStorage.getItem(OVERRIDE_KEY) || getBrowserLanguage();
|
|
12
|
-
const reloadWithLanguageOverride = (lang) => {
|
|
13
|
-
localStorage.setItem(OVERRIDE_KEY, lang);
|
|
14
|
-
location.reload();
|
|
15
|
-
};
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
const getTranslation = (k) => translations[k] || k;
|
|
18
|
-
const initLanguage = (translations_, defaultLanguage = 'en') => {
|
|
19
|
-
translations = translations_[chosenLanguage] || translations_[defaultLanguage];
|
|
20
|
-
document.title = getTranslation('title');
|
|
21
|
-
document.documentElement.lang = translations_[chosenLanguage] ? chosenLanguage : defaultLanguage;
|
|
3
|
+
const getBrowserLanguage = () => {
|
|
4
|
+
const result = (navigator.languages && navigator.languages.length)
|
|
5
|
+
? navigator.languages[0]
|
|
6
|
+
: navigator.userLanguage || navigator.language || navigator.browserLanguage || 'en';
|
|
7
|
+
return result.substring(0, 2);
|
|
8
|
+
};
|
|
9
|
+
const OVERRIDE_KEY = 'jux.language.override';
|
|
10
|
+
let translations = {};
|
|
11
|
+
const chosenLanguage = localStorage.getItem(OVERRIDE_KEY) || getBrowserLanguage();
|
|
12
|
+
const reloadWithLanguageOverride = (lang) => {
|
|
13
|
+
localStorage.setItem(OVERRIDE_KEY, lang);
|
|
14
|
+
location.reload();
|
|
15
|
+
};
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
const getTranslation = (k) => translations[k] || k;
|
|
18
|
+
const initLanguage = (translations_, defaultLanguage = 'en') => {
|
|
19
|
+
translations = translations_[chosenLanguage] || translations_[defaultLanguage];
|
|
20
|
+
document.title = getTranslation('title');
|
|
21
|
+
document.documentElement.lang = translations_[chosenLanguage] ? chosenLanguage : defaultLanguage;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
const THRESHOLD_WIDTH = 640;
|
|
25
25
|
|
|
26
|
-
const icons = {
|
|
27
|
-
email: '<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 64.000000 48.000000" preserveAspectRatio="xMidYMid meet"> <g transform="translate(0.000000,48.000000) scale(0.100000,-0.100000)" fill="#000000" stroke="none"> <path d="M44 468 c-38 -18 -44 -51 -44 -228 0 -180 6 -210 47 -229 33 -15 513 -15 546 0 41 19 47 49 47 229 0 180 -6 210 -47 229 -31 14 -519 14 -549 -1z m516 -33 c0 -7 -232 -205 -240 -205 -8 0 -240 198 -240 205 0 3 108 5 240 5 132 0 240 -2 240 -5z m-406 -118 l59 -53 -87 -97 -86 -97 0 170 0 171 28 -20 c15 -11 54 -44 86 -74z m446 -77 l0 -170 -85 95 c-47 53 -85 98 -85 99 0 5 162 146 167 146 1 0 3 -77 3 -170z m-319 -31 l39 -31 40 32 39 31 33 -37 c18 -21 57 -65 87 -99 l53 -60 -126 -3 c-69 -1 -183 -1 -252 0 l-126 3 84 97 c46 53 85 97 87 97 2 1 21 -13 42 -30z"/> </g> </svg>',
|
|
28
|
-
google: '<svg viewBox="0 0 24 24" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><g transform="matrix(1, 0, 0, 1, 27.009001, -39.238998)"><path fill="#4285F4" d="M -3.264 51.509 C -3.264 50.719 -3.334 49.969 -3.454 49.239 L -14.754 49.239 L -14.754 53.749 L -8.284 53.749 C -8.574 55.229 -9.424 56.479 -10.684 57.329 L -10.684 60.329 L -6.824 60.329 C -4.564 58.239 -3.264 55.159 -3.264 51.509 Z"/><path fill="#34A853" d="M -14.754 63.239 C -11.514 63.239 -8.804 62.159 -6.824 60.329 L -10.684 57.329 C -11.764 58.049 -13.134 58.489 -14.754 58.489 C -17.884 58.489 -20.534 56.379 -21.484 53.529 L -25.464 53.529 L -25.464 56.619 C -23.494 60.539 -19.444 63.239 -14.754 63.239 Z"/><path fill="#FBBC05" d="M -21.484 53.529 C -21.734 52.809 -21.864 52.039 -21.864 51.239 C -21.864 50.439 -21.724 49.669 -21.484 48.949 L -21.484 45.859 L -25.464 45.859 C -26.284 47.479 -26.754 49.299 -26.754 51.239 C -26.754 53.179 -26.284 54.999 -25.464 56.619 L -21.484 53.529 Z"/><path fill="#EA4335" d="M -14.754 43.989 C -12.984 43.989 -11.404 44.599 -10.154 45.789 L -6.734 42.369 C -8.804 40.429 -11.514 39.239 -14.754 39.239 C -19.444 39.239 -23.494 41.939 -25.464 45.859 L -21.484 48.949 C -20.534 46.099 -17.884 43.989 -14.754 43.989 Z"/></g></svg>',
|
|
29
|
-
linkedin: '<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="100%" height="100%" viewBox="1.786 1.783 76.226652 76.248" version="1.1" id="svg72" sodipodi:docname="linkedin.svg" inkscape:version="0.92.4 (5da689c313, 2019-01-14)"> <metadata id="metadata78"> <rdf:RDF> <cc:Work rdf:about=""> <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> <dc:title></dc:title> </cc:Work> </rdf:RDF> </metadata> <defs id="defs76" /> <sodipodi:namedview pagecolor="#ffffff" bordercolor="#666666" borderopacity="1" objecttolerance="10" gridtolerance="10" guidetolerance="10" inkscape:pageopacity="0" inkscape:pageshadow="2" inkscape:window-width="1916" inkscape:window-height="1036" id="namedview74" showgrid="false" inkscape:zoom="0.79365665" inkscape:cx="428.70379" inkscape:cy="325.16058" inkscape:window-x="0" inkscape:window-y="20" inkscape:window-maximized="0" inkscape:current-layer="svg72" inkscape:pagecheckerboard="false" /> <path d="m 2.10821,7.2952417 c 0,-3.015 2.508,-5.462 5.6,-5.462 h 64.568 c 3.093,0 5.6,2.447 5.6,5.462 V 72.620242 c 0,3.016 -2.507,5.461 -5.6,5.461 h -64.568 c -3.092,0 -5.6,-2.445 -5.6,-5.46 V 7.2942417 Z" id="path64" inkscape:connector-curvature="0" style="fill:#0b78b7;fill-opacity:1" /> <path d="m 25.07621,65.660242 v -34.43 h -11.444 v 34.43 h 11.445 z m -5.72,-39.13 c 3.99,0 6.474,-2.644 6.474,-5.948 -0.075,-3.379 -2.484,-5.949 -6.398,-5.949 -3.917,0 -6.475,2.57 -6.475,5.949 0,3.304 2.483,5.948 6.324,5.948 h 0.074 z m 12.054,39.13 h 11.443 v -19.225 c 0,-1.028 0.075,-2.058 0.377,-2.792 0.827,-2.057 2.71,-4.186 5.872,-4.186 4.14,0 5.797,3.157 5.797,7.786 v 18.417 h 11.443 v -19.741 c 0,-10.575 -5.645,-15.496 -13.174,-15.496 -6.173,0 -8.884,3.45 -10.39,5.8 h 0.076 v -4.992 h -11.443 c 0.149,3.23 -0.001,34.43 -0.001,34.43 z" id="path70" inkscape:connector-curvature="0" style="fill:#ffffff" /> </svg>',
|
|
30
|
-
microsoft: '<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 21 21"><title>MS-SymbolLockup</title><rect x="1" y="1" width="9" height="9" fill="#f25022"/><rect x="1" y="11" width="9" height="9" fill="#00a4ef"/><rect x="11" y="1" width="9" height="9" fill="#7fba00"/><rect x="11" y="11" width="9" height="9" fill="#ffb900"/></svg>',
|
|
31
|
-
};
|
|
32
|
-
const applyComponentStyle = (component) => {
|
|
33
|
-
component.style.alignItems = 'center';
|
|
34
|
-
component.style.background = '#fff';
|
|
35
|
-
component.style.border = 'thin solid #888';
|
|
36
|
-
component.style.borderRadius = '5px';
|
|
37
|
-
component.style.boxShadow = '1px 1px 1px grey';
|
|
38
|
-
component.style.boxSizing = 'content - box';
|
|
39
|
-
component.style.color = '#444';
|
|
40
|
-
component.style.display = 'grid';
|
|
41
|
-
component.style.gridTemplateColumns = '12% 1fr 4fr';
|
|
42
|
-
component.style.height = '42px';
|
|
43
|
-
component.style.marginTop = '16px';
|
|
44
|
-
component.style.padding = '0 12px';
|
|
45
|
-
component.style.whiteSpace = 'nowrap';
|
|
46
|
-
component.style.width = '276px';
|
|
47
|
-
component.style.boxSizing = 'content-box';
|
|
48
|
-
};
|
|
49
|
-
const applyLabelStyle = (label) => {
|
|
50
|
-
label.style.display = 'inline-block';
|
|
51
|
-
label.style.fontSize = '14px';
|
|
52
|
-
label.style.fontWeight = '500';
|
|
53
|
-
label.style.gridColumnStart = '3';
|
|
54
|
-
label.style.marginRight = '34px';
|
|
55
|
-
label.style.paddingLeft = '20px';
|
|
56
|
-
};
|
|
57
|
-
const loginButton = (type, fn) => {
|
|
58
|
-
const loweredCasedType = type.toLowerCase();
|
|
59
|
-
const result = document.createElement('login-button');
|
|
60
|
-
applyComponentStyle(result);
|
|
61
|
-
result.tabIndex = 0;
|
|
62
|
-
result.setAttribute('data-cy', `${loweredCasedType}-button`);
|
|
63
|
-
const icon = document.createElement('login-icon');
|
|
64
|
-
icon.style.gridColumnStart = '2';
|
|
65
|
-
icon.style.width = '28px';
|
|
66
|
-
icon.style.height = '28px';
|
|
67
|
-
icon.style.padding = '6px';
|
|
68
|
-
icon.style.marginLeft = '4px';
|
|
69
|
-
icon.style.boxSizing = 'content-box';
|
|
70
|
-
icon.className = 'ico';
|
|
71
|
-
// @ts-ignore
|
|
72
|
-
icon.innerHTML = icons[loweredCasedType];
|
|
73
|
-
const label = document.createElement('login-label');
|
|
74
|
-
label.textContent = window.innerWidth <= THRESHOLD_WIDTH ? type : getTranslation(`${loweredCasedType}-label`);
|
|
75
|
-
applyLabelStyle(label);
|
|
76
|
-
result.append(icon, label);
|
|
77
|
-
result.addEventListener('click', fn);
|
|
78
|
-
result.addEventListener('mouseenter', () => {
|
|
79
|
-
result.style.cursor = 'pointer';
|
|
80
|
-
result.style.boxShadow = '0 0 6px #808080';
|
|
81
|
-
});
|
|
82
|
-
result.addEventListener('mouseleave', () => {
|
|
83
|
-
result.style.cursor = 'auto';
|
|
84
|
-
result.style.boxShadow = '1px 1px 1px grey';
|
|
85
|
-
});
|
|
86
|
-
return result;
|
|
26
|
+
const icons = {
|
|
27
|
+
email: '<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 64.000000 48.000000" preserveAspectRatio="xMidYMid meet"> <g transform="translate(0.000000,48.000000) scale(0.100000,-0.100000)" fill="#000000" stroke="none"> <path d="M44 468 c-38 -18 -44 -51 -44 -228 0 -180 6 -210 47 -229 33 -15 513 -15 546 0 41 19 47 49 47 229 0 180 -6 210 -47 229 -31 14 -519 14 -549 -1z m516 -33 c0 -7 -232 -205 -240 -205 -8 0 -240 198 -240 205 0 3 108 5 240 5 132 0 240 -2 240 -5z m-406 -118 l59 -53 -87 -97 -86 -97 0 170 0 171 28 -20 c15 -11 54 -44 86 -74z m446 -77 l0 -170 -85 95 c-47 53 -85 98 -85 99 0 5 162 146 167 146 1 0 3 -77 3 -170z m-319 -31 l39 -31 40 32 39 31 33 -37 c18 -21 57 -65 87 -99 l53 -60 -126 -3 c-69 -1 -183 -1 -252 0 l-126 3 84 97 c46 53 85 97 87 97 2 1 21 -13 42 -30z"/> </g> </svg>',
|
|
28
|
+
google: '<svg viewBox="0 0 24 24" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><g transform="matrix(1, 0, 0, 1, 27.009001, -39.238998)"><path fill="#4285F4" d="M -3.264 51.509 C -3.264 50.719 -3.334 49.969 -3.454 49.239 L -14.754 49.239 L -14.754 53.749 L -8.284 53.749 C -8.574 55.229 -9.424 56.479 -10.684 57.329 L -10.684 60.329 L -6.824 60.329 C -4.564 58.239 -3.264 55.159 -3.264 51.509 Z"/><path fill="#34A853" d="M -14.754 63.239 C -11.514 63.239 -8.804 62.159 -6.824 60.329 L -10.684 57.329 C -11.764 58.049 -13.134 58.489 -14.754 58.489 C -17.884 58.489 -20.534 56.379 -21.484 53.529 L -25.464 53.529 L -25.464 56.619 C -23.494 60.539 -19.444 63.239 -14.754 63.239 Z"/><path fill="#FBBC05" d="M -21.484 53.529 C -21.734 52.809 -21.864 52.039 -21.864 51.239 C -21.864 50.439 -21.724 49.669 -21.484 48.949 L -21.484 45.859 L -25.464 45.859 C -26.284 47.479 -26.754 49.299 -26.754 51.239 C -26.754 53.179 -26.284 54.999 -25.464 56.619 L -21.484 53.529 Z"/><path fill="#EA4335" d="M -14.754 43.989 C -12.984 43.989 -11.404 44.599 -10.154 45.789 L -6.734 42.369 C -8.804 40.429 -11.514 39.239 -14.754 39.239 C -19.444 39.239 -23.494 41.939 -25.464 45.859 L -21.484 48.949 C -20.534 46.099 -17.884 43.989 -14.754 43.989 Z"/></g></svg>',
|
|
29
|
+
linkedin: '<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="100%" height="100%" viewBox="1.786 1.783 76.226652 76.248" version="1.1" id="svg72" sodipodi:docname="linkedin.svg" inkscape:version="0.92.4 (5da689c313, 2019-01-14)"> <metadata id="metadata78"> <rdf:RDF> <cc:Work rdf:about=""> <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> <dc:title></dc:title> </cc:Work> </rdf:RDF> </metadata> <defs id="defs76" /> <sodipodi:namedview pagecolor="#ffffff" bordercolor="#666666" borderopacity="1" objecttolerance="10" gridtolerance="10" guidetolerance="10" inkscape:pageopacity="0" inkscape:pageshadow="2" inkscape:window-width="1916" inkscape:window-height="1036" id="namedview74" showgrid="false" inkscape:zoom="0.79365665" inkscape:cx="428.70379" inkscape:cy="325.16058" inkscape:window-x="0" inkscape:window-y="20" inkscape:window-maximized="0" inkscape:current-layer="svg72" inkscape:pagecheckerboard="false" /> <path d="m 2.10821,7.2952417 c 0,-3.015 2.508,-5.462 5.6,-5.462 h 64.568 c 3.093,0 5.6,2.447 5.6,5.462 V 72.620242 c 0,3.016 -2.507,5.461 -5.6,5.461 h -64.568 c -3.092,0 -5.6,-2.445 -5.6,-5.46 V 7.2942417 Z" id="path64" inkscape:connector-curvature="0" style="fill:#0b78b7;fill-opacity:1" /> <path d="m 25.07621,65.660242 v -34.43 h -11.444 v 34.43 h 11.445 z m -5.72,-39.13 c 3.99,0 6.474,-2.644 6.474,-5.948 -0.075,-3.379 -2.484,-5.949 -6.398,-5.949 -3.917,0 -6.475,2.57 -6.475,5.949 0,3.304 2.483,5.948 6.324,5.948 h 0.074 z m 12.054,39.13 h 11.443 v -19.225 c 0,-1.028 0.075,-2.058 0.377,-2.792 0.827,-2.057 2.71,-4.186 5.872,-4.186 4.14,0 5.797,3.157 5.797,7.786 v 18.417 h 11.443 v -19.741 c 0,-10.575 -5.645,-15.496 -13.174,-15.496 -6.173,0 -8.884,3.45 -10.39,5.8 h 0.076 v -4.992 h -11.443 c 0.149,3.23 -0.001,34.43 -0.001,34.43 z" id="path70" inkscape:connector-curvature="0" style="fill:#ffffff" /> </svg>',
|
|
30
|
+
microsoft: '<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 21 21"><title>MS-SymbolLockup</title><rect x="1" y="1" width="9" height="9" fill="#f25022"/><rect x="1" y="11" width="9" height="9" fill="#00a4ef"/><rect x="11" y="1" width="9" height="9" fill="#7fba00"/><rect x="11" y="11" width="9" height="9" fill="#ffb900"/></svg>',
|
|
31
|
+
};
|
|
32
|
+
const applyComponentStyle = (component) => {
|
|
33
|
+
component.style.alignItems = 'center';
|
|
34
|
+
component.style.background = '#fff';
|
|
35
|
+
component.style.border = 'thin solid #888';
|
|
36
|
+
component.style.borderRadius = '5px';
|
|
37
|
+
component.style.boxShadow = '1px 1px 1px grey';
|
|
38
|
+
component.style.boxSizing = 'content - box';
|
|
39
|
+
component.style.color = '#444';
|
|
40
|
+
component.style.display = 'grid';
|
|
41
|
+
component.style.gridTemplateColumns = '12% 1fr 4fr';
|
|
42
|
+
component.style.height = '42px';
|
|
43
|
+
component.style.marginTop = '16px';
|
|
44
|
+
component.style.padding = '0 12px';
|
|
45
|
+
component.style.whiteSpace = 'nowrap';
|
|
46
|
+
component.style.width = '276px';
|
|
47
|
+
component.style.boxSizing = 'content-box';
|
|
48
|
+
};
|
|
49
|
+
const applyLabelStyle = (label) => {
|
|
50
|
+
label.style.display = 'inline-block';
|
|
51
|
+
label.style.fontSize = '14px';
|
|
52
|
+
label.style.fontWeight = '500';
|
|
53
|
+
label.style.gridColumnStart = '3';
|
|
54
|
+
label.style.marginRight = '34px';
|
|
55
|
+
label.style.paddingLeft = '20px';
|
|
56
|
+
};
|
|
57
|
+
const loginButton = (type, fn) => {
|
|
58
|
+
const loweredCasedType = type.toLowerCase();
|
|
59
|
+
const result = document.createElement('login-button');
|
|
60
|
+
applyComponentStyle(result);
|
|
61
|
+
result.tabIndex = 0;
|
|
62
|
+
result.setAttribute('data-cy', `${loweredCasedType}-button`);
|
|
63
|
+
const icon = document.createElement('login-icon');
|
|
64
|
+
icon.style.gridColumnStart = '2';
|
|
65
|
+
icon.style.width = '28px';
|
|
66
|
+
icon.style.height = '28px';
|
|
67
|
+
icon.style.padding = '6px';
|
|
68
|
+
icon.style.marginLeft = '4px';
|
|
69
|
+
icon.style.boxSizing = 'content-box';
|
|
70
|
+
icon.className = 'ico';
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
icon.innerHTML = icons[loweredCasedType];
|
|
73
|
+
const label = document.createElement('login-label');
|
|
74
|
+
label.textContent = window.innerWidth <= THRESHOLD_WIDTH ? type : getTranslation(`${loweredCasedType}-label`);
|
|
75
|
+
applyLabelStyle(label);
|
|
76
|
+
result.append(icon, label);
|
|
77
|
+
result.addEventListener('click', fn);
|
|
78
|
+
result.addEventListener('mouseenter', () => {
|
|
79
|
+
result.style.cursor = 'pointer';
|
|
80
|
+
result.style.boxShadow = '0 0 6px #808080';
|
|
81
|
+
});
|
|
82
|
+
result.addEventListener('mouseleave', () => {
|
|
83
|
+
result.style.cursor = 'auto';
|
|
84
|
+
result.style.boxShadow = '1px 1px 1px grey';
|
|
85
|
+
});
|
|
86
|
+
return result;
|
|
87
87
|
};
|
|
88
88
|
|
|
89
89
|
/******************************************************************************
|
|
@@ -111,1146 +111,1193 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
const extractTokenFromWindowLocation = (tokenParam, additionalParam = '') => {
|
|
115
|
-
if (!tokenParam)
|
|
116
|
-
return;
|
|
117
|
-
let token = '';
|
|
118
|
-
const tokenParameterName = `${tokenParam}=`;
|
|
119
|
-
const search = window.location.search;
|
|
120
|
-
const tokenParameterIndex = search.indexOf(tokenParameterName);
|
|
121
|
-
if (tokenParameterIndex !== -1) {
|
|
122
|
-
const tokenParameterNameLength = tokenParameterName.length;
|
|
123
|
-
const leadingAmpersandIndex = search.indexOf('&', tokenParameterIndex);
|
|
124
|
-
let searchWithoutToken = search;
|
|
125
|
-
token = search.substring(tokenParameterIndex + tokenParameterNameLength);
|
|
126
|
-
if (leadingAmpersandIndex !== -1) {
|
|
127
|
-
token = search.substring(tokenParameterIndex + tokenParameterNameLength, leadingAmpersandIndex);
|
|
128
|
-
searchWithoutToken = searchWithoutToken.slice(0, leadingAmpersandIndex) + searchWithoutToken.slice(leadingAmpersandIndex + 1);
|
|
129
|
-
}
|
|
130
|
-
searchWithoutToken = searchWithoutToken.replace(`${tokenParam}=` + token, '')
|
|
131
|
-
.replace(additionalParam, '')
|
|
132
|
-
.replace('\&cypress=true', '');
|
|
133
|
-
if (searchWithoutToken === '?') {
|
|
134
|
-
searchWithoutToken = '';
|
|
135
|
-
}
|
|
136
|
-
window.history.replaceState({}, document.title, window.location.pathname + searchWithoutToken);
|
|
137
|
-
}
|
|
138
|
-
return token;
|
|
114
|
+
const extractTokenFromWindowLocation = (tokenParam, additionalParam = '') => {
|
|
115
|
+
if (!tokenParam)
|
|
116
|
+
return;
|
|
117
|
+
let token = '';
|
|
118
|
+
const tokenParameterName = `${tokenParam}=`;
|
|
119
|
+
const search = window.location.search;
|
|
120
|
+
const tokenParameterIndex = search.indexOf(tokenParameterName);
|
|
121
|
+
if (tokenParameterIndex !== -1) {
|
|
122
|
+
const tokenParameterNameLength = tokenParameterName.length;
|
|
123
|
+
const leadingAmpersandIndex = search.indexOf('&', tokenParameterIndex);
|
|
124
|
+
let searchWithoutToken = search;
|
|
125
|
+
token = search.substring(tokenParameterIndex + tokenParameterNameLength);
|
|
126
|
+
if (leadingAmpersandIndex !== -1) {
|
|
127
|
+
token = search.substring(tokenParameterIndex + tokenParameterNameLength, leadingAmpersandIndex);
|
|
128
|
+
searchWithoutToken = searchWithoutToken.slice(0, leadingAmpersandIndex) + searchWithoutToken.slice(leadingAmpersandIndex + 1);
|
|
129
|
+
}
|
|
130
|
+
searchWithoutToken = searchWithoutToken.replace(`${tokenParam}=` + token, '')
|
|
131
|
+
.replace(additionalParam, '')
|
|
132
|
+
.replace('\&cypress=true', '');
|
|
133
|
+
if (searchWithoutToken === '?') {
|
|
134
|
+
searchWithoutToken = '';
|
|
135
|
+
}
|
|
136
|
+
window.history.replaceState({}, document.title, window.location.pathname + searchWithoutToken);
|
|
137
|
+
}
|
|
138
|
+
return token;
|
|
139
139
|
};
|
|
140
140
|
|
|
141
|
-
const setBackendUrl = (backendUrl) => localStorage.setItem('backend-url', backendUrl);
|
|
142
|
-
//@ts-ignore
|
|
143
|
-
const getBackendUrl = () => process.env.BACKEND_URL || localStorage.getItem('backend-url');
|
|
144
|
-
//@ts-ignore
|
|
145
|
-
const getSecondaryBackendUrl = () => process.env.STAGING_BACKEND_URL || getBackendUrl();
|
|
146
|
-
const getApiUrl = () => getBackendUrl() + 'api/';
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
spinner.style.
|
|
172
|
-
spinner.style.
|
|
173
|
-
spinner.style.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
spinner
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
document.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
if (requestType === '
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
141
|
+
const setBackendUrl = (backendUrl) => localStorage.setItem('backend-url', backendUrl);
|
|
142
|
+
//@ts-ignore
|
|
143
|
+
const getBackendUrl = () => process.env.BACKEND_URL || localStorage.getItem('backend-url');
|
|
144
|
+
//@ts-ignore
|
|
145
|
+
const getSecondaryBackendUrl = () => process.env.STAGING_BACKEND_URL || getBackendUrl();
|
|
146
|
+
const getApiUrl = () => getBackendUrl() + 'api/';
|
|
147
|
+
const getMagicAuthUrl = () => {
|
|
148
|
+
var _a;
|
|
149
|
+
// @ts-ignore
|
|
150
|
+
const endpoint = ((_a = window === null || window === void 0 ? void 0 : window.store) === null || _a === void 0 ? void 0 : _a.magicLinkAuthEndpoint) || 'auth-magic';
|
|
151
|
+
return getBackendUrl() + endpoint + '?token=';
|
|
152
|
+
};
|
|
153
|
+
const getMagicAuthReqUrl = () => {
|
|
154
|
+
var _a;
|
|
155
|
+
// @ts-ignore
|
|
156
|
+
const endpoint = ((_a = window === null || window === void 0 ? void 0 : window.store) === null || _a === void 0 ? void 0 : _a.magicLinkRequestEndpoint) || 'magic-link-request';
|
|
157
|
+
return getBackendUrl() + endpoint + '?email=';
|
|
158
|
+
};
|
|
159
|
+
// TODO: use jux-events to call commands and queries inside jux-web library
|
|
160
|
+
const handleJuxEvent = (ev) => {
|
|
161
|
+
const { requestType, endpoint, onResult, params, onError, onRedirect } = ev;
|
|
162
|
+
const onJsonResponse = (res) => onResult ? onResult(res) : null;
|
|
163
|
+
const onHelpMessage = (err) => onError ? onError(err) : null;
|
|
164
|
+
post(endpoint, params, onJsonResponse, onHelpMessage, onRedirect, requestType);
|
|
165
|
+
};
|
|
166
|
+
const applySpinnerStyle = (spinner) => {
|
|
167
|
+
spinner.style.position = 'fixed';
|
|
168
|
+
spinner.style.top = '50%';
|
|
169
|
+
spinner.style.zIndex = '2147483647';
|
|
170
|
+
spinner.style.border = '8px solid #bababa';
|
|
171
|
+
spinner.style.borderTopColor = '#171f1c';
|
|
172
|
+
spinner.style.height = '80px';
|
|
173
|
+
spinner.style.width = '80px';
|
|
174
|
+
};
|
|
175
|
+
const renderOverlay = () => {
|
|
176
|
+
const overlay = document.createElement('reconnect-overlay');
|
|
177
|
+
const spinner = document.createElement('loading-spinner');
|
|
178
|
+
spinner.className = 'reconnect-spinner';
|
|
179
|
+
applySpinnerStyle(spinner);
|
|
180
|
+
document.body.append(overlay, spinner);
|
|
181
|
+
};
|
|
182
|
+
const removeOverlay = () => {
|
|
183
|
+
var _a, _b;
|
|
184
|
+
(_a = document.querySelector('reconnect-overlay')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
185
|
+
(_b = document.querySelector('.reconnect-spinner')) === null || _b === void 0 ? void 0 : _b.remove();
|
|
186
|
+
};
|
|
187
|
+
const defaultHandleUnauthorized = () => {
|
|
188
|
+
localStorage.removeItem('token');
|
|
189
|
+
alert(getTranslation('session-expired-msg'));
|
|
190
|
+
location.reload();
|
|
191
|
+
// googleAuthSignOut(); TODO
|
|
192
|
+
};
|
|
193
|
+
let requestRunning = false;
|
|
194
|
+
const maxRetries = 20;
|
|
195
|
+
const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1, ...args_1) => __awaiter(void 0, [url_1, options_1, onSuccess_1, onError_1, onRedirect_1, ...args_1], void 0, function* (url, options, onSuccess, onError, onRedirect, requestType = 'query', handleUnauthorized = defaultHandleUnauthorized, retrial = false, retrialNum = 0) {
|
|
196
|
+
if (requestRunning && !retrial) { // only allow one request at a time
|
|
197
|
+
setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false), 300);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
// @ts-ignore
|
|
201
|
+
const backendToken = window.store.backendToken;
|
|
202
|
+
if (backendToken) {
|
|
203
|
+
if (!options.headers)
|
|
204
|
+
options.headers = {};
|
|
205
|
+
options.headers.auth = backendToken;
|
|
206
|
+
}
|
|
207
|
+
let response;
|
|
208
|
+
requestRunning = true;
|
|
209
|
+
const requestInit = Object.assign({}, options);
|
|
210
|
+
if (requestType === 'query') {
|
|
211
|
+
requestInit.signal = AbortSignal.timeout(6000);
|
|
212
|
+
}
|
|
213
|
+
if (onRedirect)
|
|
214
|
+
requestInit.redirect = 'manual'; // Treat redirects manually instead of following them automatically.
|
|
215
|
+
try {
|
|
216
|
+
response = yield fetch(url, requestInit);
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
// network errors
|
|
220
|
+
if (requestType === 'command') {
|
|
221
|
+
// Do not retry applying command if it fails for the first time.
|
|
222
|
+
onError('There was an error performing your request. Please try again later.');
|
|
223
|
+
requestRunning = false;
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (retrialNum > maxRetries) {
|
|
227
|
+
removeOverlay();
|
|
228
|
+
requestRunning = false;
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const retryRequest = () => {
|
|
232
|
+
retrialNum++;
|
|
233
|
+
if (!document.querySelector('reconnect-overlay')) {
|
|
234
|
+
renderOverlay();
|
|
235
|
+
}
|
|
236
|
+
if (url.includes(getBackendUrl())) {
|
|
237
|
+
url = url.replace(getBackendUrl(), getSecondaryBackendUrl());
|
|
238
|
+
}
|
|
239
|
+
else if (url.includes(getSecondaryBackendUrl())) {
|
|
240
|
+
url = url.replace(getSecondaryBackendUrl(), getBackendUrl());
|
|
241
|
+
}
|
|
242
|
+
setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, true, retrialNum), 2000);
|
|
243
|
+
};
|
|
244
|
+
retryRequest();
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
finally {
|
|
248
|
+
requestRunning = false;
|
|
249
|
+
}
|
|
250
|
+
removeOverlay();
|
|
251
|
+
if (onRedirect)
|
|
252
|
+
onRedirect(response);
|
|
253
|
+
if (response.status === 401) {
|
|
254
|
+
handleUnauthorized();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
const jsonResponse = yield response.json();
|
|
259
|
+
if (response.ok) {
|
|
260
|
+
if (onSuccess) {
|
|
261
|
+
onSuccess(jsonResponse);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
return jsonResponse;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
// backend predicted exceptions
|
|
269
|
+
onError(jsonResponse.error);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
catch (err) {
|
|
273
|
+
// json conversion error / json response dealing errors
|
|
274
|
+
onError(err);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
const post = (endpoint, body, onSuccess, onError, onRedirect, requestType = "query") => {
|
|
278
|
+
const options = {
|
|
279
|
+
method: 'POST',
|
|
280
|
+
headers: {
|
|
281
|
+
'Accept': 'application/json',
|
|
282
|
+
'Content-Type': 'application/json',
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
if (body) {
|
|
286
|
+
// @ts-ignore
|
|
287
|
+
options.body = JSON.stringify(body);
|
|
288
|
+
}
|
|
289
|
+
return backendRequest(getApiUrl() + endpoint, options, onSuccess, onError, onRedirect, requestType);
|
|
290
|
+
};
|
|
291
|
+
const get = (endpoint, onSuccess, onError, onRedirect) => {
|
|
292
|
+
const options = {
|
|
293
|
+
method: 'GET',
|
|
294
|
+
headers: {
|
|
295
|
+
'Accept': 'application/json',
|
|
296
|
+
'Content-Type': 'application/json',
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
return backendRequest(getApiUrl() + endpoint, options, onSuccess, onError, onRedirect);
|
|
300
|
+
};
|
|
301
|
+
const backendPost = (endpoint, postContent, onJsonResponse, onHelpMessage) => {
|
|
302
|
+
post(endpoint, postContent, onJsonResponse, onHelpMessage);
|
|
303
|
+
};
|
|
304
|
+
const backendGet = (endpoint, params, onJsonResponse, onHelpMessage) => {
|
|
305
|
+
if (params) {
|
|
306
|
+
endpoint += '?';
|
|
307
|
+
Object.keys(params).forEach((k, i) => {
|
|
308
|
+
if (i > 0)
|
|
309
|
+
endpoint += '&';
|
|
310
|
+
endpoint += `${k}=${params[k]}`;
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
get(endpoint, onJsonResponse, onHelpMessage);
|
|
314
|
+
};
|
|
315
|
+
const requestMagicLink = (data, onJsonResponse, onUnauthorized) => {
|
|
316
|
+
const { email, token } = data;
|
|
317
|
+
const url = getMagicAuthReqUrl() + encodeURIComponent(email) + '&destination=' + extractTokenFromWindowLocation('destination') + '&token=' + token;
|
|
318
|
+
const options = {};
|
|
319
|
+
backendRequest(url, options, onJsonResponse, console.error, null, 'query', onUnauthorized);
|
|
320
|
+
};
|
|
321
|
+
const openMagicLink = (magicToken, onJsonResponse, onHelpMessage) => {
|
|
322
|
+
backendRequest(getMagicAuthUrl() + magicToken, {}, onJsonResponse, onHelpMessage);
|
|
323
|
+
};
|
|
324
|
+
const googleLogin = (token, onLogin, onLoginError) => {
|
|
325
|
+
const url = getBackendUrl() + 'auth-google?google-id-token=' + token;
|
|
326
|
+
backendRequest(url, {}, onLogin, onLoginError);
|
|
327
|
+
};
|
|
328
|
+
const microsoftLogin = (token, onLogin, onLoginError) => {
|
|
329
|
+
const url = getBackendUrl() + 'auth-microsoft?access-token=' + token;
|
|
330
|
+
backendRequest(url, {}, onLogin, onLoginError);
|
|
331
|
+
};
|
|
332
|
+
const getMXData = (domainName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
333
|
+
try {
|
|
334
|
+
const records = yield fetch(`https://dns.google.com/resolve?name=${domainName}&type=MX`, {
|
|
335
|
+
method: 'GET',
|
|
336
|
+
mode: 'cors'
|
|
337
|
+
});
|
|
338
|
+
if (!records.ok) {
|
|
339
|
+
console.log('response was not ok');
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
const recordsJson = yield records.json();
|
|
343
|
+
const answer = recordsJson.Answer;
|
|
344
|
+
if (!answer) {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
return Array.from(answer).map((a) => a.data);
|
|
348
|
+
}
|
|
349
|
+
catch (error) {
|
|
350
|
+
console.error('Fetch failed: ', error);
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
308
353
|
});
|
|
309
354
|
|
|
310
|
-
let cleared = false;
|
|
311
|
-
const clearCookieValidation = () => {
|
|
312
|
-
var _a;
|
|
313
|
-
(_a = document.querySelector('#cookie-test-iframe')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
314
|
-
cleared = true;
|
|
315
|
-
};
|
|
316
|
-
const checkCookiesEnable = (ev, onEnabled, onDisabled) => {
|
|
317
|
-
if (ev.data === 'MM:3PCunsupported') {
|
|
318
|
-
clearCookieValidation();
|
|
319
|
-
if (onDisabled) {
|
|
320
|
-
onDisabled();
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
else if (ev.data === 'MM:3PCsupported') {
|
|
324
|
-
clearCookieValidation();
|
|
325
|
-
onEnabled();
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
const cookieTest = () => {
|
|
329
|
-
const frame = document.createElement('iframe');
|
|
330
|
-
frame.id = 'cookie-test-iframe';
|
|
331
|
-
frame.src = 'https://mindmup.github.io/3rdpartycookiecheck/start.html';
|
|
332
|
-
frame.style.display = 'none';
|
|
333
|
-
document.body.appendChild(frame);
|
|
334
|
-
};
|
|
335
|
-
const validateThirdPartyCookies = (onEnabled, onDisabled) => {
|
|
336
|
-
cleared = false;
|
|
337
|
-
const listener = (ev) => checkCookiesEnable(ev, onEnabled, onDisabled);
|
|
338
|
-
window.addEventListener('message', listener);
|
|
339
|
-
const timer = setInterval(() => {
|
|
340
|
-
if (cleared) {
|
|
341
|
-
window.removeEventListener('message', listener);
|
|
342
|
-
clearInterval(timer);
|
|
343
|
-
}
|
|
344
|
-
}, 50);
|
|
345
|
-
cookieTest();
|
|
355
|
+
let cleared = false;
|
|
356
|
+
const clearCookieValidation = () => {
|
|
357
|
+
var _a;
|
|
358
|
+
(_a = document.querySelector('#cookie-test-iframe')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
359
|
+
cleared = true;
|
|
360
|
+
};
|
|
361
|
+
const checkCookiesEnable = (ev, onEnabled, onDisabled) => {
|
|
362
|
+
if (ev.data === 'MM:3PCunsupported') {
|
|
363
|
+
clearCookieValidation();
|
|
364
|
+
if (onDisabled) {
|
|
365
|
+
onDisabled();
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
else if (ev.data === 'MM:3PCsupported') {
|
|
369
|
+
clearCookieValidation();
|
|
370
|
+
onEnabled();
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
const cookieTest = () => {
|
|
374
|
+
const frame = document.createElement('iframe');
|
|
375
|
+
frame.id = 'cookie-test-iframe';
|
|
376
|
+
frame.src = 'https://mindmup.github.io/3rdpartycookiecheck/start.html';
|
|
377
|
+
frame.style.display = 'none';
|
|
378
|
+
document.body.appendChild(frame);
|
|
379
|
+
};
|
|
380
|
+
const validateThirdPartyCookies = (onEnabled, onDisabled) => {
|
|
381
|
+
cleared = false;
|
|
382
|
+
const listener = (ev) => checkCookiesEnable(ev, onEnabled, onDisabled);
|
|
383
|
+
window.addEventListener('message', listener);
|
|
384
|
+
const timer = setInterval(() => {
|
|
385
|
+
if (cleared) {
|
|
386
|
+
window.removeEventListener('message', listener);
|
|
387
|
+
clearInterval(timer);
|
|
388
|
+
}
|
|
389
|
+
}, 50);
|
|
390
|
+
cookieTest();
|
|
346
391
|
};
|
|
347
392
|
|
|
348
|
-
const enableSignInLayout = () => {
|
|
349
|
-
document.documentElement.style.cursor = 'progress';
|
|
350
|
-
document.body.style.opacity = '0.5';
|
|
351
|
-
document.body.style.pointerEvents = 'none';
|
|
352
|
-
};
|
|
353
|
-
const disableSignInLayout = () => {
|
|
354
|
-
document.documentElement.style.cursor = 'default';
|
|
355
|
-
document.body.style.opacity = '1';
|
|
356
|
-
document.body.style.pointerEvents = 'auto';
|
|
393
|
+
const enableSignInLayout = () => {
|
|
394
|
+
document.documentElement.style.cursor = 'progress';
|
|
395
|
+
document.body.style.opacity = '0.5';
|
|
396
|
+
document.body.style.pointerEvents = 'none';
|
|
397
|
+
};
|
|
398
|
+
const disableSignInLayout = () => {
|
|
399
|
+
document.documentElement.style.cursor = 'default';
|
|
400
|
+
document.body.style.opacity = '1';
|
|
401
|
+
document.body.style.pointerEvents = 'auto';
|
|
357
402
|
};
|
|
358
403
|
|
|
359
|
-
// TODO: find a better way to import external scripts
|
|
360
|
-
const script$1 = document.createElement('script');
|
|
361
|
-
script$1.type = 'text/javascript';
|
|
362
|
-
script$1.src = 'https://apis.google.com/js/api.js';
|
|
363
|
-
document.head.appendChild(script$1);
|
|
364
|
-
let authStatus;
|
|
365
|
-
let authError;
|
|
366
|
-
const highLevelUser = (gUser) => {
|
|
367
|
-
const profile = gUser.getBasicProfile();
|
|
368
|
-
return {
|
|
369
|
-
name: profile.getName(),
|
|
370
|
-
email: profile.getEmail(),
|
|
371
|
-
picture: profile.getImageUrl(),
|
|
372
|
-
googletoken: gUser.getAuthResponse().id_token
|
|
373
|
-
};
|
|
374
|
-
};
|
|
375
|
-
const onUserChanged = (googleUser, onUserLogin) => {
|
|
376
|
-
document.documentElement.classList.remove('progress');
|
|
377
|
-
document.body.classList.remove('disabled');
|
|
378
|
-
if (googleUser) {
|
|
379
|
-
// mixpanelIdentify(googleUser); TODO
|
|
380
|
-
const onSuccess = (res) => {
|
|
381
|
-
const { token } = res;
|
|
382
|
-
// @ts-ignore
|
|
383
|
-
window.store.currentUser = res;
|
|
384
|
-
onTokenAcquired(token, onUserLogin);
|
|
385
|
-
};
|
|
386
|
-
const onError = (err) => {
|
|
387
|
-
console.error(err);
|
|
388
|
-
// logError(error); TODO
|
|
389
|
-
// checkMixpanel(() => mixpanel.track('Login Error', { 'Login Type': 'Google', 'Error': error })); TODO
|
|
390
|
-
};
|
|
391
|
-
googleLogin(googleUser.googletoken, onSuccess, onError);
|
|
392
|
-
// checkMixpanel(() => mixpanel.track('Login', { 'Login Type': 'Google' })); TODO
|
|
393
|
-
}
|
|
394
|
-
else {
|
|
395
|
-
setBackendToken('');
|
|
396
|
-
// checkMixpanel(() => mixpanel.reset()); TODO
|
|
397
|
-
// displayPage(Page.LOGIN); TODO
|
|
398
|
-
}
|
|
399
|
-
};
|
|
400
|
-
const onGoogleUserChanged = (gUser, onUserLogin) => {
|
|
401
|
-
onUserChanged(gUser.isSignedIn() ? highLevelUser(gUser) : null, onUserLogin);
|
|
402
|
-
};
|
|
403
|
-
const initGapiClient = (callbackFn, onUserLogin) => {
|
|
404
|
-
// @ts-ignore
|
|
405
|
-
const clientId = process.env.GOOGLE_CLIENT_ID;
|
|
406
|
-
gapi.auth2.init({ client_id: clientId, prompt: 'select_account' }).then(() => {
|
|
407
|
-
authStatus = 'LOADED';
|
|
408
|
-
const currentUser = getAuth().currentUser;
|
|
409
|
-
currentUser.listen(onGoogleUserChanged);
|
|
410
|
-
callbackFn ? callbackFn(clientId) : onGoogleUserChanged(currentUser.get(), onUserLogin);
|
|
411
|
-
}, onAuthError);
|
|
412
|
-
};
|
|
413
|
-
const onAuthError = (error) => {
|
|
414
|
-
authError = error;
|
|
415
|
-
console.error(error);
|
|
416
|
-
// logError(error, authError); // TODO
|
|
417
|
-
};
|
|
418
|
-
const initGapi = (callbackFn = null, onUserLogin) => {
|
|
419
|
-
if (!window.location.protocol.startsWith('http')) {
|
|
420
|
-
onAuthError('To use Google Auth you must access this page using http(s), not ' + window.location.protocol);
|
|
421
|
-
return;
|
|
422
|
-
}
|
|
423
|
-
if (typeof gapi === 'undefined') {
|
|
424
|
-
onAuthError('Unable to load the Google API');
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
authStatus = 'LOADING';
|
|
428
|
-
gapi.load('auth2', {
|
|
429
|
-
callback: () => initGapiClient(callbackFn, onUserLogin),
|
|
430
|
-
onerror: onAuthError,
|
|
431
|
-
ontimeout: onAuthError,
|
|
432
|
-
timeout: 5000
|
|
433
|
-
});
|
|
434
|
-
};
|
|
435
|
-
const authAlert = (error) => {
|
|
436
|
-
alert('Google authentication is not working at this moment.\n\nPlease try again later or use a magic sign-in link.\n\nError: ' + JSON.stringify(error));
|
|
437
|
-
location.reload();
|
|
438
|
-
};
|
|
439
|
-
const onSignInError = (error) => {
|
|
440
|
-
disableSignInLayout();
|
|
441
|
-
console.error(error);
|
|
442
|
-
// logError(error); TODO
|
|
443
|
-
if (error && error.error === 'popup_closed_by_user') {
|
|
444
|
-
onUserChanged(null, () => { });
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
authAlert(error);
|
|
448
|
-
};
|
|
449
|
-
const getAuth = () => {
|
|
450
|
-
if (typeof gapi === 'undefined') {
|
|
451
|
-
console.error('gapi is undefined');
|
|
452
|
-
// logError('gapi is undefined'); TODO
|
|
453
|
-
return null;
|
|
454
|
-
}
|
|
455
|
-
return gapi.auth2 && gapi.auth2.getAuthInstance();
|
|
456
|
-
};
|
|
457
|
-
const googleSignIn = () => getAuth().signIn().catch(onSignInError);
|
|
458
|
-
const authSignIn = (onUserLogin) => {
|
|
459
|
-
if (authError) {
|
|
460
|
-
authAlert(authError);
|
|
461
|
-
return;
|
|
462
|
-
}
|
|
463
|
-
if (authStatus === 'LOADING') {
|
|
464
|
-
setTimeout(authSignIn, 400);
|
|
465
|
-
}
|
|
466
|
-
else {
|
|
467
|
-
try {
|
|
468
|
-
googleSignIn();
|
|
469
|
-
}
|
|
470
|
-
catch (err) {
|
|
471
|
-
try {
|
|
472
|
-
initGapi(() => googleSignIn(), onUserLogin);
|
|
473
|
-
}
|
|
474
|
-
catch (error) {
|
|
475
|
-
onSignInError(error);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
}
|
|
404
|
+
// TODO: find a better way to import external scripts
|
|
405
|
+
const script$1 = document.createElement('script');
|
|
406
|
+
script$1.type = 'text/javascript';
|
|
407
|
+
script$1.src = 'https://apis.google.com/js/api.js';
|
|
408
|
+
document.head.appendChild(script$1);
|
|
409
|
+
let authStatus;
|
|
410
|
+
let authError;
|
|
411
|
+
const highLevelUser = (gUser) => {
|
|
412
|
+
const profile = gUser.getBasicProfile();
|
|
413
|
+
return {
|
|
414
|
+
name: profile.getName(),
|
|
415
|
+
email: profile.getEmail(),
|
|
416
|
+
picture: profile.getImageUrl(),
|
|
417
|
+
googletoken: gUser.getAuthResponse().id_token
|
|
418
|
+
};
|
|
419
|
+
};
|
|
420
|
+
const onUserChanged = (googleUser, onUserLogin) => {
|
|
421
|
+
document.documentElement.classList.remove('progress');
|
|
422
|
+
document.body.classList.remove('disabled');
|
|
423
|
+
if (googleUser) {
|
|
424
|
+
// mixpanelIdentify(googleUser); TODO
|
|
425
|
+
const onSuccess = (res) => {
|
|
426
|
+
const { token } = res;
|
|
427
|
+
// @ts-ignore
|
|
428
|
+
window.store.currentUser = res;
|
|
429
|
+
onTokenAcquired(token, onUserLogin);
|
|
430
|
+
};
|
|
431
|
+
const onError = (err) => {
|
|
432
|
+
console.error(err);
|
|
433
|
+
// logError(error); TODO
|
|
434
|
+
// checkMixpanel(() => mixpanel.track('Login Error', { 'Login Type': 'Google', 'Error': error })); TODO
|
|
435
|
+
};
|
|
436
|
+
googleLogin(googleUser.googletoken, onSuccess, onError);
|
|
437
|
+
// checkMixpanel(() => mixpanel.track('Login', { 'Login Type': 'Google' })); TODO
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
setBackendToken('');
|
|
441
|
+
// checkMixpanel(() => mixpanel.reset()); TODO
|
|
442
|
+
// displayPage(Page.LOGIN); TODO
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
const onGoogleUserChanged = (gUser, onUserLogin) => {
|
|
446
|
+
onUserChanged(gUser.isSignedIn() ? highLevelUser(gUser) : null, onUserLogin);
|
|
447
|
+
};
|
|
448
|
+
const initGapiClient = (callbackFn, onUserLogin) => {
|
|
449
|
+
// @ts-ignore
|
|
450
|
+
const clientId = process.env.GOOGLE_CLIENT_ID;
|
|
451
|
+
gapi.auth2.init({ client_id: clientId, prompt: 'select_account' }).then(() => {
|
|
452
|
+
authStatus = 'LOADED';
|
|
453
|
+
const currentUser = getAuth().currentUser;
|
|
454
|
+
currentUser.listen(onGoogleUserChanged);
|
|
455
|
+
callbackFn ? callbackFn(clientId) : onGoogleUserChanged(currentUser.get(), onUserLogin);
|
|
456
|
+
}, onAuthError);
|
|
457
|
+
};
|
|
458
|
+
const onAuthError = (error) => {
|
|
459
|
+
authError = error;
|
|
460
|
+
console.error(error);
|
|
461
|
+
// logError(error, authError); // TODO
|
|
462
|
+
};
|
|
463
|
+
const initGapi = (callbackFn = null, onUserLogin) => {
|
|
464
|
+
if (!window.location.protocol.startsWith('http')) {
|
|
465
|
+
onAuthError('To use Google Auth you must access this page using http(s), not ' + window.location.protocol);
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (typeof gapi === 'undefined') {
|
|
469
|
+
onAuthError('Unable to load the Google API');
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
authStatus = 'LOADING';
|
|
473
|
+
gapi.load('auth2', {
|
|
474
|
+
callback: () => initGapiClient(callbackFn, onUserLogin),
|
|
475
|
+
onerror: onAuthError,
|
|
476
|
+
ontimeout: onAuthError,
|
|
477
|
+
timeout: 5000
|
|
478
|
+
});
|
|
479
|
+
};
|
|
480
|
+
const authAlert = (error) => {
|
|
481
|
+
alert('Google authentication is not working at this moment.\n\nPlease try again later or use a magic sign-in link.\n\nError: ' + JSON.stringify(error));
|
|
482
|
+
location.reload();
|
|
483
|
+
};
|
|
484
|
+
const onSignInError = (error) => {
|
|
485
|
+
disableSignInLayout();
|
|
486
|
+
console.error(error);
|
|
487
|
+
// logError(error); TODO
|
|
488
|
+
if (error && error.error === 'popup_closed_by_user') {
|
|
489
|
+
onUserChanged(null, () => { });
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
authAlert(error);
|
|
493
|
+
};
|
|
494
|
+
const getAuth = () => {
|
|
495
|
+
if (typeof gapi === 'undefined') {
|
|
496
|
+
console.error('gapi is undefined');
|
|
497
|
+
// logError('gapi is undefined'); TODO
|
|
498
|
+
return null;
|
|
499
|
+
}
|
|
500
|
+
return gapi.auth2 && gapi.auth2.getAuthInstance();
|
|
501
|
+
};
|
|
502
|
+
const googleSignIn = () => getAuth().signIn().catch(onSignInError);
|
|
503
|
+
const authSignIn = (onUserLogin) => {
|
|
504
|
+
if (authError) {
|
|
505
|
+
authAlert(authError);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
if (authStatus === 'LOADING') {
|
|
509
|
+
setTimeout(authSignIn, 400);
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
try {
|
|
513
|
+
googleSignIn();
|
|
514
|
+
}
|
|
515
|
+
catch (err) {
|
|
516
|
+
try {
|
|
517
|
+
initGapi(() => googleSignIn(), onUserLogin);
|
|
518
|
+
}
|
|
519
|
+
catch (error) {
|
|
520
|
+
onSignInError(error);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
479
524
|
};
|
|
480
525
|
|
|
481
|
-
// TODO: find a better way to import external scripts
|
|
482
|
-
const script = document.createElement('script');
|
|
483
|
-
script.type = 'text/javascript';
|
|
484
|
-
script.src = 'https://www.google.com/recaptcha/api.js';
|
|
485
|
-
document.head.appendChild(script);
|
|
486
|
-
const googleCaptcha = () => {
|
|
487
|
-
const result = document.createElement('google-captcha');
|
|
488
|
-
window.submitCaptcha = (token) => result.setAttribute('token', token);
|
|
489
|
-
result.className = 'g-recaptcha';
|
|
490
|
-
// @ts-ignore
|
|
491
|
-
result.setAttribute('data-sitekey', process.env.GOOGLE_CAPTCHA_KEY);
|
|
492
|
-
result.setAttribute('data-callback', 'submitCaptcha');
|
|
493
|
-
grecaptcha.render(result);
|
|
494
|
-
return result;
|
|
526
|
+
// TODO: find a better way to import external scripts
|
|
527
|
+
const script = document.createElement('script');
|
|
528
|
+
script.type = 'text/javascript';
|
|
529
|
+
script.src = 'https://www.google.com/recaptcha/api.js';
|
|
530
|
+
document.head.appendChild(script);
|
|
531
|
+
const googleCaptcha = () => {
|
|
532
|
+
const result = document.createElement('google-captcha');
|
|
533
|
+
window.submitCaptcha = (token) => result.setAttribute('token', token);
|
|
534
|
+
result.className = 'g-recaptcha';
|
|
535
|
+
// @ts-ignore
|
|
536
|
+
result.setAttribute('data-sitekey', process.env.GOOGLE_CAPTCHA_KEY);
|
|
537
|
+
result.setAttribute('data-callback', 'submitCaptcha');
|
|
538
|
+
grecaptcha.render(result);
|
|
539
|
+
return result;
|
|
495
540
|
};
|
|
496
541
|
|
|
497
|
-
const juxWhite = '#FFF';
|
|
498
|
-
const juxDarkGrey = '#282828';
|
|
499
|
-
const juxDimmedDarkGrey = '#28282822';
|
|
500
|
-
const juxDimmedBlack = '#00000088';
|
|
501
|
-
const juxLightGreen = '#20B03D';
|
|
542
|
+
const juxWhite = '#FFF';
|
|
543
|
+
const juxDarkGrey = '#282828';
|
|
544
|
+
const juxDimmedDarkGrey = '#28282822';
|
|
545
|
+
const juxDimmedBlack = '#00000088';
|
|
546
|
+
const juxLightGreen = '#20B03D';
|
|
502
547
|
const juxMediumGreen = '#0D631E';
|
|
503
548
|
|
|
504
|
-
const onKeyDown = (ev, el, persitent, onClose) => {
|
|
505
|
-
if (ev.key === 'Escape') {
|
|
506
|
-
if (persitent) {
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
close(el, onClose);
|
|
510
|
-
}
|
|
511
|
-
else if (ev.key === 'Enter') {
|
|
512
|
-
if (ev.target.id === 'members-textarea') {
|
|
513
|
-
return;
|
|
514
|
-
}
|
|
515
|
-
el.dispatchEvent(new CustomEvent('ok'));
|
|
516
|
-
}
|
|
517
|
-
};
|
|
518
|
-
const close = (el, onClose) => {
|
|
519
|
-
el.remove();
|
|
520
|
-
if (onClose) {
|
|
521
|
-
onClose();
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
|
-
const attachEventHandlers = (el, persitent, onClose) => {
|
|
525
|
-
const cancelButton = el.querySelector('.cancel');
|
|
526
|
-
cancelButton === null || cancelButton === void 0 ? void 0 : cancelButton.addEventListener('click', (_e) => {
|
|
527
|
-
el.dispatchEvent(new CustomEvent('cancel'));
|
|
528
|
-
if (el.hasAttribute('dont-remove')) {
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
close(el, onClose);
|
|
532
|
-
});
|
|
533
|
-
const closeButton = el.querySelector('.close');
|
|
534
|
-
if (closeButton) {
|
|
535
|
-
closeButton.addEventListener('click', (_e) => {
|
|
536
|
-
close(el, onClose);
|
|
537
|
-
});
|
|
538
|
-
}
|
|
539
|
-
const okButton = el.querySelector('.ok');
|
|
540
|
-
okButton === null || okButton === void 0 ? void 0 : okButton.addEventListener('click', (_e) => {
|
|
541
|
-
el.dispatchEvent(new CustomEvent('ok'));
|
|
542
|
-
});
|
|
543
|
-
el.removeEventListener('keydown', (ev) => onKeyDown(ev, el, persitent, () => onClose));
|
|
544
|
-
el.addEventListener('keydown', (ev) => onKeyDown(ev, el, persitent, () => onClose));
|
|
545
|
-
el === null || el === void 0 ? void 0 : el.addEventListener('click', (e) => {
|
|
546
|
-
if (e.target === el) {
|
|
547
|
-
if (persitent) {
|
|
548
|
-
return;
|
|
549
|
-
}
|
|
550
|
-
close(el, onClose);
|
|
551
|
-
}
|
|
552
|
-
});
|
|
553
|
-
};
|
|
554
|
-
// TODO: Mudar construtor para usar essa interface
|
|
555
|
-
// interface JuxModalOptions {
|
|
556
|
-
// title?: string,
|
|
557
|
-
// btns?: string[],
|
|
558
|
-
// content?: string,
|
|
559
|
-
// isPersistent?: boolean,
|
|
560
|
-
// isBusy?: boolean,
|
|
561
|
-
// body?: HTMLElement,
|
|
562
|
-
// okTxt?: string,
|
|
563
|
-
// cancelTxt?: string,
|
|
564
|
-
// onClose?: any,
|
|
565
|
-
// titleStyle?: string,
|
|
566
|
-
// }
|
|
567
|
-
const applyWrapperStyle = (wrapper) => {
|
|
568
|
-
wrapper.style.alignItems = 'center';
|
|
569
|
-
wrapper.style.backgroundColor = juxWhite;
|
|
570
|
-
wrapper.style.borderRadius = '.3125rem';
|
|
571
|
-
wrapper.style.boxShadow = `0 0 1.33rem ${juxDimmedBlack}`;
|
|
572
|
-
wrapper.style.boxSizing = 'content-box';
|
|
573
|
-
wrapper.style.display = 'flex';
|
|
574
|
-
wrapper.style.flexDirection = 'column';
|
|
575
|
-
wrapper.style.justifyContent = 'flex-start';
|
|
576
|
-
wrapper.style.margin = '0';
|
|
577
|
-
wrapper.style.maxHeight = '88%';
|
|
578
|
-
wrapper.style.maxWidth = '40%';
|
|
579
|
-
wrapper.style.minWidth = '20%';
|
|
580
|
-
wrapper.style.padding = '1.33rem';
|
|
581
|
-
wrapper.style.position = 'relative';
|
|
582
|
-
};
|
|
583
|
-
const applyModalStyle = (modal) => {
|
|
584
|
-
modal.style.alignItems = 'center';
|
|
585
|
-
modal.style.backgroundColor = juxDimmedBlack;
|
|
586
|
-
modal.style.display = 'flex';
|
|
587
|
-
modal.style.height = '100vh';
|
|
588
|
-
modal.style.justifyContent = 'center';
|
|
589
|
-
modal.style.left = '0';
|
|
590
|
-
modal.style.overflow = 'hidden';
|
|
591
|
-
modal.style.position = 'fixed';
|
|
592
|
-
modal.style.top = '0';
|
|
593
|
-
modal.style.width = '100%';
|
|
594
|
-
modal.style.zIndex = '9999';
|
|
595
|
-
};
|
|
596
|
-
const applyHeaderStyle = (header) => {
|
|
597
|
-
header.style.alignItems = 'center';
|
|
598
|
-
header.style.color = juxMediumGreen;
|
|
599
|
-
header.style.flexDirection = 'row';
|
|
600
|
-
header.style.fontSize = '16px';
|
|
601
|
-
header.style.fontWeight = '700';
|
|
602
|
-
header.style.justifyContent = 'space-between';
|
|
603
|
-
header.style.margin = '0';
|
|
604
|
-
header.style.display = 'flex';
|
|
605
|
-
header.style.position = 'relative';
|
|
606
|
-
header.style.width = '100%';
|
|
607
|
-
};
|
|
608
|
-
const applyJuxModalContentStyle = (el) => {
|
|
609
|
-
el.style.display = 'flex';
|
|
610
|
-
el.style.position = 'relative';
|
|
611
|
-
el.style.width = '100%';
|
|
612
|
-
el.style.flexFlow = 'column';
|
|
613
|
-
el.style.marginTop = '1.33rem';
|
|
614
|
-
el.style.rowGap = '8px';
|
|
615
|
-
};
|
|
616
|
-
const juxModal = (title, btns = ['ok', 'cancel'], content = '', persistent = false, _busy = false, body, okTxt = getTranslation('alert-ok-btn-txt'), cancelTxt = getTranslation('alert-cancel-btn-txt'), onClose, titleStyle) => {
|
|
617
|
-
const result = document.createElement('jux-modal');
|
|
618
|
-
applyModalStyle(result);
|
|
619
|
-
const wrapper = document.createElement('modal-wrapper');
|
|
620
|
-
applyWrapperStyle(wrapper);
|
|
621
|
-
// START close
|
|
622
|
-
const closeBtn = document.createElement('button');
|
|
623
|
-
if (!persistent) {
|
|
624
|
-
closeBtn.className = 'close';
|
|
625
|
-
closeBtn.setAttribute('aria-label', getTranslation('close'));
|
|
626
|
-
}
|
|
627
|
-
// END close
|
|
628
|
-
// START header
|
|
629
|
-
const header = document.createElement('modal-header');
|
|
630
|
-
applyHeaderStyle(header);
|
|
631
|
-
if (title) {
|
|
632
|
-
if (titleStyle) {
|
|
633
|
-
header.classList.add(titleStyle);
|
|
634
|
-
}
|
|
635
|
-
const h3 = document.createElement('h3');
|
|
636
|
-
h3.textContent = title;
|
|
637
|
-
header.appendChild(h3);
|
|
638
|
-
}
|
|
639
|
-
// END header
|
|
640
|
-
// START content
|
|
641
|
-
const modalContent = document.createElement('jux-modal-content');
|
|
642
|
-
applyJuxModalContentStyle(modalContent);
|
|
643
|
-
if (content) {
|
|
644
|
-
modalContent.innerHTML = content;
|
|
645
|
-
}
|
|
646
|
-
else if (body) {
|
|
647
|
-
modalContent.appendChild(body);
|
|
648
|
-
}
|
|
649
|
-
// END content
|
|
650
|
-
// START footer
|
|
651
|
-
const footer = document.createElement('modal-footer');
|
|
652
|
-
if (btns.includes('cancel')) {
|
|
653
|
-
const cancelBtn = document.createElement('button');
|
|
654
|
-
cancelBtn.classList.add('secondary-button', 'modal-button', 'action', 'cancel-btn', 'cancel');
|
|
655
|
-
const cancelText = document.createElement('button-text');
|
|
656
|
-
cancelText.textContent = cancelTxt;
|
|
657
|
-
const cancelSpinner = document.createElement('loading-spinner');
|
|
658
|
-
cancelBtn.append(cancelText, cancelSpinner);
|
|
659
|
-
footer.appendChild(cancelBtn);
|
|
660
|
-
}
|
|
661
|
-
if (btns.includes('ok')) {
|
|
662
|
-
const okBtn = document.createElement('button');
|
|
663
|
-
okBtn.classList.add('primary-button', 'modal-button', 'action', 'ok');
|
|
664
|
-
const okText = document.createElement('button-text');
|
|
665
|
-
okText.textContent = okTxt;
|
|
666
|
-
const okSpinner = document.createElement('loading-spinner');
|
|
667
|
-
okBtn.append(okText, okSpinner);
|
|
668
|
-
footer.appendChild(okBtn);
|
|
669
|
-
}
|
|
670
|
-
// END footer
|
|
671
|
-
if (footer.hasChildNodes()) {
|
|
672
|
-
wrapper.append(closeBtn, header, modalContent, footer);
|
|
673
|
-
}
|
|
674
|
-
else {
|
|
675
|
-
wrapper.append(closeBtn, header, modalContent);
|
|
676
|
-
}
|
|
677
|
-
result.appendChild(wrapper);
|
|
678
|
-
if (!persistent) {
|
|
679
|
-
result.querySelector('.close').focus();
|
|
680
|
-
}
|
|
681
|
-
else {
|
|
682
|
-
if (btns.includes('ok')) {
|
|
683
|
-
result.querySelector('.ok').focus();
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
attachEventHandlers(result, persistent, onClose);
|
|
687
|
-
return result;
|
|
549
|
+
const onKeyDown = (ev, el, persitent, onClose) => {
|
|
550
|
+
if (ev.key === 'Escape') {
|
|
551
|
+
if (persitent) {
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
close(el, onClose);
|
|
555
|
+
}
|
|
556
|
+
else if (ev.key === 'Enter') {
|
|
557
|
+
if (ev.target.id === 'members-textarea') {
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
el.dispatchEvent(new CustomEvent('ok'));
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
const close = (el, onClose) => {
|
|
564
|
+
el.remove();
|
|
565
|
+
if (onClose) {
|
|
566
|
+
onClose();
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
const attachEventHandlers = (el, persitent, onClose) => {
|
|
570
|
+
const cancelButton = el.querySelector('.cancel');
|
|
571
|
+
cancelButton === null || cancelButton === void 0 ? void 0 : cancelButton.addEventListener('click', (_e) => {
|
|
572
|
+
el.dispatchEvent(new CustomEvent('cancel'));
|
|
573
|
+
if (el.hasAttribute('dont-remove')) {
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
close(el, onClose);
|
|
577
|
+
});
|
|
578
|
+
const closeButton = el.querySelector('.close');
|
|
579
|
+
if (closeButton) {
|
|
580
|
+
closeButton.addEventListener('click', (_e) => {
|
|
581
|
+
close(el, onClose);
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
const okButton = el.querySelector('.ok');
|
|
585
|
+
okButton === null || okButton === void 0 ? void 0 : okButton.addEventListener('click', (_e) => {
|
|
586
|
+
el.dispatchEvent(new CustomEvent('ok'));
|
|
587
|
+
});
|
|
588
|
+
el.removeEventListener('keydown', (ev) => onKeyDown(ev, el, persitent, () => onClose));
|
|
589
|
+
el.addEventListener('keydown', (ev) => onKeyDown(ev, el, persitent, () => onClose));
|
|
590
|
+
el === null || el === void 0 ? void 0 : el.addEventListener('click', (e) => {
|
|
591
|
+
if (e.target === el) {
|
|
592
|
+
if (persitent) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
close(el, onClose);
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
};
|
|
599
|
+
// TODO: Mudar construtor para usar essa interface
|
|
600
|
+
// interface JuxModalOptions {
|
|
601
|
+
// title?: string,
|
|
602
|
+
// btns?: string[],
|
|
603
|
+
// content?: string,
|
|
604
|
+
// isPersistent?: boolean,
|
|
605
|
+
// isBusy?: boolean,
|
|
606
|
+
// body?: HTMLElement,
|
|
607
|
+
// okTxt?: string,
|
|
608
|
+
// cancelTxt?: string,
|
|
609
|
+
// onClose?: any,
|
|
610
|
+
// titleStyle?: string,
|
|
611
|
+
// }
|
|
612
|
+
const applyWrapperStyle = (wrapper) => {
|
|
613
|
+
wrapper.style.alignItems = 'center';
|
|
614
|
+
wrapper.style.backgroundColor = juxWhite;
|
|
615
|
+
wrapper.style.borderRadius = '.3125rem';
|
|
616
|
+
wrapper.style.boxShadow = `0 0 1.33rem ${juxDimmedBlack}`;
|
|
617
|
+
wrapper.style.boxSizing = 'content-box';
|
|
618
|
+
wrapper.style.display = 'flex';
|
|
619
|
+
wrapper.style.flexDirection = 'column';
|
|
620
|
+
wrapper.style.justifyContent = 'flex-start';
|
|
621
|
+
wrapper.style.margin = '0';
|
|
622
|
+
wrapper.style.maxHeight = '88%';
|
|
623
|
+
wrapper.style.maxWidth = '40%';
|
|
624
|
+
wrapper.style.minWidth = '20%';
|
|
625
|
+
wrapper.style.padding = '1.33rem';
|
|
626
|
+
wrapper.style.position = 'relative';
|
|
627
|
+
};
|
|
628
|
+
const applyModalStyle = (modal) => {
|
|
629
|
+
modal.style.alignItems = 'center';
|
|
630
|
+
modal.style.backgroundColor = juxDimmedBlack;
|
|
631
|
+
modal.style.display = 'flex';
|
|
632
|
+
modal.style.height = '100vh';
|
|
633
|
+
modal.style.justifyContent = 'center';
|
|
634
|
+
modal.style.left = '0';
|
|
635
|
+
modal.style.overflow = 'hidden';
|
|
636
|
+
modal.style.position = 'fixed';
|
|
637
|
+
modal.style.top = '0';
|
|
638
|
+
modal.style.width = '100%';
|
|
639
|
+
modal.style.zIndex = '9999';
|
|
640
|
+
};
|
|
641
|
+
const applyHeaderStyle = (header) => {
|
|
642
|
+
header.style.alignItems = 'center';
|
|
643
|
+
header.style.color = juxMediumGreen;
|
|
644
|
+
header.style.flexDirection = 'row';
|
|
645
|
+
header.style.fontSize = '16px';
|
|
646
|
+
header.style.fontWeight = '700';
|
|
647
|
+
header.style.justifyContent = 'space-between';
|
|
648
|
+
header.style.margin = '0';
|
|
649
|
+
header.style.display = 'flex';
|
|
650
|
+
header.style.position = 'relative';
|
|
651
|
+
header.style.width = '100%';
|
|
652
|
+
};
|
|
653
|
+
const applyJuxModalContentStyle = (el) => {
|
|
654
|
+
el.style.display = 'flex';
|
|
655
|
+
el.style.position = 'relative';
|
|
656
|
+
el.style.width = '100%';
|
|
657
|
+
el.style.flexFlow = 'column';
|
|
658
|
+
el.style.marginTop = '1.33rem';
|
|
659
|
+
el.style.rowGap = '8px';
|
|
660
|
+
};
|
|
661
|
+
const juxModal = (title, btns = ['ok', 'cancel'], content = '', persistent = false, _busy = false, body, okTxt = getTranslation('alert-ok-btn-txt'), cancelTxt = getTranslation('alert-cancel-btn-txt'), onClose, titleStyle) => {
|
|
662
|
+
const result = document.createElement('jux-modal');
|
|
663
|
+
applyModalStyle(result);
|
|
664
|
+
const wrapper = document.createElement('modal-wrapper');
|
|
665
|
+
applyWrapperStyle(wrapper);
|
|
666
|
+
// START close
|
|
667
|
+
const closeBtn = document.createElement('button');
|
|
668
|
+
if (!persistent) {
|
|
669
|
+
closeBtn.className = 'close';
|
|
670
|
+
closeBtn.setAttribute('aria-label', getTranslation('close'));
|
|
671
|
+
}
|
|
672
|
+
// END close
|
|
673
|
+
// START header
|
|
674
|
+
const header = document.createElement('modal-header');
|
|
675
|
+
applyHeaderStyle(header);
|
|
676
|
+
if (title) {
|
|
677
|
+
if (titleStyle) {
|
|
678
|
+
header.classList.add(titleStyle);
|
|
679
|
+
}
|
|
680
|
+
const h3 = document.createElement('h3');
|
|
681
|
+
h3.textContent = title;
|
|
682
|
+
header.appendChild(h3);
|
|
683
|
+
}
|
|
684
|
+
// END header
|
|
685
|
+
// START content
|
|
686
|
+
const modalContent = document.createElement('jux-modal-content');
|
|
687
|
+
applyJuxModalContentStyle(modalContent);
|
|
688
|
+
if (content) {
|
|
689
|
+
modalContent.innerHTML = content;
|
|
690
|
+
}
|
|
691
|
+
else if (body) {
|
|
692
|
+
modalContent.appendChild(body);
|
|
693
|
+
}
|
|
694
|
+
// END content
|
|
695
|
+
// START footer
|
|
696
|
+
const footer = document.createElement('modal-footer');
|
|
697
|
+
if (btns.includes('cancel')) {
|
|
698
|
+
const cancelBtn = document.createElement('button');
|
|
699
|
+
cancelBtn.classList.add('secondary-button', 'modal-button', 'action', 'cancel-btn', 'cancel');
|
|
700
|
+
const cancelText = document.createElement('button-text');
|
|
701
|
+
cancelText.textContent = cancelTxt;
|
|
702
|
+
const cancelSpinner = document.createElement('loading-spinner');
|
|
703
|
+
cancelBtn.append(cancelText, cancelSpinner);
|
|
704
|
+
footer.appendChild(cancelBtn);
|
|
705
|
+
}
|
|
706
|
+
if (btns.includes('ok')) {
|
|
707
|
+
const okBtn = document.createElement('button');
|
|
708
|
+
okBtn.classList.add('primary-button', 'modal-button', 'action', 'ok');
|
|
709
|
+
const okText = document.createElement('button-text');
|
|
710
|
+
okText.textContent = okTxt;
|
|
711
|
+
const okSpinner = document.createElement('loading-spinner');
|
|
712
|
+
okBtn.append(okText, okSpinner);
|
|
713
|
+
footer.appendChild(okBtn);
|
|
714
|
+
}
|
|
715
|
+
// END footer
|
|
716
|
+
if (footer.hasChildNodes()) {
|
|
717
|
+
wrapper.append(closeBtn, header, modalContent, footer);
|
|
718
|
+
}
|
|
719
|
+
else {
|
|
720
|
+
wrapper.append(closeBtn, header, modalContent);
|
|
721
|
+
}
|
|
722
|
+
result.appendChild(wrapper);
|
|
723
|
+
if (!persistent) {
|
|
724
|
+
result.querySelector('.close').focus();
|
|
725
|
+
}
|
|
726
|
+
else {
|
|
727
|
+
if (btns.includes('ok')) {
|
|
728
|
+
result.querySelector('.ok').focus();
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
attachEventHandlers(result, persistent, onClose);
|
|
732
|
+
return result;
|
|
688
733
|
};
|
|
689
734
|
|
|
690
|
-
const contactField = (tag = 'input', elType, elName, required = true, value) => {
|
|
691
|
-
const result = document.createElement('contact-field');
|
|
692
|
-
const elId = 'contact-' + elName;
|
|
693
|
-
const label = document.createElement('label');
|
|
694
|
-
label.textContent = getTranslation(elId + '-label');
|
|
695
|
-
label.htmlFor = elId;
|
|
696
|
-
const el = document.createElement(tag);
|
|
697
|
-
el.id = elId;
|
|
698
|
-
el.setAttribute('name', elName);
|
|
699
|
-
el.setAttribute('placeholder', getTranslation(elId + '-placeholder'));
|
|
700
|
-
if (tag === 'input') {
|
|
701
|
-
el.setAttribute('type', elType);
|
|
702
|
-
}
|
|
703
|
-
if (required) {
|
|
704
|
-
el.setAttribute('required', 'true');
|
|
705
|
-
}
|
|
706
|
-
if (value) {
|
|
707
|
-
el.setAttribute('value', value);
|
|
708
|
-
}
|
|
709
|
-
result.append(label, el);
|
|
710
|
-
return result;
|
|
735
|
+
const contactField = (tag = 'input', elType, elName, required = true, value) => {
|
|
736
|
+
const result = document.createElement('contact-field');
|
|
737
|
+
const elId = 'contact-' + elName;
|
|
738
|
+
const label = document.createElement('label');
|
|
739
|
+
label.textContent = getTranslation(elId + '-label');
|
|
740
|
+
label.htmlFor = elId;
|
|
741
|
+
const el = document.createElement(tag);
|
|
742
|
+
el.id = elId;
|
|
743
|
+
el.setAttribute('name', elName);
|
|
744
|
+
el.setAttribute('placeholder', getTranslation(elId + '-placeholder'));
|
|
745
|
+
if (tag === 'input') {
|
|
746
|
+
el.setAttribute('type', elType);
|
|
747
|
+
}
|
|
748
|
+
if (required) {
|
|
749
|
+
el.setAttribute('required', 'true');
|
|
750
|
+
}
|
|
751
|
+
if (value) {
|
|
752
|
+
el.setAttribute('value', value);
|
|
753
|
+
}
|
|
754
|
+
result.append(label, el);
|
|
755
|
+
return result;
|
|
711
756
|
};
|
|
712
757
|
|
|
713
|
-
const getNestedElValue = (el, nestedTag) => {
|
|
714
|
-
const nestedEl = el.querySelector(nestedTag);
|
|
715
|
-
return nestedEl.value;
|
|
716
|
-
};
|
|
717
|
-
const sendInquiry = (name, email, msg, whatsapp, subject, token) => {
|
|
718
|
-
const inquiryPayload = {
|
|
719
|
-
subject: `[${subject.charAt(0).toUpperCase()}${subject.slice(1)}] ${getNestedElValue(name, 'input')}`,
|
|
758
|
+
const getNestedElValue = (el, nestedTag) => {
|
|
759
|
+
const nestedEl = el.querySelector(nestedTag);
|
|
760
|
+
return nestedEl.value;
|
|
761
|
+
};
|
|
762
|
+
const sendInquiry = (name, email, msg, whatsapp, subject, token) => {
|
|
763
|
+
const inquiryPayload = {
|
|
764
|
+
subject: `[${subject.charAt(0).toUpperCase()}${subject.slice(1)}] ${getNestedElValue(name, 'input')}`,
|
|
720
765
|
body: `<strong>Name</strong>: ${getNestedElValue(name, 'input')}<br><br>
|
|
721
766
|
<strong>E-mail</strong>: ${getNestedElValue(email, 'input')}<br><br>
|
|
722
767
|
<strong>Whatsapp</strong>: ${getNestedElValue(whatsapp, 'input')}<br><br>
|
|
723
|
-
<strong>Message</strong>: ${getNestedElValue(msg, 'textarea')}`,
|
|
724
|
-
token,
|
|
725
|
-
};
|
|
726
|
-
backendPost('contact-us', inquiryPayload, (_res) => {
|
|
727
|
-
var _a;
|
|
728
|
-
// success(getTranslation('form-success'), Length.long);
|
|
729
|
-
(_a = document.querySelector('#contact-us-modal')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
730
|
-
}, () => { } // TODO: change it to be an error handling fn provided by the client
|
|
731
|
-
);
|
|
732
|
-
// checkMixpanel(() => mixpanel.track('Sent Contact Inquiry', {}));
|
|
733
|
-
};
|
|
734
|
-
const contactUsModal = (subject) => {
|
|
735
|
-
var _a, _b, _c, _d, _e;
|
|
736
|
-
const result = document.createElement('contact-us-modal');
|
|
737
|
-
// @ts-ignore
|
|
738
|
-
const currentName = window.store.currentUser ? window.store.currentUser.name : '';
|
|
739
|
-
// @ts-ignore
|
|
740
|
-
const currentEmail = window.store.currentUser ? window.store.currentUser.email : (_a = document.querySelector('#magic-link-email')) === null || _a === void 0 ? void 0 : _a.textContent;
|
|
741
|
-
const modalBody = document.createElement('modal-body');
|
|
742
|
-
const form = document.createElement('form');
|
|
743
|
-
form.id = 'contact-form';
|
|
744
|
-
const nameField = contactField('input', 'text', 'name', true, currentName);
|
|
745
|
-
const emailField = contactField('input', 'email', 'email', true, currentEmail);
|
|
746
|
-
const messageField = contactField('textarea', 'text', 'message', true);
|
|
747
|
-
const whatsappField = contactField('input', 'tel', 'whatsapp', false);
|
|
748
|
-
const btn = document.createElement('button');
|
|
749
|
-
btn.textContent = getTranslation('contact-submit');
|
|
750
|
-
btn.className = 'primary-button';
|
|
751
|
-
form.append(nameField, emailField, whatsappField, messageField, btn);
|
|
752
|
-
modalBody.appendChild(form);
|
|
753
|
-
const modal = juxModal(getTranslation('contact-page'), [], '', false, false, modalBody, '', '', () => result.remove());
|
|
754
|
-
modal.id = 'contact-us-modal';
|
|
755
|
-
document.body.appendChild(modal);
|
|
756
|
-
(_b = modal.querySelector('modal-wrapper')) === null || _b === void 0 ? void 0 : _b.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
|
|
757
|
-
const captcha = googleCaptcha();
|
|
758
|
-
if (subject !== 'email-not-sent') {
|
|
759
|
-
// @ts-ignore
|
|
760
|
-
const admin = ((_d = (_c = window.store) === null || _c === void 0 ? void 0 : _c.selectedTeam) === null || _d === void 0 ? void 0 : _d.admin) || window.store.currentUser.email;
|
|
761
|
-
backendGet('credits-balance-for', { admin }, (res) => {
|
|
762
|
-
const balance = res;
|
|
763
|
-
if (balance <= 0) {
|
|
764
|
-
form.insertBefore(captcha, btn);
|
|
765
|
-
}
|
|
766
|
-
}, () => { } // TODO: change it to be an error handling fn provided by the client
|
|
767
|
-
);
|
|
768
|
-
}
|
|
769
|
-
else {
|
|
770
|
-
form.insertBefore(captcha, btn);
|
|
771
|
-
}
|
|
772
|
-
(_e = nameField.querySelector('input')) === null || _e === void 0 ? void 0 : _e.select();
|
|
773
|
-
form.addEventListener('submit', (event) => {
|
|
774
|
-
event.preventDefault();
|
|
775
|
-
sendInquiry(nameField, emailField, messageField, whatsappField, subject, captcha.getAttribute('token'));
|
|
776
|
-
});
|
|
777
|
-
return result;
|
|
768
|
+
<strong>Message</strong>: ${getNestedElValue(msg, 'textarea')}`,
|
|
769
|
+
token,
|
|
770
|
+
};
|
|
771
|
+
backendPost('contact-us', inquiryPayload, (_res) => {
|
|
772
|
+
var _a;
|
|
773
|
+
// success(getTranslation('form-success'), Length.long);
|
|
774
|
+
(_a = document.querySelector('#contact-us-modal')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
775
|
+
}, () => { } // TODO: change it to be an error handling fn provided by the client
|
|
776
|
+
);
|
|
777
|
+
// checkMixpanel(() => mixpanel.track('Sent Contact Inquiry', {}));
|
|
778
|
+
};
|
|
779
|
+
const contactUsModal = (subject) => {
|
|
780
|
+
var _a, _b, _c, _d, _e;
|
|
781
|
+
const result = document.createElement('contact-us-modal');
|
|
782
|
+
// @ts-ignore
|
|
783
|
+
const currentName = window.store.currentUser ? window.store.currentUser.name : '';
|
|
784
|
+
// @ts-ignore
|
|
785
|
+
const currentEmail = window.store.currentUser ? window.store.currentUser.email : (_a = document.querySelector('#magic-link-email')) === null || _a === void 0 ? void 0 : _a.textContent;
|
|
786
|
+
const modalBody = document.createElement('modal-body');
|
|
787
|
+
const form = document.createElement('form');
|
|
788
|
+
form.id = 'contact-form';
|
|
789
|
+
const nameField = contactField('input', 'text', 'name', true, currentName);
|
|
790
|
+
const emailField = contactField('input', 'email', 'email', true, currentEmail);
|
|
791
|
+
const messageField = contactField('textarea', 'text', 'message', true);
|
|
792
|
+
const whatsappField = contactField('input', 'tel', 'whatsapp', false);
|
|
793
|
+
const btn = document.createElement('button');
|
|
794
|
+
btn.textContent = getTranslation('contact-submit');
|
|
795
|
+
btn.className = 'primary-button';
|
|
796
|
+
form.append(nameField, emailField, whatsappField, messageField, btn);
|
|
797
|
+
modalBody.appendChild(form);
|
|
798
|
+
const modal = juxModal(getTranslation('contact-page'), [], '', false, false, modalBody, '', '', () => result.remove());
|
|
799
|
+
modal.id = 'contact-us-modal';
|
|
800
|
+
document.body.appendChild(modal);
|
|
801
|
+
(_b = modal.querySelector('modal-wrapper')) === null || _b === void 0 ? void 0 : _b.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
|
|
802
|
+
const captcha = googleCaptcha();
|
|
803
|
+
if (subject !== 'email-not-sent') {
|
|
804
|
+
// @ts-ignore
|
|
805
|
+
const admin = ((_d = (_c = window.store) === null || _c === void 0 ? void 0 : _c.selectedTeam) === null || _d === void 0 ? void 0 : _d.admin) || window.store.currentUser.email;
|
|
806
|
+
backendGet('credits-balance-for', { admin }, (res) => {
|
|
807
|
+
const balance = res;
|
|
808
|
+
if (balance <= 0) {
|
|
809
|
+
form.insertBefore(captcha, btn);
|
|
810
|
+
}
|
|
811
|
+
}, () => { } // TODO: change it to be an error handling fn provided by the client
|
|
812
|
+
);
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
form.insertBefore(captcha, btn);
|
|
816
|
+
}
|
|
817
|
+
(_e = nameField.querySelector('input')) === null || _e === void 0 ? void 0 : _e.select();
|
|
818
|
+
form.addEventListener('submit', (event) => {
|
|
819
|
+
event.preventDefault();
|
|
820
|
+
sendInquiry(nameField, emailField, messageField, whatsappField, subject, captcha.getAttribute('token'));
|
|
821
|
+
});
|
|
822
|
+
return result;
|
|
778
823
|
};
|
|
779
824
|
|
|
780
|
-
const applyContainerStyles = (container) => {
|
|
781
|
-
container.style.backgroundColor = '#ffffffdd';
|
|
782
|
-
container.style.borderRadius = '16px';
|
|
783
|
-
container.style.inset = '50% 50% 50% 0';
|
|
784
|
-
container.style.position = 'relative';
|
|
785
|
-
container.style.transform = 'translateY(-50%)';
|
|
786
|
-
container.style.width = '620px';
|
|
787
|
-
container.style.alignItems = 'center';
|
|
788
|
-
container.style.display = 'flex';
|
|
789
|
-
container.style.flexDirection = 'column';
|
|
790
|
-
container.style.fontSize = '16px';
|
|
791
|
-
container.style.height = '100%';
|
|
792
|
-
container.style.justifyContent = 'center';
|
|
793
|
-
container.style.margin = '0 auto';
|
|
794
|
-
container.style.paddingTop = '0';
|
|
795
|
-
};
|
|
796
|
-
const applyPageStyles = (page, backgroundImg) => {
|
|
797
|
-
page.style.backgroundImage = `url(${backgroundImg})`;
|
|
798
|
-
page.style.backgroundPosition = '50%';
|
|
799
|
-
page.style.backgroundSize = 'cover';
|
|
800
|
-
page.style.display = 'block';
|
|
801
|
-
page.style.height = '100%';
|
|
802
|
-
};
|
|
803
|
-
const basePage = (pageName, backgroundImg, content) => {
|
|
804
|
-
const result = document.createElement(pageName);
|
|
805
|
-
result.className = 'base-login-page';
|
|
806
|
-
applyPageStyles(result, backgroundImg);
|
|
807
|
-
const section = document.createElement('section');
|
|
808
|
-
applyContainerStyles(section);
|
|
809
|
-
content.forEach(element => section.appendChild(element));
|
|
810
|
-
result.appendChild(section);
|
|
811
|
-
return result;
|
|
825
|
+
const applyContainerStyles = (container) => {
|
|
826
|
+
container.style.backgroundColor = '#ffffffdd';
|
|
827
|
+
container.style.borderRadius = '16px';
|
|
828
|
+
container.style.inset = '50% 50% 50% 0';
|
|
829
|
+
container.style.position = 'relative';
|
|
830
|
+
container.style.transform = 'translateY(-50%)';
|
|
831
|
+
container.style.width = '620px';
|
|
832
|
+
container.style.alignItems = 'center';
|
|
833
|
+
container.style.display = 'flex';
|
|
834
|
+
container.style.flexDirection = 'column';
|
|
835
|
+
container.style.fontSize = '16px';
|
|
836
|
+
container.style.height = '100%';
|
|
837
|
+
container.style.justifyContent = 'center';
|
|
838
|
+
container.style.margin = '0 auto';
|
|
839
|
+
container.style.paddingTop = '0';
|
|
840
|
+
};
|
|
841
|
+
const applyPageStyles = (page, backgroundImg) => {
|
|
842
|
+
page.style.backgroundImage = `url(${backgroundImg})`;
|
|
843
|
+
page.style.backgroundPosition = '50%';
|
|
844
|
+
page.style.backgroundSize = 'cover';
|
|
845
|
+
page.style.display = 'block';
|
|
846
|
+
page.style.height = '100%';
|
|
847
|
+
};
|
|
848
|
+
const basePage = (pageName, backgroundImg, content) => {
|
|
849
|
+
const result = document.createElement(pageName);
|
|
850
|
+
result.className = 'base-login-page';
|
|
851
|
+
applyPageStyles(result, backgroundImg);
|
|
852
|
+
const section = document.createElement('section');
|
|
853
|
+
applyContainerStyles(section);
|
|
854
|
+
content.forEach(element => section.appendChild(element));
|
|
855
|
+
result.appendChild(section);
|
|
856
|
+
return result;
|
|
812
857
|
};
|
|
813
858
|
|
|
814
|
-
const applyBtnStyles = (btn) => {
|
|
815
|
-
btn.style.cursor = 'pointer';
|
|
816
|
-
btn.style.textDecoration = 'underline';
|
|
817
|
-
btn.style.border = 'none';
|
|
818
|
-
btn.style.backgroundColor = '';
|
|
819
|
-
btn.style.background = 'none';
|
|
820
|
-
btn.style.boxSizing = 'border-box';
|
|
821
|
-
btn.style.margin = '0';
|
|
822
|
-
btn.style.outline = 'none';
|
|
823
|
-
btn.style.padding = '0';
|
|
824
|
-
btn.style.whiteSpace = 'normal';
|
|
825
|
-
btn.style.font = 'inherit';
|
|
826
|
-
};
|
|
827
|
-
const magicLinkRequestedPage = (backgroundImg, onReturn) => {
|
|
828
|
-
const content = [];
|
|
829
|
-
const sent = document.createElement('p');
|
|
830
|
-
sent.id = 'magic-link-sent';
|
|
831
|
-
sent.textContent = getTranslation(sent.id);
|
|
832
|
-
sent.style.marginBottom = '10px';
|
|
833
|
-
const email = document.createElement('p');
|
|
834
|
-
email.id = 'magic-link-email';
|
|
835
|
-
email.style.fontWeight = '700';
|
|
836
|
-
email.style.marginBottom = '10px';
|
|
837
|
-
const howTo = document.createElement('p');
|
|
838
|
-
howTo.id = 'magic-link-how-to';
|
|
839
|
-
howTo.innerHTML = getTranslation(howTo.id);
|
|
840
|
-
howTo.style.padding = '0 30px';
|
|
841
|
-
howTo.style.textAlign = 'center';
|
|
842
|
-
const btn = document.createElement('button');
|
|
843
|
-
btn.id = 'email-not-received-btn';
|
|
844
|
-
btn.addEventListener('click', () => document.body.appendChild(contactUsModal('email-not-sent')));
|
|
845
|
-
btn.textContent = getTranslation('magic-link-let-us-know');
|
|
846
|
-
applyBtnStyles(btn);
|
|
847
|
-
const returnLink = document.createElement('a');
|
|
848
|
-
returnLink.textContent = getTranslation('return-link');
|
|
849
|
-
returnLink.onclick = () => {
|
|
850
|
-
result.remove();
|
|
851
|
-
onReturn();
|
|
852
|
-
};
|
|
853
|
-
returnLink.style.marginTop = '32px';
|
|
854
|
-
returnLink.style.cursor = 'pointer';
|
|
855
|
-
returnLink.style.fontWeight = '700';
|
|
856
|
-
returnLink.style.textDecoration = 'underline';
|
|
857
|
-
content.push(sent, email, howTo, btn, returnLink);
|
|
858
|
-
const result = basePage('magic-link-requested-page', backgroundImg, content);
|
|
859
|
-
return result;
|
|
859
|
+
const applyBtnStyles = (btn) => {
|
|
860
|
+
btn.style.cursor = 'pointer';
|
|
861
|
+
btn.style.textDecoration = 'underline';
|
|
862
|
+
btn.style.border = 'none';
|
|
863
|
+
btn.style.backgroundColor = '';
|
|
864
|
+
btn.style.background = 'none';
|
|
865
|
+
btn.style.boxSizing = 'border-box';
|
|
866
|
+
btn.style.margin = '0';
|
|
867
|
+
btn.style.outline = 'none';
|
|
868
|
+
btn.style.padding = '0';
|
|
869
|
+
btn.style.whiteSpace = 'normal';
|
|
870
|
+
btn.style.font = 'inherit';
|
|
871
|
+
};
|
|
872
|
+
const magicLinkRequestedPage = (backgroundImg, onReturn) => {
|
|
873
|
+
const content = [];
|
|
874
|
+
const sent = document.createElement('p');
|
|
875
|
+
sent.id = 'magic-link-sent';
|
|
876
|
+
sent.textContent = getTranslation(sent.id);
|
|
877
|
+
sent.style.marginBottom = '10px';
|
|
878
|
+
const email = document.createElement('p');
|
|
879
|
+
email.id = 'magic-link-email';
|
|
880
|
+
email.style.fontWeight = '700';
|
|
881
|
+
email.style.marginBottom = '10px';
|
|
882
|
+
const howTo = document.createElement('p');
|
|
883
|
+
howTo.id = 'magic-link-how-to';
|
|
884
|
+
howTo.innerHTML = getTranslation(howTo.id);
|
|
885
|
+
howTo.style.padding = '0 30px';
|
|
886
|
+
howTo.style.textAlign = 'center';
|
|
887
|
+
const btn = document.createElement('button');
|
|
888
|
+
btn.id = 'email-not-received-btn';
|
|
889
|
+
btn.addEventListener('click', () => document.body.appendChild(contactUsModal('email-not-sent')));
|
|
890
|
+
btn.textContent = getTranslation('magic-link-let-us-know');
|
|
891
|
+
applyBtnStyles(btn);
|
|
892
|
+
const returnLink = document.createElement('a');
|
|
893
|
+
returnLink.textContent = getTranslation('return-link');
|
|
894
|
+
returnLink.onclick = () => {
|
|
895
|
+
result.remove();
|
|
896
|
+
onReturn();
|
|
897
|
+
};
|
|
898
|
+
returnLink.style.marginTop = '32px';
|
|
899
|
+
returnLink.style.cursor = 'pointer';
|
|
900
|
+
returnLink.style.fontWeight = '700';
|
|
901
|
+
returnLink.style.textDecoration = 'underline';
|
|
902
|
+
content.push(sent, email, howTo, btn, returnLink);
|
|
903
|
+
const result = basePage('magic-link-requested-page', backgroundImg, content);
|
|
904
|
+
return result;
|
|
860
905
|
};
|
|
861
906
|
|
|
862
|
-
const unauthorizedMagicLinkRequestPage = (backgroundImg, onReturn) => {
|
|
863
|
-
const content = [];
|
|
864
|
-
const notSent = document.createElement('p');
|
|
865
|
-
notSent.id = 'magic-link-not-sent';
|
|
866
|
-
notSent.textContent = getTranslation(notSent.id);
|
|
867
|
-
notSent.style.marginBottom = '10px';
|
|
868
|
-
const email = document.createElement('p');
|
|
869
|
-
email.id = 'magic-link-email';
|
|
870
|
-
email.style.fontWeight = '700';
|
|
871
|
-
email.style.marginBottom = '10px';
|
|
872
|
-
const info = document.createElement('p');
|
|
873
|
-
info.id = 'magic-link-fail-info';
|
|
874
|
-
info.innerHTML = getTranslation(info.id);
|
|
875
|
-
info.style.padding = '0 30px';
|
|
876
|
-
info.style.textAlign = 'center';
|
|
877
|
-
const back = document.createElement('a');
|
|
878
|
-
back.textContent = getTranslation('return-link');
|
|
879
|
-
back.onclick = () => {
|
|
880
|
-
result.remove();
|
|
881
|
-
onReturn();
|
|
882
|
-
};
|
|
883
|
-
back.style.marginTop = '32px';
|
|
884
|
-
back.style.cursor = 'pointer';
|
|
885
|
-
back.style.fontWeight = '700';
|
|
886
|
-
back.style.textDecoration = 'underline';
|
|
887
|
-
content.push(notSent, email, info, back);
|
|
888
|
-
const result = basePage('unauthorized-magic-link-request-page', backgroundImg, content);
|
|
889
|
-
return result;
|
|
907
|
+
const unauthorizedMagicLinkRequestPage = (backgroundImg, onReturn) => {
|
|
908
|
+
const content = [];
|
|
909
|
+
const notSent = document.createElement('p');
|
|
910
|
+
notSent.id = 'magic-link-not-sent';
|
|
911
|
+
notSent.textContent = getTranslation(notSent.id);
|
|
912
|
+
notSent.style.marginBottom = '10px';
|
|
913
|
+
const email = document.createElement('p');
|
|
914
|
+
email.id = 'magic-link-email';
|
|
915
|
+
email.style.fontWeight = '700';
|
|
916
|
+
email.style.marginBottom = '10px';
|
|
917
|
+
const info = document.createElement('p');
|
|
918
|
+
info.id = 'magic-link-fail-info';
|
|
919
|
+
info.innerHTML = getTranslation(info.id);
|
|
920
|
+
info.style.padding = '0 30px';
|
|
921
|
+
info.style.textAlign = 'center';
|
|
922
|
+
const back = document.createElement('a');
|
|
923
|
+
back.textContent = getTranslation('return-link');
|
|
924
|
+
back.onclick = () => {
|
|
925
|
+
result.remove();
|
|
926
|
+
onReturn();
|
|
927
|
+
};
|
|
928
|
+
back.style.marginTop = '32px';
|
|
929
|
+
back.style.cursor = 'pointer';
|
|
930
|
+
back.style.fontWeight = '700';
|
|
931
|
+
back.style.textDecoration = 'underline';
|
|
932
|
+
content.push(notSent, email, info, back);
|
|
933
|
+
const result = basePage('unauthorized-magic-link-request-page', backgroundImg, content);
|
|
934
|
+
return result;
|
|
890
935
|
};
|
|
891
936
|
|
|
892
|
-
const setBackendToken = (token) => {
|
|
893
|
-
// @ts-ignore
|
|
894
|
-
window.store.backendToken = token;
|
|
895
|
-
if (token) {
|
|
896
|
-
localStorage.setItem('token', token);
|
|
897
|
-
}
|
|
898
|
-
};
|
|
899
|
-
const getBackendToken = () => {
|
|
900
|
-
var _a;
|
|
901
|
-
const token = (_a = localStorage.getItem('token')) !== null && _a !== void 0 ? _a : '';
|
|
902
|
-
// @ts-ignore
|
|
903
|
-
window.store.backendToken = token;
|
|
904
|
-
return token;
|
|
905
|
-
};
|
|
906
|
-
const onTokenAcquired = (token, onUserLogin) => {
|
|
907
|
-
setBackendToken(token);
|
|
908
|
-
// setSuperToken();
|
|
909
|
-
onUserLogin();
|
|
910
|
-
};
|
|
911
|
-
const clearSession = () => {
|
|
912
|
-
// onUserChanged(null);
|
|
913
|
-
// TODO: find a better way to preserve backend-url
|
|
914
|
-
const backendUrl = getBackendUrl(); // Preserve backend, since the authentication was succcessfull
|
|
915
|
-
localStorage.clear();
|
|
916
|
-
setBackendUrl(backendUrl);
|
|
917
|
-
// @ts-ignore
|
|
918
|
-
window.store = {};
|
|
919
|
-
};
|
|
920
|
-
const onAuthenticationFailure = (msg) => {
|
|
921
|
-
localStorage.removeItem('token');
|
|
922
|
-
// displayPage(Page.LOGIN);
|
|
923
|
-
alert(getTranslation(msg));
|
|
924
|
-
};
|
|
925
|
-
const onAuthentication = (onUserLogin, user, type) => {
|
|
926
|
-
if ((user.token && getBackendToken()) && getBackendToken() !== user.token) {
|
|
927
|
-
clearSession();
|
|
928
|
-
}
|
|
929
|
-
// @ts-ignore
|
|
930
|
-
window.store.currentUser = user;
|
|
931
|
-
if (type === 'Token Authentication') {
|
|
932
|
-
user.token = localStorage.getItem('token');
|
|
933
|
-
}
|
|
934
|
-
onTokenAcquired(user.token, onUserLogin);
|
|
935
|
-
// mixpanelIdentify(user);
|
|
936
|
-
// checkMixpanel(() => mixpanel.track('Login', { 'Login Type': type }));
|
|
937
|
-
};
|
|
938
|
-
const displayPage = (clientApp, page) => {
|
|
939
|
-
Array.from(clientApp.children).forEach(el => el.remove());
|
|
940
|
-
clientApp.appendChild(page);
|
|
941
|
-
};
|
|
942
|
-
const initSession = (clientApp, supportedLoginTypes, onUserLogin, backgroundImage, fetchUserBackendUrl, magicLinkRequestEndpoint, magicLinkAuthEndpoint) => {
|
|
943
|
-
// if (startNewDemo()) {
|
|
944
|
-
// initDemo(setBackendToken, onAuthentication);
|
|
945
|
-
// return;
|
|
946
|
-
// }
|
|
947
|
-
// @ts-ignore
|
|
948
|
-
if (!window.store) {
|
|
949
|
-
// @ts-ignore
|
|
950
|
-
window.store = {};
|
|
951
|
-
}
|
|
952
|
-
// @ts-ignore
|
|
953
|
-
window.store.fetchUserBackendUrl = fetchUserBackendUrl;
|
|
954
|
-
// @ts-ignore
|
|
955
|
-
window.store.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
|
|
956
|
-
// @ts-ignore
|
|
957
|
-
window.store.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
|
|
958
|
-
const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
|
|
959
|
-
if (signInToken) {
|
|
960
|
-
const onOpenMagicLink = () => {
|
|
961
|
-
openMagicLink(signInToken, (res) => onAuthentication(onUserLogin, res, 'Magic Link'), () => onAuthenticationFailure('unable-magic-login'));
|
|
962
|
-
};
|
|
963
|
-
const host = extractTokenFromWindowLocation('host');
|
|
964
|
-
if (host) {
|
|
965
|
-
// @ts-ignore
|
|
966
|
-
window.store.fetchUserBackendUrl({ host }, (backendUrl) => {
|
|
967
|
-
setBackendUrl(backendUrl);
|
|
968
|
-
onOpenMagicLink();
|
|
969
|
-
});
|
|
970
|
-
return;
|
|
971
|
-
}
|
|
972
|
-
onOpenMagicLink();
|
|
973
|
-
return;
|
|
974
|
-
}
|
|
975
|
-
if (getBackendToken()) {
|
|
976
|
-
backendGet('profile', null, (res) => onAuthentication(onUserLogin, res, 'Token Authentication'), (_err) => onAuthenticationFailure('login-failed'));
|
|
977
|
-
return;
|
|
978
|
-
}
|
|
979
|
-
displayPage(clientApp, loginPage(clientApp, backgroundImage, onUserLogin, supportedLoginTypes));
|
|
980
|
-
// const linkedinToken = extractTokenFromWindowLocation('code', '\&state=9893849343');
|
|
981
|
-
// if (linkedinToken) {
|
|
982
|
-
// openLinkedinSession(
|
|
983
|
-
// linkedinToken,
|
|
984
|
-
// (res) => onAuthentication(res, 'Linkedin Authentication'),
|
|
985
|
-
// () => onAuthenticationFailure('unable-linkedin-login')
|
|
986
|
-
// );
|
|
987
|
-
// return;
|
|
988
|
-
// }
|
|
989
|
-
// validateThirdPartyCookies(initGapi, () => displayPage(Page.LOGIN));
|
|
990
|
-
// checkMixpanel(() => mixpanel.track('View Login Page'));
|
|
991
|
-
};
|
|
992
|
-
const onMicrosoftSignIn = (onUserLogin) => __awaiter(void 0, void 0, void 0, function* () {
|
|
993
|
-
const msalConfig = { auth: { clientId: process.env.MICROSOFT_CLIENT_ID } };
|
|
994
|
-
const msalInstance = new msal.PublicClientApplication(msalConfig);
|
|
995
|
-
const loginRequest = { scopes: ['user.read'] };
|
|
996
|
-
enableSignInLayout();
|
|
997
|
-
try {
|
|
998
|
-
const loginResponse = yield msalInstance.loginPopup(loginRequest);
|
|
999
|
-
const { accessToken } = loginResponse;
|
|
1000
|
-
const onSuccess = (res) => {
|
|
1001
|
-
const { token } = res;
|
|
1002
|
-
// @ts-ignore
|
|
1003
|
-
window.store.currentUser = res;
|
|
1004
|
-
onTokenAcquired(token, onUserLogin);
|
|
1005
|
-
disableSignInLayout();
|
|
1006
|
-
};
|
|
1007
|
-
const onError = (err) => {
|
|
1008
|
-
console.error(err);
|
|
1009
|
-
reportError(err);
|
|
1010
|
-
disableSignInLayout();
|
|
1011
|
-
};
|
|
1012
|
-
microsoftLogin(accessToken, onSuccess, onError);
|
|
1013
|
-
}
|
|
1014
|
-
catch (err) {
|
|
1015
|
-
reportError(err);
|
|
1016
|
-
disableSignInLayout();
|
|
1017
|
-
}
|
|
1018
|
-
});
|
|
1019
|
-
const onCookieError = () => {
|
|
1020
|
-
disableSignInLayout();
|
|
1021
|
-
// warning('cookie-error'); TODO
|
|
1022
|
-
return;
|
|
1023
|
-
};
|
|
1024
|
-
const onGoogleSignIn = (onUserLogin) => {
|
|
1025
|
-
validateThirdPartyCookies(() => {
|
|
1026
|
-
enableSignInLayout();
|
|
1027
|
-
authSignIn(onUserLogin);
|
|
1028
|
-
}, onCookieError);
|
|
1029
|
-
};
|
|
1030
|
-
const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, clientBody, email = '') => {
|
|
1031
|
-
if (!email) {
|
|
1032
|
-
const mailMagic = document.querySelector('#mail-magic');
|
|
1033
|
-
email = mailMagic.value;
|
|
1034
|
-
}
|
|
1035
|
-
const payload = { email, token };
|
|
1036
|
-
const onRequestMagicLink = () => {
|
|
1037
|
-
const onResponse = (page) => {
|
|
1038
|
-
currentPage.remove();
|
|
1039
|
-
clientBody.appendChild(page);
|
|
1040
|
-
const magicLinkEmail = page.querySelector('#magic-link-email');
|
|
1041
|
-
magicLinkEmail.textContent = email;
|
|
1042
|
-
};
|
|
1043
|
-
const onSuccess = () => onResponse(magicLinkRequestedPage(backgroundImage, onReturn));
|
|
1044
|
-
const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
|
|
1045
|
-
requestMagicLink(payload, onSuccess, onUnauthorized);
|
|
1046
|
-
};
|
|
1047
|
-
// @ts-ignore
|
|
1048
|
-
if (window.store.fetchUserBackendUrl) {
|
|
1049
|
-
// @ts-ignore
|
|
1050
|
-
window.store.fetchUserBackendUrl({ email }, (backendUrl) => {
|
|
1051
|
-
setBackendUrl(backendUrl);
|
|
1052
|
-
onRequestMagicLink();
|
|
1053
|
-
});
|
|
1054
|
-
return;
|
|
1055
|
-
}
|
|
1056
|
-
onRequestMagicLink();
|
|
937
|
+
const setBackendToken = (token) => {
|
|
938
|
+
// @ts-ignore
|
|
939
|
+
window.store.backendToken = token;
|
|
940
|
+
if (token) {
|
|
941
|
+
localStorage.setItem('token', token);
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
const getBackendToken = () => {
|
|
945
|
+
var _a;
|
|
946
|
+
const token = (_a = localStorage.getItem('token')) !== null && _a !== void 0 ? _a : '';
|
|
947
|
+
// @ts-ignore
|
|
948
|
+
window.store.backendToken = token;
|
|
949
|
+
return token;
|
|
950
|
+
};
|
|
951
|
+
const onTokenAcquired = (token, onUserLogin) => {
|
|
952
|
+
setBackendToken(token);
|
|
953
|
+
// setSuperToken();
|
|
954
|
+
onUserLogin();
|
|
955
|
+
};
|
|
956
|
+
const clearSession = () => {
|
|
957
|
+
// onUserChanged(null);
|
|
958
|
+
// TODO: find a better way to preserve backend-url
|
|
959
|
+
const backendUrl = getBackendUrl(); // Preserve backend, since the authentication was succcessfull
|
|
960
|
+
localStorage.clear();
|
|
961
|
+
setBackendUrl(backendUrl);
|
|
962
|
+
// @ts-ignore
|
|
963
|
+
window.store = {};
|
|
964
|
+
};
|
|
965
|
+
const onAuthenticationFailure = (msg) => {
|
|
966
|
+
localStorage.removeItem('token');
|
|
967
|
+
// displayPage(Page.LOGIN);
|
|
968
|
+
alert(getTranslation(msg));
|
|
969
|
+
};
|
|
970
|
+
const onAuthentication = (onUserLogin, user, type) => {
|
|
971
|
+
if ((user.token && getBackendToken()) && getBackendToken() !== user.token) {
|
|
972
|
+
clearSession();
|
|
973
|
+
}
|
|
974
|
+
// @ts-ignore
|
|
975
|
+
window.store.currentUser = user;
|
|
976
|
+
if (type === 'Token Authentication') {
|
|
977
|
+
user.token = localStorage.getItem('token');
|
|
978
|
+
}
|
|
979
|
+
onTokenAcquired(user.token, onUserLogin);
|
|
980
|
+
// mixpanelIdentify(user);
|
|
981
|
+
// checkMixpanel(() => mixpanel.track('Login', { 'Login Type': type }));
|
|
982
|
+
};
|
|
983
|
+
const displayPage = (clientApp, page) => {
|
|
984
|
+
Array.from(clientApp.children).forEach(el => el.remove());
|
|
985
|
+
clientApp.appendChild(page);
|
|
986
|
+
};
|
|
987
|
+
const initSession = (clientApp, supportedLoginTypes, onUserLogin, backgroundImage, fetchUserBackendUrl, magicLinkRequestEndpoint, magicLinkAuthEndpoint) => {
|
|
988
|
+
// if (startNewDemo()) {
|
|
989
|
+
// initDemo(setBackendToken, onAuthentication);
|
|
990
|
+
// return;
|
|
991
|
+
// }
|
|
992
|
+
// @ts-ignore
|
|
993
|
+
if (!window.store) {
|
|
994
|
+
// @ts-ignore
|
|
995
|
+
window.store = {};
|
|
996
|
+
}
|
|
997
|
+
// @ts-ignore
|
|
998
|
+
window.store.fetchUserBackendUrl = fetchUserBackendUrl;
|
|
999
|
+
// @ts-ignore
|
|
1000
|
+
window.store.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
|
|
1001
|
+
// @ts-ignore
|
|
1002
|
+
window.store.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
|
|
1003
|
+
const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
|
|
1004
|
+
if (signInToken) {
|
|
1005
|
+
const onOpenMagicLink = () => {
|
|
1006
|
+
openMagicLink(signInToken, (res) => onAuthentication(onUserLogin, res, 'Magic Link'), () => onAuthenticationFailure('unable-magic-login'));
|
|
1007
|
+
};
|
|
1008
|
+
const host = extractTokenFromWindowLocation('host');
|
|
1009
|
+
if (host) {
|
|
1010
|
+
// @ts-ignore
|
|
1011
|
+
window.store.fetchUserBackendUrl({ host }, (backendUrl) => {
|
|
1012
|
+
setBackendUrl(backendUrl);
|
|
1013
|
+
onOpenMagicLink();
|
|
1014
|
+
});
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
onOpenMagicLink();
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
if (getBackendToken()) {
|
|
1021
|
+
backendGet('profile', null, (res) => onAuthentication(onUserLogin, res, 'Token Authentication'), (_err) => onAuthenticationFailure('login-failed'));
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
displayPage(clientApp, loginPage(clientApp, backgroundImage, onUserLogin, supportedLoginTypes));
|
|
1025
|
+
// const linkedinToken = extractTokenFromWindowLocation('code', '\&state=9893849343');
|
|
1026
|
+
// if (linkedinToken) {
|
|
1027
|
+
// openLinkedinSession(
|
|
1028
|
+
// linkedinToken,
|
|
1029
|
+
// (res) => onAuthentication(res, 'Linkedin Authentication'),
|
|
1030
|
+
// () => onAuthenticationFailure('unable-linkedin-login')
|
|
1031
|
+
// );
|
|
1032
|
+
// return;
|
|
1033
|
+
// }
|
|
1034
|
+
// validateThirdPartyCookies(initGapi, () => displayPage(Page.LOGIN));
|
|
1035
|
+
// checkMixpanel(() => mixpanel.track('View Login Page'));
|
|
1036
|
+
};
|
|
1037
|
+
const onMicrosoftSignIn = (onUserLogin) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1038
|
+
const msalConfig = { auth: { clientId: process.env.MICROSOFT_CLIENT_ID } };
|
|
1039
|
+
const msalInstance = new msal.PublicClientApplication(msalConfig);
|
|
1040
|
+
const loginRequest = { scopes: ['user.read'] };
|
|
1041
|
+
enableSignInLayout();
|
|
1042
|
+
try {
|
|
1043
|
+
const loginResponse = yield msalInstance.loginPopup(loginRequest);
|
|
1044
|
+
const { accessToken } = loginResponse;
|
|
1045
|
+
const onSuccess = (res) => {
|
|
1046
|
+
const { token } = res;
|
|
1047
|
+
// @ts-ignore
|
|
1048
|
+
window.store.currentUser = res;
|
|
1049
|
+
onTokenAcquired(token, onUserLogin);
|
|
1050
|
+
disableSignInLayout();
|
|
1051
|
+
};
|
|
1052
|
+
const onError = (err) => {
|
|
1053
|
+
console.error(err);
|
|
1054
|
+
reportError(err);
|
|
1055
|
+
disableSignInLayout();
|
|
1056
|
+
};
|
|
1057
|
+
microsoftLogin(accessToken, onSuccess, onError);
|
|
1058
|
+
}
|
|
1059
|
+
catch (err) {
|
|
1060
|
+
reportError(err);
|
|
1061
|
+
disableSignInLayout();
|
|
1062
|
+
}
|
|
1063
|
+
});
|
|
1064
|
+
const onCookieError = () => {
|
|
1065
|
+
disableSignInLayout();
|
|
1066
|
+
// warning('cookie-error'); TODO
|
|
1067
|
+
return;
|
|
1068
|
+
};
|
|
1069
|
+
const onGoogleSignIn = (onUserLogin) => {
|
|
1070
|
+
validateThirdPartyCookies(() => {
|
|
1071
|
+
enableSignInLayout();
|
|
1072
|
+
authSignIn(onUserLogin);
|
|
1073
|
+
}, onCookieError);
|
|
1074
|
+
};
|
|
1075
|
+
const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, clientBody, email = '') => {
|
|
1076
|
+
if (!email) {
|
|
1077
|
+
const mailMagic = document.querySelector('#mail-magic');
|
|
1078
|
+
email = mailMagic.value;
|
|
1079
|
+
}
|
|
1080
|
+
const payload = { email, token };
|
|
1081
|
+
const onRequestMagicLink = () => {
|
|
1082
|
+
const onResponse = (page) => {
|
|
1083
|
+
currentPage.remove();
|
|
1084
|
+
clientBody.appendChild(page);
|
|
1085
|
+
const magicLinkEmail = page.querySelector('#magic-link-email');
|
|
1086
|
+
magicLinkEmail.textContent = email;
|
|
1087
|
+
};
|
|
1088
|
+
const onSuccess = () => onResponse(magicLinkRequestedPage(backgroundImage, onReturn));
|
|
1089
|
+
const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
|
|
1090
|
+
requestMagicLink(payload, onSuccess, onUnauthorized);
|
|
1091
|
+
};
|
|
1092
|
+
// @ts-ignore
|
|
1093
|
+
if (window.store.fetchUserBackendUrl) {
|
|
1094
|
+
// @ts-ignore
|
|
1095
|
+
window.store.fetchUserBackendUrl({ email }, (backendUrl) => {
|
|
1096
|
+
setBackendUrl(backendUrl);
|
|
1097
|
+
onRequestMagicLink();
|
|
1098
|
+
});
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1101
|
+
onRequestMagicLink();
|
|
1057
1102
|
};
|
|
1058
1103
|
|
|
1059
|
-
const socialLoginModal = (userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal) => {
|
|
1060
|
-
const result = document.createElement('social-login-modal');
|
|
1061
|
-
const email = document.createElement('p');
|
|
1062
|
-
email.textContent = `"${userEmail}"`;
|
|
1063
|
-
const msg = document.createElement('social-login-msg');
|
|
1064
|
-
msg.textContent = getTranslation('social-login-recommendation') + mailExchanger + '.' + getTranslation('social-login-advantage');
|
|
1065
|
-
const body = document.createElement('social-login-body');
|
|
1066
|
-
const socialLoginBtn = mailExchanger === 'Microsoft' ?
|
|
1067
|
-
loginButton('Microsoft', () => onMicrosoftSignIn(onUserLogin)) :
|
|
1068
|
-
loginButton('Google', () => onGoogleSignIn(onUserLogin));
|
|
1069
|
-
const proceedMagicLinkRequest = document.createElement('a');
|
|
1070
|
-
proceedMagicLinkRequest.textContent = getTranslation('proceed-magic-link-request');
|
|
1071
|
-
proceedMagicLinkRequest.addEventListener('click', () => {
|
|
1072
|
-
handleMagicLinkRequest(token, onReturn, backgroundImage, currentPage, clientBody, userEmail);
|
|
1073
|
-
closeMagicLinkModal();
|
|
1074
|
-
result.remove();
|
|
1075
|
-
});
|
|
1076
|
-
body.append(email, msg, socialLoginBtn, proceedMagicLinkRequest);
|
|
1077
|
-
const modal = juxModal(getTranslation(`using-${mailExchanger.toLowerCase()}-email`), [], '', false, false, body, '', '', () => result.remove());
|
|
1078
|
-
modal.setAttribute('data-cy', 'social-login-modal');
|
|
1079
|
-
result.appendChild(modal);
|
|
1080
|
-
const wrapper = modal.querySelector('modal-wrapper');
|
|
1081
|
-
wrapper.style.maxWidth = '360px';
|
|
1082
|
-
wrapper.style.width = '100%';
|
|
1083
|
-
return result;
|
|
1104
|
+
const socialLoginModal = (userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal) => {
|
|
1105
|
+
const result = document.createElement('social-login-modal');
|
|
1106
|
+
const email = document.createElement('p');
|
|
1107
|
+
email.textContent = `"${userEmail}"`;
|
|
1108
|
+
const msg = document.createElement('social-login-msg');
|
|
1109
|
+
msg.textContent = getTranslation('social-login-recommendation') + mailExchanger + '.' + getTranslation('social-login-advantage');
|
|
1110
|
+
const body = document.createElement('social-login-body');
|
|
1111
|
+
const socialLoginBtn = mailExchanger === 'Microsoft' ?
|
|
1112
|
+
loginButton('Microsoft', () => onMicrosoftSignIn(onUserLogin)) :
|
|
1113
|
+
loginButton('Google', () => onGoogleSignIn(onUserLogin));
|
|
1114
|
+
const proceedMagicLinkRequest = document.createElement('a');
|
|
1115
|
+
proceedMagicLinkRequest.textContent = getTranslation('proceed-magic-link-request');
|
|
1116
|
+
proceedMagicLinkRequest.addEventListener('click', () => {
|
|
1117
|
+
handleMagicLinkRequest(token, onReturn, backgroundImage, currentPage, clientBody, userEmail);
|
|
1118
|
+
closeMagicLinkModal();
|
|
1119
|
+
result.remove();
|
|
1120
|
+
});
|
|
1121
|
+
body.append(email, msg, socialLoginBtn, proceedMagicLinkRequest);
|
|
1122
|
+
const modal = juxModal(getTranslation(`using-${mailExchanger.toLowerCase()}-email`), [], '', false, false, body, '', '', () => result.remove());
|
|
1123
|
+
modal.setAttribute('data-cy', 'social-login-modal');
|
|
1124
|
+
result.appendChild(modal);
|
|
1125
|
+
const wrapper = modal.querySelector('modal-wrapper');
|
|
1126
|
+
wrapper.style.maxWidth = '360px';
|
|
1127
|
+
wrapper.style.width = '100%';
|
|
1128
|
+
return result;
|
|
1084
1129
|
};
|
|
1085
1130
|
|
|
1086
|
-
const isValidEmail = (email) => {
|
|
1087
|
-
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
1088
|
-
return re.test(email);
|
|
1131
|
+
const isValidEmail = (email) => {
|
|
1132
|
+
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
1133
|
+
return re.test(email);
|
|
1089
1134
|
};
|
|
1090
1135
|
|
|
1091
|
-
const recommendSocialLogin = (userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal) => {
|
|
1092
|
-
var _a;
|
|
1093
|
-
(_a = document.querySelector('magic-link-modal')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
1094
|
-
document.body.appendChild(socialLoginModal(userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal));
|
|
1095
|
-
};
|
|
1096
|
-
const hasProvider = (data, provider) => {
|
|
1097
|
-
return data.some((entry) => entry.includes(provider));
|
|
1098
|
-
};
|
|
1099
|
-
const getMailExchanger = (domainName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1100
|
-
const data = yield getMXData(domainName);
|
|
1101
|
-
if (!data) {
|
|
1102
|
-
return null;
|
|
1103
|
-
}
|
|
1104
|
-
if (hasProvider(data, 'outlook.com')) {
|
|
1105
|
-
return 'Microsoft';
|
|
1106
|
-
}
|
|
1107
|
-
if (hasProvider(data, 'google.com')) {
|
|
1108
|
-
return 'Google';
|
|
1109
|
-
}
|
|
1110
|
-
return null;
|
|
1111
|
-
});
|
|
1112
|
-
const onMagicLinkRequest = (token, input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1113
|
-
const email = input.value;
|
|
1114
|
-
if (!email.includes('-test@') && !token) {
|
|
1115
|
-
console.error('invalid-captcha-response');
|
|
1116
|
-
// logError('invalid-captcha-response');
|
|
1117
|
-
return;
|
|
1118
|
-
}
|
|
1119
|
-
if (isValidEmail(email)) {
|
|
1120
|
-
const domain = email.split('@')[1] || '';
|
|
1121
|
-
const mailExchanger = yield getMailExchanger(domain);
|
|
1122
|
-
const supportedMailExchanger = mailExchanger !== null;
|
|
1123
|
-
if (supportedMailExchanger && loginTypes.includes(mailExchanger)) {
|
|
1124
|
-
recommendSocialLogin(email, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal);
|
|
1125
|
-
return;
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
handleMagicLinkRequest(token, onReturn, backgroundImage, currentPage, clientBody);
|
|
1129
|
-
closeMagicLinkModal();
|
|
1130
|
-
});
|
|
1131
|
-
const applyMagicEmailFieldStyle = (el) => {
|
|
1132
|
-
el.style.display = 'flex';
|
|
1133
|
-
el.style.flexFlow = 'column';
|
|
1134
|
-
el.style.marginTop = '8px';
|
|
1135
|
-
el.style.rowGap = '8px';
|
|
1136
|
-
el.style.width = '100%';
|
|
1137
|
-
};
|
|
1138
|
-
const applyInputStyle = (input) => {
|
|
1139
|
-
input.style.border = `1px solid ${juxDarkGrey}`;
|
|
1140
|
-
input.style.maxWidth = '390px';
|
|
1141
|
-
input.style.padding = '10px';
|
|
1142
|
-
input.style.width = '100%';
|
|
1143
|
-
input.style.backgroundColor = juxWhite;
|
|
1144
|
-
input.style.borderRadius = '8px';
|
|
1145
|
-
input.style.boxShadow = `inset 0 2px 3px ${juxDimmedDarkGrey}`;
|
|
1146
|
-
input.style.height = '40px';
|
|
1147
|
-
input.style.whiteSpace = 'pre-line';
|
|
1148
|
-
input.style.boxSizing = 'border-box';
|
|
1149
|
-
};
|
|
1150
|
-
const applyBtnStyle = (btn) => {
|
|
1151
|
-
btn.style.alignSelf = 'flex-end';
|
|
1152
|
-
btn.style.backgroundColor = juxLightGreen;
|
|
1153
|
-
btn.style.border = `2px solid ${juxLightGreen}`;
|
|
1154
|
-
btn.style.borderRadius = '8px';
|
|
1155
|
-
btn.style.color = juxWhite;
|
|
1156
|
-
btn.style.cursor = 'pointer';
|
|
1157
|
-
btn.style.display = 'inline-block';
|
|
1158
|
-
btn.style.fontWeight = '700';
|
|
1159
|
-
btn.style.height = '40px';
|
|
1160
|
-
btn.style.lineHeight = '1';
|
|
1161
|
-
btn.style.marginLeft = '10px';
|
|
1162
|
-
btn.style.padding = '10px 16px';
|
|
1163
|
-
btn.style.position = 'relative';
|
|
1164
|
-
};
|
|
1165
|
-
const magicEmailField = (onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes) => {
|
|
1166
|
-
const result = document.createElement('magic-email-field');
|
|
1167
|
-
applyMagicEmailFieldStyle(result);
|
|
1168
|
-
const captcha = googleCaptcha();
|
|
1169
|
-
const input = document.createElement('input');
|
|
1170
|
-
input.id = 'mail-magic';
|
|
1171
|
-
input.type = 'text';
|
|
1172
|
-
input.className = 'textfield';
|
|
1173
|
-
input.placeholder = 'e-mail';
|
|
1174
|
-
applyInputStyle(input);
|
|
1175
|
-
input.addEventListener('keydown', (ev) => {
|
|
1176
|
-
if (ev.key === 'Enter') {
|
|
1177
|
-
onMagicLinkRequest(captcha.getAttribute('token'), input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes);
|
|
1178
|
-
}
|
|
1179
|
-
});
|
|
1180
|
-
const btn = document.createElement('button');
|
|
1181
|
-
applyBtnStyle(btn);
|
|
1182
|
-
btn.id = 'send-magic';
|
|
1183
|
-
btn.className = 'primary-button';
|
|
1184
|
-
btn.addEventListener('click', (_ev) => onMagicLinkRequest(captcha.getAttribute('token'), input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes));
|
|
1185
|
-
btn.textContent = getTranslation('send-magic');
|
|
1186
|
-
result.append(input, captcha, btn);
|
|
1187
|
-
return result;
|
|
1136
|
+
const recommendSocialLogin = (userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal) => {
|
|
1137
|
+
var _a;
|
|
1138
|
+
(_a = document.querySelector('magic-link-modal')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
1139
|
+
document.body.appendChild(socialLoginModal(userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal));
|
|
1140
|
+
};
|
|
1141
|
+
const hasProvider = (data, provider) => {
|
|
1142
|
+
return data.some((entry) => entry.includes(provider));
|
|
1143
|
+
};
|
|
1144
|
+
const getMailExchanger = (domainName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1145
|
+
const data = yield getMXData(domainName);
|
|
1146
|
+
if (!data) {
|
|
1147
|
+
return null;
|
|
1148
|
+
}
|
|
1149
|
+
if (hasProvider(data, 'outlook.com')) {
|
|
1150
|
+
return 'Microsoft';
|
|
1151
|
+
}
|
|
1152
|
+
if (hasProvider(data, 'google.com')) {
|
|
1153
|
+
return 'Google';
|
|
1154
|
+
}
|
|
1155
|
+
return null;
|
|
1156
|
+
});
|
|
1157
|
+
const onMagicLinkRequest = (token, input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1158
|
+
const email = input.value;
|
|
1159
|
+
if (!email.includes('-test@') && !token) {
|
|
1160
|
+
console.error('invalid-captcha-response');
|
|
1161
|
+
// logError('invalid-captcha-response');
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
if (isValidEmail(email)) {
|
|
1165
|
+
const domain = email.split('@')[1] || '';
|
|
1166
|
+
const mailExchanger = yield getMailExchanger(domain);
|
|
1167
|
+
const supportedMailExchanger = mailExchanger !== null;
|
|
1168
|
+
if (supportedMailExchanger && loginTypes.includes(mailExchanger)) {
|
|
1169
|
+
recommendSocialLogin(email, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal);
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
handleMagicLinkRequest(token, onReturn, backgroundImage, currentPage, clientBody);
|
|
1174
|
+
closeMagicLinkModal();
|
|
1175
|
+
});
|
|
1176
|
+
const applyMagicEmailFieldStyle = (el) => {
|
|
1177
|
+
el.style.display = 'flex';
|
|
1178
|
+
el.style.flexFlow = 'column';
|
|
1179
|
+
el.style.marginTop = '8px';
|
|
1180
|
+
el.style.rowGap = '8px';
|
|
1181
|
+
el.style.width = '100%';
|
|
1182
|
+
};
|
|
1183
|
+
const applyInputStyle = (input) => {
|
|
1184
|
+
input.style.border = `1px solid ${juxDarkGrey}`;
|
|
1185
|
+
input.style.maxWidth = '390px';
|
|
1186
|
+
input.style.padding = '10px';
|
|
1187
|
+
input.style.width = '100%';
|
|
1188
|
+
input.style.backgroundColor = juxWhite;
|
|
1189
|
+
input.style.borderRadius = '8px';
|
|
1190
|
+
input.style.boxShadow = `inset 0 2px 3px ${juxDimmedDarkGrey}`;
|
|
1191
|
+
input.style.height = '40px';
|
|
1192
|
+
input.style.whiteSpace = 'pre-line';
|
|
1193
|
+
input.style.boxSizing = 'border-box';
|
|
1194
|
+
};
|
|
1195
|
+
const applyBtnStyle = (btn) => {
|
|
1196
|
+
btn.style.alignSelf = 'flex-end';
|
|
1197
|
+
btn.style.backgroundColor = juxLightGreen;
|
|
1198
|
+
btn.style.border = `2px solid ${juxLightGreen}`;
|
|
1199
|
+
btn.style.borderRadius = '8px';
|
|
1200
|
+
btn.style.color = juxWhite;
|
|
1201
|
+
btn.style.cursor = 'pointer';
|
|
1202
|
+
btn.style.display = 'inline-block';
|
|
1203
|
+
btn.style.fontWeight = '700';
|
|
1204
|
+
btn.style.height = '40px';
|
|
1205
|
+
btn.style.lineHeight = '1';
|
|
1206
|
+
btn.style.marginLeft = '10px';
|
|
1207
|
+
btn.style.padding = '10px 16px';
|
|
1208
|
+
btn.style.position = 'relative';
|
|
1209
|
+
};
|
|
1210
|
+
const magicEmailField = (onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes) => {
|
|
1211
|
+
const result = document.createElement('magic-email-field');
|
|
1212
|
+
applyMagicEmailFieldStyle(result);
|
|
1213
|
+
const captcha = googleCaptcha();
|
|
1214
|
+
const input = document.createElement('input');
|
|
1215
|
+
input.id = 'mail-magic';
|
|
1216
|
+
input.type = 'text';
|
|
1217
|
+
input.className = 'textfield';
|
|
1218
|
+
input.placeholder = 'e-mail';
|
|
1219
|
+
applyInputStyle(input);
|
|
1220
|
+
input.addEventListener('keydown', (ev) => {
|
|
1221
|
+
if (ev.key === 'Enter') {
|
|
1222
|
+
onMagicLinkRequest(captcha.getAttribute('token'), input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes);
|
|
1223
|
+
}
|
|
1224
|
+
});
|
|
1225
|
+
const btn = document.createElement('button');
|
|
1226
|
+
applyBtnStyle(btn);
|
|
1227
|
+
btn.id = 'send-magic';
|
|
1228
|
+
btn.className = 'primary-button';
|
|
1229
|
+
btn.addEventListener('click', (_ev) => onMagicLinkRequest(captcha.getAttribute('token'), input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes));
|
|
1230
|
+
btn.textContent = getTranslation('send-magic');
|
|
1231
|
+
result.append(input, captcha, btn);
|
|
1232
|
+
return result;
|
|
1188
1233
|
};
|
|
1189
1234
|
|
|
1190
|
-
const magicLinkModal = (onUserLogin, onReturn, backgroundImage, currentPage, clientBody, loginTypes) => {
|
|
1191
|
-
const result = document.createElement('magic-link-modal');
|
|
1192
|
-
const subtitle = document.createElement('magic-link-request-subtitle');
|
|
1193
|
-
subtitle.style.fontSize = '14px';
|
|
1194
|
-
subtitle.textContent = getTranslation('magic-link-request-subtitle');
|
|
1195
|
-
const body = document.createElement('magic-link-request-body');
|
|
1196
|
-
body.append(subtitle, magicEmailField(onUserLogin, onReturn, backgroundImage, currentPage, clientBody, () => result.remove(), loginTypes));
|
|
1197
|
-
const modal = juxModal(getTranslation('magic-link-request-title'), [], '', false, false, body, '', '', () => result.remove());
|
|
1198
|
-
modal.setAttribute('data-cy', 'magic-link-modal');
|
|
1199
|
-
result.appendChild(modal);
|
|
1200
|
-
const wrapper = modal.querySelector('modal-wrapper');
|
|
1201
|
-
wrapper.style.maxWidth = '360px';
|
|
1202
|
-
wrapper.style.width = '100%';
|
|
1203
|
-
return result;
|
|
1235
|
+
const magicLinkModal = (onUserLogin, onReturn, backgroundImage, currentPage, clientBody, loginTypes) => {
|
|
1236
|
+
const result = document.createElement('magic-link-modal');
|
|
1237
|
+
const subtitle = document.createElement('magic-link-request-subtitle');
|
|
1238
|
+
subtitle.style.fontSize = '14px';
|
|
1239
|
+
subtitle.textContent = getTranslation('magic-link-request-subtitle');
|
|
1240
|
+
const body = document.createElement('magic-link-request-body');
|
|
1241
|
+
body.append(subtitle, magicEmailField(onUserLogin, onReturn, backgroundImage, currentPage, clientBody, () => result.remove(), loginTypes));
|
|
1242
|
+
const modal = juxModal(getTranslation('magic-link-request-title'), [], '', false, false, body, '', '', () => result.remove());
|
|
1243
|
+
modal.setAttribute('data-cy', 'magic-link-modal');
|
|
1244
|
+
result.appendChild(modal);
|
|
1245
|
+
const wrapper = modal.querySelector('modal-wrapper');
|
|
1246
|
+
wrapper.style.maxWidth = '360px';
|
|
1247
|
+
wrapper.style.width = '100%';
|
|
1248
|
+
return result;
|
|
1204
1249
|
};
|
|
1205
1250
|
|
|
1206
|
-
const onEmailLoginRequest = (clientApp, loginPage, onUserLogin, backgroundImage, loginTypes) => {
|
|
1207
|
-
const onReturn = () => clientApp.appendChild(loginPage);
|
|
1208
|
-
loginPage.appendChild(magicLinkModal(onUserLogin, onReturn, backgroundImage, loginPage, clientApp, loginTypes));
|
|
1209
|
-
};
|
|
1210
|
-
const appendLoginTypes = (loginPage, section, clientApp, onUserLogin, loginTypes, backgroundImg) => {
|
|
1211
|
-
if (loginTypes.includes('Google')) {
|
|
1212
|
-
section.appendChild(loginButton('Google', () => onGoogleSignIn(onUserLogin)));
|
|
1213
|
-
}
|
|
1214
|
-
if (loginTypes.includes('Microsoft')) {
|
|
1215
|
-
section.appendChild(loginButton('Microsoft', () => onMicrosoftSignIn(onUserLogin)));
|
|
1216
|
-
}
|
|
1217
|
-
if (loginTypes.includes('Linkedin')) {
|
|
1218
|
-
section.appendChild(loginButton('LinkedIn', () => console.log('login with Linkedin')));
|
|
1219
|
-
}
|
|
1220
|
-
if (loginTypes.includes('Email')) {
|
|
1221
|
-
section.appendChild(loginButton('Email', () => onEmailLoginRequest(clientApp, loginPage, onUserLogin, backgroundImg, loginTypes)));
|
|
1222
|
-
}
|
|
1223
|
-
};
|
|
1224
|
-
const loginPage = (clientApp, backgroundImg, onUserLogin, loginTypes) => {
|
|
1225
|
-
const content = [];
|
|
1226
|
-
const salutation = document.createElement('sign-in-salutation');
|
|
1227
|
-
salutation.textContent = getTranslation('sign-in-salutation');
|
|
1228
|
-
const explanation = document.createElement('sign-in-explanation');
|
|
1229
|
-
explanation.textContent = getTranslation('sign-in-explanation');
|
|
1230
|
-
const msg = document.createElement('sign-in-msg');
|
|
1231
|
-
msg.textContent = getTranslation('sign-in-msg-general');
|
|
1232
|
-
content.push(salutation, explanation, msg);
|
|
1233
|
-
const result = basePage('login-page', backgroundImg, content);
|
|
1234
|
-
const section = result.querySelector('section');
|
|
1235
|
-
appendLoginTypes(result, section, clientApp, onUserLogin, loginTypes, backgroundImg);
|
|
1236
|
-
return result;
|
|
1251
|
+
const onEmailLoginRequest = (clientApp, loginPage, onUserLogin, backgroundImage, loginTypes) => {
|
|
1252
|
+
const onReturn = () => clientApp.appendChild(loginPage);
|
|
1253
|
+
loginPage.appendChild(magicLinkModal(onUserLogin, onReturn, backgroundImage, loginPage, clientApp, loginTypes));
|
|
1254
|
+
};
|
|
1255
|
+
const appendLoginTypes = (loginPage, section, clientApp, onUserLogin, loginTypes, backgroundImg) => {
|
|
1256
|
+
if (loginTypes.includes('Google')) {
|
|
1257
|
+
section.appendChild(loginButton('Google', () => onGoogleSignIn(onUserLogin)));
|
|
1258
|
+
}
|
|
1259
|
+
if (loginTypes.includes('Microsoft')) {
|
|
1260
|
+
section.appendChild(loginButton('Microsoft', () => onMicrosoftSignIn(onUserLogin)));
|
|
1261
|
+
}
|
|
1262
|
+
if (loginTypes.includes('Linkedin')) {
|
|
1263
|
+
section.appendChild(loginButton('LinkedIn', () => console.log('login with Linkedin')));
|
|
1264
|
+
}
|
|
1265
|
+
if (loginTypes.includes('Email')) {
|
|
1266
|
+
section.appendChild(loginButton('Email', () => onEmailLoginRequest(clientApp, loginPage, onUserLogin, backgroundImg, loginTypes)));
|
|
1267
|
+
}
|
|
1268
|
+
};
|
|
1269
|
+
const loginPage = (clientApp, backgroundImg, onUserLogin, loginTypes) => {
|
|
1270
|
+
const content = [];
|
|
1271
|
+
const salutation = document.createElement('sign-in-salutation');
|
|
1272
|
+
salutation.textContent = getTranslation('sign-in-salutation');
|
|
1273
|
+
const explanation = document.createElement('sign-in-explanation');
|
|
1274
|
+
explanation.textContent = getTranslation('sign-in-explanation');
|
|
1275
|
+
const msg = document.createElement('sign-in-msg');
|
|
1276
|
+
msg.textContent = getTranslation('sign-in-msg-general');
|
|
1277
|
+
content.push(salutation, explanation, msg);
|
|
1278
|
+
const result = basePage('login-page', backgroundImg, content);
|
|
1279
|
+
const section = result.querySelector('section');
|
|
1280
|
+
appendLoginTypes(result, section, clientApp, onUserLogin, loginTypes, backgroundImg);
|
|
1281
|
+
return result;
|
|
1237
1282
|
};
|
|
1238
1283
|
|
|
1239
|
-
class JuxEvent extends Event {
|
|
1240
|
-
constructor(method, endpoint, onResult, params, onError) {
|
|
1241
|
-
super('jux-event', { bubbles: true, cancelable: true, composed: true });
|
|
1242
|
-
this.
|
|
1243
|
-
this.
|
|
1244
|
-
this.
|
|
1245
|
-
this.
|
|
1246
|
-
this.
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1284
|
+
class JuxEvent extends Event {
|
|
1285
|
+
constructor(type, method, endpoint, onResult, params, onError, onRedirect) {
|
|
1286
|
+
super('jux-event', { bubbles: true, cancelable: true, composed: true });
|
|
1287
|
+
this.requestType = type;
|
|
1288
|
+
this.method = method;
|
|
1289
|
+
this.endpoint = endpoint;
|
|
1290
|
+
this.onResult = onResult;
|
|
1291
|
+
this.params = params;
|
|
1292
|
+
this.onError = onError;
|
|
1293
|
+
this.onRedirect = onRedirect;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
const query = (element, endpoint, onResult, params, onError, onRedirect) => {
|
|
1297
|
+
element.dispatchEvent(new JuxEvent('query', 'POST', endpoint, onResult, params, onError, onRedirect));
|
|
1298
|
+
};
|
|
1299
|
+
const command = (element, endpoint, onResult, params, onError, onRedirect) => {
|
|
1300
|
+
element.dispatchEvent(new JuxEvent('command', 'POST', endpoint, onResult, params, onError, onRedirect));
|
|
1254
1301
|
};
|
|
1255
1302
|
|
|
1256
|
-
export { chosenLanguage, command, getTranslation,
|
|
1303
|
+
export { chosenLanguage, command, getTranslation, handleJuxEvent, handleMagicLinkRequest, initLanguage, initSession, loginButton, loginPage, magicLinkModal, onMicrosoftSignIn, query, reloadWithLanguageOverride, requestMagicLink };
|