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