@trackunit/react-core-hooks 1.0.4 → 1.0.7
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/index.cjs.js +7 -7
- package/index.esm.js +7 -7
- package/package.json +4 -4
package/index.cjs.js
CHANGED
|
@@ -58,8 +58,8 @@ const useAnalytics = (events) => {
|
|
|
58
58
|
// Automatically append the description from the event type
|
|
59
59
|
const logEventWithDescription = (logEvent, events) => {
|
|
60
60
|
return (eventName, details, nameSupplement) => {
|
|
61
|
-
const event = events
|
|
62
|
-
const eventDescription = event
|
|
61
|
+
const event = events?.[eventName];
|
|
62
|
+
const eventDescription = event?.description;
|
|
63
63
|
// Include description in the details object.
|
|
64
64
|
const detailsWithDescription = {
|
|
65
65
|
eventDescription,
|
|
@@ -457,7 +457,7 @@ const useHasAccessTo = (options) => {
|
|
|
457
457
|
React.useEffect(() => {
|
|
458
458
|
async function checkAccess() {
|
|
459
459
|
if (options.assetId) {
|
|
460
|
-
const doHaveAccess = await
|
|
460
|
+
const doHaveAccess = await context?.hasAccessTo(options);
|
|
461
461
|
setHasAccess(() => doHaveAccess);
|
|
462
462
|
}
|
|
463
463
|
}
|
|
@@ -893,13 +893,13 @@ const useCurrentUser = () => {
|
|
|
893
893
|
const validateState = ({ state, schema, onValidationFailed, onValidationSuccessful, defaultState, }) => {
|
|
894
894
|
try {
|
|
895
895
|
const parsedState = schema.parse(state);
|
|
896
|
-
onValidationSuccessful
|
|
896
|
+
onValidationSuccessful?.(parsedState);
|
|
897
897
|
return parsedState;
|
|
898
898
|
}
|
|
899
899
|
catch (error) {
|
|
900
900
|
// eslint-disable-next-line no-console
|
|
901
901
|
console.error("Failed to parse and validate the state from local storage.", error);
|
|
902
|
-
onValidationFailed
|
|
902
|
+
onValidationFailed?.(error);
|
|
903
903
|
return defaultState;
|
|
904
904
|
}
|
|
905
905
|
};
|
|
@@ -974,11 +974,11 @@ const useLocalStorageEffect = ({ key, state, defaultState, schema, onValidationF
|
|
|
974
974
|
// eslint-disable-next-line no-console
|
|
975
975
|
console.error(`State validation failed. Resetting local storage to default state: ${defaultState}.`, error);
|
|
976
976
|
localStorage.removeItem(key);
|
|
977
|
-
onValidationFailed
|
|
977
|
+
onValidationFailed?.(error);
|
|
978
978
|
},
|
|
979
979
|
onValidationSuccessful: data => {
|
|
980
980
|
setLocalStorage(key, data);
|
|
981
|
-
onValidationSuccessful
|
|
981
|
+
onValidationSuccessful?.(data);
|
|
982
982
|
},
|
|
983
983
|
});
|
|
984
984
|
}
|
package/index.esm.js
CHANGED
|
@@ -38,8 +38,8 @@ const useAnalytics = (events) => {
|
|
|
38
38
|
// Automatically append the description from the event type
|
|
39
39
|
const logEventWithDescription = (logEvent, events) => {
|
|
40
40
|
return (eventName, details, nameSupplement) => {
|
|
41
|
-
const event = events
|
|
42
|
-
const eventDescription = event
|
|
41
|
+
const event = events?.[eventName];
|
|
42
|
+
const eventDescription = event?.description;
|
|
43
43
|
// Include description in the details object.
|
|
44
44
|
const detailsWithDescription = {
|
|
45
45
|
eventDescription,
|
|
@@ -437,7 +437,7 @@ const useHasAccessTo = (options) => {
|
|
|
437
437
|
useEffect(() => {
|
|
438
438
|
async function checkAccess() {
|
|
439
439
|
if (options.assetId) {
|
|
440
|
-
const doHaveAccess = await
|
|
440
|
+
const doHaveAccess = await context?.hasAccessTo(options);
|
|
441
441
|
setHasAccess(() => doHaveAccess);
|
|
442
442
|
}
|
|
443
443
|
}
|
|
@@ -873,13 +873,13 @@ const useCurrentUser = () => {
|
|
|
873
873
|
const validateState = ({ state, schema, onValidationFailed, onValidationSuccessful, defaultState, }) => {
|
|
874
874
|
try {
|
|
875
875
|
const parsedState = schema.parse(state);
|
|
876
|
-
onValidationSuccessful
|
|
876
|
+
onValidationSuccessful?.(parsedState);
|
|
877
877
|
return parsedState;
|
|
878
878
|
}
|
|
879
879
|
catch (error) {
|
|
880
880
|
// eslint-disable-next-line no-console
|
|
881
881
|
console.error("Failed to parse and validate the state from local storage.", error);
|
|
882
|
-
onValidationFailed
|
|
882
|
+
onValidationFailed?.(error);
|
|
883
883
|
return defaultState;
|
|
884
884
|
}
|
|
885
885
|
};
|
|
@@ -954,11 +954,11 @@ const useLocalStorageEffect = ({ key, state, defaultState, schema, onValidationF
|
|
|
954
954
|
// eslint-disable-next-line no-console
|
|
955
955
|
console.error(`State validation failed. Resetting local storage to default state: ${defaultState}.`, error);
|
|
956
956
|
localStorage.removeItem(key);
|
|
957
|
-
onValidationFailed
|
|
957
|
+
onValidationFailed?.(error);
|
|
958
958
|
},
|
|
959
959
|
onValidationSuccessful: data => {
|
|
960
960
|
setLocalStorage(key, data);
|
|
961
|
-
onValidationSuccessful
|
|
961
|
+
onValidationSuccessful?.(data);
|
|
962
962
|
},
|
|
963
963
|
});
|
|
964
964
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-hooks",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"react": "18.3.1",
|
|
11
11
|
"jest-fetch-mock": "^3.0.3",
|
|
12
12
|
"zod": "3.22.4",
|
|
13
|
-
"@trackunit/react-core-contexts-api": "^1.0.
|
|
14
|
-
"@trackunit/iris-app-runtime-core": "^1.0.
|
|
15
|
-
"@trackunit/shared-utils": "^1.
|
|
13
|
+
"@trackunit/react-core-contexts-api": "^1.0.7",
|
|
14
|
+
"@trackunit/iris-app-runtime-core": "^1.0.7",
|
|
15
|
+
"@trackunit/shared-utils": "^1.1.1"
|
|
16
16
|
},
|
|
17
17
|
"module": "./index.esm.js",
|
|
18
18
|
"main": "./index.cjs.js",
|