diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-11 18:32:36 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-11 18:32:36 -0700 |
commit | e7995f3b7a6b0828b81bebaf556ef7afb59bef61 (patch) | |
tree | bd9aebc2ed24253ca0bb2a604ac65ae96730a3d1 /modern/src/settings/UserPage.js | |
parent | 0aecbc3bf856b17f42e363eff2bac4fb0ce1f7ed (diff) | |
download | trackermap-web-e7995f3b7a6b0828b81bebaf556ef7afb59bef61.tar.gz trackermap-web-e7995f3b7a6b0828b81bebaf556ef7afb59bef61.tar.bz2 trackermap-web-e7995f3b7a6b0828b81bebaf556ef7afb59bef61.zip |
Automatically add map keys
Diffstat (limited to 'modern/src/settings/UserPage.js')
-rw-r--r-- | modern/src/settings/UserPage.js | 26 |
1 files changed, 21 insertions, 5 deletions
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 && ( <> - <Accordion defaultExpanded> + <Accordion defaultExpanded={!attribute}> <AccordionSummary expandIcon={<ExpandMoreIcon />}> <Typography variant="subtitle1"> {t('sharedRequired')} @@ -286,7 +301,7 @@ const UserPage = () => { </FormGroup> </AccordionDetails> </Accordion> - <Accordion> + <Accordion defaultExpanded={!!attribute}> <AccordionSummary expandIcon={<ExpandMoreIcon />}> <Typography variant="subtitle1"> {t('sharedAttributes')} @@ -297,6 +312,7 @@ const UserPage = () => { attributes={item.attributes} setAttributes={(attributes) => setItem({ ...item, attributes })} definitions={{ ...commonUserAttributes, ...userAttributes }} + focusAttribute={attribute} /> </AccordionDetails> </Accordion> |