@beinformed/ui 1.20.0 → 1.20.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 +22 -2
- package/esm/constants/Constants.js +0 -15
- package/esm/constants/Constants.js.map +1 -1
- package/esm/constants/Settings.js +6 -0
- package/esm/constants/Settings.js.map +1 -1
- package/esm/hooks/useAuthentication.js +40 -5
- package/esm/hooks/useAuthentication.js.map +1 -1
- package/esm/hooks/useContent.js +2 -6
- package/esm/hooks/useContent.js.map +1 -1
- package/esm/hooks/useI18n.js +10 -11
- package/esm/hooks/useI18n.js.map +1 -1
- package/esm/hooks/useModularUI.js +2 -3
- package/esm/hooks/useModularUI.js.map +1 -1
- package/esm/hooks/useModularUIRequest.js +2 -5
- package/esm/hooks/useModularUIRequest.js.map +1 -1
- package/esm/i18n/Message.js.map +1 -1
- package/esm/i18n/withMessage.js +2 -10
- package/esm/i18n/withMessage.js.map +1 -1
- package/esm/models/application/ApplicationModel.js +6 -1
- package/esm/models/application/ApplicationModel.js.map +1 -1
- package/esm/redux/_modularui/connector.js +3 -4
- package/esm/redux/_modularui/connector.js.map +1 -1
- package/esm/redux/_modularui/selectors.js +22 -5
- package/esm/redux/_modularui/selectors.js.map +1 -1
- package/esm/redux/_modularui/withModularUI.js +2 -10
- package/esm/redux/_modularui/withModularUI.js.map +1 -1
- package/esm/redux/actions/Application.js +26 -7
- package/esm/redux/actions/Application.js.map +1 -1
- package/esm/redux/actions/Authorization.js +2 -1
- package/esm/redux/actions/Authorization.js.map +1 -1
- package/esm/redux/actions/Error.js +3 -1
- package/esm/redux/actions/Error.js.map +1 -1
- package/esm/redux/selectors/i18n.js +16 -0
- package/esm/redux/selectors/i18n.js.map +1 -0
- package/esm/utils/datetime/DateTimeUtil.js +3 -1
- package/esm/utils/datetime/DateTimeUtil.js.map +1 -1
- package/lib/constants/Constants.js +2 -20
- package/lib/constants/Constants.js.flow +0 -15
- package/lib/constants/Constants.js.map +1 -1
- package/lib/constants/Settings.js +6 -0
- package/lib/constants/Settings.js.flow +9 -0
- package/lib/constants/Settings.js.map +1 -1
- package/lib/hooks/__tests__/useAuthentication.spec.js.flow +0 -8
- package/lib/hooks/useAuthentication.js +47 -5
- package/lib/hooks/useAuthentication.js.flow +40 -3
- package/lib/hooks/useAuthentication.js.map +1 -1
- package/lib/hooks/useContent.js +3 -7
- package/lib/hooks/useContent.js.flow +2 -2
- package/lib/hooks/useContent.js.map +1 -1
- package/lib/hooks/useI18n.js +12 -9
- package/lib/hooks/useI18n.js.flow +10 -11
- package/lib/hooks/useI18n.js.map +1 -1
- package/lib/hooks/useModularUI.js +3 -3
- package/lib/hooks/useModularUI.js.flow +3 -2
- package/lib/hooks/useModularUI.js.map +1 -1
- package/lib/hooks/useModularUIRequest.js +2 -4
- package/lib/hooks/useModularUIRequest.js.flow +8 -10
- package/lib/hooks/useModularUIRequest.js.map +1 -1
- package/lib/i18n/Message.js.flow +1 -1
- package/lib/i18n/Message.js.map +1 -1
- package/lib/i18n/withMessage.js +2 -8
- package/lib/i18n/withMessage.js.flow +3 -4
- package/lib/i18n/withMessage.js.map +1 -1
- package/lib/models/application/ApplicationModel.js +7 -1
- package/lib/models/application/ApplicationModel.js.flow +7 -1
- package/lib/models/application/ApplicationModel.js.map +1 -1
- package/lib/redux/_modularui/connector.js +3 -3
- package/lib/redux/_modularui/connector.js.flow +3 -2
- package/lib/redux/_modularui/connector.js.map +1 -1
- package/lib/redux/_modularui/selectors.js +26 -6
- package/lib/redux/_modularui/selectors.js.flow +19 -1
- package/lib/redux/_modularui/selectors.js.map +1 -1
- package/lib/redux/_modularui/withModularUI.js +3 -9
- package/lib/redux/_modularui/withModularUI.js.flow +3 -5
- package/lib/redux/_modularui/withModularUI.js.map +1 -1
- package/lib/redux/actions/Application.js +31 -8
- package/lib/redux/actions/Application.js.flow +6 -8
- package/lib/redux/actions/Application.js.map +1 -1
- package/lib/redux/actions/Authorization.js +3 -2
- package/lib/redux/actions/Authorization.js.flow +2 -1
- package/lib/redux/actions/Authorization.js.map +1 -1
- package/lib/redux/actions/Error.js +4 -1
- package/lib/redux/actions/Error.js.flow +3 -1
- package/lib/redux/actions/Error.js.map +1 -1
- package/lib/redux/actions/__tests__/Application.spec.js.flow +1 -5
- package/lib/redux/actions/__tests__/Authorization.spec.js.flow +1 -1
- package/lib/redux/selectors/i18n.js +28 -0
- package/lib/redux/selectors/i18n.js.flow +15 -0
- package/lib/redux/selectors/i18n.js.map +1 -0
- package/lib/utils/datetime/DateTimeUtil.js +3 -1
- package/lib/utils/datetime/DateTimeUtil.js.flow +1 -1
- package/lib/utils/datetime/DateTimeUtil.js.map +1 -1
- package/package.json +5 -5
- package/src/constants/Constants.js +0 -15
- package/src/constants/Settings.js +9 -0
- package/src/hooks/__tests__/useAuthentication.spec.js +0 -8
- package/src/hooks/useAuthentication.js +40 -3
- package/src/hooks/useContent.js +2 -2
- package/src/hooks/useI18n.js +10 -11
- package/src/hooks/useModularUI.js +3 -2
- package/src/hooks/useModularUIRequest.js +8 -10
- package/src/i18n/Message.js +1 -1
- package/src/i18n/withMessage.js +3 -4
- package/src/models/application/ApplicationModel.js +7 -1
- package/src/redux/_modularui/connector.js +3 -2
- package/src/redux/_modularui/selectors.js +19 -1
- package/src/redux/_modularui/withModularUI.js +3 -5
- package/src/redux/actions/Application.js +6 -8
- package/src/redux/actions/Authorization.js +2 -1
- package/src/redux/actions/Error.js +3 -1
- package/src/redux/actions/__tests__/Application.spec.js +1 -5
- package/src/redux/actions/__tests__/Authorization.spec.js +1 -1
- package/src/redux/selectors/i18n.js +15 -0
- package/src/utils/datetime/DateTimeUtil.js +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import { loadModularUI, removeModelByKey } from "../_modularui/actions";
|
|
3
|
-
import {
|
|
3
|
+
import { allKeysByHref } from "../_modularui/selectors";
|
|
4
4
|
import { ApplicationModel, Href } from "../../models";
|
|
5
|
+
import { getLocale } from "../selectors/i18n";
|
|
5
6
|
|
|
6
7
|
import type { Dispatch, GetState, ThunkAction } from "../types";
|
|
7
8
|
|
|
@@ -9,15 +10,12 @@ import type { Dispatch, GetState, ThunkAction } from "../types";
|
|
|
9
10
|
*/
|
|
10
11
|
export const reloadApplication =
|
|
11
12
|
(): ThunkAction => (dispatch: Dispatch, getState: GetState) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const locale = getState().i18n?.locale;
|
|
16
|
-
modelKey = `application(/)(${locale})`;
|
|
13
|
+
const allKeys = allKeysByHref(getState(), "/");
|
|
14
|
+
for (const key of allKeys) {
|
|
15
|
+
dispatch(removeModelByKey(key));
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const modelKey = `application(/)(${getLocale(getState())})`;
|
|
21
19
|
return dispatch(
|
|
22
20
|
loadModularUI(modelKey, new Href("/", "Application"), {
|
|
23
21
|
targetModel: ApplicationModel,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Application.js","names":["reloadApplication","dispatch","getState","
|
|
1
|
+
{"version":3,"file":"Application.js","names":["reloadApplication","dispatch","getState","allKeys","allKeysByHref","key","removeModelByKey","modelKey","getLocale","loadModularUI","Href","targetModel","ApplicationModel"],"sources":["../../../src/redux/actions/Application.js"],"sourcesContent":["// @flow\nimport { loadModularUI, removeModelByKey } from \"../_modularui/actions\";\nimport { allKeysByHref } from \"../_modularui/selectors\";\nimport { ApplicationModel, Href } from \"../../models\";\nimport { getLocale } from \"../selectors/i18n\";\n\nimport type { Dispatch, GetState, ThunkAction } from \"../types\";\n\n/**\n */\nexport const reloadApplication =\n (): ThunkAction => (dispatch: Dispatch, getState: GetState) => {\n const allKeys = allKeysByHref(getState(), \"/\");\n for (const key of allKeys) {\n dispatch(removeModelByKey(key));\n }\n\n const modelKey = `application(/)(${getLocale(getState())})`;\n return dispatch(\n loadModularUI(modelKey, new Href(\"/\", \"Application\"), {\n targetModel: ApplicationModel,\n })\n );\n };\n"],"mappings":";;;;;;;;;;;;;;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAIA;AACA;AACO,IAAMA,iBAAiB,GAC5B,SADWA,iBACX;EAAA,OAAmB,UAACC,QAAD,EAAqBC,QAArB,EAA4C;IAC7D,IAAMC,OAAO,GAAG,IAAAC,wBAAA,EAAcF,QAAQ,EAAtB,EAA0B,GAA1B,CAAhB;;IAD6D,2CAE3CC,OAF2C;IAAA;;IAAA;MAE7D,oDAA2B;QAAA,IAAhBE,GAAgB;QACzBJ,QAAQ,CAAC,IAAAK,yBAAA,EAAiBD,GAAjB,CAAD,CAAR;MACD;IAJ4D;MAAA;IAAA;MAAA;IAAA;;IAM7D,IAAME,QAAQ,4BAAqB,IAAAC,eAAA,EAAUN,QAAQ,EAAlB,CAArB,MAAd;IACA,OAAOD,QAAQ,CACb,IAAAQ,sBAAA,EAAcF,QAAd,EAAwB,IAAIG,YAAJ,CAAS,GAAT,EAAc,aAAd,CAAxB,EAAsD;MACpDC,WAAW,EAAEC;IADuC,CAAtD,CADa,CAAf;EAKD,CAZD;AAAA,CADK"}
|
|
@@ -64,12 +64,13 @@ var handleUnauthorized = function handleUnauthorized(errorResponse) {
|
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
var location = getState().router.location;
|
|
67
|
+
var LOGIN_PATH = (0, _constants.getSetting)("LOGIN_PATH", "/signin");
|
|
67
68
|
|
|
68
|
-
if ((location === null || location === void 0 ? void 0 : location.pathname) !==
|
|
69
|
+
if ((location === null || location === void 0 ? void 0 : location.pathname) !== LOGIN_PATH) {
|
|
69
70
|
var _location$state;
|
|
70
71
|
|
|
71
72
|
var locationFrom = location === null || location === void 0 ? void 0 : (_location$state = location.state) === null || _location$state === void 0 ? void 0 : _location$state.from;
|
|
72
|
-
return dispatch((0, _actions.replace)(
|
|
73
|
+
return dispatch((0, _actions.replace)(LOGIN_PATH, {
|
|
73
74
|
from: locationFrom ? locationFrom : getState().router.location,
|
|
74
75
|
// cannot open login in a modal, because of previous locations that might be secure
|
|
75
76
|
modal: false
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {
|
|
2
|
+
import { NOTIFICATION_TYPES } from "../../constants/Constants";
|
|
3
3
|
|
|
4
4
|
import ErrorResponse from "../../models/error/ErrorResponse";
|
|
5
5
|
|
|
@@ -62,6 +62,7 @@ export const handleUnauthorized =
|
|
|
62
62
|
|
|
63
63
|
// add current location as from location before redirect
|
|
64
64
|
const location = getState().router.location;
|
|
65
|
+
const LOGIN_PATH = getSetting("LOGIN_PATH", "/signin");
|
|
65
66
|
if (location?.pathname !== LOGIN_PATH) {
|
|
66
67
|
const locationFrom = location?.state?.from;
|
|
67
68
|
return dispatch(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Authorization.js","names":["handleUnauthorized","errorResponse","dispatch","getState","connectKey","removeModelByKey","getSetting","response","error","window","location","reload","application","getApplication","Cache","getItem","isLoggedIn","reloadApplication","logoutSuccess","removeItem","isInvalidUsername","WARNING_TIMEOUT","showNotification","NOTIFICATION_TYPES","WARNING","id","defaultMessage","message","router","
|
|
1
|
+
{"version":3,"file":"Authorization.js","names":["handleUnauthorized","errorResponse","dispatch","getState","connectKey","removeModelByKey","getSetting","response","error","window","location","reload","application","getApplication","Cache","getItem","isLoggedIn","reloadApplication","logoutSuccess","removeItem","isInvalidUsername","WARNING_TIMEOUT","showNotification","NOTIFICATION_TYPES","WARNING","id","defaultMessage","message","router","LOGIN_PATH","pathname","locationFrom","state","from","replace","modal","type"],"sources":["../../../src/redux/actions/Authorization.js"],"sourcesContent":["// @flow\nimport { NOTIFICATION_TYPES } from \"../../constants/Constants\";\n\nimport ErrorResponse from \"../../models/error/ErrorResponse\";\n\nimport { replace } from \"../_router/actions\";\nimport { logoutSuccess } from \"./SignOut\";\nimport { showNotification } from \"./Notification\";\n\nimport Cache from \"../../utils/browser/Cache\";\n\nimport { removeModelByKey } from \"../_modularui/actions\";\nimport { getApplication } from \"../_modularui/selectors\";\nimport { reloadApplication } from \"./Application\";\n\nimport { getSetting } from \"../../constants\";\n\nimport type { ThunkAction } from \"../types\";\n\n/**\n */\nexport const handleUnauthorized =\n (errorResponse: ErrorResponse): ThunkAction =>\n (dispatch, getState) => {\n if (errorResponse.connectKey) {\n dispatch(removeModelByKey(errorResponse.connectKey));\n }\n\n if (\n getSetting(\"PAGE_RELOAD_ON_UNAUTHORIZED_ERROR\", false) &&\n errorResponse.response?.error\n ) {\n window.location.reload();\n return;\n }\n\n // reload application when flag auth is set or isLogged\n const application = getApplication(getState());\n if (Cache.getItem(\"auth\") || application?.isLoggedIn) {\n dispatch(reloadApplication());\n }\n\n // set logged auth\n dispatch(logoutSuccess());\n\n Cache.removeItem(\"auth\");\n\n if (errorResponse.isInvalidUsername) {\n const WARNING_TIMEOUT = 4000;\n dispatch(\n showNotification(\n NOTIFICATION_TYPES.WARNING,\n {\n id: errorResponse.id,\n defaultMessage: errorResponse.message,\n },\n null,\n WARNING_TIMEOUT\n )\n );\n }\n\n // add current location as from location before redirect\n const location = getState().router.location;\n const LOGIN_PATH = getSetting(\"LOGIN_PATH\", \"/signin\");\n if (location?.pathname !== LOGIN_PATH) {\n const locationFrom = location?.state?.from;\n return dispatch(\n replace(LOGIN_PATH, {\n from: locationFrom ? locationFrom : getState().router.location,\n // cannot open login in a modal, because of previous locations that might be secure\n modal: false,\n })\n );\n }\n\n return { type: \"NO_ACTION\" };\n };\n"],"mappings":";;;;;;;;;AACA;;AAEA;;AAEA;;AACA;;AACA;;AAEA;;AAEA;;AACA;;AACA;;AAEA;;AAIA;AACA;AACO,IAAMA,kBAAkB,GAC7B,SADWA,kBACX,CAACC,aAAD;EAAA,OACA,UAACC,QAAD,EAAWC,QAAX,EAAwB;IAAA;;IACtB,IAAIF,aAAa,CAACG,UAAlB,EAA8B;MAC5BF,QAAQ,CAAC,IAAAG,0BAAA,EAAiBJ,aAAa,CAACG,UAA/B,CAAD,CAAR;I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AAEF,YAAY,GAAGA,YAAH,GAAkB5B,QAAQ,GAAGyB,MAAX,CAAkBlB,QADpC;QAElB;QACAyB,KAAK,EAAE;MAHW,CAApB,CADa,CAAf;IAOD;;IAED,OAAO;MAAEC,IAAI,EAAE;IAAR,CAAP;EACD,CAvDD;AAAA,CADK"}
|
|
@@ -9,6 +9,8 @@ exports.setCustomErrorResponseHandler = exports.handleError = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _Constants = require("../../constants/Constants");
|
|
11
11
|
|
|
12
|
+
var _Settings = require("../../constants/Settings");
|
|
13
|
+
|
|
12
14
|
var _ErrorResponse = _interopRequireDefault(require("../../models/error/ErrorResponse"));
|
|
13
15
|
|
|
14
16
|
var _actions = require("../_router/actions");
|
|
@@ -46,7 +48,8 @@ var defaultErrorResponseHandler = function defaultErrorResponseHandler(error) {
|
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
if (error.isBlocked || error.isConcurrentUser) {
|
|
49
|
-
|
|
51
|
+
var LOGOUT_PATH = (0, _Settings.getSetting)("LOGOUT_PATH", "/signout");
|
|
52
|
+
dispatch((0, _actions.push)(LOGOUT_PATH));
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
if (error.isChangePassword) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {
|
|
2
|
+
import { IS_SERVER } from "../../constants/Constants";
|
|
3
|
+
import { getSetting } from "../../constants/Settings";
|
|
3
4
|
|
|
4
5
|
import ErrorResponse from "../../models/error/ErrorResponse";
|
|
5
6
|
|
|
@@ -39,6 +40,7 @@ const defaultErrorResponseHandler: DefaultErrorResponseHandler =
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
if (error.isBlocked || error.isConcurrentUser) {
|
|
43
|
+
const LOGOUT_PATH = getSetting("LOGOUT_PATH", "/signout");
|
|
42
44
|
dispatch(push(LOGOUT_PATH));
|
|
43
45
|
}
|
|
44
46
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Error.js","names":["saveError","error","type","payload","defaultErrorResponseHandler","dispatch","isResourceNotFoundAfterReload","isRemoteServiceException","isUnauthorized","handleUnauthorized","isBlocked","isConcurrentUser","
|
|
1
|
+
{"version":3,"file":"Error.js","names":["saveError","error","type","payload","defaultErrorResponseHandler","dispatch","isResourceNotFoundAfterReload","isRemoteServiceException","isUnauthorized","handleUnauthorized","isBlocked","isConcurrentUser","LOGOUT_PATH","getSetting","push","isChangePassword","changePassword","IS_SERVER","setTimeout","showXHRErrorNotification","customErrorResponseHandler","errorResponse","defaultHandler","setCustomErrorResponseHandler","handler","handleError","resetProgress","ErrorResponse"],"sources":["../../../src/redux/actions/Error.js"],"sourcesContent":["// @flow\nimport { IS_SERVER } from \"../../constants/Constants\";\nimport { getSetting } from \"../../constants/Settings\";\n\nimport ErrorResponse from \"../../models/error/ErrorResponse\";\n\nimport { push } from \"../_router/actions\";\nimport { showXHRErrorNotification } from \"./Notification\";\nimport { resetProgress } from \"./ProgressIndicator\";\nimport { changePassword } from \"./SignIn\";\nimport { handleUnauthorized } from \"./Authorization\";\n\nimport type { FetchException } from \"../../exceptions\";\nimport type { Dispatch, SaveErrorAction, ThunkAction } from \"../types\";\n\ntype DefaultErrorResponseHandler = (error: ErrorResponse) => ThunkAction;\ntype CustomErrorResponseHandler = (\n errorResponse: ErrorResponse,\n defaultHandler: DefaultErrorResponseHandler\n) => ThunkAction;\n\n/**\n */\nconst saveError = (error): SaveErrorAction => ({\n type: \"SAVE_ERROR\",\n payload: error,\n});\n\n/**\n */\nconst defaultErrorResponseHandler: DefaultErrorResponseHandler =\n (error: ErrorResponse): ThunkAction =>\n (dispatch: Dispatch) => {\n if (error.isResourceNotFoundAfterReload || error.isRemoteServiceException) {\n return dispatch({ type: \"NO_ACTION\" });\n }\n\n if (error.isUnauthorized) {\n return dispatch(handleUnauthorized(error));\n }\n\n if (error.isBlocked || error.isConcurrentUser) {\n const LOGOUT_PATH = getSetting(\"LOGOUT_PATH\", \"/signout\");\n dispatch(push(LOGOUT_PATH));\n }\n\n if (error.isChangePassword) {\n return dispatch(changePassword());\n }\n\n if (IS_SERVER) {\n return dispatch(saveError(error));\n }\n\n setTimeout(() => {\n throw error;\n });\n\n return dispatch(showXHRErrorNotification(error));\n };\n\n/**\n * Standard Custom error response, acts as a proxy and can be overwritten by {@link setCustomErrorResponseHandler}\n */\nlet customErrorResponseHandler: CustomErrorResponseHandler =\n (errorResponse, defaultHandler) => (dispatch: Dispatch) =>\n dispatch(defaultHandler(errorResponse));\n\n/**\n * Set a custom error response handler,\n * can be used when custom functionality is needed on certain (error) response\n * of the modular ui, for example when custom logic is needed when a user is unauthorized<br>\n * It receives an {@link ErrorResponse} and the {@link defaultErrorResponseHandler}\n */\nexport const setCustomErrorResponseHandler = (\n handler: CustomErrorResponseHandler\n) => {\n customErrorResponseHandler = handler;\n};\n\n/**\n * Handle errors by sending an error notification message\n */\nexport const handleError =\n (error: Error | FetchException): ThunkAction =>\n (dispatch: Dispatch) => {\n dispatch(resetProgress());\n\n const errorResponse = new ErrorResponse(error);\n\n return dispatch(\n customErrorResponseHandler(errorResponse, defaultErrorResponseHandler)\n );\n };\n"],"mappings":";;;;;;;;;AACA;;AACA;;AAEA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAWA;AACA;AACA,IAAMA,SAAS,GAAG,SAAZA,SAAY,CAACC,KAAD;EAAA,OAA6B;IAC7CC,IAAI,EAAE,YADuC;IAE7CC,OAAO,EAAEF;EAFoC,CAA7B;AAAA,CAAlB;AAKA;AACA;;;AACA,IAAMG,2BAAwD,GAC5D,SADIA,2BACJ,CAACH,KAAD;EAAA,OACA,UAACI,QAAD,EAAwB;IACtB,IAAIJ,KAAK,CAACK,6BAAN,IAAuCL,KAAK,CAACM,wBAAjD,EAA2E;MACzE,OAAOF,QAAQ,CAAC;QAAEH,IAAI,EAAE;MAAR,CAAD,CAAf;IACD;;IAED,IAAID,KAAK,CAACO,cAAV,EAA0B;MACxB,OAAOH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CADK"}
|
|
@@ -16,10 +16,6 @@ describe("application actions", () => {
|
|
|
16
16
|
await store.dispatch(reloadApplication());
|
|
17
17
|
|
|
18
18
|
expect(store.getActions()).toStrictEqual([
|
|
19
|
-
{
|
|
20
|
-
type: "MODULARUI/REMOVE_KEY",
|
|
21
|
-
payload: "application(/)(en)",
|
|
22
|
-
},
|
|
23
19
|
{
|
|
24
20
|
type: "MODULARUI/STATUS",
|
|
25
21
|
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
@@ -49,7 +45,7 @@ describe("application actions", () => {
|
|
|
49
45
|
},
|
|
50
46
|
{
|
|
51
47
|
type: "MODULARUI/STATUS",
|
|
52
|
-
payload: { key: "/", status: "LOADING" },
|
|
48
|
+
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
53
49
|
},
|
|
54
50
|
{ type: "START_PROGRESS" },
|
|
55
51
|
expect.objectContaining({
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getLocales = exports.getLocale = void 0;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Retrieve the locale from state
|
|
10
|
+
*/
|
|
11
|
+
var getLocale = function getLocale(state) {
|
|
12
|
+
var _state$i18n$locale, _state$i18n;
|
|
13
|
+
|
|
14
|
+
return (_state$i18n$locale = (_state$i18n = state.i18n) === null || _state$i18n === void 0 ? void 0 : _state$i18n.locale) !== null && _state$i18n$locale !== void 0 ? _state$i18n$locale : "en";
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Retrieve all available locales in the store
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
exports.getLocale = getLocale;
|
|
22
|
+
|
|
23
|
+
var getLocales = function getLocales(state) {
|
|
24
|
+
return state.i18n.locales;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
exports.getLocales = getLocales;
|
|
28
|
+
//# sourceMappingURL=i18n.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import type Locales from "../../i18n/Locales";
|
|
3
|
+
import type { ReduxState } from "../types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Retrieve the locale from state
|
|
7
|
+
*/
|
|
8
|
+
export const getLocale = (state: ReduxState): string => {
|
|
9
|
+
return state.i18n?.locale ?? "en";
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Retrieve all available locales in the store
|
|
14
|
+
*/
|
|
15
|
+
export const getLocales = (state: ReduxState): Locales => state.i18n.locales;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.js","names":["getLocale","state","i18n","locale","getLocales","locales"],"sources":["../../../src/redux/selectors/i18n.js"],"sourcesContent":["// @flow\nimport type Locales from \"../../i18n/Locales\";\nimport type { ReduxState } from \"../types\";\n\n/**\n * Retrieve the locale from state\n */\nexport const getLocale = (state: ReduxState): string => {\n return state.i18n?.locale ?? \"en\";\n};\n\n/**\n * Retrieve all available locales in the store\n */\nexport const getLocales = (state: ReduxState): Locales => state.i18n.locales;\n"],"mappings":";;;;;;;AAIA;AACA;AACA;AACO,IAAMA,SAAS,GAAG,SAAZA,SAAY,CAACC,KAAD,EAA+B;EAAA;;EACtD,4CAAOA,KAAK,CAACC,IAAb,gDAAO,YAAYC,MAAnB,mEAA6B,IAA7B;AACD,CAFM;AAIP;AACA;AACA;;;;;AACO,IAAMC,UAAU,GAAG,SAAbA,UAAa,CAACH,KAAD;EAAA,OAAgCA,KAAK,CAACC,IAAN,CAAWG,OAA3C;AAAA,CAAnB"}
|
|
@@ -39,7 +39,9 @@ var BaseDateTimeUtil = /*#__PURE__*/function () {
|
|
|
39
39
|
(0, _createClass2.default)(BaseDateTimeUtil, [{
|
|
40
40
|
key: "getLocale",
|
|
41
41
|
value: function getLocale() {
|
|
42
|
-
var
|
|
42
|
+
var _getCookie;
|
|
43
|
+
|
|
44
|
+
var locale = (_getCookie = (0, _Cookies.getCookie)("locale")) !== null && _getCookie !== void 0 ? _getCookie : "en";
|
|
43
45
|
|
|
44
46
|
if (locale === "nl") {
|
|
45
47
|
return _locale.nl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTimeUtil.js","names":["BaseDateTimeUtil","isoFormat","_isoFormat","locale","getCookie","nl","enGB","weekStartsOn","getSetting","DEFAULT_WEEK_STARTS_ON","firstWeekContainsDate","DEFAULT_FIRST_WEEK_CONTAINS_DATE","date","inputFormat","getOptions","parse","Date","targetFormat","parsedDate","toDate","isValid","format","getLocale","sourceFormat","toISO","realDate","formattedValue","isOutsideRange","isBefore","isAfter","replace","toUpperCase","inputDate","afterISODate","isSame","beforeISODate","compareDate","getTime","isSameDay","SATURDAY_NUMBER","SUNDAY_NUMBER","weekDay","getDay","amount","addSeconds","addMinutes","addHours","addDays","addWeeks","addMonths","addYears","subSeconds","subMinutes","subHours","subDays","subWeeks","subMonths","subYears","startOfMonth","endOfMonth","startOfWeek","getHours","getMinutes","getWeek","year","setYear","month","setMonth","hour","setHours","minute","setMinutes","second","setSeconds","milliseconds","setMilliseconds","hours","minutes","seconds","set","DateUtil","ISO_DATE_FORMAT","DateTimeUtil","ISO_DATETIME_FORMAT","TimeUtil","ISO_TIME_FORMAT","TimestampUtil","ISO_TIMESTAMP_FORMAT"],"sources":["../../../src/utils/datetime/DateTimeUtil.js"],"sourcesContent":["// @flow\nimport {\n parse,\n format,\n isValid,\n isAfter,\n isBefore,\n isSameDay,\n addSeconds,\n addMinutes,\n addHours,\n addDays,\n addWeeks,\n addMonths,\n addYears,\n subSeconds,\n subMinutes,\n subHours,\n subDays,\n subWeeks,\n subMonths,\n subYears,\n startOfMonth,\n endOfMonth,\n startOfWeek,\n getHours,\n getMinutes,\n getDay,\n getWeek,\n setMilliseconds,\n setSeconds,\n setMinutes,\n setHours,\n setMonth,\n setYear,\n set,\n} from \"date-fns\";\nimport { nl, enGB } from \"date-fns/locale\";\n\nimport { getCookie } from \"../browser/Cookies\";\n\nimport { getSetting } from \"../../constants/Settings\";\n\nimport {\n ISO_DATE_FORMAT,\n ISO_DATETIME_FORMAT,\n ISO_TIME_FORMAT,\n ISO_TIMESTAMP_FORMAT,\n DEFAULT_WEEK_STARTS_ON,\n DEFAULT_FIRST_WEEK_CONTAINS_DATE,\n} from \"../../constants\";\n\n/**\n * @hideconstructor\n */\nclass BaseDateTimeUtil {\n _isoFormat: string;\n\n constructor(isoFormat: string) {\n this._isoFormat = isoFormat;\n }\n\n /**\n */\n getLocale(): typeof nl | typeof enGB {\n const locale = getCookie(\"locale\") || \"en\";\n\n if (locale === \"nl\") {\n return nl;\n }\n\n return enGB;\n }\n\n // returns the options defined in settings\n getOptions(): {\n weekStartsOn: 0 | 1 | 2 | 3 | 4 | 5 | 6,\n firstWeekContainsDate: 1 | 2 | 3 | 4 | 5 | 6 | 7,\n } {\n // indicates on what day the week starts\n const weekStartsOn = getSetting(\n \"CALENDAR_WEEK_STARTS_ON\",\n DEFAULT_WEEK_STARTS_ON\n );\n\n // indicates which date indicates the first week of the year\n const firstWeekContainsDate = getSetting(\n \"CALENDAR_FIRST_WEEK_CONTAINS_DATE\",\n DEFAULT_FIRST_WEEK_CONTAINS_DATE\n );\n\n return { weekStartsOn, firstWeekContainsDate };\n }\n\n /**\n */\n toDate(date: string, inputFormat: string = this._isoFormat): Date {\n const { weekStartsOn, firstWeekContainsDate } = this.getOptions();\n\n return parse(date, inputFormat, new Date(), {\n weekStartsOn,\n firstWeekContainsDate,\n });\n }\n\n /**\n */\n toFormat(date: string | Date, targetFormat: string): string {\n const { weekStartsOn } = this.getOptions();\n\n const parsedDate = typeof date === \"string\" ? this.toDate(date) : date;\n\n if (isValid(parsedDate)) {\n return format(parsedDate, targetFormat, {\n weekStartsOn,\n locale: this.getLocale(),\n });\n }\n\n return \"Invalid Date\";\n }\n\n /**\n */\n toISO(date: string | Date, sourceFormat: string = this._isoFormat): string {\n const { weekStartsOn } = this.getOptions();\n\n const parsedDate =\n typeof date === \"string\" ? this.toDate(date, sourceFormat) : date;\n\n if (isValid(parsedDate)) {\n return format(parsedDate, this._isoFormat, {\n weekStartsOn,\n });\n }\n\n return \"Invalid Date\";\n }\n\n /**\n */\n now(): string {\n return this.toISO(new Date());\n }\n\n /**\n */\n convertFormat(sourceFormat: string): string {\n return sourceFormat ? sourceFormat : this._isoFormat;\n }\n\n /**\n * VALIDATION\n */\n hasFormat(date: string, sourceFormat: string): boolean {\n const { weekStartsOn } = this.getOptions();\n\n const realDate = this.toDate(date, sourceFormat);\n if (isValid(realDate)) {\n const formattedValue = format(realDate, sourceFormat, {\n weekStartsOn,\n });\n\n const isOutsideRange =\n isBefore(realDate, new Date(1000, 1, 1)) ||\n isAfter(realDate, new Date(9999, 11, 31));\n if (isOutsideRange) {\n return false;\n }\n\n return (\n formattedValue.replace(/0/gu, \"\").toUpperCase() ===\n date.replace(/0/gu, \"\").toUpperCase()\n );\n }\n\n return false;\n }\n\n /**\n */\n isValid(date: string, inputFormat: string = this._isoFormat): boolean {\n return isValid(this.toDate(date, inputFormat));\n }\n\n /**\n */\n isAfter(\n inputDate: string,\n afterISODate: ?string,\n inputFormat: string = this._isoFormat\n ): boolean {\n return (\n afterISODate != null &&\n isAfter(this.toDate(inputDate, inputFormat), this.toDate(afterISODate))\n );\n }\n\n /**\n */\n isSameOrAfter(\n inputDate: string,\n afterISODate: ?string,\n inputFormat: string = this._isoFormat\n ): boolean {\n return (\n afterISODate != null &&\n (this.isAfter(inputDate, afterISODate, inputFormat) ||\n this.isSame(inputDate, afterISODate, inputFormat))\n );\n }\n\n /**\n */\n isBefore(\n inputDate: string,\n beforeISODate: ?string,\n inputFormat: string = this._isoFormat\n ): boolean {\n return (\n beforeISODate != null &&\n isBefore(this.toDate(inputDate, inputFormat), this.toDate(beforeISODate))\n );\n }\n\n /**\n */\n isSameOrBefore(\n inputDate: string,\n beforeISODate: ?string,\n inputFormat: string = this._isoFormat\n ): boolean {\n return (\n beforeISODate != null &&\n (this.isBefore(inputDate, beforeISODate, inputFormat) ||\n this.isSame(inputDate, beforeISODate, inputFormat))\n );\n }\n\n /**\n */\n isSame(\n inputDate: string,\n compareDate: ?string,\n inputFormat: string = this._isoFormat\n ): boolean {\n return (\n compareDate != null &&\n this.toDate(inputDate, inputFormat).getTime() ===\n this.toDate(compareDate).getTime()\n );\n }\n\n /**\n */\n isSameDay(\n inputDate: string,\n compareDate: string,\n inputFormat: string = this._isoFormat\n ): boolean {\n return (\n compareDate != null &&\n isSameDay(\n this.toDate(inputDate, inputFormat),\n this.toDate(compareDate, inputFormat)\n )\n );\n }\n\n /**\n */\n isOther(\n inputDate: string,\n compareDate: ?string,\n inputFormat: string = this._isoFormat\n ): boolean {\n return !this.isSame(inputDate, compareDate, inputFormat);\n }\n\n /**\n */\n isWeekend(inputDate: string): boolean {\n const SATURDAY_NUMBER = 6;\n const SUNDAY_NUMBER = 0;\n const weekDay = getDay(this.toDate(inputDate));\n\n return weekDay === SATURDAY_NUMBER || weekDay === SUNDAY_NUMBER;\n }\n\n /**\n * CALCULATIONS\n */\n addSeconds(date: string, amount: number): string {\n return this.toISO(addSeconds(this.toDate(date), amount));\n }\n\n /**\n */\n addMinutes(date: string, amount: number): string {\n return this.toISO(addMinutes(this.toDate(date), amount));\n }\n\n /**\n */\n addHours(date: string, amount: number): string {\n return this.toISO(addHours(this.toDate(date), amount));\n }\n\n /**\n */\n addDays(date: string, amount: number): string {\n return this.toISO(addDays(this.toDate(date), amount));\n }\n\n /**\n */\n addWeeks(date: string, amount: number): string {\n return this.toISO(addWeeks(this.toDate(date), amount));\n }\n\n /**\n */\n addMonths(date: string, amount: number): string {\n return this.toISO(addMonths(this.toDate(date), amount));\n }\n\n /**\n */\n addYears(date: string, amount: number): string {\n return this.toISO(addYears(this.toDate(date), amount));\n }\n\n /**\n */\n subtractSeconds(date: string, amount: number): string {\n return this.toISO(subSeconds(this.toDate(date), amount));\n }\n\n /**\n */\n subtractMinutes(date: string, amount: number): string {\n return this.toISO(subMinutes(this.toDate(date), amount));\n }\n\n /**\n */\n subtractHours(date: string, amount: number): string {\n return this.toISO(subHours(this.toDate(date), amount));\n }\n\n /**\n */\n subtractDays(date: string, amount: number): string {\n return this.toISO(subDays(this.toDate(date), amount));\n }\n\n /**\n */\n subtractWeeks(date: string, amount: number): string {\n return this.toISO(subWeeks(this.toDate(date), amount));\n }\n\n /**\n */\n subtractMonths(date: string, amount: number): string {\n return this.toISO(subMonths(this.toDate(date), amount));\n }\n\n /**\n */\n subtractYears(date: string, amount: number): string {\n return this.toISO(subYears(this.toDate(date), amount));\n }\n\n /**\n * GETTERS\n */\n startOfMonth(date: string, inputFormat: string = this._isoFormat): string {\n return this.toISO(startOfMonth(this.toDate(date, inputFormat)));\n }\n\n /**\n */\n endOfMonth(date: string, inputFormat: string = this._isoFormat): string {\n return this.toISO(endOfMonth(this.toDate(date, inputFormat)));\n }\n\n /**\n */\n startOfWeek(date: string, inputFormat: string = this._isoFormat): string {\n const { weekStartsOn } = this.getOptions();\n\n return this.toISO(\n startOfWeek(this.toDate(date, inputFormat), {\n weekStartsOn,\n })\n );\n }\n\n /**\n */\n getHours(date: string | Date): number {\n const parsedDate = typeof date === \"string\" ? this.toDate(date) : date;\n return getHours(parsedDate);\n }\n\n /**\n */\n getMinutes(date: string | Date): number {\n const parsedDate = typeof date === \"string\" ? this.toDate(date) : date;\n return getMinutes(parsedDate);\n }\n\n /**\n */\n getWeek(date: string): number {\n const { weekStartsOn, firstWeekContainsDate } = this.getOptions();\n\n return getWeek(this.toDate(date), {\n weekStartsOn,\n firstWeekContainsDate,\n });\n }\n\n /**\n * SETTERS\n */\n setYear(date: string, year: number): string {\n return this.toISO(setYear(this.toDate(date), year));\n }\n\n /**\n */\n setMonth(date: string, month: number): string {\n return this.toISO(setMonth(this.toDate(date), month));\n }\n\n /**\n */\n setHour(date: string, hour: number): string {\n return this.toISO(setHours(this.toDate(date), hour));\n }\n\n /**\n */\n setMinute(date: string, minute: number): string {\n return this.toISO(setMinutes(this.toDate(date), minute));\n }\n\n /**\n */\n setSecond(date: string, second: number): string {\n return this.toISO(setSeconds(this.toDate(date), second));\n }\n\n /**\n */\n setMilliseconds(date: string, milliseconds: number): string {\n return this.toISO(setMilliseconds(this.toDate(date), milliseconds));\n }\n\n /**\n */\n setTime(\n date: string,\n hours: number,\n minutes: number,\n seconds: number,\n milliseconds: number\n ): string {\n return this.toISO(\n set(this.toDate(date), {\n hours,\n minutes,\n seconds,\n milliseconds,\n })\n );\n }\n}\n\n/**\n * DateUtil\n */\nconst DateUtil: BaseDateTimeUtil = new BaseDateTimeUtil(ISO_DATE_FORMAT);\n\n/**\n * DateTimeUtil\n */\nconst DateTimeUtil: BaseDateTimeUtil = new BaseDateTimeUtil(\n ISO_DATETIME_FORMAT\n);\n\n/**\n * TimeUtil\n */\nconst TimeUtil: BaseDateTimeUtil = new BaseDateTimeUtil(ISO_TIME_FORMAT);\n\n/**\n * TimestampUtil\n */\nconst TimestampUtil: BaseDateTimeUtil = new BaseDateTimeUtil(\n ISO_TIMESTAMP_FORMAT\n);\n\nexport { DateUtil, DateTimeUtil, TimeUtil, TimestampUtil };\n"],"mappings":";;;;;;;;;;;;;;;AACA;;AAoCA;;AAEA;;AAEA;;AAEA;;AASA;AACA;AACA;IACMA,gB;EAGJ,0BAAYC,SAAZ,EAA+B;IAAA;IAAA;IAC7B,KAAKC,UAAL,GAAkBD,SAAlB;EACD;EAED;AACF;;;;;WACE,qBAAqC;MACnC,IAAME,MAAM,GAAG,IAAAC,kBAAA,EAAU,QAAV,KAAuB,IAAtC;;MAEA,IAAID,MAAM,KAAK,IAAf,EAAqB;QACnB,OAAOE,UAAP;MACD;;MAED,OAAOC,YAAP;IACD,C,CAED;;;;WACA,sBAGE;MACA;MACA,IAAMC,YAAY,GAAG,IAAAC,oBAAA,EACnB,yBADmB,EAEnBC,iCAFmB,CAArB,CAFA,CAOA;;M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EAAI,KAAK5D,MAAL,CAAYP,IAAZ,CAAJ,EAAuB;QACrBgE,KAAK,EAALA,KADqB;QAErBC,OAAO,EAAPA,OAFqB;QAGrBC,OAAO,EAAPA,OAHqB;QAIrBJ,YAAY,EAAZA;MAJqB,CAAvB,CADK,CAAP;IAQD;;;;AAGH;AACA;AACA;;;AACA,IAAMM,QAA0B,GAAG,IAAIhF,gBAAJ,CAAqBiF,0BAArB,CAAnC;AAEA;AACA;AACA;;;AACA,IAAMC,YAA8B,GAAG,IAAIlF,gBAAJ,CACrCmF,8BADqC,CAAvC;AAIA;AACA;AACA;;;AACA,IAAMC,QAA0B,GAAG,IAAIpF,gBAAJ,CAAqBqF,0BAArB,CAAnC;AAEA;AACA;AACA;;;AACA,IAAMC,aAA+B,GAAG,IAAItF,gBAAJ,CACtCuF,+BADsC,CAAxC"}
|
|
1
|
+
{"version":3,"file":"DateTimeUtil.js","names":["BaseDateTimeUtil","isoFormat","_isoFormat","locale","getCookie","nl","enGB","weekStartsOn","getSetting","DEFAULT_WEEK_STARTS_ON","firstWeekContainsDate","DEFAULT_FIRST_WEEK_CONTAINS_DATE","date","inputFormat","getOptions","parse","Date","targetFormat","parsedDate","toDate","isValid","format","getLocale","sourceFormat","toISO","realDate","formattedValue","isOutsideRange","isBefore","isAfter","replace","toUpperCase","inputDate","afterISODate","isSame","beforeISODate","compareDate","getTime","isSameDay","SATURDAY_NUMBER","SUNDAY_NUMBER","weekDay","getDay","amount","addSeconds","addMinutes","addHours","addDays","addWeeks","addMonths","addYears","subSeconds","subMinutes","subHours","subDays","subWeeks","subMonths","subYears","startOfMonth","endOfMonth","startOfWeek","getHours","getMinutes","getWeek","year","setYear","month","setMonth","hour","setHours","minute","setMinutes","second","setSeconds","milliseconds","setMilliseconds","hours","minutes","seconds","set","DateUtil","ISO_DATE_FORMAT","DateTimeUtil","ISO_DATETIME_FORMAT","TimeUtil","ISO_TIME_FORMAT","TimestampUtil","ISO_TIMESTAMP_FORMAT"],"sources":["../../../src/utils/datetime/DateTimeUtil.js"],"sourcesContent":["// @flow\nimport {\n parse,\n format,\n isValid,\n isAfter,\n isBefore,\n isSameDay,\n addSeconds,\n addMinutes,\n addHours,\n addDays,\n addWeeks,\n addMonths,\n addYears,\n subSeconds,\n subMinutes,\n subHours,\n subDays,\n subWeeks,\n subMonths,\n subYears,\n startOfMonth,\n endOfMonth,\n startOfWeek,\n getHours,\n getMinutes,\n getDay,\n getWeek,\n setMilliseconds,\n setSeconds,\n setMinutes,\n setHours,\n setMonth,\n setYear,\n set,\n} from \"date-fns\";\nimport { nl, enGB } from \"date-fns/locale\";\n\nimport { getCookie } from \"../browser/Cookies\";\n\nimport { getSetting } from \"../../constants/Settings\";\n\nimport {\n ISO_DATE_FORMAT,\n ISO_DATETIME_FORMAT,\n ISO_TIME_FORMAT,\n ISO_TIMESTAMP_FORMAT,\n DEFAULT_WEEK_STARTS_ON,\n DEFAULT_FIRST_WEEK_CONTAINS_DATE,\n} from \"../../constants\";\n\n/**\n * @hideconstructor\n */\nclass BaseDateTimeUtil {\n _isoFormat: string;\n\n constructor(isoFormat: string) {\n this._isoFormat = isoFormat;\n }\n\n /**\n */\n getLocale(): typeof nl | typeof enGB {\n const locale = getCookie(\"locale\") ?? \"en\";\n\n if (locale === \"nl\") {\n return nl;\n }\n\n return enGB;\n }\n\n // returns the options defined in settings\n getOptions(): {\n weekStartsOn: 0 | 1 | 2 | 3 | 4 | 5 | 6,\n firstWeekContainsDate: 1 | 2 | 3 | 4 | 5 | 6 | 7,\n } {\n // indicates on what day the week starts\n const weekStartsOn = getSetting(\n \"CALENDAR_WEEK_STARTS_ON\",\n DEFAULT_WEEK_STARTS_ON\n );\n\n // indicates which date indicates the first week of the year\n const firstWeekContainsDate = getSetting(\n \"CALENDAR_FIRST_WEEK_CONTAINS_DATE\",\n DEFAULT_FIRST_WEEK_CONTAINS_DATE\n );\n\n return { weekStartsOn, firstWeekContainsDate };\n }\n\n /**\n */\n toDate(date: string, inputFormat: string = this._isoFormat): Date {\n const { weekStartsOn, firstWeekContainsDate } = this.getOptions();\n\n return parse(date, inputFormat, new Date(), {\n weekStartsOn,\n firstWeekContainsDate,\n });\n }\n\n /**\n */\n toFormat(date: string | Date, targetFormat: string): string {\n const { weekStartsOn } = this.getOptions();\n\n const parsedDate = typeof date === \"string\" ? this.toDate(date) : date;\n\n if (isValid(parsedDate)) {\n return format(parsedDate, targetFormat, {\n weekStartsOn,\n locale: this.getLocale(),\n });\n }\n\n return \"Invalid Date\";\n }\n\n /**\n */\n toISO(date: string | Date, sourceFormat: string = this._isoFormat): string {\n const { weekStartsOn } = this.getOptions();\n\n const parsedDate =\n typeof date === \"string\" ? this.toDate(date, sourceFormat) : date;\n\n if (isValid(parsedDate)) {\n return format(parsedDate, this._isoFormat, {\n weekStartsOn,\n });\n }\n\n return \"Invalid Date\";\n }\n\n /**\n */\n now(): string {\n return this.toISO(new Date());\n }\n\n /**\n */\n convertFormat(sourceFormat: string): string {\n return sourceFormat ? sourceFormat : this._isoFormat;\n }\n\n /**\n * VALIDATION\n */\n hasFormat(date: string, sourceFormat: string): boolean {\n const { weekStartsOn } = this.getOptions();\n\n const realDate = this.toDate(date, sourceFormat);\n if (isValid(realDate)) {\n const formattedValue = format(realDate, sourceFormat, {\n weekStartsOn,\n });\n\n const isOutsideRange =\n isBefore(realDate, new Date(1000, 1, 1)) ||\n isAfter(realDate, new Date(9999, 11, 31));\n if (isOutsideRange) {\n return false;\n }\n\n return (\n formattedValue.replace(/0/gu, \"\").toUpperCase() ===\n date.replace(/0/gu, \"\").toUpperCase()\n );\n }\n\n return false;\n }\n\n /**\n */\n isValid(date: string, inputFormat: string = this._isoFormat): boolean {\n return isValid(this.toDate(date, inputFormat));\n }\n\n /**\n */\n isAfter(\n inputDate: string,\n afterISODate: ?string,\n inputFormat: string = this._isoFormat\n ): boolean {\n return (\n afterISODate != null &&\n isAfter(this.toDate(inputDate, inputFormat), this.toDate(afterISODate))\n );\n }\n\n /**\n */\n isSameOrAfter(\n inputDate: string,\n afterISODate: ?string,\n inputFormat: string = this._isoFormat\n ): boolean {\n return (\n afterISODate != null &&\n (this.isAfter(inputDate, afterISODate, inputFormat) ||\n this.isSame(inputDate, afterISODate, inputFormat))\n );\n }\n\n /**\n */\n isBefore(\n inputDate: string,\n beforeISODate: ?string,\n inputFormat: string = this._isoFormat\n ): boolean {\n return (\n beforeISODate != null &&\n isBefore(this.toDate(inputDate, inputFormat), this.toDate(beforeISODate))\n );\n }\n\n /**\n */\n isSameOrBefore(\n inputDate: string,\n beforeISODate: ?string,\n inputFormat: string = this._isoFormat\n ): boolean {\n return (\n beforeISODate != null &&\n (this.isBefore(inputDate, beforeISODate, inputFormat) ||\n this.isSame(inputDate, beforeISODate, inputFormat))\n );\n }\n\n /**\n */\n isSame(\n inputDate: string,\n compareDate: ?string,\n inputFormat: string = this._isoFormat\n ): boolean {\n return (\n compareDate != null &&\n this.toDate(inputDate, inputFormat).getTime() ===\n this.toDate(compareDate).getTime()\n );\n }\n\n /**\n */\n isSameDay(\n inputDate: string,\n compareDate: string,\n inputFormat: string = this._isoFormat\n ): boolean {\n return (\n compareDate != null &&\n isSameDay(\n this.toDate(inputDate, inputFormat),\n this.toDate(compareDate, inputFormat)\n )\n );\n }\n\n /**\n */\n isOther(\n inputDate: string,\n compareDate: ?string,\n inputFormat: string = this._isoFormat\n ): boolean {\n return !this.isSame(inputDate, compareDate, inputFormat);\n }\n\n /**\n */\n isWeekend(inputDate: string): boolean {\n const SATURDAY_NUMBER = 6;\n const SUNDAY_NUMBER = 0;\n const weekDay = getDay(this.toDate(inputDate));\n\n return weekDay === SATURDAY_NUMBER || weekDay === SUNDAY_NUMBER;\n }\n\n /**\n * CALCULATIONS\n */\n addSeconds(date: string, amount: number): string {\n return this.toISO(addSeconds(this.toDate(date), amount));\n }\n\n /**\n */\n addMinutes(date: string, amount: number): string {\n return this.toISO(addMinutes(this.toDate(date), amount));\n }\n\n /**\n */\n addHours(date: string, amount: number): string {\n return this.toISO(addHours(this.toDate(date), amount));\n }\n\n /**\n */\n addDays(date: string, amount: number): string {\n return this.toISO(addDays(this.toDate(date), amount));\n }\n\n /**\n */\n addWeeks(date: string, amount: number): string {\n return this.toISO(addWeeks(this.toDate(date), amount));\n }\n\n /**\n */\n addMonths(date: string, amount: number): string {\n return this.toISO(addMonths(this.toDate(date), amount));\n }\n\n /**\n */\n addYears(date: string, amount: number): string {\n return this.toISO(addYears(this.toDate(date), amount));\n }\n\n /**\n */\n subtractSeconds(date: string, amount: number): string {\n return this.toISO(subSeconds(this.toDate(date), amount));\n }\n\n /**\n */\n subtractMinutes(date: string, amount: number): string {\n return this.toISO(subMinutes(this.toDate(date), amount));\n }\n\n /**\n */\n subtractHours(date: string, amount: number): string {\n return this.toISO(subHours(this.toDate(date), amount));\n }\n\n /**\n */\n subtractDays(date: string, amount: number): string {\n return this.toISO(subDays(this.toDate(date), amount));\n }\n\n /**\n */\n subtractWeeks(date: string, amount: number): string {\n return this.toISO(subWeeks(this.toDate(date), amount));\n }\n\n /**\n */\n subtractMonths(date: string, amount: number): string {\n return this.toISO(subMonths(this.toDate(date), amount));\n }\n\n /**\n */\n subtractYears(date: string, amount: number): string {\n return this.toISO(subYears(this.toDate(date), amount));\n }\n\n /**\n * GETTERS\n */\n startOfMonth(date: string, inputFormat: string = this._isoFormat): string {\n return this.toISO(startOfMonth(this.toDate(date, inputFormat)));\n }\n\n /**\n */\n endOfMonth(date: string, inputFormat: string = this._isoFormat): string {\n return this.toISO(endOfMonth(this.toDate(date, inputFormat)));\n }\n\n /**\n */\n startOfWeek(date: string, inputFormat: string = this._isoFormat): string {\n const { weekStartsOn } = this.getOptions();\n\n return this.toISO(\n startOfWeek(this.toDate(date, inputFormat), {\n weekStartsOn,\n })\n );\n }\n\n /**\n */\n getHours(date: string | Date): number {\n const parsedDate = typeof date === \"string\" ? this.toDate(date) : date;\n return getHours(parsedDate);\n }\n\n /**\n */\n getMinutes(date: string | Date): number {\n const parsedDate = typeof date === \"string\" ? this.toDate(date) : date;\n return getMinutes(parsedDate);\n }\n\n /**\n */\n getWeek(date: string): number {\n const { weekStartsOn, firstWeekContainsDate } = this.getOptions();\n\n return getWeek(this.toDate(date), {\n weekStartsOn,\n firstWeekContainsDate,\n });\n }\n\n /**\n * SETTERS\n */\n setYear(date: string, year: number): string {\n return this.toISO(setYear(this.toDate(date), year));\n }\n\n /**\n */\n setMonth(date: string, month: number): string {\n return this.toISO(setMonth(this.toDate(date), month));\n }\n\n /**\n */\n setHour(date: string, hour: number): string {\n return this.toISO(setHours(this.toDate(date), hour));\n }\n\n /**\n */\n setMinute(date: string, minute: number): string {\n return this.toISO(setMinutes(this.toDate(date), minute));\n }\n\n /**\n */\n setSecond(date: string, second: number): string {\n return this.toISO(setSeconds(this.toDate(date), second));\n }\n\n /**\n */\n setMilliseconds(date: string, milliseconds: number): string {\n return this.toISO(setMilliseconds(this.toDate(date), milliseconds));\n }\n\n /**\n */\n setTime(\n date: string,\n hours: number,\n minutes: number,\n seconds: number,\n milliseconds: number\n ): string {\n return this.toISO(\n set(this.toDate(date), {\n hours,\n minutes,\n seconds,\n milliseconds,\n })\n );\n }\n}\n\n/**\n * DateUtil\n */\nconst DateUtil: BaseDateTimeUtil = new BaseDateTimeUtil(ISO_DATE_FORMAT);\n\n/**\n * DateTimeUtil\n */\nconst DateTimeUtil: BaseDateTimeUtil = new BaseDateTimeUtil(\n ISO_DATETIME_FORMAT\n);\n\n/**\n * TimeUtil\n */\nconst TimeUtil: BaseDateTimeUtil = new BaseDateTimeUtil(ISO_TIME_FORMAT);\n\n/**\n * TimestampUtil\n */\nconst TimestampUtil: BaseDateTimeUtil = new BaseDateTimeUtil(\n ISO_TIMESTAMP_FORMAT\n);\n\nexport { DateUtil, DateTimeUtil, TimeUtil, TimestampUtil };\n"],"mappings":";;;;;;;;;;;;;;;AACA;;AAoCA;;AAEA;;AAEA;;AAEA;;AASA;AACA;AACA;IACMA,gB;EAGJ,0BAAYC,SAAZ,EAA+B;IAAA;IAAA;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8B4D,MAA9B,CAAX,CAAP;IACD;IAED;AACF;;;;WACE,yBAAgB5D,IAAhB,EAA8B8D,YAA9B,EAA4D;MAC1D,OAAO,KAAKlD,KAAL,CAAW,IAAAmD,wBAAA,EAAgB,KAAKxD,MAAL,CAAYP,IAAZ,CAAhB,EAAmC8D,YAAnC,CAAX,CAAP;IACD;IAED;AACF;;;;WACE,iBACE9D,IADF,EAEEgE,KAFF,EAGEC,OAHF,EAIEC,OAJF,EAKEJ,YALF,EAMU;MACR,OAAO,KAAKlD,KAAL,CACL,IAAAuD,YAAA,EAAI,KAAK5D,MAAL,CAAYP,IAAZ,CAAJ,EAAuB;QACrBgE,KAAK,EAALA,KADqB;QAErBC,OAAO,EAAPA,OAFqB;QAGrBC,OAAO,EAAPA,OAHqB;QAIrBJ,YAAY,EAAZA;MAJqB,CAAvB,CADK,CAAP;IAQD;;;;AAGH;AACA;AACA;;;AACA,IAAMM,QAA0B,GAAG,IAAIhF,gBAAJ,CAAqBiF,0BAArB,CAAnC;AAEA;AACA;AACA;;;AACA,IAAMC,YAA8B,GAAG,IAAIlF,gBAAJ,CACrCmF,8BADqC,CAAvC;AAIA;AACA;AACA;;;AACA,IAAMC,QAA0B,GAAG,IAAIpF,gBAAJ,CAAqBqF,0BAArB,CAAnC;AAEA;AACA;AACA;;;AACA,IAAMC,aAA+B,GAAG,IAAItF,gBAAJ,CACtCuF,+BADsC,CAAxC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beinformed/ui",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.3",
|
|
4
4
|
"description": "Toolbox for be informed javascript layouts",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"bugs": "http://support.beinformed.com",
|
|
@@ -114,16 +114,16 @@
|
|
|
114
114
|
"cherry-pick": "^0.5.0",
|
|
115
115
|
"cross-env": "^7.0.3",
|
|
116
116
|
"documentation": "^13.2.5",
|
|
117
|
-
"eslint": "^8.
|
|
117
|
+
"eslint": "^8.18.0",
|
|
118
118
|
"eslint-config-prettier": "^8.3.0",
|
|
119
119
|
"eslint-plugin-babel": "^5.3.1",
|
|
120
120
|
"eslint-plugin-ft-flow": "^2.0.1",
|
|
121
121
|
"eslint-plugin-import": "^2.26.0",
|
|
122
122
|
"eslint-plugin-jest": "^26.5.3",
|
|
123
|
-
"eslint-plugin-jsdoc": "^39.3.
|
|
123
|
+
"eslint-plugin-jsdoc": "^39.3.3",
|
|
124
124
|
"eslint-plugin-react": "^7.30.0",
|
|
125
125
|
"eslint-plugin-react-hooks": "^4.5.0",
|
|
126
|
-
"flow-bin": "^0.180.
|
|
126
|
+
"flow-bin": "^0.180.1",
|
|
127
127
|
"flow-copy-source": "^2.0.9",
|
|
128
128
|
"flow-typed": "^3.6.1",
|
|
129
129
|
"glob": "^8.0.3",
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
"jest-junit": "^13.2.0",
|
|
135
135
|
"jest-sonar-reporter": "^2.0.0",
|
|
136
136
|
"jscodeshift": "^0.13.1",
|
|
137
|
-
"lint-staged": "^13.0.
|
|
137
|
+
"lint-staged": "^13.0.2",
|
|
138
138
|
"polished": "^4.0.0",
|
|
139
139
|
"prettier": "^2.7.1",
|
|
140
140
|
"react": "^18.0.0",
|
|
@@ -51,21 +51,6 @@ export const UPLOAD_PATH = `${BASE}/uploadFile`;
|
|
|
51
51
|
*/
|
|
52
52
|
export const CAPTCHA_PATH = `${BASE}/captchaServices`;
|
|
53
53
|
|
|
54
|
-
/**
|
|
55
|
-
* Path to login page / component
|
|
56
|
-
*/
|
|
57
|
-
export const LOGIN_PATH = "/signin";
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Path to administrator login page / component
|
|
61
|
-
*/
|
|
62
|
-
export const ADMINISTRATOR_LOGIN_PATH = "/administrator";
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Path to logout page / component
|
|
66
|
-
*/
|
|
67
|
-
export const LOGOUT_PATH = "/signout";
|
|
68
|
-
|
|
69
54
|
/**
|
|
70
55
|
* Path to change password page / component
|
|
71
56
|
*/
|
|
@@ -51,6 +51,15 @@ const defaultSettings = {
|
|
|
51
51
|
// Renders the login variants as option on the global logout page
|
|
52
52
|
RENDER_MULTI_LOGIN_ON_GLOBAL_LOGOUT_PAGE: false,
|
|
53
53
|
|
|
54
|
+
// Path to login page / component
|
|
55
|
+
LOGIN_PATH: "/signin",
|
|
56
|
+
|
|
57
|
+
// Path to administrator login page / component
|
|
58
|
+
ADMINISTRATOR_LOGIN_PATH: "",
|
|
59
|
+
|
|
60
|
+
// Path to logout page / component
|
|
61
|
+
LOGOUT_PATH: "/signout",
|
|
62
|
+
|
|
54
63
|
// Render forms in a modal
|
|
55
64
|
RENDER_FORMS_IN_MODAL: true,
|
|
56
65
|
|
|
@@ -61,10 +61,6 @@ describe("authentication hooks", () => {
|
|
|
61
61
|
|
|
62
62
|
expect(store.getActions()).toStrictEqual([
|
|
63
63
|
{ type: "START_PROGRESS" },
|
|
64
|
-
{
|
|
65
|
-
type: "MODULARUI/REMOVE_KEY",
|
|
66
|
-
payload: "application(/)(en)",
|
|
67
|
-
},
|
|
68
64
|
{
|
|
69
65
|
type: "MODULARUI/STATUS",
|
|
70
66
|
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
@@ -112,10 +108,6 @@ describe("authentication hooks", () => {
|
|
|
112
108
|
expect(store.getActions()).toStrictEqual([
|
|
113
109
|
{ type: "START_PROGRESS" },
|
|
114
110
|
{ type: "MODULARUI/RESET" },
|
|
115
|
-
{
|
|
116
|
-
type: "MODULARUI/REMOVE_KEY",
|
|
117
|
-
payload: "application(/)(en)",
|
|
118
|
-
},
|
|
119
111
|
{
|
|
120
112
|
type: "MODULARUI/STATUS",
|
|
121
113
|
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
@@ -4,15 +4,23 @@ import { useSelector, useDispatch } from "react-redux";
|
|
|
4
4
|
import { getApplication } from "../redux/_modularui/selectors";
|
|
5
5
|
import { login, logout, resetAuthErrors } from "../redux/actions";
|
|
6
6
|
|
|
7
|
+
import Cache from "../utils/browser/Cache";
|
|
8
|
+
import { BASE, getSetting } from "../constants";
|
|
9
|
+
|
|
7
10
|
import type { ResetAuthErrorsAction } from "../redux/types";
|
|
11
|
+
import type { AuthenticationType } from "../models/types";
|
|
12
|
+
import { IllegalStateException } from "../exceptions";
|
|
8
13
|
type LoginHook = {
|
|
9
14
|
isAuthenticated: boolean,
|
|
15
|
+
authenticationTypes: Array<AuthenticationType>,
|
|
10
16
|
errorMessage: ?string,
|
|
11
17
|
resetErrors: () => ResetAuthErrorsAction,
|
|
12
18
|
login: (username: string, password: string) => void,
|
|
19
|
+
redirectLogin: (authenticationType: AuthenticationType) => void,
|
|
13
20
|
};
|
|
14
21
|
type LogoutHook = {
|
|
15
22
|
isAuthenticated: boolean,
|
|
23
|
+
authenticationTypes: Array<AuthenticationType>,
|
|
16
24
|
logout: () => void,
|
|
17
25
|
};
|
|
18
26
|
|
|
@@ -24,12 +32,28 @@ export const useLogin = (): LoginHook => {
|
|
|
24
32
|
const application = useSelector(getApplication);
|
|
25
33
|
const auth = useSelector((state) => state.auth);
|
|
26
34
|
|
|
35
|
+
const isAuthenticated = application?.isLoggedIn ?? false;
|
|
36
|
+
|
|
27
37
|
return {
|
|
28
|
-
isAuthenticated
|
|
38
|
+
isAuthenticated,
|
|
39
|
+
authenticationTypes: application?.authenticationTypes ?? [],
|
|
29
40
|
errorMessage: auth.error,
|
|
30
41
|
resetErrors: () => dispatch(resetAuthErrors()),
|
|
31
42
|
login: (username: string, password: string) =>
|
|
32
43
|
dispatch(login(username, password)),
|
|
44
|
+
redirectLogin: (authenticationType: AuthenticationType) => {
|
|
45
|
+
if (Cache.getItem("isRedirectLogin")) {
|
|
46
|
+
// prevent endless loop in redirects when authentication type can't be redirected
|
|
47
|
+
throw new IllegalStateException(
|
|
48
|
+
`Could not redirect to '${authenticationType.authentication}' using url: '${authenticationType.redirectUri}'`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!isAuthenticated) {
|
|
53
|
+
Cache.setItem("isRedirectLogin", true);
|
|
54
|
+
window.location.assign(`${BASE}${authenticationType.redirectUri}`);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
33
57
|
};
|
|
34
58
|
};
|
|
35
59
|
|
|
@@ -39,8 +63,21 @@ export const useLogout = (): LogoutHook => {
|
|
|
39
63
|
const dispatch = useDispatch();
|
|
40
64
|
const application = useSelector(getApplication);
|
|
41
65
|
|
|
66
|
+
const LOGOUT_PATH = getSetting("LOGOUT_PATH", "/signout");
|
|
67
|
+
|
|
68
|
+
const isAuthenticated = application?.isLoggedIn ?? false;
|
|
42
69
|
return {
|
|
43
|
-
isAuthenticated
|
|
44
|
-
|
|
70
|
+
isAuthenticated,
|
|
71
|
+
authenticationTypes: application?.authenticationTypes ?? [],
|
|
72
|
+
logout: () => {
|
|
73
|
+
if (Cache.getItem("isRedirectLogin")) {
|
|
74
|
+
const origin = window.location.origin;
|
|
75
|
+
const url = `${origin}${BASE}/logout?url=${origin}${BASE}${LOGOUT_PATH}`;
|
|
76
|
+
Cache.setItem("isRedirectLogin", false);
|
|
77
|
+
window.location.assign(url);
|
|
78
|
+
} else {
|
|
79
|
+
return dispatch(logout());
|
|
80
|
+
}
|
|
81
|
+
},
|
|
45
82
|
};
|
|
46
83
|
};
|
package/src/hooks/useContent.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import { useState, useEffect } from "react";
|
|
3
|
-
import { useSelector } from "react-redux";
|
|
4
3
|
|
|
5
4
|
import SourceReferenceCollection from "../models/concepts/SourceReferenceCollection";
|
|
6
5
|
import ModularUIRequest from "../modularui/ModularUIRequest";
|
|
7
6
|
|
|
8
7
|
import { useProgressIndicator } from "../hooks/useProgressIndicator";
|
|
8
|
+
import { useLocale } from "../hooks/useI18n";
|
|
9
9
|
|
|
10
10
|
import type ContentModel from "../models/content/ContentModel";
|
|
11
11
|
|
|
@@ -17,7 +17,7 @@ export const useContentFromSourceReferences = (
|
|
|
17
17
|
renderChildSections: boolean
|
|
18
18
|
): Array<ContentModel> => {
|
|
19
19
|
const [content, setContent] = useState([]);
|
|
20
|
-
const localeCode =
|
|
20
|
+
const localeCode = useLocale();
|
|
21
21
|
|
|
22
22
|
const { start, finish } = useProgressIndicator();
|
|
23
23
|
|
package/src/hooks/useI18n.js
CHANGED
|
@@ -3,18 +3,13 @@ import { useSelector } from "react-redux";
|
|
|
3
3
|
import { createSelector } from "reselect";
|
|
4
4
|
import memoize from "lodash/memoize";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
const getLocales = (state) => state.i18n.locales;
|
|
6
|
+
import { getLocales, getLocale } from "../redux/selectors/i18n";
|
|
8
7
|
|
|
9
8
|
const getMessage = createSelector(
|
|
10
|
-
[getLocales,
|
|
9
|
+
[getLocales, getLocale],
|
|
11
10
|
(locales, localeCode) =>
|
|
12
11
|
memoize(
|
|
13
|
-
(
|
|
14
|
-
id?: string | null,
|
|
15
|
-
defaultMessage?: string | null,
|
|
16
|
-
placeholders?: Object
|
|
17
|
-
) =>
|
|
12
|
+
(id: string, defaultMessage?: string, placeholders?: Object) =>
|
|
18
13
|
locales
|
|
19
14
|
.getLocale(localeCode)
|
|
20
15
|
.getMessage(id, defaultMessage, placeholders),
|
|
@@ -25,8 +20,8 @@ const getMessage = createSelector(
|
|
|
25
20
|
/**
|
|
26
21
|
*/
|
|
27
22
|
const useMessage = (
|
|
28
|
-
id
|
|
29
|
-
defaultMessage?: string
|
|
23
|
+
id: string,
|
|
24
|
+
defaultMessage?: string,
|
|
30
25
|
placeholders?: Object | null
|
|
31
26
|
): any => useSelector(getMessage)(id, defaultMessage, placeholders);
|
|
32
27
|
|
|
@@ -34,4 +29,8 @@ const useMessage = (
|
|
|
34
29
|
*/
|
|
35
30
|
const useTranslate = (): ((...any) => any) => useSelector(getMessage);
|
|
36
31
|
|
|
37
|
-
|
|
32
|
+
/**
|
|
33
|
+
*/
|
|
34
|
+
const useLocale = (): string => useSelector(getLocale);
|
|
35
|
+
|
|
36
|
+
export { useTranslate, useMessage, useLocale };
|