@pagopa/selfcare-common-frontend 1.1.1 → 1.2.3
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/CHANGELOG.md +48 -5
- package/README.md +85 -1
- package/build.info +2 -2
- package/components/ErrorBoundary/ErrorBoundary.js +6 -9
- package/components/ErrorBoundary/ErrorBoundary.js.map +1 -1
- package/components/FilterModal.d.ts +1 -1
- package/components/FilterModal.js +1 -0
- package/components/FilterModal.js.map +1 -1
- package/components/Footer/Footer.d.ts +2 -1
- package/components/Footer/Footer.js +9 -5
- package/components/Footer/Footer.js.map +1 -1
- package/components/SessionModal.js +1 -1
- package/components/SessionModal.js.map +1 -1
- package/components/TitleBox.d.ts +1 -2
- package/components/TitleBox.js.map +1 -1
- package/components/UnloadEventHandler.d.ts +8 -0
- package/components/UnloadEventHandler.js +33 -0
- package/components/UnloadEventHandler.js.map +1 -0
- package/components/UserNotifyHandle.d.ts +7 -0
- package/components/UserNotifyHandle.js +55 -0
- package/components/UserNotifyHandle.js.map +1 -0
- package/decorators/__mocks__/withLogin.js +2 -1
- package/decorators/__mocks__/withLogin.js.map +1 -1
- package/hooks/useErrorDispatcher.d.ts +1 -1
- package/hooks/useErrorDispatcher.js +1 -1
- package/hooks/useErrorDispatcher.js.map +1 -1
- package/hooks/useLoading.d.ts +1 -1
- package/hooks/useLoading.js +1 -1
- package/hooks/useLoading.js.map +1 -1
- package/hooks/useUnloadEventInterceptor.d.ts +17 -0
- package/hooks/useUnloadEventInterceptor.js +60 -0
- package/hooks/useUnloadEventInterceptor.js.map +1 -0
- package/hooks/useUserNotify.d.ts +3 -0
- package/hooks/useUserNotify.js +11 -0
- package/hooks/useUserNotify.js.map +1 -0
- package/index.d.ts +3 -11
- package/index.js +20 -24
- package/index.js.map +1 -1
- package/model/UserNotify.d.ts +23 -0
- package/model/UserNotify.js +3 -0
- package/model/UserNotify.js.map +1 -0
- package/package.json +14 -6
- package/redux/slices/appStateSlice.d.ts +45 -2
- package/redux/slices/appStateSlice.js +43 -0
- package/redux/slices/appStateSlice.js.map +1 -1
- package/redux/slices/userSlice.d.ts +3 -1
- package/redux/slices/userSlice.js.map +1 -1
- package/utils/api-utils.d.ts +16 -0
- package/utils/api-utils.js +63 -0
- package/utils/api-utils.js.map +1 -0
- package/utils/constants.d.ts +3 -0
- package/utils/constants.js +3 -0
- package/utils/constants.js.map +1 -1
- package/utils/fixSwagger20ArraySchemaDef.js +67 -0
- package/utils/routes-utils.d.ts +1 -0
- package/utils/routes-utils.js +1 -0
- package/utils/routes-utils.js.map +1 -1
- package/utils/storage-utils.d.ts +3 -0
- package/utils/storage-utils.js +3 -0
- package/utils/storage-utils.js.map +1 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useUnloadEventLogout = exports.useUnloadEventOnExit = exports.useUnloadEventInterceptorAndActivate = exports.useUnloadEventInterceptor = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const react_redux_1 = require("react-redux");
|
|
6
|
+
const env_1 = require("../config/env");
|
|
7
|
+
const appStateSlice_1 = require("../redux/slices/appStateSlice");
|
|
8
|
+
const appStateSlice_2 = require("./../redux/slices/appStateSlice");
|
|
9
|
+
/** In order to use this feature you have to use the custom hook useUnloadEventInterceptor, which will return an object having the following keys:
|
|
10
|
+
1. registerUnloadEvent: an arrow function which takes two optional parameters to customize the title and the description of the pop-up opened when invoking the exitAction function (see below) and enable the functionality.
|
|
11
|
+
2. unregisterUnloadEvent: an arrow function to call in order to disable this functionality.
|
|
12
|
+
*/
|
|
13
|
+
const useUnloadEventInterceptor = () => {
|
|
14
|
+
const dispatch = (0, react_redux_1.useDispatch)();
|
|
15
|
+
const registerUnloadEvent = (title, description) => {
|
|
16
|
+
dispatch(appStateSlice_1.appStateActions.enableUnloadEventInterceptor({ title, description }));
|
|
17
|
+
};
|
|
18
|
+
const unregisterUnloadEvent = () => {
|
|
19
|
+
dispatch(appStateSlice_1.appStateActions.disableUnloadEventInterceptor());
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
registerUnloadEvent,
|
|
23
|
+
unregisterUnloadEvent,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
exports.useUnloadEventInterceptor = useUnloadEventInterceptor;
|
|
27
|
+
/** If you wont to enable immediately this functionality when invoking the custom hook you can use the hook useUnloadEventInterceptorAndActivate, which will enable the functionality and will disable it when unmounting the component. */
|
|
28
|
+
const useUnloadEventInterceptorAndActivate = (title, description) => {
|
|
29
|
+
const { registerUnloadEvent, unregisterUnloadEvent } = (0, exports.useUnloadEventInterceptor)();
|
|
30
|
+
(0, react_1.useEffect)(() => {
|
|
31
|
+
registerUnloadEvent(title, description);
|
|
32
|
+
return () => unregisterUnloadEvent();
|
|
33
|
+
}, []);
|
|
34
|
+
return {
|
|
35
|
+
registerUnloadEvent,
|
|
36
|
+
unregisterUnloadEvent,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
exports.useUnloadEventInterceptorAndActivate = useUnloadEventInterceptorAndActivate;
|
|
40
|
+
/** In order to show a custom pop-up when the user trigger an exit action you have to use the custom hook useUnloadEventOnExit which will return an arrow function to invoke instead of the exit action passing to it the exitAction itself. */
|
|
41
|
+
const useUnloadEventOnExit = () => {
|
|
42
|
+
const dispatch = (0, react_redux_1.useDispatch)();
|
|
43
|
+
const eventconfiguration = (0, react_redux_1.useSelector)(appStateSlice_2.appStateSelectors.selectUnloadEventConfiguration);
|
|
44
|
+
return (exitAction) => {
|
|
45
|
+
if (eventconfiguration.enabled) {
|
|
46
|
+
dispatch(appStateSlice_1.appStateActions.openUnloadEventNotify(exitAction));
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
exitAction();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
exports.useUnloadEventOnExit = useUnloadEventOnExit;
|
|
54
|
+
/** When the exitAction is the Logout you can use the custom hook useUnloadEventLogout which is the customization of the useUnloadEventOnExit using the logout as an exit action. */
|
|
55
|
+
const useUnloadEventLogout = () => {
|
|
56
|
+
const onExit = (0, exports.useUnloadEventOnExit)();
|
|
57
|
+
return () => onExit(() => window.location.assign(env_1.CONFIG.URL_FE.LOGOUT));
|
|
58
|
+
};
|
|
59
|
+
exports.useUnloadEventLogout = useUnloadEventLogout;
|
|
60
|
+
//# sourceMappingURL=useUnloadEventInterceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUnloadEventInterceptor.js","sourceRoot":"","sources":["../../src/lib/hooks/useUnloadEventInterceptor.ts"],"names":[],"mappings":";;;AAAA,iCAAkC;AAClC,6CAAuD;AACvD,uCAAuC;AACvC,iEAAgE;AAChE,mEAAoE;AAEpE;;;GAGG;AACI,MAAM,yBAAyB,GAAG,GAAG,EAAE;IAC5C,MAAM,QAAQ,GAAG,IAAA,yBAAW,GAAE,CAAC;IAC/B,MAAM,mBAAmB,GAAG,CAAC,KAAc,EAAE,WAAoB,EAAE,EAAE;QACnE,QAAQ,CAAC,+BAAe,CAAC,4BAA4B,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;IACjF,CAAC,CAAC;IAEF,MAAM,qBAAqB,GAAG,GAAG,EAAE;QACjC,QAAQ,CAAC,+BAAe,CAAC,6BAA6B,EAAE,CAAC,CAAC;IAC5D,CAAC,CAAC;IAEF,OAAO;QACL,mBAAmB;QACnB,qBAAqB;KACtB,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,yBAAyB,6BAcpC;AAEF,2OAA2O;AACpO,MAAM,oCAAoC,GAAG,CAAC,KAAc,EAAE,WAAoB,EAAE,EAAE;IAC3F,MAAM,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,GAAG,IAAA,iCAAyB,GAAE,CAAC;IACnF,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,mBAAmB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QACxC,OAAO,GAAG,EAAE,CAAC,qBAAqB,EAAE,CAAC;IACvC,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO;QACL,mBAAmB;QACnB,qBAAqB;KACtB,CAAC;AACJ,CAAC,CAAC;AAVW,QAAA,oCAAoC,wCAU/C;AAEF,+OAA+O;AACxO,MAAM,oBAAoB,GAAG,GAAG,EAAE;IACvC,MAAM,QAAQ,GAAG,IAAA,yBAAW,GAAE,CAAC;IAC/B,MAAM,kBAAkB,GAAG,IAAA,yBAAW,EAAC,iCAAiB,CAAC,8BAA8B,CAAC,CAAC;IACzF,OAAO,CAAC,UAAsB,EAAE,EAAE;QAChC,IAAI,kBAAkB,CAAC,OAAO,EAAE;YAC9B,QAAQ,CAAC,+BAAe,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAC;SAC7D;aAAM;YACL,UAAU,EAAE,CAAC;SACd;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAVW,QAAA,oBAAoB,wBAU/B;AAEF,oLAAoL;AAC7K,MAAM,oBAAoB,GAAG,GAAG,EAAE;IACvC,MAAM,MAAM,GAAG,IAAA,4BAAoB,GAAE,CAAC;IACtC,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;AAC1E,CAAC,CAAC;AAHW,QAAA,oBAAoB,wBAG/B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_redux_1 = require("react-redux");
|
|
4
|
+
const appStateSlice_1 = require("../redux/slices/appStateSlice");
|
|
5
|
+
/** @see {@link UserNotifyHandle} */
|
|
6
|
+
function default_1() {
|
|
7
|
+
const dispatch = (0, react_redux_1.useDispatch)();
|
|
8
|
+
return (notify) => dispatch(appStateSlice_1.appStateActions.addNotify(notify));
|
|
9
|
+
}
|
|
10
|
+
exports.default = default_1;
|
|
11
|
+
//# sourceMappingURL=useUserNotify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUserNotify.js","sourceRoot":"","sources":["../../src/lib/hooks/useUserNotify.ts"],"names":[],"mappings":";;AAAA,6CAA0C;AAE1C,iEAAgE;AAEhE,oCAAoC;AACpC;IACE,MAAM,QAAQ,GAAG,IAAA,yBAAW,GAAE,CAAC;IAC/B,OAAO,CAAC,MAAkB,EAAE,EAAE,CAAC,QAAQ,CAAC,+BAAe,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7E,CAAC;AAHD,4BAGC"}
|
package/index.d.ts
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
export { default as Header } from './components/Header/Header';
|
|
2
|
-
export * from './components/Header/Header';
|
|
3
2
|
export { default as Footer } from './components/Footer/Footer';
|
|
4
|
-
export * from './components/Footer/Footer';
|
|
5
3
|
export { default as CustomAvatar } from './components/CustomAvatar';
|
|
6
|
-
export * from './components/CustomAvatar';
|
|
7
4
|
export { default as CustomPagination } from './components/CustomPagination';
|
|
8
|
-
export * from './components/CustomPagination';
|
|
9
5
|
export { default as FilterModal } from './components/FilterModal';
|
|
10
|
-
export * from './components/FilterModal';
|
|
11
6
|
export { default as SessionModal } from './components/SessionModal';
|
|
12
|
-
export * from './components/SessionModal';
|
|
13
7
|
export { default as TitleBox } from './components/TitleBox';
|
|
14
|
-
export * from './components/TitleBox';
|
|
15
8
|
export { default as Toast } from './components/Toast';
|
|
16
|
-
export
|
|
9
|
+
export { default as EndingPage } from './components/EndingPage';
|
|
17
10
|
export { default as ErrorBoundary } from './components/ErrorBoundary/ErrorBoundary';
|
|
18
|
-
export * from './components/ErrorBoundary/ErrorBoundary';
|
|
19
11
|
export { default as LoadingOverlay } from './components/Loading/LoadingOverlay';
|
|
20
|
-
export
|
|
21
|
-
export { default as
|
|
12
|
+
export { default as UserNotifyHandle } from './components/UserNotifyHandle';
|
|
13
|
+
export { default as UnloadEventHandler } from './components/UnloadEventHandler';
|
package/index.js
CHANGED
|
@@ -1,37 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
6
|
+
exports.UnloadEventHandler = exports.UserNotifyHandle = exports.LoadingOverlay = exports.ErrorBoundary = exports.EndingPage = exports.Toast = exports.TitleBox = exports.SessionModal = exports.FilterModal = exports.CustomPagination = exports.CustomAvatar = exports.Footer = exports.Header = void 0;
|
|
5
7
|
var Header_1 = require("./components/Header/Header");
|
|
6
|
-
Object.defineProperty(exports, "Header", { enumerable: true, get: function () { return
|
|
7
|
-
(0, tslib_1.__exportStar)(require("./components/Header/Header"), exports);
|
|
8
|
+
Object.defineProperty(exports, "Header", { enumerable: true, get: function () { return __importDefault(Header_1).default; } });
|
|
8
9
|
var Footer_1 = require("./components/Footer/Footer");
|
|
9
|
-
Object.defineProperty(exports, "Footer", { enumerable: true, get: function () { return
|
|
10
|
-
(0, tslib_1.__exportStar)(require("./components/Footer/Footer"), exports);
|
|
10
|
+
Object.defineProperty(exports, "Footer", { enumerable: true, get: function () { return __importDefault(Footer_1).default; } });
|
|
11
11
|
var CustomAvatar_1 = require("./components/CustomAvatar");
|
|
12
|
-
Object.defineProperty(exports, "CustomAvatar", { enumerable: true, get: function () { return
|
|
13
|
-
(0, tslib_1.__exportStar)(require("./components/CustomAvatar"), exports);
|
|
12
|
+
Object.defineProperty(exports, "CustomAvatar", { enumerable: true, get: function () { return __importDefault(CustomAvatar_1).default; } });
|
|
14
13
|
var CustomPagination_1 = require("./components/CustomPagination");
|
|
15
|
-
Object.defineProperty(exports, "CustomPagination", { enumerable: true, get: function () { return
|
|
16
|
-
(0, tslib_1.__exportStar)(require("./components/CustomPagination"), exports);
|
|
14
|
+
Object.defineProperty(exports, "CustomPagination", { enumerable: true, get: function () { return __importDefault(CustomPagination_1).default; } });
|
|
17
15
|
var FilterModal_1 = require("./components/FilterModal");
|
|
18
|
-
Object.defineProperty(exports, "FilterModal", { enumerable: true, get: function () { return
|
|
19
|
-
(0, tslib_1.__exportStar)(require("./components/FilterModal"), exports);
|
|
16
|
+
Object.defineProperty(exports, "FilterModal", { enumerable: true, get: function () { return __importDefault(FilterModal_1).default; } });
|
|
20
17
|
var SessionModal_1 = require("./components/SessionModal");
|
|
21
|
-
Object.defineProperty(exports, "SessionModal", { enumerable: true, get: function () { return
|
|
22
|
-
(0, tslib_1.__exportStar)(require("./components/SessionModal"), exports);
|
|
18
|
+
Object.defineProperty(exports, "SessionModal", { enumerable: true, get: function () { return __importDefault(SessionModal_1).default; } });
|
|
23
19
|
var TitleBox_1 = require("./components/TitleBox");
|
|
24
|
-
Object.defineProperty(exports, "TitleBox", { enumerable: true, get: function () { return
|
|
25
|
-
(0, tslib_1.__exportStar)(require("./components/TitleBox"), exports);
|
|
20
|
+
Object.defineProperty(exports, "TitleBox", { enumerable: true, get: function () { return __importDefault(TitleBox_1).default; } });
|
|
26
21
|
var Toast_1 = require("./components/Toast");
|
|
27
|
-
Object.defineProperty(exports, "Toast", { enumerable: true, get: function () { return
|
|
28
|
-
|
|
22
|
+
Object.defineProperty(exports, "Toast", { enumerable: true, get: function () { return __importDefault(Toast_1).default; } });
|
|
23
|
+
var EndingPage_1 = require("./components/EndingPage");
|
|
24
|
+
Object.defineProperty(exports, "EndingPage", { enumerable: true, get: function () { return __importDefault(EndingPage_1).default; } });
|
|
29
25
|
var ErrorBoundary_1 = require("./components/ErrorBoundary/ErrorBoundary");
|
|
30
|
-
Object.defineProperty(exports, "ErrorBoundary", { enumerable: true, get: function () { return
|
|
31
|
-
(0, tslib_1.__exportStar)(require("./components/ErrorBoundary/ErrorBoundary"), exports);
|
|
26
|
+
Object.defineProperty(exports, "ErrorBoundary", { enumerable: true, get: function () { return __importDefault(ErrorBoundary_1).default; } });
|
|
32
27
|
var LoadingOverlay_1 = require("./components/Loading/LoadingOverlay");
|
|
33
|
-
Object.defineProperty(exports, "LoadingOverlay", { enumerable: true, get: function () { return
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
Object.defineProperty(exports, "LoadingOverlay", { enumerable: true, get: function () { return __importDefault(LoadingOverlay_1).default; } });
|
|
29
|
+
var UserNotifyHandle_1 = require("./components/UserNotifyHandle");
|
|
30
|
+
Object.defineProperty(exports, "UserNotifyHandle", { enumerable: true, get: function () { return __importDefault(UserNotifyHandle_1).default; } });
|
|
31
|
+
var UnloadEventHandler_1 = require("./components/UnloadEventHandler");
|
|
32
|
+
Object.defineProperty(exports, "UnloadEventHandler", { enumerable: true, get: function () { return __importDefault(UnloadEventHandler_1).default; } });
|
|
37
33
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":";;;;;;AAAA,qDAA+D;AAAtD,iHAAA,OAAO,OAAU;AAC1B,qDAA+D;AAAtD,iHAAA,OAAO,OAAU;AAC1B,0DAAoE;AAA3D,6HAAA,OAAO,OAAgB;AAChC,kEAA4E;AAAnE,qIAAA,OAAO,OAAoB;AACpC,wDAAkE;AAAzD,2HAAA,OAAO,OAAe;AAC/B,0DAAoE;AAA3D,6HAAA,OAAO,OAAgB;AAChC,kDAA4D;AAAnD,qHAAA,OAAO,OAAY;AAC5B,4CAAsD;AAA7C,+GAAA,OAAO,OAAS;AACzB,sDAAgE;AAAvD,yHAAA,OAAO,OAAc;AAE9B,0EAAoF;AAA3E,+HAAA,OAAO,OAAiB;AACjC,sEAAgF;AAAvE,iIAAA,OAAO,OAAkB;AAClC,kEAA4E;AAAnE,qIAAA,OAAO,OAAoB;AACpC,sEAAgF;AAAvE,yIAAA,OAAO,OAAsB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare type UserNotify = {
|
|
3
|
+
/** The identifier used to recognize the user notify: it cannot be possible to have the same error id at the same time */
|
|
4
|
+
id: string;
|
|
5
|
+
/** The title to show in the popup or toast */
|
|
6
|
+
title: string;
|
|
7
|
+
/** The body to show in the popup or toast */
|
|
8
|
+
message: React.ReactNode;
|
|
9
|
+
/** If component === 'Toast'. The logo to be rendered. As default a confirm logo will be used */
|
|
10
|
+
logo?: React.ElementType;
|
|
11
|
+
/** If component === 'Toast'. The color used for the left border */
|
|
12
|
+
leftBorderColor?: string;
|
|
13
|
+
/** If component === 'SessionModal'. If defined, it will render a confirm button which will execute this function */
|
|
14
|
+
onConfirm?: () => void;
|
|
15
|
+
/** If component === 'SessionModal'. If present, this string will rappresent the confirm button label */
|
|
16
|
+
confirmLabel?: string;
|
|
17
|
+
/** If defined, it will be executed when closing the popup */
|
|
18
|
+
onClose?: () => void;
|
|
19
|
+
/** If component === 'SessionModal'. The close button label */
|
|
20
|
+
closeLabel?: string;
|
|
21
|
+
/** Can render a SessionModal or Toast component */
|
|
22
|
+
component?: 'SessionModal' | 'Toast';
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserNotify.js","sourceRoot":"","sources":["../../src/lib/model/UserNotify.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagopa/selfcare-common-frontend",
|
|
3
3
|
"description": "Shared React components for the pagopa selfcare project",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/pagopa/selfcare-common-frontend",
|
|
7
7
|
"author": "https://www.pagopa.gov.it",
|
|
@@ -55,16 +55,16 @@
|
|
|
55
55
|
"build": "yarn setTsConfigStart && react-scripts build",
|
|
56
56
|
"clean:build": "rimraf build",
|
|
57
57
|
"setTsConfigDist": "copyfiles tsconfigDist.json build && renamer --replace tsconfig.json build/tsconfigDist.json && copyfiles -u 1 build/tsconfig.json . && rimraf build/tsconfig.json",
|
|
58
|
-
"cpDistStatic": "copyfiles -u 2 src/lib/index.css dist && copyfiles package.json README.md CHANGELOG.md dist",
|
|
58
|
+
"cpDistStatic": "copyfiles -u 2 src/lib/index.css src/lib/utils/fixSwagger20ArraySchemaDef.js dist && copyfiles package.json README.md CHANGELOG.md dist",
|
|
59
59
|
"dist": "yarn setTsConfigDist && tsc && yarn cpDistStatic",
|
|
60
60
|
"clean:dist": "rimraf dist",
|
|
61
|
-
"test": "yarn setTsConfigStart && react-scripts test
|
|
62
|
-
"test:coverage": "react-scripts test
|
|
61
|
+
"test": "yarn setTsConfigStart && react-scripts test -i",
|
|
62
|
+
"test:coverage": "react-scripts test -i --coverage",
|
|
63
63
|
"clean:coverage": "rimraf coverage",
|
|
64
64
|
"lint-autofix": "yarn setTsConfigStart && eslint . -c .eslintrc.js --ext .ts,.tsx --fix",
|
|
65
65
|
"lint": "yarn setTsConfigStart && eslint . -c .eslintrc.js --ext .ts,.tsx ",
|
|
66
66
|
"prettify": "prettier --write \"./**/*.{ts,tsx}\"",
|
|
67
|
-
"version": "auto-changelog -p --config .auto-changelog.json
|
|
67
|
+
"version": "auto-changelog -p --config .auto-changelog.json && git add CHANGELOG.md"
|
|
68
68
|
},
|
|
69
69
|
"eslintConfig": {
|
|
70
70
|
"extends": [
|
|
@@ -112,7 +112,15 @@
|
|
|
112
112
|
"coveragePathIgnorePatterns": [
|
|
113
113
|
"src/index.tsx",
|
|
114
114
|
"src/reportWebVitals.ts",
|
|
115
|
-
"src/api/generated"
|
|
115
|
+
"src/api/generated",
|
|
116
|
+
"src/examples/*",
|
|
117
|
+
"src/AppExample.tsx",
|
|
118
|
+
"src/lib/utils/fixSwagger20ArraySchemaDef.js",
|
|
119
|
+
"src/lib/common-polyfill.ts",
|
|
120
|
+
"src/lib/index.ts",
|
|
121
|
+
"src/lib/components/icons/*",
|
|
122
|
+
"src/lib/model/*",
|
|
123
|
+
"src/store.ts"
|
|
116
124
|
]
|
|
117
125
|
}
|
|
118
126
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PayloadAction } from '@reduxjs/toolkit';
|
|
2
2
|
import { ErrorInfo } from 'react';
|
|
3
|
+
import { UserNotify } from '../../model/UserNotify';
|
|
3
4
|
export declare type AppError = {
|
|
4
5
|
/** The identifier used to recognize the error: it cannot be possible to have the same error id at the same time */
|
|
5
6
|
id: string;
|
|
@@ -31,6 +32,14 @@ interface AppStateState {
|
|
|
31
32
|
};
|
|
32
33
|
};
|
|
33
34
|
errors: Array<AppError>;
|
|
35
|
+
userNotifies: Array<UserNotify>;
|
|
36
|
+
unloadEventConfiguration: {
|
|
37
|
+
enabled: boolean;
|
|
38
|
+
open: boolean;
|
|
39
|
+
title?: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
exitAction?: () => void;
|
|
42
|
+
};
|
|
34
43
|
}
|
|
35
44
|
export declare const appStateSlice: import("@reduxjs/toolkit").Slice<AppStateState, {
|
|
36
45
|
setLoading: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<{
|
|
@@ -39,6 +48,15 @@ export declare const appStateSlice: import("@reduxjs/toolkit").Slice<AppStateSta
|
|
|
39
48
|
}>) => void;
|
|
40
49
|
addError: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<AppError>) => void;
|
|
41
50
|
removeError: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<AppError>) => void;
|
|
51
|
+
addNotify: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<UserNotify>) => void;
|
|
52
|
+
removeNotify: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<UserNotify>) => void;
|
|
53
|
+
enableUnloadEventInterceptor: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<{
|
|
54
|
+
title?: string;
|
|
55
|
+
description?: string;
|
|
56
|
+
}>) => void;
|
|
57
|
+
disableUnloadEventInterceptor: (state: import("immer/dist/internal").WritableDraft<AppStateState>) => void;
|
|
58
|
+
openUnloadEventNotify: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<() => void>) => void;
|
|
59
|
+
closeUnloadEventNotify: (state: import("immer/dist/internal").WritableDraft<AppStateState>) => void;
|
|
42
60
|
}, "appState">;
|
|
43
61
|
export declare const appStateActions: import("@reduxjs/toolkit").CaseReducerActions<{
|
|
44
62
|
setLoading: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<{
|
|
@@ -47,10 +65,35 @@ export declare const appStateActions: import("@reduxjs/toolkit").CaseReducerActi
|
|
|
47
65
|
}>) => void;
|
|
48
66
|
addError: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<AppError>) => void;
|
|
49
67
|
removeError: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<AppError>) => void;
|
|
68
|
+
addNotify: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<UserNotify>) => void;
|
|
69
|
+
removeNotify: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<UserNotify>) => void;
|
|
70
|
+
enableUnloadEventInterceptor: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<{
|
|
71
|
+
title?: string;
|
|
72
|
+
description?: string;
|
|
73
|
+
}>) => void;
|
|
74
|
+
disableUnloadEventInterceptor: (state: import("immer/dist/internal").WritableDraft<AppStateState>) => void;
|
|
75
|
+
openUnloadEventNotify: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<() => void>) => void;
|
|
76
|
+
closeUnloadEventNotify: (state: import("immer/dist/internal").WritableDraft<AppStateState>) => void;
|
|
50
77
|
}>;
|
|
51
78
|
export declare const appStateReducer: import("redux").Reducer<AppStateState, import("redux").AnyAction>;
|
|
52
79
|
export declare const appStateSelectors: {
|
|
53
|
-
selectLoading: (state:
|
|
54
|
-
|
|
80
|
+
selectLoading: (state: {
|
|
81
|
+
appState: AppStateState;
|
|
82
|
+
}) => boolean;
|
|
83
|
+
selectErrors: (state: {
|
|
84
|
+
appState: AppStateState;
|
|
85
|
+
}) => AppError[];
|
|
86
|
+
selectNotifies: (state: {
|
|
87
|
+
appState: AppStateState;
|
|
88
|
+
}) => UserNotify[];
|
|
89
|
+
selectUnloadEventConfiguration: (state: {
|
|
90
|
+
appState: AppStateState;
|
|
91
|
+
}) => {
|
|
92
|
+
enabled: boolean;
|
|
93
|
+
open: boolean;
|
|
94
|
+
title?: string | undefined;
|
|
95
|
+
description?: string | undefined;
|
|
96
|
+
exitAction?: (() => void) | undefined;
|
|
97
|
+
};
|
|
55
98
|
};
|
|
56
99
|
export {};
|
|
@@ -8,6 +8,18 @@ const initialState = {
|
|
|
8
8
|
tasks: {},
|
|
9
9
|
},
|
|
10
10
|
errors: [],
|
|
11
|
+
userNotifies: [],
|
|
12
|
+
unloadEventConfiguration: {
|
|
13
|
+
enabled: false,
|
|
14
|
+
open: false,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
const keepOnPage = (e) => {
|
|
18
|
+
const message = "Warning!\n\nNavigating away from this page will delete your text if you haven't already saved it.";
|
|
19
|
+
e.preventDefault();
|
|
20
|
+
// eslint-disable-next-line functional/immutable-data
|
|
21
|
+
e.returnValue = message;
|
|
22
|
+
return message;
|
|
11
23
|
};
|
|
12
24
|
/* eslint-disable functional/immutable-data */
|
|
13
25
|
exports.appStateSlice = (0, toolkit_1.createSlice)({
|
|
@@ -25,11 +37,40 @@ exports.appStateSlice = (0, toolkit_1.createSlice)({
|
|
|
25
37
|
}
|
|
26
38
|
},
|
|
27
39
|
addError: (state, action) => {
|
|
40
|
+
if (!action.payload.component) {
|
|
41
|
+
action.payload.component = 'SessionModal';
|
|
42
|
+
}
|
|
28
43
|
state.errors.push(action.payload);
|
|
29
44
|
},
|
|
30
45
|
removeError: (state, action) => {
|
|
31
46
|
state.errors = state.errors.filter((e) => e.id !== action.payload.id);
|
|
32
47
|
},
|
|
48
|
+
addNotify: (state, action) => {
|
|
49
|
+
state.userNotifies.push(action.payload);
|
|
50
|
+
},
|
|
51
|
+
removeNotify: (state, action) => {
|
|
52
|
+
state.userNotifies = state.userNotifies.filter((e) => e.id !== action.payload.id);
|
|
53
|
+
},
|
|
54
|
+
enableUnloadEventInterceptor: (state, action) => {
|
|
55
|
+
state.unloadEventConfiguration.open = false;
|
|
56
|
+
state.unloadEventConfiguration.enabled = true;
|
|
57
|
+
state.unloadEventConfiguration.title = action.payload.title;
|
|
58
|
+
state.unloadEventConfiguration.description = action.payload.description;
|
|
59
|
+
window.addEventListener('beforeunload', keepOnPage);
|
|
60
|
+
},
|
|
61
|
+
disableUnloadEventInterceptor: (state) => {
|
|
62
|
+
state.unloadEventConfiguration.open = false;
|
|
63
|
+
state.unloadEventConfiguration.enabled = false;
|
|
64
|
+
window.removeEventListener('beforeunload', keepOnPage);
|
|
65
|
+
},
|
|
66
|
+
openUnloadEventNotify: (state, action) => {
|
|
67
|
+
state.unloadEventConfiguration.open = true;
|
|
68
|
+
state.unloadEventConfiguration.exitAction = action.payload;
|
|
69
|
+
},
|
|
70
|
+
closeUnloadEventNotify: (state) => {
|
|
71
|
+
state.unloadEventConfiguration.open = false;
|
|
72
|
+
state.unloadEventConfiguration.exitAction = undefined;
|
|
73
|
+
},
|
|
33
74
|
},
|
|
34
75
|
});
|
|
35
76
|
exports.appStateActions = exports.appStateSlice.actions;
|
|
@@ -37,5 +78,7 @@ exports.appStateReducer = exports.appStateSlice.reducer;
|
|
|
37
78
|
exports.appStateSelectors = {
|
|
38
79
|
selectLoading: (state) => state.appState.loading.result,
|
|
39
80
|
selectErrors: (state) => state.appState.errors,
|
|
81
|
+
selectNotifies: (state) => state.appState.userNotifies,
|
|
82
|
+
selectUnloadEventConfiguration: (state) => state.appState.unloadEventConfiguration,
|
|
40
83
|
};
|
|
41
84
|
//# sourceMappingURL=appStateSlice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appStateSlice.js","sourceRoot":"","sources":["../../../src/lib/redux/slices/appStateSlice.ts"],"names":[],"mappings":";;;AAAA,8CAA8D;
|
|
1
|
+
{"version":3,"file":"appStateSlice.js","sourceRoot":"","sources":["../../../src/lib/redux/slices/appStateSlice.ts"],"names":[],"mappings":";;;AAAA,8CAA8D;AA4C9D,MAAM,YAAY,GAAkB;IAClC,OAAO,EAAE;QACP,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,EAAE;KACV;IACD,MAAM,EAAE,EAAE;IACV,YAAY,EAAE,EAAE;IAChB,wBAAwB,EAAE;QACxB,OAAO,EAAE,KAAK;QACd,IAAI,EAAE,KAAK;KACZ;CACF,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,CAAoB,EAAE,EAAE;IAC1C,MAAM,OAAO,GACX,mGAAmG,CAAC;IACtG,CAAC,CAAC,cAAc,EAAE,CAAC;IACnB,qDAAqD;IACrD,CAAC,CAAC,WAAW,GAAG,OAAO,CAAC;IACxB,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,8CAA8C;AACjC,QAAA,aAAa,GAAG,IAAA,qBAAW,EAAC;IACvC,IAAI,EAAE,UAAU;IAChB,YAAY;IACZ,QAAQ,EAAE;QACR,UAAU,EAAE,CAAC,KAAK,EAAE,MAAyD,EAAE,EAAE;YAC/E,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE;gBAC1B,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;gBAC5B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAA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CAAC,KAAkC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY;IACnF,8BAA8B,EAAE,CAAC,KAAkC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,wBAAwB;CAChH,CAAC"}
|
|
@@ -11,6 +11,8 @@ export declare const userActions: import("@reduxjs/toolkit").CaseReducerActions<
|
|
|
11
11
|
}>;
|
|
12
12
|
export declare const userReducer: import("redux").Reducer<UserState, import("redux").AnyAction>;
|
|
13
13
|
export declare const userSelectors: {
|
|
14
|
-
selectLoggedUser: (state:
|
|
14
|
+
selectLoggedUser: (state: {
|
|
15
|
+
user: UserState;
|
|
16
|
+
}) => User | undefined;
|
|
15
17
|
};
|
|
16
18
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userSlice.js","sourceRoot":"","sources":["../../../src/lib/redux/slices/userSlice.ts"],"names":[],"mappings":";;;AAAA,8CAA8D;AAO9D,MAAM,YAAY,GAAc,EAAE,CAAC;AAEnC,8CAA8C;AACjC,QAAA,SAAS,GAAG,IAAA,qBAAW,EAAC;IACnC,IAAI,EAAE,MAAM;IACZ,YAAY;IACZ,QAAQ,EAAE;QACR,aAAa,EAAE,CAAC,KAAK,EAAE,MAA2B,EAAE,EAAE;YACpD,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;QAChC,CAAC;KACF;CACF,CAAC,CAAC;AAEU,QAAA,WAAW,GAAG,iBAAS,CAAC,OAAO,CAAC;AAChC,QAAA,WAAW,GAAG,iBAAS,CAAC,OAAO,CAAC;AAEhC,QAAA,aAAa,GAAG;IAC3B,gBAAgB,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"userSlice.js","sourceRoot":"","sources":["../../../src/lib/redux/slices/userSlice.ts"],"names":[],"mappings":";;;AAAA,8CAA8D;AAO9D,MAAM,YAAY,GAAc,EAAE,CAAC;AAEnC,8CAA8C;AACjC,QAAA,SAAS,GAAG,IAAA,qBAAW,EAAC;IACnC,IAAI,EAAE,MAAM;IACZ,YAAY;IACZ,QAAQ,EAAE;QACR,aAAa,EAAE,CAAC,KAAK,EAAE,MAA2B,EAAE,EAAE;YACpD,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;QAChC,CAAC;KACF;CACF,CAAC,CAAC;AAEU,QAAA,WAAW,GAAG,iBAAS,CAAC,OAAO,CAAC;AAChC,QAAA,WAAW,GAAG,iBAAS,CAAC,OAAO,CAAC;AAEhC,QAAA,aAAa,GAAG;IAC3B,gBAAgB,EAAE,CAAC,KAA0B,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM;CACpE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ApiRequestType, IResponseType, TypeofApiResponse } from '@pagopa/ts-commons/lib/requests';
|
|
2
|
+
import * as t from 'io-ts';
|
|
3
|
+
import { EnhancedStore } from '@reduxjs/toolkit';
|
|
4
|
+
/** To show an error popup to inform of the not valid session */
|
|
5
|
+
export declare const onRedirectToLogin: (store: EnhancedStore) => {
|
|
6
|
+
payload: import("../redux/slices/appStateSlice").AppError;
|
|
7
|
+
type: string;
|
|
8
|
+
};
|
|
9
|
+
/** Return the implementation of fetch configured with a timeout */
|
|
10
|
+
export declare const buildFetchApi: (timeoutMs?: number) => (input: string | Request, init?: RequestInit | undefined) => Promise<Response>;
|
|
11
|
+
/** Extract the response of a @pagopa/openapi-codegen-ts generated client rest invocation having status code successHttpStatus.
|
|
12
|
+
If notValidTokenHttpStatus is not null and the returned status is equal to notValidTokenHttpStatus, it will call the onRedirectToLogin function and will schedule the redirect towards logout path.
|
|
13
|
+
If notAuthorizedTokenHttpStatus is not null and the returned status is equal to notAuthorizedTokenHttpStatus, it will throw an Error with message "Operation not allowed".
|
|
14
|
+
If emptyResponseHttpStatus is not null and the returned status is equal to emptyResponseHttpStatus, it will return a promise that resolve to null value.
|
|
15
|
+
Other statuses will return will throw a generic error. */
|
|
16
|
+
export declare const extractResponse: <R>(response: t.Validation<TypeofApiResponse<ApiRequestType<any, any, any, IResponseType<any, any, any>>>>, successHttpStatus: number, onRedirectToLogin: () => void, notValidTokenHttpStatus?: number | null, notAuthorizedTokenHttpStatus?: number | null, emptyResponseHttpStatus?: number | null) => Promise<R>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractResponse = exports.buildFetchApi = exports.onRedirectToLogin = void 0;
|
|
4
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
5
|
+
const ts_commons_1 = require("@pagopa/ts-commons");
|
|
6
|
+
const fetch_1 = require("@pagopa/ts-commons/lib/fetch");
|
|
7
|
+
const env_1 = require("../config/env");
|
|
8
|
+
const appStateSlice_1 = require("../redux/slices/appStateSlice");
|
|
9
|
+
/** To show an error popup to inform of the not valid session */
|
|
10
|
+
const onRedirectToLogin = (store) => store.dispatch(appStateSlice_1.appStateActions.addError({
|
|
11
|
+
id: 'tokenNotValid',
|
|
12
|
+
error: new Error(),
|
|
13
|
+
techDescription: 'token expired or not valid',
|
|
14
|
+
toNotify: false,
|
|
15
|
+
blocking: false,
|
|
16
|
+
displayableTitle: 'Sessione scaduta',
|
|
17
|
+
displayableDescription: 'Stai per essere rediretto alla pagina di login...',
|
|
18
|
+
}));
|
|
19
|
+
exports.onRedirectToLogin = onRedirectToLogin;
|
|
20
|
+
/** Return the implementation of fetch configured with a timeout */
|
|
21
|
+
const buildFetchApi = (timeoutMs = 300000) => {
|
|
22
|
+
// Must be an https endpoint so we use an https agent
|
|
23
|
+
const abortableFetch = (0, fetch_1.AbortableFetch)(ts_commons_1.agent.getHttpFetch(process.env));
|
|
24
|
+
const fetchWithTimeout = (0, fetch_1.toFetch)((0, fetch_1.setFetchTimeout)(timeoutMs, abortableFetch));
|
|
25
|
+
// tslint:disable-next-line: no-any
|
|
26
|
+
return fetch;
|
|
27
|
+
};
|
|
28
|
+
exports.buildFetchApi = buildFetchApi;
|
|
29
|
+
/** Extract the response of a @pagopa/openapi-codegen-ts generated client rest invocation having status code successHttpStatus.
|
|
30
|
+
If notValidTokenHttpStatus is not null and the returned status is equal to notValidTokenHttpStatus, it will call the onRedirectToLogin function and will schedule the redirect towards logout path.
|
|
31
|
+
If notAuthorizedTokenHttpStatus is not null and the returned status is equal to notAuthorizedTokenHttpStatus, it will throw an Error with message "Operation not allowed".
|
|
32
|
+
If emptyResponseHttpStatus is not null and the returned status is equal to emptyResponseHttpStatus, it will return a promise that resolve to null value.
|
|
33
|
+
Other statuses will return will throw a generic error. */
|
|
34
|
+
const extractResponse = async (response, successHttpStatus, onRedirectToLogin, notValidTokenHttpStatus = 401, notAuthorizedTokenHttpStatus = 403, emptyResponseHttpStatus = 404) => {
|
|
35
|
+
if ((0, Either_1.isRight)(response)) {
|
|
36
|
+
if (response.right.status === successHttpStatus) {
|
|
37
|
+
return response.right.value;
|
|
38
|
+
}
|
|
39
|
+
else if (notValidTokenHttpStatus && response.right.status === notValidTokenHttpStatus) {
|
|
40
|
+
onRedirectToLogin();
|
|
41
|
+
window.setTimeout(() => window.location.assign(env_1.CONFIG.URL_FE.LOGOUT), 2000);
|
|
42
|
+
return new Promise(() => null);
|
|
43
|
+
}
|
|
44
|
+
else if (notAuthorizedTokenHttpStatus &&
|
|
45
|
+
response.right.status === notAuthorizedTokenHttpStatus) {
|
|
46
|
+
throw new Error(`Operation not allowed!`);
|
|
47
|
+
}
|
|
48
|
+
else if (emptyResponseHttpStatus && response.right.status === emptyResponseHttpStatus) {
|
|
49
|
+
return new Promise((resolve) => resolve(null));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.error(JSON.stringify(response.right));
|
|
53
|
+
throw new Error(`Unexpected HTTP status! Expected ${successHttpStatus} obtained ${response.right.status}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
console.error('Something gone wrong while fetching data');
|
|
58
|
+
console.error(JSON.stringify(response.left));
|
|
59
|
+
throw (0, Either_1.toError)(response.left);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
exports.extractResponse = extractResponse;
|
|
63
|
+
//# sourceMappingURL=api-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-utils.js","sourceRoot":"","sources":["../../src/lib/utils/api-utils.ts"],"names":[],"mappings":";;;AACA,6CAAoD;AAEpD,mDAA2C;AAC3C,wDAAwF;AAGxF,uCAAuC;AACvC,iEAAgE;AAEhE,gEAAgE;AACzD,MAAM,iBAAiB,GAAG,CAAC,KAAoB,EAAE,EAAE,CACxD,KAAK,CAAC,QAAQ,CACZ,+BAAe,CAAC,QAAQ,CAAC;IACvB,EAAE,EAAE,eAAe;IACnB,KAAK,EAAE,IAAI,KAAK,EAAE;IAClB,eAAe,EAAE,4BAA4B;IAC7C,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,KAAK;IACf,gBAAgB,EAAE,kBAAkB;IACpC,sBAAsB,EAAE,mDAAmD;CAC5E,CAAC,CACH,CAAC;AAXS,QAAA,iBAAiB,qBAW1B;AAEJ,mEAAmE;AAC5D,MAAM,aAAa,GAAG,CAAC,YAAoB,MAAM,EAA2B,EAAE;IACnF,qDAAqD;IACrD,MAAM,cAAc,GAAG,IAAA,sBAAc,EAAC,kBAAK,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IACvE,MAAM,gBAAgB,GAAG,IAAA,eAAO,EAAC,IAAA,uBAAe,EAAC,SAAwB,EAAE,cAAc,CAAC,CAAC,CAAC;IAC5F,mCAAmC;IACnC,OAAO,KAAuC,CAAC;AACjD,CAAC,CAAC;AANW,QAAA,aAAa,iBAMxB;AAEF;;;;yDAIyD;AAClD,MAAM,eAAe,GAAG,KAAK,EAClC,QAEC,EACD,iBAAyB,EACzB,iBAA6B,EAC7B,0BAAyC,GAAG,EAC5C,+BAA8C,GAAG,EACjD,0BAAyC,GAAG,EACh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C,CAAC;KAC9B;AACH,CAAC,CAAC;AAnCW,QAAA,eAAe,mBAmC1B"}
|
package/utils/constants.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { UserRole } from '../model/Party';
|
|
2
|
+
/** The key used to store in the session storage the loggedUser in selfcare projects */
|
|
2
3
|
export declare const STORAGE_KEY_USER = "user";
|
|
4
|
+
/** The key used to store in the session storage the logged user token in selfcare projects */
|
|
3
5
|
export declare const STORAGE_KEY_TOKEN = "token";
|
|
4
6
|
export declare const LOADING_TASK_LOGIN_CHECK = "LOGIN_CHECK";
|
|
7
|
+
/** The short and long labels used for the roles of selfcare's projects */
|
|
5
8
|
export declare const roleLabels: {
|
|
6
9
|
[key in UserRole]: {
|
|
7
10
|
shortLabel: string;
|
package/utils/constants.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.roleLabels = exports.LOADING_TASK_LOGIN_CHECK = exports.STORAGE_KEY_TOKEN = exports.STORAGE_KEY_USER = void 0;
|
|
4
|
+
/** The key used to store in the session storage the loggedUser in selfcare projects */
|
|
4
5
|
exports.STORAGE_KEY_USER = 'user';
|
|
6
|
+
/** The key used to store in the session storage the logged user token in selfcare projects */
|
|
5
7
|
exports.STORAGE_KEY_TOKEN = 'token';
|
|
6
8
|
exports.LOADING_TASK_LOGIN_CHECK = 'LOGIN_CHECK';
|
|
9
|
+
/** The short and long labels used for the roles of selfcare's projects */
|
|
7
10
|
exports.roleLabels = {
|
|
8
11
|
ADMIN: { shortLabel: 'Ref. Amministrativo', longLabel: 'Referente Amministrativo' },
|
|
9
12
|
LIMITED: { shortLabel: 'Ref. Operativo', longLabel: 'Referente Operativo' },
|
package/utils/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/lib/utils/constants.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/lib/utils/constants.ts"],"names":[],"mappings":";;;AAEA,uFAAuF;AAC1E,QAAA,gBAAgB,GAAG,MAAM,CAAC;AACvC,8FAA8F;AACjF,QAAA,iBAAiB,GAAG,OAAO,CAAC;AAE5B,QAAA,wBAAwB,GAAG,aAAa,CAAC;AAEtD,0EAA0E;AAC7D,QAAA,UAAU,GAAqE;IAC1F,KAAK,EAAE,EAAE,UAAU,EAAE,qBAAqB,EAAE,SAAS,EAAE,0BAA0B,EAAE;IACnF,OAAO,EAAE,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,qBAAqB,EAAE;CAC5E,CAAC"}
|