aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common/util/useFeatures.js
blob: 7a7ffcd285dfd061f0f17315ada3c8d6984a5597 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { useSelector } from 'react-redux';

const get = (server, user, key) => {
  if (server && user) {
    if (user.administrator) {
      return false;
    }
    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,
  };
});