From 6afcf8a80dd297a228fb744a3f3e2ecdc70704b5 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 2 Oct 2022 10:03:02 -0700 Subject: Reflect group updates --- modern/src/settings/GroupPage.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'modern/src/settings') diff --git a/modern/src/settings/GroupPage.js b/modern/src/settings/GroupPage.js index 0bf66c69..b9ec36c9 100644 --- a/modern/src/settings/GroupPage.js +++ b/modern/src/settings/GroupPage.js @@ -1,4 +1,5 @@ import React, { useState } from 'react'; +import { useDispatch } from 'react-redux'; import TextField from '@mui/material/TextField'; import { @@ -16,6 +17,8 @@ import useCommonDeviceAttributes from '../common/attributes/useCommonDeviceAttri import useGroupAttributes from '../common/attributes/useGroupAttributes'; import useFeatures from '../common/util/useFeatures'; import { formatNotificationTitle } from '../common/util/formatter'; +import { useCatch } from '../reactHelper'; +import { groupsActions } from '../store'; const useStyles = makeStyles((theme) => ({ details: { @@ -28,6 +31,7 @@ const useStyles = makeStyles((theme) => ({ const GroupPage = () => { const classes = useStyles(); + const dispatch = useDispatch(); const t = useTranslation(); const commonDeviceAttributes = useCommonDeviceAttributes(t); @@ -37,6 +41,15 @@ const GroupPage = () => { const [item, setItem] = useState(); + const onItemSaved = useCatch(async () => { + const response = await fetch('/api/groups'); + if (response.ok) { + dispatch(groupsActions.update(await response.json())); + } else { + throw Error(await response.text()); + } + }); + const validate = () => item && item.name; return ( @@ -45,6 +58,7 @@ const GroupPage = () => { item={item} setItem={setItem} validate={validate} + onItemSaved={onItemSaved} menu={} breadcrumbs={['settingsTitle', 'groupDialog']} > -- cgit v1.2.3