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