aboutsummaryrefslogtreecommitdiff
path: root/modern/src
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src')
-rw-r--r--modern/src/CachingController.js29
-rw-r--r--modern/src/store/drivers.js16
-rw-r--r--modern/src/store/groups.js16
-rw-r--r--modern/src/store/index.js9
-rw-r--r--modern/src/store/maintenances.js16
5 files changed, 85 insertions, 1 deletions
diff --git a/modern/src/CachingController.js b/modern/src/CachingController.js
index fa3b9f6b..3f808de2 100644
--- a/modern/src/CachingController.js
+++ b/modern/src/CachingController.js
@@ -1,6 +1,6 @@
import { useDispatch, useSelector } from 'react-redux';
import { connect } from 'react-redux';
-import { geofencesActions } from './store';
+import { geofencesActions, groupsActions, driversActions, maintenancesActions } from './store';
import { useEffectAsync } from './reactHelper';
const CachingController = () => {
@@ -15,6 +15,33 @@ const CachingController = () => {
}
}
}, [authenticated]);
+
+ useEffectAsync(async () => {
+ if (authenticated) {
+ const response = await fetch('/api/groups');
+ if (response.ok) {
+ dispatch(groupsActions.update(await response.json()));
+ }
+ }
+ }, [authenticated]);
+
+ useEffectAsync(async () => {
+ if (authenticated) {
+ const response = await fetch('/api/drivers');
+ if (response.ok) {
+ dispatch(driversActions.update(await response.json()));
+ }
+ }
+ }, [authenticated]);
+
+ useEffectAsync(async () => {
+ if (authenticated) {
+ const response = await fetch('/api/maintenance');
+ if (response.ok) {
+ dispatch(maintenancesActions.update(await response.json()));
+ }
+ }
+ }, [authenticated]);
return null;
}
diff --git a/modern/src/store/drivers.js b/modern/src/store/drivers.js
new file mode 100644
index 00000000..63522d78
--- /dev/null
+++ b/modern/src/store/drivers.js
@@ -0,0 +1,16 @@
+import { createSlice } from '@reduxjs/toolkit';
+
+const { reducer, actions } = createSlice({
+ name: 'drivers',
+ initialState: {
+ items: {},
+ },
+ reducers: {
+ update(state, action) {
+ action.payload.forEach(item => state.items[item['id']] = item);
+ },
+ }
+});
+
+export { actions as driversActions };
+export { reducer as driversReducer };
diff --git a/modern/src/store/groups.js b/modern/src/store/groups.js
new file mode 100644
index 00000000..483323f3
--- /dev/null
+++ b/modern/src/store/groups.js
@@ -0,0 +1,16 @@
+import { createSlice } from '@reduxjs/toolkit';
+
+const { reducer, actions } = createSlice({
+ name: 'groups',
+ initialState: {
+ items: {},
+ },
+ reducers: {
+ update(state, action) {
+ action.payload.forEach(item => state.items[item['id']] = item);
+ },
+ }
+});
+
+export { actions as groupsActions };
+export { reducer as groupsReducer };
diff --git a/modern/src/store/index.js b/modern/src/store/index.js
index 1fddae99..6e2bb204 100644
--- a/modern/src/store/index.js
+++ b/modern/src/store/index.js
@@ -4,17 +4,26 @@ import { sessionReducer as session } from './session';
import { devicesReducer as devices } from './devices';
import { positionsReducer as positions } from './positions';
import { geofencesReducer as geofences } from './geofences';
+import { groupsReducer as groups } from './groups';
+import { driversReducer as drivers } from './drivers';
+import { maintenancesReducer as maintenances } from './maintenances';
const reducer = combineReducers({
session,
devices,
positions,
geofences,
+ groups,
+ drivers,
+ maintenances,
});
export { sessionActions } from './session';
export { devicesActions } from './devices';
export { positionsActions } from './positions';
export { geofencesActions } from './geofences';
+export { groupsActions } from './groups';
+export { driversActions } from './drivers';
+export { maintenancesActions } from './maintenances';
export default configureStore({ reducer });
diff --git a/modern/src/store/maintenances.js b/modern/src/store/maintenances.js
new file mode 100644
index 00000000..0813f6b6
--- /dev/null
+++ b/modern/src/store/maintenances.js
@@ -0,0 +1,16 @@
+import { createSlice } from '@reduxjs/toolkit';
+
+const { reducer, actions } = createSlice({
+ name: 'maintenances',
+ initialState: {
+ items: {},
+ },
+ reducers: {
+ update(state, action) {
+ action.payload.forEach(item => state.items[item['id']] = item);
+ },
+ }
+});
+
+export { actions as maintenancesActions };
+export { reducer as maintenancesReducer };