aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common/util
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-03 16:22:21 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-03 16:22:21 -0700
commitb418d001a498b5a5108bb13983b4f3aba6c60dbc (patch)
tree464dd5e4fc3f13a6209c05df4d3db3cbbe8e85d6 /modern/src/common/util
parent5d17af8102f17d41610acb9ff34aabbff871cda1 (diff)
downloadtrackermap-web-b418d001a498b5a5108bb13983b4f3aba6c60dbc.tar.gz
trackermap-web-b418d001a498b5a5108bb13983b4f3aba6c60dbc.tar.bz2
trackermap-web-b418d001a498b5a5108bb13983b4f3aba6c60dbc.zip
Support feature disabling
Diffstat (limited to 'modern/src/common/util')
-rw-r--r--modern/src/common/util/useFeatures.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/modern/src/common/util/useFeatures.js b/modern/src/common/util/useFeatures.js
new file mode 100644
index 00000000..f0a8299a
--- /dev/null
+++ b/modern/src/common/util/useFeatures.js
@@ -0,0 +1,30 @@
+import { useSelector } from 'react-redux';
+
+const get = (server, user, key) => {
+ if (server && user) {
+ if (server.forceSettings) {
+ return server.attributes[key] || user.attributes[key] || false;
+ }
+ return user.attributes[key] || server.attributes[key] || false;
+ }
+ return false;
+};
+
+export default () => useSelector((state) => {
+ const { server, user } = state.session;
+
+ const disableVehicleFetures = get(server, user, 'ui.disableVehicleFetures');
+ const disableDrivers = disableVehicleFetures || get(server, user, 'ui.disableDrivers');
+ const disableMaintenance = disableVehicleFetures || get(server, user, 'ui.disableMaintenance');
+ const disableEvents = get(server, user, 'ui.disableEvents');
+ const disableComputedAttributes = get(server, user, 'ui.disableComputedAttributes');
+ const disableCalendars = get(server, user, 'ui.disableCalendars');
+
+ return {
+ disableDrivers,
+ disableMaintenance,
+ disableEvents,
+ disableComputedAttributes,
+ disableCalendars,
+ };
+});