@arquimedes.co/eureka-forms 2.0.118 → 2.0.120

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.
@@ -11,6 +11,7 @@ export interface Form {
11
11
  size: FormSize;
12
12
  firstSection: string;
13
13
  type?: FormTypes;
14
+ hasLogin?: boolean;
14
15
  hasCaptcha?: boolean;
15
16
  isStandAlone?: boolean;
16
17
  style?: FormStyle;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The currently active user
3
+ */
4
+ export interface User {
5
+ /** The User's id (if capta agent)*/
6
+ _id?: string;
7
+ /** The User's name */
8
+ name?: string;
9
+ /** The user's Email*/
10
+ email: string;
11
+ /** The expiration of the token */
12
+ exp: number;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -63,6 +63,7 @@ import { fetchForm } from '../Services/FormService';
63
63
  import { calcCbrForm } from '../Utils/CBRFunctions';
64
64
  import { calcInitialSections, calcValuesStore } from './AppFunctions';
65
65
  import { useAppDispatch } from '../hooks';
66
+ import { jwtDecode } from 'jwt-decode';
66
67
  import InternalFormStyle from '../constants/InternalFormStyle';
67
68
  import { calcDependencies } from '../Form/FormFunctions';
68
69
  import { iterateNestedSteps } from '../FormSteps/StepFunctions';
@@ -108,19 +109,20 @@ export var useSetupApp = function (isEmbedded, _a) {
108
109
  });
109
110
  }); };
110
111
  var loadData = function () { return __awaiter(void 0, void 0, void 0, function () {
111
- var idOrganization, organization, form, countryCode, match, dependencies, values;
112
+ var idOrganization, organization, user, form, countryCode, match, dependencies, values, token;
112
113
  var _a;
113
- var _b, _c, _d, _e, _f;
114
- return __generator(this, function (_g) {
115
- switch (_g.label) {
114
+ var _b, _c, _d, _e, _f, _g;
115
+ return __generator(this, function (_h) {
116
+ switch (_h.label) {
116
117
  case 0:
117
118
  idOrganization = others.idOrganization;
118
119
  organization = null;
120
+ user = null;
119
121
  form = formData !== null && formData !== void 0 ? formData : null;
120
122
  if (!(form && preview && form.isStandAlone)) return [3 /*break*/, 2];
121
123
  return [4 /*yield*/, loadOrg()];
122
124
  case 1:
123
- organization = _g.sent();
125
+ organization = _h.sent();
124
126
  return [3 /*break*/, 4];
125
127
  case 2:
126
128
  if (!(!form && apiKey)) return [3 /*break*/, 4];
@@ -130,8 +132,8 @@ export var useSetupApp = function (isEmbedded, _a) {
130
132
  ])];
131
133
  case 3:
132
134
  //Is iframe or widget
133
- _a = _g.sent(), organization = _a[0], form = _a[1];
134
- _g.label = 4;
135
+ _a = _h.sent(), organization = _a[0], form = _a[1];
136
+ _h.label = 4;
135
137
  case 4:
136
138
  if (organization && !idOrganization)
137
139
  idOrganization = organization.idOrganization;
@@ -185,13 +187,30 @@ export var useSetupApp = function (isEmbedded, _a) {
185
187
  dependencies = {};
186
188
  return [4 /*yield*/, calcValuesStore({ idOrganization: idOrganization, countryCode: countryCode }, form, valuesData, postview, customSteps)];
187
189
  case 5:
188
- values = _g.sent();
189
- dispatch(reset(__assign(__assign({ apiKey: apiKey, formStyle: internal
190
+ values = _h.sent();
191
+ if (form.hasLogin && !internal && !preview) {
192
+ token = localStorage.getItem('token');
193
+ if (token) {
194
+ try {
195
+ user = jwtDecode(token);
196
+ if (user && Date.now() / 1000 >= user.exp) {
197
+ //TODO: Posible check specific login key to make sure this user is valid? or have token per key?
198
+ user = null;
199
+ localStorage.removeItem('token');
200
+ }
201
+ }
202
+ catch (error) {
203
+ user = null;
204
+ localStorage.removeItem('token');
205
+ }
206
+ }
207
+ }
208
+ dispatch(reset(__assign(__assign({ user: user, apiKey: apiKey, formStyle: internal
190
209
  ? InternalFormStyle
191
210
  : __assign(__assign({}, InternalFormStyle), ((_d = form === null || form === void 0 ? void 0 : form.style) !== null && _d !== void 0 ? _d : {})), confirmation: {
192
211
  confirmationMessage: (_e = form.confirmationMessage) !== null && _e !== void 0 ? _e : BaseConfirmationMessage,
193
212
  showLink: (_f = form.showLink) !== null && _f !== void 0 ? _f : false,
194
- }, internal: !!internal, idOrganization: idOrganization, idCurrentAgent: idCurrentAgent, preview: !!preview, partial: !!partial, postview: !!postview, editable: !!(editable !== null && editable !== void 0 ? editable : true), values: values }, calcInitialSections(form)), { dependencies: calcDependencies(form.steps, customSteps, form.steps, dependencies, values), countryCode: countryCode })));
213
+ }, internal: !!internal, idOrganization: idOrganization, idCurrentAgent: (_g = user === null || user === void 0 ? void 0 : user._id) !== null && _g !== void 0 ? _g : idCurrentAgent, preview: !!preview, partial: !!partial, postview: !!postview, editable: !!(editable !== null && editable !== void 0 ? editable : true), values: values }, calcInitialSections(form)), { dependencies: calcDependencies(form.steps, customSteps, form.steps, dependencies, values), countryCode: countryCode })));
195
214
  return [2 /*return*/];
196
215
  }
197
216
  });
package/dist/Form/Form.js CHANGED
@@ -68,6 +68,7 @@ import { useAppDispatch, useAppSelector } from '../hooks';
68
68
  import FormContext from '../Contexts/FormContext';
69
69
  import { getAppState } from '../Utils/store';
70
70
  import { focusStep } from '../States/SiteSlice';
71
+ import LoginPage from '../Login/LoginPage';
71
72
  var localeMap = {
72
73
  en: enLocale,
73
74
  'en-US': enLocale,
@@ -85,7 +86,7 @@ function FormComponent(_a) {
85
86
  var _this = this;
86
87
  var _b, _c, _d, _e, _f, _g, _h, _j, _k;
87
88
  var form = _a.form, apiKey = _a.apiKey, reload = _a.reload, isWidget = _a.isWidget, branding = _a.branding, setSubmit = _a.setSubmit, scrollToTop = _a.scrollToTop, customSteps = _a.customSteps, containerRef = _a.containerRef, customSubmit = _a.customSubmit, customSubmitBtns = _a.customSubmitBtns, customConfirmation = _a.customConfirmation;
88
- var _l = useAppSelector(function (state) { return state.global; }), idOrganization = _l.idOrganization, internal = _l.internal, postview = _l.postview;
89
+ var _l = useAppSelector(function (state) { return state.global; }), idOrganization = _l.idOrganization, internal = _l.internal, postview = _l.postview, user = _l.user;
89
90
  var formMethods = useForm({
90
91
  mode: 'onTouched',
91
92
  shouldFocusError: true,
@@ -184,8 +185,11 @@ function FormComponent(_a) {
184
185
  } }, { children: _jsx("div", __assign({ className: styles.widgetFormContainer, ref: containerRef }, { children: renderForm() })) })));
185
186
  }
186
187
  else {
188
+ if (user === null && form.hasLogin) {
189
+ return (_jsx("div", __assign({ className: styles.loginContainer }, { children: _jsx(LoginPage, { form: form }) })));
190
+ }
187
191
  //Standalone cant have widget
188
- return (_jsxs(React.Fragment, { children: [_jsx(Navbar, { logo: branding === null || branding === void 0 ? void 0 : branding.images.logoUrl, color: (_e = (_d = branding === null || branding === void 0 ? void 0 : branding.colors) === null || _d === void 0 ? void 0 : _d.navbarColor) !== null && _e !== void 0 ? _e : (_f = branding === null || branding === void 0 ? void 0 : branding.colors) === null || _f === void 0 ? void 0 : _f.primaryColor }), _jsx("div", __assign({ className: styles.standAloneFormContainer, ref: containerRef, style: {
192
+ return (_jsxs(React.Fragment, { children: [_jsx(Navbar, { apiKey: form.apiKey, logo: branding === null || branding === void 0 ? void 0 : branding.images.logoUrl, color: (_e = (_d = branding === null || branding === void 0 ? void 0 : branding.colors) === null || _d === void 0 ? void 0 : _d.navbarColor) !== null && _e !== void 0 ? _e : (_f = branding === null || branding === void 0 ? void 0 : branding.colors) === null || _f === void 0 ? void 0 : _f.primaryColor }), _jsx("div", __assign({ className: styles.standAloneFormContainer, ref: containerRef, style: {
189
193
  background: (_h = (_g = form.style) === null || _g === void 0 ? void 0 : _g.standAloneBackgroundColor) !== null && _h !== void 0 ? _h : '#ffffff',
190
194
  } }, { children: _jsx("div", __assign({ className: isResponsive
191
195
  ? styles.fullScreenStandAloneForm
@@ -14,6 +14,15 @@
14
14
  overflow: hidden;
15
15
  }
16
16
 
17
+ .loginContainer {
18
+ width: 100%;
19
+ max-width: 100%;
20
+ overflow: hidden;
21
+ min-height: 100vh;
22
+ display: flex;
23
+ overflow-x: hidden;
24
+ }
25
+
17
26
  .standAloneFormCard {
18
27
  -webkit-box-shadow: -6px 0px 8px 5px rgba(0, 0, 0, 0.2);
19
28
  -moz-box-shadow: -6px 0px 8px 5px rgba(0, 0, 0, 0.2);
@@ -62,8 +62,8 @@ function ClassifierSelectorStep(_a) {
62
62
  if (!classifier)
63
63
  return _jsx("div", {});
64
64
  var options = useMemo(function () {
65
- var _a;
66
- return (_a = classifier.children) === null || _a === void 0 ? void 0 : _a.filter(function (idClassifier) {
65
+ var _a, _b;
66
+ return ((_b = (_a = classifier.children) === null || _a === void 0 ? void 0 : _a.filter(function (idClassifier) {
67
67
  var _a;
68
68
  var option = step.options[idClassifier];
69
69
  if ((option === null || option === void 0 ? void 0 : option.type) === ClassifierOptionTypes.HIDE ||
@@ -82,7 +82,7 @@ function ClassifierSelectorStep(_a) {
82
82
  ? classifier === null || classifier === void 0 ? void 0 : classifier.clientName
83
83
  : classifier === null || classifier === void 0 ? void 0 : classifier.name,
84
84
  };
85
- });
85
+ })) !== null && _b !== void 0 ? _b : []);
86
86
  }, idDependencies.map(function (id) { return dependencies[id].value; }));
87
87
  var mapNestedOption = function () {
88
88
  if (value) {
@@ -151,7 +151,7 @@ export var calcDefaultValue = function (step) {
151
151
  }
152
152
  };
153
153
  export var iterateNestedSteps = function (idStep, steps, iteration, path) {
154
- if (path === void 0) { path = [idStep]; }
154
+ if (path === void 0) { path = []; }
155
155
  var step = steps[idStep];
156
156
  if (!step) {
157
157
  console.error('Missing Step:', idStep);
@@ -9,6 +9,15 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
12
21
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
22
  import { calcStepWidth } from '../../StepFunctions';
14
23
  import styles from './MaterialTitleStep.module.css';
@@ -44,6 +53,7 @@ function TitleStep(_a) {
44
53
  }
45
54
  return values;
46
55
  }, [dependencies]);
56
+ var path = useMemo(function () { return __spreadArray(__spreadArray([], step.stepPath, true), [step.id], false).join('.'); }, [step.stepPath, step.id]);
47
57
  return (_jsxs("div", __assign({ className: styles.container, style: {
48
58
  color: formStyle.textColor,
49
59
  width: widthStats.currentBreakPoint <= size
@@ -54,7 +64,7 @@ function TitleStep(_a) {
54
64
  widthStats.currentBreakPoint <= size
55
65
  ? 'center'
56
66
  : 'start',
57
- } }, { children: _jsx(SmartDraftRenderer, { draft: title, dependencies: values, property: "".concat(step.stepPath.join('.'), ".title"), onChange: function (title) { return onChange(__assign(__assign({}, value), { title: title })); } }) })), _jsx("div", __assign({ className: styles.descriptionPar }, { children: _jsx(SmartDraftRenderer, { draft: description, dependencies: values, margin: title ? '10px 0px' : '0px 0px 5px 0px', property: "".concat(step.stepPath.join('.'), ".description"), onChange: function (description) {
67
+ } }, { children: _jsx(SmartDraftRenderer, { draft: title, dependencies: values, property: "".concat(path, ".title"), onChange: function (title) { return onChange(__assign(__assign({}, value), { title: title })); } }) })), _jsx("div", __assign({ className: styles.descriptionPar }, { children: _jsx(SmartDraftRenderer, { draft: description, dependencies: values, margin: title ? '10px 0px' : '0px 0px 5px 0px', property: "".concat(path, ".description"), onChange: function (description) {
58
68
  return onChange(__assign(__assign({}, value), { description: description }));
59
69
  } }) }))] })));
60
70
  }
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { IconProps } from './@IconTypes';
3
+ declare function EmailIcon({ className, style, fill }: IconProps): JSX.Element;
4
+ export default EmailIcon;
@@ -0,0 +1,17 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ function EmailIcon(_a) {
14
+ var className = _a.className, style = _a.style, fill = _a.fill;
15
+ return (_jsx("svg", __assign({ fill: fill, style: style, className: className, version: "1.1", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, { children: _jsx("path", { d: "M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm-1 14H5c-.55 0-1-.45-1-1V8l6.94 4.34c.65.41 1.47.41 2.12 0L20 8v9c0 .55-.45 1-1 1zm-7-7L4 6h16l-8 5z" }) })));
16
+ }
17
+ export default EmailIcon;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { IconProps } from './@IconTypes';
3
+ declare function LockedIcon({ className, style, fill }: IconProps): JSX.Element;
4
+ export default LockedIcon;
@@ -0,0 +1,17 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ function LockedIcon(_a) {
14
+ var className = _a.className, style = _a.style, fill = _a.fill;
15
+ return (_jsx("svg", __assign({ fill: fill, style: style, className: className, version: "1.1", viewBox: "0 0 100 100", xmlns: "http://www.w3.org/2000/svg" }, { children: _jsx("path", { d: "M81.9,49.6c0-9-0.4-9.4-9.3-9.7c0,0,0,0,0,0c0-4,0-9-0.1-12.1C72,16,64.7,8.9,53,8.7c-2,0-4,0-6.1,0 c-13,0.1-20.6,8-20.4,20.9c0,0,0,0.1,0,0.1V40c-0.7,0-1.4,0-2.2,0c-5.8,0-7.1,1.4-7.1,7.2c0,12.3,0.1,24.6-0.1,36.9 c-0.1,4.7,1.8,6.9,6.5,6.9c17.4,0,34.7,0,52.1,0c4.4,0,6.4-2,6.3-6.5C81.8,72.9,81.9,61.3,81.9,49.6z M53.1,67.5v5.8 c0,2-1.6,3.5-3.5,3.5S46,75.2,46,73.3v-5.8c-2.9-1.3-5-4.3-5-7.8c0-4.7,3.8-8.5,8.5-8.5c4.7,0,8.5,3.8,8.5,8.5 C58.1,63.2,56,66.2,53.1,67.5z M61.7,39.9C61.7,39.9,61.7,39.9,61.7,39.9c-8.1,0-16.1,0.1-24.2,0.1v-8.5c0.1-0.6,0.1-1.2,0.1-1.7 c-0.1-7.3,4-10.3,13-10.1c7.4,0.1,11.1,3.6,11.1,10.6C61.7,33.5,61.7,36.7,61.7,39.9z" }) })));
16
+ }
17
+ export default LockedIcon;
@@ -0,0 +1,135 @@
1
+ .rightPanel {
2
+ background-color: #3d5a7f;
3
+ display: flex;
4
+ border-radius: 0 20px 20px 0;
5
+ flex-grow: 0;
6
+ max-width: 41.666667%;
7
+ flex-basis: 41.666667%;
8
+ }
9
+ .rightPanelMessage {
10
+ margin: auto;
11
+ text-align: center;
12
+ padding: 0 30px 0 30px;
13
+ }
14
+ .rightPanelMessage h1 {
15
+ color: white;
16
+ font-size: 40px;
17
+ font-weight: 900;
18
+ }
19
+ .rightPanelMessage p {
20
+ color: white;
21
+ }
22
+ .leftPanel {
23
+ display: flex;
24
+ text-align: center;
25
+ flex-direction: column;
26
+ flex-grow: 1;
27
+ max-width: 100%;
28
+ min-height: fit-content;
29
+ flex-basis: 0;
30
+ position: relative;
31
+ justify-content: center;
32
+ }
33
+ .leftPanel h1 {
34
+ margin-left: auto;
35
+ margin-right: auto;
36
+ color: #3d5a7f;
37
+ font-size: 40px;
38
+ font-weight: 900;
39
+ margin-top: 40px;
40
+ padding-left: 20px;
41
+ padding-right: 20px;
42
+ margin-bottom: 40px;
43
+ }
44
+ .leftPanel a {
45
+ font-size: 22px;
46
+ cursor: pointer;
47
+ -moz-user-select: none;
48
+ -khtml-user-select: none;
49
+ -webkit-user-select: none;
50
+ -ms-user-select: none;
51
+ user-select: none;
52
+ padding-left: 20px;
53
+ padding-right: 20px;
54
+ margin: 0px auto 25px auto;
55
+ text-decoration: underline;
56
+ }
57
+ .loginButton {
58
+ background-color: #3d5a7f;
59
+ border-radius: 40px;
60
+ padding: 22px 50px;
61
+ margin: 0 auto 0 auto;
62
+ color: white;
63
+ font-weight: 800;
64
+ font-size: 22px;
65
+ cursor: pointer;
66
+ -moz-user-select: none;
67
+ -khtml-user-select: none;
68
+ -webkit-user-select: none;
69
+ -ms-user-select: none;
70
+ user-select: none;
71
+ width: fit-content;
72
+ max-width: calc(100% - 40px);
73
+ height: fit-content;
74
+ position: relative;
75
+ display: flex;
76
+ align-items: center;
77
+ justify-content: center;
78
+ }
79
+ .loginButton[disabled] {
80
+ pointer-events: none;
81
+ opacity: 0.5;
82
+ }
83
+ .loaderContainer {
84
+ position: absolute;
85
+ margin: auto;
86
+ height: 40px;
87
+ width: 40px;
88
+ }
89
+ .logo {
90
+ position: absolute;
91
+ display: flex;
92
+ flex-direction: row;
93
+ justify-content: center;
94
+ left: 40px;
95
+ top: 33px;
96
+ height: 65px;
97
+ margin-right: auto;
98
+ }
99
+ .loginInputsContainer {
100
+ width: 60%;
101
+ margin: 0 auto 0 auto;
102
+ }
103
+ .loginInput {
104
+ min-height: 80px;
105
+ }
106
+ @media screen and (max-width: 825px) {
107
+ .rightPanel {
108
+ display: none;
109
+ }
110
+ .loginInputsContainer {
111
+ width: 70%;
112
+ margin: 0 auto 0 auto;
113
+ }
114
+ .leftPanel h1 {
115
+ margin-top: 5%;
116
+ }
117
+ }
118
+
119
+ @media screen and (max-width: 678px) {
120
+ .logo {
121
+ display: none;
122
+ }
123
+ .loginInputsContainer {
124
+ width: 80%;
125
+ }
126
+ }
127
+
128
+ @media screen and (max-height: 720px) {
129
+ .logo {
130
+ display: none;
131
+ }
132
+ .loginButton {
133
+ margin-bottom: 40px;
134
+ }
135
+ }
@@ -0,0 +1,68 @@
1
+ .loginLayout {
2
+ height: 100vh;
3
+ display: flex;
4
+ width: 100vw;
5
+ overflow: hidden;
6
+ background-color: #f0f0f0;
7
+
8
+ position: relative;
9
+ }
10
+ .semiCircle {
11
+ margin-top: auto;
12
+ width: 30vmin;
13
+ height: 30vmin;
14
+ min-width: 100px;
15
+ min-height: 100px;
16
+ object-fit: contain;
17
+ background-color: #98c1d9;
18
+ border-top-left-radius: 0%;
19
+ border-top-right-radius: 100%;
20
+ border-bottom-left-radius: 0%;
21
+ border-bottom-right-radius: 0%;
22
+ }
23
+ .triangle {
24
+ width: 0;
25
+ height: 0;
26
+ border-bottom: 500px solid #ee6c4d;
27
+ border-left: 500px solid transparent;
28
+ margin-left: auto;
29
+ transform: translateY(-300px) translateX(150px) rotate(10deg);
30
+ }
31
+ .cardLayout {
32
+ height: 100%;
33
+ width: 100%;
34
+ display: flex;
35
+ position: absolute;
36
+ left: 0;
37
+ right: 0;
38
+ top: 0;
39
+ bottom: 0;
40
+ overflow: hidden;
41
+ overflow-y: auto;
42
+ }
43
+ .loginCard {
44
+ margin: 7.5vh auto;
45
+ z-index: 2;
46
+ width: 85vw;
47
+ background-color: white;
48
+ border-radius: 20px;
49
+ min-height: 85vh;
50
+ height: fit-content;
51
+ display: flex;
52
+ flex-direction: column;
53
+ }
54
+ .cardContainer {
55
+ display: flex;
56
+ flex-grow: 1;
57
+ flex-direction: row;
58
+ height: 100%;
59
+ }
60
+
61
+ @media screen and (max-width: 320px) {
62
+ .loginCard {
63
+ width: 100vw;
64
+ height: 100vh;
65
+ margin: 0px;
66
+ border-radius: 0px;
67
+ }
68
+ }
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { Form } from '../@Types';
3
+ interface LoginPageProps {
4
+ form: Form;
5
+ }
6
+ /**
7
+ * Displays the specific login component depending on the url
8
+ * @returns the respective component
9
+ */
10
+ declare function LoginPage({ form }: LoginPageProps): JSX.Element;
11
+ export default LoginPage;
@@ -0,0 +1,177 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
49
+ import { useState } from 'react';
50
+ import layoutStyles from './LoginLayout.module.css';
51
+ import styles from './Login.module.css';
52
+ import Loader from '../Shared/Loader/Loader';
53
+ import { Controller, useForm } from 'react-hook-form';
54
+ import axiosInstance from '../Utils/AxiosAPI';
55
+ import { useAppDispatch } from '../hooks';
56
+ import { login } from '../Services/UserService';
57
+ import { setUser } from '../States/GlobalSlice';
58
+ import { jwtDecode } from 'jwt-decode';
59
+ import LoginTextField from './LoginTextField';
60
+ import MaterialProviders from '../Utils/MaterialProviders';
61
+ var EMAIL_REGEX = /^(([^<>()[\]\\.,;:\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,}))$/;
62
+ /**
63
+ * Displays the specific login component depending on the url
64
+ * @returns the respective component
65
+ */
66
+ function LoginPage(_a) {
67
+ var _this = this;
68
+ var form = _a.form;
69
+ var dispatch = useAppDispatch();
70
+ /** If login has errors */
71
+ var _b = useState(false), wrongLogin = _b[0], setWrongLogin = _b[1];
72
+ /** if waiting for response */
73
+ var _c = useState(false), loading = _c[0], setLoading = _c[1];
74
+ var _d = useForm({
75
+ mode: 'onTouched',
76
+ }), getValues = _d.getValues, clearErrors = _d.clearErrors, errors = _d.formState.errors, setError = _d.setError, trigger = _d.trigger, control = _d.control;
77
+ /**
78
+ * Handles login, redirects the user if the current subdomain is not valid
79
+ */
80
+ var handleLogin = function () { return __awaiter(_this, void 0, void 0, function () {
81
+ var isValid, values, isInternal, payload, token, user, err_1;
82
+ var _a, _b;
83
+ return __generator(this, function (_c) {
84
+ switch (_c.label) {
85
+ case 0: return [4 /*yield*/, trigger()];
86
+ case 1:
87
+ isValid = _c.sent();
88
+ values = getValues();
89
+ isInternal = ['andres'].includes(values.email);
90
+ if (!((isValid || isInternal) && form.apiKey)) return [3 /*break*/, 6];
91
+ _c.label = 2;
92
+ case 2:
93
+ _c.trys.push([2, 5, , 6]);
94
+ setLoading(true);
95
+ payload = values;
96
+ if (isInternal) {
97
+ payload.email = values.email + '@capta.co';
98
+ }
99
+ return [4 /*yield*/, login(form.apiKey, payload)];
100
+ case 3:
101
+ token = _c.sent();
102
+ localStorage.setItem('token', token);
103
+ user = jwtDecode(token);
104
+ axiosInstance.defaults.headers.Authorization =
105
+ 'Bearer ' + token;
106
+ return [4 /*yield*/, dispatch(setUser(user))];
107
+ case 4:
108
+ _c.sent();
109
+ return [3 /*break*/, 6];
110
+ case 5:
111
+ err_1 = _c.sent();
112
+ setLoading(false);
113
+ if (((_a = err_1 === null || err_1 === void 0 ? void 0 : err_1.response) === null || _a === void 0 ? void 0 : _a.status) !== 400) {
114
+ console.error(err_1);
115
+ }
116
+ if (((_b = err_1 === null || err_1 === void 0 ? void 0 : err_1.response) === null || _b === void 0 ? void 0 : _b.data) === 'Invalid Organization') {
117
+ setError('password', {
118
+ type: 'pattern',
119
+ message: 'Organización inválida',
120
+ });
121
+ }
122
+ else {
123
+ setError('password', {
124
+ type: 'pattern',
125
+ message: 'Correo o contraseña incorrecta',
126
+ });
127
+ }
128
+ setError('email', {
129
+ type: 'pattern',
130
+ message: '',
131
+ });
132
+ setWrongLogin(true);
133
+ return [3 /*break*/, 6];
134
+ case 6: return [2 /*return*/];
135
+ }
136
+ });
137
+ }); };
138
+ /**
139
+ * Function that clears errors if there are any.
140
+ */
141
+ var clearWrongLogin = function () {
142
+ if (wrongLogin) {
143
+ setWrongLogin(false);
144
+ clearErrors(['email', 'password']);
145
+ }
146
+ };
147
+ return (_jsx(MaterialProviders, { children: _jsxs("div", __assign({ className: layoutStyles.loginLayout }, { children: [_jsx("div", { className: layoutStyles.semiCircle }), _jsx("div", { className: layoutStyles.triangle }), _jsx("div", __assign({ className: layoutStyles.cardLayout }, { children: _jsx("div", __assign({ className: layoutStyles.loginCard }, { children: _jsxs("div", __assign({ className: layoutStyles.cardContainer }, { children: [_jsxs("div", __assign({ className: styles.leftPanel }, { children: [_jsx("div", __assign({ className: styles.logo }, { children: _jsx("img", { alt: 'Capta', className: 'capta-logo', src: '/Capta.svg' }) })), _jsx("h1", { children: "Inicia sesi\u00F3n en Capta" }), _jsxs("div", __assign({ className: styles.loginInputsContainer }, { children: [_jsx("div", __assign({ className: styles.loginInput }, { children: _jsx(Controller, { name: "email", control: control, defaultValue: "", rules: {
148
+ required: 'El correo es obligatorio',
149
+ pattern: {
150
+ value: EMAIL_REGEX,
151
+ message: 'El correo no es válido',
152
+ },
153
+ }, render: function (_a) {
154
+ var _b;
155
+ var field = _a.field;
156
+ return (_jsx(LoginTextField, __assign({}, field, { "data-testid": "login_email", handleEnter: handleLogin, handleChange: clearWrongLogin, email: true, name: "email", disabled: loading, placeholder: "Correo", error: !!errors.email, helperText: errors.email
157
+ ? (_b = errors.email.message) === null || _b === void 0 ? void 0 : _b.toString()
158
+ : '' })));
159
+ } }) })), _jsx("div", __assign({ className: styles.loginInput }, { children: _jsx(Controller, { name: "password", control: control, defaultValue: "", rules: {
160
+ required: 'La contraseña es obligatoria',
161
+ }, render: function (_a) {
162
+ var _b;
163
+ var field = _a.field;
164
+ return (_jsx(LoginTextField, __assign({}, field, { disabled: loading, "data-testid": "login_password", handleEnter: handleLogin, handleChange: clearWrongLogin, name: "password", placeholder: "Contrase\u00F1a", error: !!errors.password, helperText: errors.password
165
+ ? (_b = errors.password.message) === null || _b === void 0 ? void 0 : _b.toString()
166
+ : '' })));
167
+ } }) }))] })), _jsxs("button", __assign({ "data-testid": "login_submit", className: styles.loginButton, onClick: function () {
168
+ if (!loading) {
169
+ void handleLogin();
170
+ }
171
+ }, disabled: loading }, { children: [_jsx("label", __assign({ style: {
172
+ visibility: loading
173
+ ? 'hidden'
174
+ : 'visible',
175
+ } }, { children: "Inicia sesi\u00F3n" })), loading && (_jsx("div", __assign({ className: styles.loaderContainer }, { children: _jsx(Loader, { color: "white" }) })))] }))] })), _jsx("div", __assign({ className: styles.rightPanel }, { children: _jsxs("div", __assign({ className: styles.rightPanelMessage }, { children: [_jsx("h1", { children: "\u00A1Bienvenid@!" }), _jsx("p", { children: "Ingresa tu correo y contrase\u00F1a para ingresar al formulario." })] })) }))] })) })) }))] })) }));
176
+ }
177
+ export default LoginPage;
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ interface ComponentProps {
3
+ /** Function called on Enter */
4
+ handleEnter: any;
5
+ /** IF is of type email */
6
+ email: boolean;
7
+ /** Function called on change */
8
+ onChange: React.ChangeEventHandler;
9
+ /** Function called on change */
10
+ handleChange: any;
11
+ }
12
+ declare class LoginTextField extends React.Component<ComponentProps | any> {
13
+ render(): JSX.Element;
14
+ }
15
+ export default LoginTextField;
@@ -0,0 +1,134 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ var __rest = (this && this.__rest) || function (s, e) {
28
+ var t = {};
29
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
30
+ t[p] = s[p];
31
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
32
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
33
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
34
+ t[p[i]] = s[p[i]];
35
+ }
36
+ return t;
37
+ };
38
+ import { jsx as _jsx } from "react/jsx-runtime";
39
+ import React from 'react';
40
+ import TextField from '@material-ui/core/TextField';
41
+ import { withStyles } from '@material-ui/core/styles';
42
+ import MailOutlineIcon from '@material-ui/icons/MailOutline';
43
+ import InputAdornment from '@material-ui/core/InputAdornment';
44
+ import LockIcon from '@material-ui/icons/Lock';
45
+ var CustomTextField = withStyles({
46
+ root: {
47
+ '& input': {
48
+ padding: '6px 0px',
49
+ backgroundColor: '#ebebeb',
50
+ fontWeight: 300,
51
+ height: 40,
52
+ borderRadius: 10,
53
+ },
54
+ '& label.EF-MuiInputLabel-shrink': {
55
+ marginTop: '0px',
56
+ margin: -2,
57
+ },
58
+ '& input + fieldset': {
59
+ borderRadius: 10,
60
+ },
61
+ '& .EF-MuiInput-underline:after': {
62
+ borderBottomColor: '#3d5a7f',
63
+ },
64
+ '& .EF-MuiInputBase-root': {
65
+ backgroundColor: '#ebebeb',
66
+ },
67
+ '& .EF-MuiOutlinedInput-root': {
68
+ borderRadius: 10,
69
+ backgroundColor: '#ebebeb',
70
+ '&.Mui-focused fieldset': {
71
+ borderColor: '#3d5a7f',
72
+ },
73
+ },
74
+ '& label.Mui-focused': {
75
+ color: '#3d5a7f',
76
+ },
77
+ //ESsto es lo nuevo
78
+ '& input, textarea': {
79
+ padding: '6px 0px',
80
+ fontWeight: 300,
81
+ height: 40,
82
+ backgroundColor: '#ebebeb',
83
+ borderRadius: 10,
84
+ },
85
+ '& label': {
86
+ marginTop: '-4px',
87
+ whiteSpace: 'nowrap',
88
+ overflow: 'hidden',
89
+ textOverflow: 'ellipsis',
90
+ maxWidth: 'calc(100% - 22px)',
91
+ },
92
+ '& .EF-MuiOutlinedInput-root:hover .EF-MuiOutlinedInput-notchedOutline': {
93
+ borderColor: '#3d5a7f',
94
+ },
95
+ '& .Mui-error': {},
96
+ '& .EF-MuiOutlinedInput-adornedEnd': {
97
+ paddingRight: '7px',
98
+ },
99
+ '& .EF-MuiFormHelperText-root': {
100
+ color: '#0a0101ff',
101
+ position: 'relative',
102
+ marginRight: 14,
103
+ },
104
+ '& .EF-MuiFormHelperText-root.Mui-error': {
105
+ color: '#cc2936',
106
+ },
107
+ '& .EF-MuiOutlinedInput-multiline': {
108
+ padding: 0,
109
+ backgroundColor: '#ebebeb',
110
+ },
111
+ },
112
+ })(TextField);
113
+ var LoginTextField = /** @class */ (function (_super) {
114
+ __extends(LoginTextField, _super);
115
+ function LoginTextField() {
116
+ return _super !== null && _super.apply(this, arguments) || this;
117
+ }
118
+ LoginTextField.prototype.render = function () {
119
+ var _a = this.props, handleEnter = _a.handleEnter, email = _a.email, onChange = _a.onChange, handleChange = _a.handleChange, others = __rest(_a, ["handleEnter", "email", "onChange", "handleChange"]);
120
+ return (_jsx(CustomTextField, __assign({}, others, { variant: "outlined", size: "small", fullWidth: true, type: email ? 'email' : 'password', onChange: function (event) {
121
+ handleChange === null || handleChange === void 0 ? void 0 : handleChange();
122
+ onChange === null || onChange === void 0 ? void 0 : onChange(event);
123
+ }, InputProps: {
124
+ onKeyPress: function (event) {
125
+ if (handleEnter && event.key === 'Enter') {
126
+ handleEnter();
127
+ }
128
+ },
129
+ startAdornment: (_jsx(InputAdornment, __assign({ position: "start" }, { children: email ? _jsx(MailOutlineIcon, {}) : _jsx(LockIcon, {}) }))),
130
+ } })));
131
+ };
132
+ return LoginTextField;
133
+ }(React.Component));
134
+ export default LoginTextField;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Function that handles the app's login
3
+ * @param credentials {email, password} of the user
4
+ * @returns an array with the users Token and RefreshToken
5
+ */
6
+ export declare const login: (apiKey: string, credentials: Record<string, string>) => Promise<string>;
7
+ /**
8
+ * Function that indicates to the server to delete the refresh token
9
+ */
10
+ export declare const logout: (apiKey: string) => Promise<void>;
@@ -0,0 +1,71 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import axiosInstance from '../Utils/AxiosAPI';
38
+ /**
39
+ * Function that handles the app's login
40
+ * @param credentials {email, password} of the user
41
+ * @returns an array with the users Token and RefreshToken
42
+ */
43
+ export var login = function (apiKey, credentials) { return __awaiter(void 0, void 0, void 0, function () {
44
+ var response;
45
+ return __generator(this, function (_a) {
46
+ switch (_a.label) {
47
+ case 0: return [4 /*yield*/, axiosInstance.post("forms/".concat(apiKey, "/auth"), credentials)];
48
+ case 1:
49
+ response = _a.sent();
50
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.data];
51
+ }
52
+ });
53
+ }); };
54
+ /**
55
+ * Function that indicates to the server to delete the refresh token
56
+ */
57
+ export var logout = function (apiKey) { return __awaiter(void 0, void 0, void 0, function () {
58
+ return __generator(this, function (_a) {
59
+ switch (_a.label) {
60
+ case 0: return [4 /*yield*/, axiosInstance.delete("forms/".concat(apiKey, "/auth"), {
61
+ headers: {
62
+ Authorization: 'Bearer ' + localStorage.getItem('refreshToken'),
63
+ },
64
+ timeout: 5000,
65
+ })];
66
+ case 1:
67
+ _a.sent();
68
+ return [2 /*return*/];
69
+ }
70
+ });
71
+ }); };
@@ -1,9 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  interface NavBarProps {
3
+ apiKey?: string;
3
4
  /** Url of the current logo of the current organization */
4
5
  logo?: string;
5
6
  /** The color of the navbar */
6
7
  color?: string;
7
8
  }
8
- declare function Navbar({ logo, color }: NavBarProps): JSX.Element;
9
+ declare function Navbar({ logo, color, apiKey }: NavBarProps): JSX.Element;
9
10
  export default Navbar;
@@ -9,10 +9,91 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { jsx as _jsx } from "react/jsx-runtime";
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
49
+ import { useRef, useState } from 'react';
13
50
  import styles from './Navbar.module.css';
51
+ import { IconButton, Avatar, Menu, MenuItem } from '@material-ui/core';
52
+ import { logout } from '../../Services/UserService';
53
+ import { useAppSelector } from '../../hooks';
14
54
  function Navbar(_a) {
15
- var logo = _a.logo, color = _a.color;
16
- return (_jsx("div", __assign({ className: styles.navContainer, style: { backgroundColor: color } }, { children: _jsx("img", { src: logo, alt: "Organization Logo", className: styles.navImage }) })));
55
+ var _this = this;
56
+ var _b;
57
+ var logo = _a.logo, color = _a.color, apiKey = _a.apiKey;
58
+ var ref = useRef(null);
59
+ var _c = useState(false), open = _c[0], setOpen = _c[1];
60
+ var user = useAppSelector(function (state) { return state.global.user; });
61
+ return (_jsxs("div", __assign({ className: styles.navContainer, style: { backgroundColor: color } }, { children: [_jsx("img", { src: logo, alt: "Organization Logo", className: styles.navImage }), user && apiKey && (_jsxs(_Fragment, { children: [_jsx("div", __assign({ className: styles.navBarAvatar, ref: ref }, { children: _jsx(IconButton, __assign({ style: {
62
+ width: 42,
63
+ height: 42,
64
+ padding: 0,
65
+ margin: 'auto',
66
+ }, "aria-label": "Mi Perfil", "aria-haspopup": "true", onClick: function () {
67
+ setOpen(true);
68
+ } }, { children: _jsx(Avatar, { style: { fontSize: '40px' }, alt: (_b = user === null || user === void 0 ? void 0 : user.name) !== null && _b !== void 0 ? _b : user === null || user === void 0 ? void 0 : user.email }) })) })), _jsx(Menu, __assign({ id: "simple-menu", anchorEl: ref.current, getContentAnchorEl: null, anchorOrigin: {
69
+ vertical: 'bottom',
70
+ horizontal: 'right',
71
+ }, transformOrigin: {
72
+ vertical: 'top',
73
+ horizontal: 'right',
74
+ }, open: open, onClose: function () { return setOpen(false); } }, { children: _jsx(MenuItem, __assign({ onClick: function () { return __awaiter(_this, void 0, void 0, function () {
75
+ var err_1;
76
+ return __generator(this, function (_a) {
77
+ switch (_a.label) {
78
+ case 0:
79
+ setOpen(false);
80
+ _a.label = 1;
81
+ case 1:
82
+ _a.trys.push([1, 3, , 4]);
83
+ return [4 /*yield*/, logout(apiKey)];
84
+ case 2:
85
+ _a.sent();
86
+ return [3 /*break*/, 4];
87
+ case 3:
88
+ err_1 = _a.sent();
89
+ console.error(err_1);
90
+ return [3 /*break*/, 4];
91
+ case 4:
92
+ localStorage.removeItem('token');
93
+ window.location.reload();
94
+ return [2 /*return*/];
95
+ }
96
+ });
97
+ }); } }, { children: "Cerrar sesi\u00F3n" })) }))] }))] })));
17
98
  }
18
99
  export default Navbar;
@@ -6,3 +6,18 @@
6
6
  height: 40px;
7
7
  margin: auto 0 auto 15px;
8
8
  }
9
+
10
+ .navBarAvatar {
11
+ height: 60px;
12
+ margin-left: 5px;
13
+ display: flex;
14
+ align-items: center;
15
+ justify-content: center;
16
+ margin-left: auto;
17
+ margin-right: 15px;
18
+ }
19
+
20
+ .navBarAvatarIcon {
21
+ width: 100px;
22
+ height: 100px;
23
+ }
@@ -3,6 +3,7 @@ import type { PayloadAction } from '@reduxjs/toolkit';
3
3
  import { SiteState } from './SiteSlice';
4
4
  import { EurekaDraft } from '../@Types/Draft/Draft';
5
5
  import { CountryCode } from 'libphonenumber-js';
6
+ import { User } from '../@Types/User';
6
7
  export interface GlobalState {
7
8
  apiKey?: string;
8
9
  idOrganization: string;
@@ -20,6 +21,8 @@ export interface GlobalState {
20
21
  partial: boolean;
21
22
  internal: boolean;
22
23
  loaded: boolean;
24
+ /** Current User */
25
+ user: User | null | undefined;
23
26
  }
24
27
  export declare const GlobalSlice: import("@reduxjs/toolkit").Slice<GlobalState, {
25
28
  reset: (state: import("immer/dist/internal").WritableDraft<GlobalState>, action: PayloadAction<Omit<GlobalState, 'loaded'> & SiteState>) => {
@@ -38,6 +41,7 @@ export declare const GlobalSlice: import("@reduxjs/toolkit").Slice<GlobalState,
38
41
  showLink: boolean;
39
42
  };
40
43
  internal: boolean;
44
+ user: User | null | undefined;
41
45
  dependencies: import("../Form/Form").DependencyStore;
42
46
  values: import("./SiteSlice").ValuesStore;
43
47
  idCurrentSection: string | null;
@@ -45,6 +49,7 @@ export declare const GlobalSlice: import("@reduxjs/toolkit").Slice<GlobalState,
45
49
  nextSections: string[];
46
50
  focusStep?: string | undefined;
47
51
  };
52
+ setUser: (state: import("immer/dist/internal").WritableDraft<GlobalState>, action: PayloadAction<User | null>) => void;
48
53
  }, "global">;
49
- export declare const reset: import("@reduxjs/toolkit").ActionCreatorWithPayload<Omit<GlobalState, "loaded"> & SiteState, "global/reset">;
54
+ export declare const reset: import("@reduxjs/toolkit").ActionCreatorWithPayload<Omit<GlobalState, "loaded"> & SiteState, "global/reset">, setUser: import("@reduxjs/toolkit").ActionCreatorWithPayload<User | null, "global/setUser">;
50
55
  export default GlobalSlice;
@@ -9,6 +9,7 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var _a;
12
13
  import InternalFormStyle from '../constants/InternalFormStyle';
13
14
  import { createSlice } from '@reduxjs/toolkit';
14
15
  import { BaseConfirmationMessage } from '../Contexts/FormContext';
@@ -26,6 +27,7 @@ var initialState = {
26
27
  partial: false,
27
28
  internal: false,
28
29
  loaded: false,
30
+ user: undefined,
29
31
  };
30
32
  export var GlobalSlice = createSlice({
31
33
  name: 'global',
@@ -34,7 +36,10 @@ export var GlobalSlice = createSlice({
34
36
  reset: function (state, action) {
35
37
  return __assign(__assign(__assign({}, state), action.payload), { loaded: true });
36
38
  },
39
+ setUser: function (state, action) {
40
+ state.user = action.payload;
41
+ },
37
42
  },
38
43
  });
39
- export var reset = GlobalSlice.actions.reset;
44
+ export var reset = (_a = GlobalSlice.actions, _a.reset), setUser = _a.setUser;
40
45
  export default GlobalSlice;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arquimedes.co/eureka-forms",
3
3
  "repository": "git://github.com/Arquimede5/Eureka-Forms.git",
4
- "version": "2.0.118",
4
+ "version": "2.0.120",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
7
7
  "build": "react-scripts build",
@@ -25,6 +25,7 @@
25
25
  "date-fns": "^2.23.0",
26
26
  "draft-js": "^0.11.7",
27
27
  "i18n-iso-countries": "^7.11.3",
28
+ "jwt-decode": "^4.0.0",
28
29
  "libphonenumber-js": "^1.11.7",
29
30
  "logrocket": "^2.2.1",
30
31
  "nanoid": "^3.3.7",