From e7995f3b7a6b0828b81bebaf556ef7afb59bef61 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 11 Jun 2022 18:32:36 -0700 Subject: Automatically add map keys --- modern/src/settings/UserPage.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'modern/src/settings/UserPage.js') diff --git a/modern/src/settings/UserPage.js b/modern/src/settings/UserPage.js index d4046fbf..964291e8 100644 --- a/modern/src/settings/UserPage.js +++ b/modern/src/settings/UserPage.js @@ -1,6 +1,4 @@ -import React, { useState } from 'react'; -import TextField from '@mui/material/TextField'; - +import React, { useEffect, useState } from 'react'; import { Accordion, AccordionSummary, @@ -16,6 +14,7 @@ import { IconButton, OutlinedInput, FormGroup, + TextField, } from '@mui/material'; import makeStyles from '@mui/styles/makeStyles'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; @@ -33,6 +32,7 @@ import SettingsMenu from './components/SettingsMenu'; import useCommonUserAttributes from '../common/attributes/useCommonUserAttributes'; import { useAdministrator, useManager } from '../common/util/permissions'; import { prefixString } from '../common/util/stringUtils'; +import useQuery from '../common/util/useQuery'; const useStyles = makeStyles((theme) => ({ details: { @@ -58,6 +58,21 @@ const UserPage = () => { const [item, setItem] = useState(); + const query = useQuery(); + const [queryHandled, setQueryHandled] = useState(false); + const attribute = query.get('attribute'); + + useEffect(() => { + if (!queryHandled && item && attribute) { + if (!item.attributes.hasOwnProperty('attribute')) { + const updatedAttributes = { ...item.attributes }; + updatedAttributes[attribute] = ''; + setItem({ ...item, attributes: updatedAttributes }); + } + setQueryHandled(true); + } + }, [item, queryHandled, setQueryHandled, attribute]); + const onItemSaved = (result) => { if (result.id === currentUserId) { dispatch(sessionActions.updateUser(result)); @@ -79,7 +94,7 @@ const UserPage = () => { > {item && ( <> - + }> {t('sharedRequired')} @@ -286,7 +301,7 @@ const UserPage = () => { - + }> {t('sharedAttributes')} @@ -297,6 +312,7 @@ const UserPage = () => { attributes={item.attributes} setAttributes={(attributes) => setItem({ ...item, attributes })} definitions={{ ...commonUserAttributes, ...userAttributes }} + focusAttribute={attribute} /> -- cgit v1.2.3