aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-06 14:23:44 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-06 14:23:44 -0700
commita0406374030e930b8bd8032900e83b4a432ae28a (patch)
tree7ac2a8c1ac60289477a482fd57e669362affdc7b
parent3812292cc4413efff1358eb34cc5bccab9d1cbae (diff)
downloadtrackermap-web-a0406374030e930b8bd8032900e83b4a432ae28a.tar.gz
trackermap-web-a0406374030e930b8bd8032900e83b4a432ae28a.tar.bz2
trackermap-web-a0406374030e930b8bd8032900e83b4a432ae28a.zip
Fix account and server updates
-rw-r--r--modern/src/EditItemView.js5
-rw-r--r--modern/src/UserPage.js13
-rw-r--r--modern/src/admin/ServerPage.js7
3 files changed, 20 insertions, 5 deletions
diff --git a/modern/src/EditItemView.js b/modern/src/EditItemView.js
index 5ffdd9b5..550369fc 100644
--- a/modern/src/EditItemView.js
+++ b/modern/src/EditItemView.js
@@ -23,7 +23,7 @@ const useStyles = makeStyles((theme) => ({
}));
const EditItemView = ({
- children, endpoint, item, setItem, validate,
+ children, endpoint, item, setItem, validate, onItemSaved,
}) => {
const history = useHistory();
const classes = useStyles();
@@ -55,6 +55,9 @@ const EditItemView = ({
});
if (response.ok) {
+ if (onItemSaved) {
+ onItemSaved(await response.json());
+ }
history.goBack();
}
};
diff --git a/modern/src/UserPage.js b/modern/src/UserPage.js
index ce1e082f..549d7c59 100644
--- a/modern/src/UserPage.js
+++ b/modern/src/UserPage.js
@@ -10,6 +10,8 @@ import EditAttributesView from './attributes/EditAttributesView';
import LinkField from './form/LinkField';
import { useTranslation } from './LocalizationProvider';
import useUserAttributes from './attributes/useUserAttributes';
+import { useDispatch, useSelector } from 'react-redux';
+import { sessionActions } from './store';
const useStyles = makeStyles(() => ({
details: {
@@ -19,16 +21,25 @@ const useStyles = makeStyles(() => ({
const UserPage = () => {
const classes = useStyles();
+ const dispatch = useDispatch();
const t = useTranslation();
+ const currentUserId = useSelector((state) => state.session.user.id);
+
const userAttributes = useUserAttributes(t);
const [item, setItem] = useState();
+ const onItemSaved = (result) => {
+ if (result.id === currentUserId) {
+ dispatch(sessionActions.updateUser(result));
+ }
+ };
+
const validate = () => item && item.name && item.email && (item.id || item.password);
return (
- <EditItemView endpoint="users" item={item} setItem={setItem} validate={validate}>
+ <EditItemView endpoint="users" item={item} setItem={setItem} validate={validate} onItemSaved={onItemSaved}>
{item && (
<>
<Accordion defaultExpanded>
diff --git a/modern/src/admin/ServerPage.js b/modern/src/admin/ServerPage.js
index 5e608dee..33f8eeee 100644
--- a/modern/src/admin/ServerPage.js
+++ b/modern/src/admin/ServerPage.js
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { useState } from 'react';
import TextField from '@material-ui/core/TextField';
import {
@@ -39,8 +39,8 @@ const ServerPage = () => {
const userAttributes = useUserAttributes(t);
const deviceAttributes = useDeviceAttributes(t);
- const item = useSelector((state) => state.session.server);
- const setItem = (updatedItem) => dispatch(sessionActions.updateServer(updatedItem));
+ const original = useSelector((state) => state.session.server);
+ const [item, setItem] = useState({ ...original });
const handleSave = async () => {
const response = await fetch('/api/server', {
@@ -50,6 +50,7 @@ const ServerPage = () => {
});
if (response.ok) {
+ dispatch(sessionActions.updateServer(await response.json()));
history.goBack();
}
};