diff --git a/src/fireedge/src/public/components/FormControl/ErrorHelper.js b/src/fireedge/src/public/components/FormControl/ErrorHelper.js index 84e58b50d4b..d2ff9114745 100644 --- a/src/fireedge/src/public/components/FormControl/ErrorHelper.js +++ b/src/fireedge/src/public/components/FormControl/ErrorHelper.js @@ -1,4 +1,5 @@ import React from 'react'; +import { string } from 'prop-types'; import { Box, @@ -26,12 +27,13 @@ const useStyles = makeStyles(theme => { }, text: { ...theme.typography.body1, - paddingLeft: theme.spacing(1) + paddingLeft: theme.spacing(1), + overflowWrap: 'anywhere' } }; }); -const ErrorHelper = ({ label = 'Error', ...rest }) => { +const ErrorHelper = ({ label, ...rest }) => { const classes = useStyles(); return ( @@ -44,4 +46,12 @@ const ErrorHelper = ({ label = 'Error', ...rest }) => { ); }; +ErrorHelper.propTypes = { + label: string +}; + +ErrorHelper.defaultProps = { + label: 'Error' +}; + export default ErrorHelper; diff --git a/src/fireedge/src/public/components/FormControl/GroupSelect.js b/src/fireedge/src/public/components/FormControl/GroupSelect.js index c28234f8439..23400a297cb 100644 --- a/src/fireedge/src/public/components/FormControl/GroupSelect.js +++ b/src/fireedge/src/public/components/FormControl/GroupSelect.js @@ -14,17 +14,16 @@ /* -------------------------------------------------------------------------- */ import React from 'react'; -import { func } from 'prop-types'; import { MenuItem, TextField } from '@material-ui/core'; import { FilterVintage } from '@material-ui/icons'; import useAuth from 'client/hooks/useAuth'; import useOpennebula from 'client/hooks/useOpennebula'; -import { Translate } from 'client/components/HOC'; +import { Tr } from 'client/components/HOC'; import { FILTER_POOL } from 'client/constants'; -const GroupSelect = ({ handleChange }) => { +const GroupSelect = props => { const { filterPool, authUser } = useAuth(); const { groups } = useOpennebula(); @@ -53,25 +52,21 @@ const GroupSelect = ({ handleChange }) => { } + label={Tr('Select a group')} FormHelperTextProps={{ 'data-cy': 'select-group-error' }} + {...props} > - {`Show all`} + {Tr('Show all')} {orderGroups} ); }; -GroupSelect.propTypes = { - handleChange: func -}; +GroupSelect.propTypes = {}; -GroupSelect.defaultProps = { - handleChange: () => undefined -}; +GroupSelect.defaultProps = {}; export default GroupSelect; diff --git a/src/fireedge/src/public/components/Header/FilterPoolSelect.js b/src/fireedge/src/public/components/Header/FilterPoolSelect.js deleted file mode 100644 index be3ad3102c7..00000000000 --- a/src/fireedge/src/public/components/Header/FilterPoolSelect.js +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */ -/* */ -/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ -/* not use this file except in compliance with the License. You may obtain */ -/* a copy of the License at */ -/* */ -/* http://www.apache.org/licenses/LICENSE-2.0 */ -/* */ -/* Unless required by applicable law or agreed to in writing, software */ -/* distributed under the License is distributed on an "AS IS" BASIS, */ -/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ -/* See the License for the specific language governing permissions and */ -/* limitations under the License. */ -/* -------------------------------------------------------------------------- */ - -import React from 'react'; - -import { Box } from '@material-ui/core'; - -import { FILTER_POOL } from 'client/constants'; -import useAuth from 'client/hooks/useAuth'; -import GroupSelect from '../FormControl/GroupSelect'; - -const FilterPoolSelect = () => { - const { setPrimaryGroup } = useAuth(); - - const handleChangeFilter = evt => { - console.log(evt); - // setPrimaryGroup({ group: }); - }; - - return ; -}; - -export default FilterPoolSelect; diff --git a/src/fireedge/src/public/components/Header/Group.js b/src/fireedge/src/public/components/Header/Group.js new file mode 100644 index 00000000000..ad4b933f962 --- /dev/null +++ b/src/fireedge/src/public/components/Header/Group.js @@ -0,0 +1,80 @@ +import React from 'react'; + +import { Button } from '@material-ui/core'; +import FilterIcon from '@material-ui/icons/FilterDrama'; +import SelectedIcon from '@material-ui/icons/FilterVintage'; + +import useAuth from 'client/hooks/useAuth'; +import useOpennebula from 'client/hooks/useOpennebula'; +import Search from 'client/components/Search'; + +import { FILTER_POOL } from 'client/constants'; +import HeaderPopover from 'client/components/Header/Popover'; +import headerStyles from 'client/components/Header/styles'; + +const { ALL_RESOURCES, PRIMARY_GROUP_RESOURCES } = FILTER_POOL; + +const Group = () => { + const classes = headerStyles(); + const { authUser, filterPool, setPrimaryGroup } = useAuth(); + const { groups } = useOpennebula(); + + const handleChangeGroup = group => { + group && setPrimaryGroup({ group }); + }; + + const filterSearch = ({ NAME }, search) => + NAME?.toLowerCase().includes(search); + + const renderResult = ({ ID, NAME }, handleClose) => { + const isSelected = + (filterPool === ALL_RESOURCES && ALL_RESOURCES === ID) || + (filterPool === PRIMARY_GROUP_RESOURCES && authUser?.GID === ID); + + return ( + + ); + }; + + const sortMainGroupFirst = groups + ?.concat({ ID: ALL_RESOURCES, NAME: 'Show All' }) + ?.sort((a, b) => { + if (a.ID === authUser?.GUID) { + return -1; + } else if (b.ID === authUser?.GUID) { + return 1; + } + return 0; + }); + + return ( + } + IconProps={{ 'data-cy': 'header-group-button' }} + headerTitle="Switch group" + > + {({ handleClose }) => ( + renderResult(group, handleClose)} + /> + )} + + ); +}; + +export default Group; diff --git a/src/fireedge/src/public/components/Header/Popover.js b/src/fireedge/src/public/components/Header/Popover.js new file mode 100644 index 00000000000..48dee007b85 --- /dev/null +++ b/src/fireedge/src/public/components/Header/Popover.js @@ -0,0 +1,124 @@ +import React, { useState } from 'react'; +import PropTypes from 'prop-types'; + +import { + Box, + IconButton, + useMediaQuery, + Popover, + Typography, + Button +} from '@material-ui/core'; +import CloseIcon from '@material-ui/icons/Close'; + +import { Tr } from 'client/components/HOC'; + +import headerStyles from 'client/components/Header/styles'; +import clsx from 'clsx'; + +const typeButton = { + button: Button, + iconButton: IconButton +}; + +const HeaderPopover = ({ + id, + icon, + buttonLabel, + IconProps, + headerTitle, + disablePadding, + children +}) => { + const classes = headerStyles(); + const isMobile = useMediaQuery(theme => theme.breakpoints.only('xs')); + + const [anchorEl, setAnchorEl] = useState(null); + + const handleOpen = event => setAnchorEl(event.currentTarget); + const handleClose = () => setAnchorEl(null); + + const open = Boolean(anchorEl); + const anchorId = open ? id : undefined; + + const ButtonComponent = React.useMemo( + () => (buttonLabel ? typeButton.button : typeButton.iconButton), + [buttonLabel] + ); + + return ( + <> + + {icon} + {buttonLabel && ( + {buttonLabel} + )} + + + {(headerTitle || isMobile) && ( + + {headerTitle && ( + + {Tr(headerTitle)} + + )} + {isMobile && ( + + + + )} + + )} + {children({ handleClose })} + + + ); +}; + +HeaderPopover.propTypes = { + id: PropTypes.string, + icon: PropTypes.node, + buttonLabel: PropTypes.string, + IconProps: PropTypes.objectOf(PropTypes.object), + headerTitle: PropTypes.string, + disablePadding: PropTypes.bool, + children: PropTypes.func +}; + +HeaderPopover.defaultProps = { + id: 'id-popover', + icon: null, + buttonLabel: undefined, + IconProps: {}, + headerTitle: null, + disablePadding: false, + children: () => undefined +}; + +export default HeaderPopover; diff --git a/src/fireedge/src/public/components/Header/User.js b/src/fireedge/src/public/components/Header/User.js index 779f48e8f00..983aee2e097 100644 --- a/src/fireedge/src/public/components/Header/User.js +++ b/src/fireedge/src/public/components/Header/User.js @@ -1,114 +1,40 @@ -/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */ -/* */ -/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ -/* not use this file except in compliance with the License. You may obtain */ -/* a copy of the License at */ -/* */ -/* http://www.apache.org/licenses/LICENSE-2.0 */ -/* */ -/* Unless required by applicable law or agreed to in writing, software */ -/* distributed under the License is distributed on an "AS IS" BASIS, */ -/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ -/* See the License for the specific language governing permissions and */ -/* limitations under the License. */ -/* -------------------------------------------------------------------------- */ - -import React, { useState, useRef, Fragment } from 'react'; +import React from 'react'; import { useHistory } from 'react-router-dom'; -import { - Button, - Popper, - Grow, - Paper, - MenuItem, - MenuList, - ClickAwayListener, - Divider, - useMediaQuery -} from '@material-ui/core'; +import { MenuItem, MenuList, Divider } from '@material-ui/core'; import AccountCircleIcon from '@material-ui/icons/AccountCircle'; -import { Translate } from 'client/components/HOC'; -import { PATH } from 'client/router/endpoints'; -import { SignOut } from 'client/constants'; import useAuth from 'client/hooks/useAuth'; -import FilterPoolSelect from 'client/components/Header/FilterPoolSelect'; +import { Tr } from 'client/components/HOC'; + +import { SignOut } from 'client/constants'; +import { PATH } from 'client/router/endpoints'; +import HeaderPopover from 'client/components/Header/Popover'; const User = React.memo(() => { const history = useHistory(); - const { logout, authUser, isOneAdmin } = useAuth(); - const isUpSm = useMediaQuery(theme => theme.breakpoints.up('sm')); - - const [open, setOpen] = useState(false); - const anchorRef = useRef(null); - const { current } = anchorRef; - - const handleToggle = () => setOpen(prevOpen => !prevOpen); + const { logout, authUser } = useAuth(); const handleLogout = () => logout(); const handleGoToSettings = () => history.push(PATH.SETTINGS); - const handleClose = e => { - if (current && current.contains(e.target)) { - return; - } - setOpen(false); - }; - return ( - - - - {({ TransitionProps, placement }) => ( - - - - - Settings - - - - - {!isOneAdmin && ( - <> - - - - - - )} - - - - - )} - - + } + IconProps={{ 'data-cy': 'header-user-button' }} + disablePadding + > + {() => ( + + {Tr('Settings')} + + + {Tr(SignOut)} + + + )} + ); }); diff --git a/src/fireedge/src/public/components/Header/Zone.js b/src/fireedge/src/public/components/Header/Zone.js index 43077f7711a..b194bf6c948 100644 --- a/src/fireedge/src/public/components/Header/Zone.js +++ b/src/fireedge/src/public/components/Header/Zone.js @@ -13,72 +13,27 @@ /* limitations under the License. */ /* -------------------------------------------------------------------------- */ -import React, { useState, useRef } from 'react'; -import { - Button, - Popper, - Grow, - Paper, - MenuItem, - MenuList, - ClickAwayListener -} from '@material-ui/core'; -import LanguageIcon from '@material-ui/icons/Language'; - -const Zone = React.memo(() => { - const [open, setOpen] = useState(false); - const anchorRef = useRef(null); - const { current } = anchorRef; +import React from 'react'; - const handleToggle = () => { - setOpen(prevOpen => !prevOpen); - }; +import { MenuItem, MenuList } from '@material-ui/core'; +import LanguageIcon from '@material-ui/icons/Language'; - const handleClose = e => { - if (current && current.contains(e.target)) { - return; - } - setOpen(false); - }; +import { Tr } from 'client/components/HOC'; +import HeaderPopover from 'client/components/Header/Popover'; - return ( - <> - - - {({ TransitionProps, placement }) => ( - - - - - Zone - - - - - )} - - - ); -}); +const Zone = React.memo(() => ( + } + IconProps={{ 'data-cy': 'header-zone-button' }} + disablePadding + > + {({ handleClose }) => ( + + {Tr('Zone')} + + )} + +)); export default Zone; diff --git a/src/fireedge/src/public/components/Header/index.js b/src/fireedge/src/public/components/Header/index.js index 96dc1ed8ecc..0523ce3f6cb 100644 --- a/src/fireedge/src/public/components/Header/index.js +++ b/src/fireedge/src/public/components/Header/index.js @@ -25,12 +25,15 @@ import { } from '@material-ui/core'; import MenuIcon from '@material-ui/icons/Menu'; +import useAuth from 'client/hooks/useAuth'; import useGeneral from 'client/hooks/useGeneral'; import User from 'client/components/Header/User'; +import Group from 'client/components/Header/Group'; import Zone from 'client/components/Header/Zone'; import headerStyles from 'client/components/Header/styles'; const Header = ({ title }) => { + const { isOneAdmin } = useAuth(); const { isFixMenu, fixMenu } = useGeneral(); const classes = headerStyles(); const isUpLg = useMediaQuery(theme => theme.breakpoints.up('lg')); @@ -54,11 +57,12 @@ const Header = ({ title }) => { {title} + {!isOneAdmin && } ), - [isFixMenu, fixMenu, isUpLg] + [isFixMenu, fixMenu, isUpLg, isOneAdmin] ); }; diff --git a/src/fireedge/src/public/components/Header/styles.js b/src/fireedge/src/public/components/Header/styles.js index 53908492f21..99bc9e5fd6c 100644 --- a/src/fireedge/src/public/components/Header/styles.js +++ b/src/fireedge/src/public/components/Header/styles.js @@ -4,5 +4,40 @@ export default makeStyles(theme => ({ title: { flexGrow: 1, textTransform: 'capitalize' + }, + /* POPOVER */ + backdrop: { + [theme.breakpoints.only('xs')]: { + backgroundColor: theme.palette.action.disabledOpacity + } + }, + paper: { + [theme.breakpoints.only('xs')]: { + width: '100%', + height: '100%' + } + }, + padding: { + padding: theme.spacing(2) + }, + header: { + display: 'flex', + alignItems: 'center', + justifyContent: 'flex-end', + borderBottom: '1px solid', + borderBottomColor: theme.palette.action.disabledBackground + }, + buttonLabel: { + paddingLeft: theme.spacing(1), + [theme.breakpoints.only('xs')]: { + display: 'none' + } + }, + /* GROUP SWITCHER */ + headerSwitcherLabel: { flexGrow: 1 }, + groupButton: { justifyContent: 'start' }, + groupSelectedIcon: { + fontSize: '1rem', + margin: theme.spacing(0, 2) } })); diff --git a/src/fireedge/src/public/components/Search/index.js b/src/fireedge/src/public/components/Search/index.js new file mode 100644 index 00000000000..760ae9c96a4 --- /dev/null +++ b/src/fireedge/src/public/components/Search/index.js @@ -0,0 +1,54 @@ +import React, { useState, useEffect } from 'react'; +import PropTypes from 'prop-types'; + +import { TextField, Box } from '@material-ui/core'; + +const Search = ({ + list, + maxResults, + filterSearch, + renderResult, + ResultBoxProps +}) => { + const [search, setSearch] = useState(''); + const [result, setResult] = useState(list); + + useEffect(() => { + setResult(list?.filter(item => filterSearch(item, search))); + }, [search, list]); + + const handleChange = event => setSearch(event.target.value); + + return ( + <> + + + {result?.slice(0, maxResults).map(renderResult)} + + + ); +}; + +Search.propTypes = { + list: PropTypes.arrayOf(PropTypes.object).isRequired, + maxResults: PropTypes.number, + filterSearch: PropTypes.func, + renderResult: PropTypes.func, + ResultBoxProps: PropTypes.objectOf(PropTypes.object) +}; + +Search.defaultProps = { + list: [], + maxResults: undefined, + filterSearch: (item, search) => item.toLowerCase().includes(search), + renderResult: item => item, + ResultBoxProps: {} +}; + +export default Search; diff --git a/src/fireedge/src/public/components/Search/styles.js b/src/fireedge/src/public/components/Search/styles.js new file mode 100644 index 00000000000..4d91dfda372 --- /dev/null +++ b/src/fireedge/src/public/components/Search/styles.js @@ -0,0 +1,19 @@ +import { makeStyles } from '@material-ui/core'; + +export default makeStyles(theme => ({ + backdrop: { + [theme.breakpoints.only('xs')]: { + backgroundColor: theme.palette.action.disabledOpacity + } + }, + paper: { + padding: '1rem', + [theme.breakpoints.only('xs')]: { + width: '100%', + height: '100%' + } + }, + header: { display: 'flex', alignItems: 'center' }, + title: { flexGrow: 1 }, + button: { justifyContent: 'start' } +})); diff --git a/src/fireedge/src/public/constants/index.js b/src/fireedge/src/public/constants/index.js index dc36b321ab7..42f59a8b02f 100644 --- a/src/fireedge/src/public/constants/index.js +++ b/src/fireedge/src/public/constants/index.js @@ -26,6 +26,7 @@ module.exports = { Token2FA: '2FA Token', SignOut: 'Sign Out', jwtName: 'SunstoneToken', + filterPool: 'FilterPool', Submit: 'Submit', Response: 'Response', by: { diff --git a/src/fireedge/src/public/containers/Application/index.js b/src/fireedge/src/public/containers/Application/index.js new file mode 100644 index 00000000000..cac823721ad --- /dev/null +++ b/src/fireedge/src/public/containers/Application/index.js @@ -0,0 +1,5 @@ +import Create from 'client/containers/Application/Create'; +import Deploy from 'client/containers/Application/Deploy'; +import Manage from 'client/containers/Application/Manage'; + +export { Create, Deploy, Manage }; diff --git a/src/fireedge/src/public/containers/Login/Form2fa.js b/src/fireedge/src/public/containers/Login/Form2fa.js index 7e33444efd7..a47aaff8f5a 100644 --- a/src/fireedge/src/public/containers/Login/Form2fa.js +++ b/src/fireedge/src/public/containers/Login/Form2fa.js @@ -1,5 +1,6 @@ import React from 'react'; import { func, string } from 'prop-types'; + import { Box, Button, TextField } from '@material-ui/core'; import { useForm } from 'react-hook-form'; import { yupResolver } from '@hookform/resolvers'; diff --git a/src/fireedge/src/public/containers/Login/FormGroup.js b/src/fireedge/src/public/containers/Login/FormGroup.js index bf453d397f4..b7fb0fed5d8 100644 --- a/src/fireedge/src/public/containers/Login/FormGroup.js +++ b/src/fireedge/src/public/containers/Login/FormGroup.js @@ -1,45 +1,46 @@ -/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */ -/* */ -/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ -/* not use this file except in compliance with the License. You may obtain */ -/* a copy of the License at */ -/* */ -/* http://www.apache.org/licenses/LICENSE-2.0 */ -/* */ -/* Unless required by applicable law or agreed to in writing, software */ -/* distributed under the License is distributed on an "AS IS" BASIS, */ -/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ -/* See the License for the specific language governing permissions and */ -/* limitations under the License. */ -/* -------------------------------------------------------------------------- */ - import React from 'react'; +import { func } from 'prop-types'; + import { Box, Button } from '@material-ui/core'; import { useForm, Controller } from 'react-hook-form'; import GroupSelect from 'client/components/FormControl/GroupSelect'; import ButtonSubmit from 'client/components/FormControl/SubmitButton'; +import { Tr } from 'client/components/HOC'; +import loginStyles from 'client/containers/Login/styles'; +import { Next } from 'client/constants'; -function FormGroup({ classes, onBack, onSubmit }) { +function FormGroup({ onBack, onSubmit }) { + const classes = loginStyles(); const { control, handleSubmit } = useForm(); return ( - } control={control} name="group" /> + ); } +FormGroup.propTypes = { + onBack: func.isRequired, + onSubmit: func.isRequired +}; + +FormGroup.defaultProps = { + onBack: () => undefined, + onSubmit: () => undefined +}; + FormGroup.propTypes = {}; FormGroup.defaultProps = {}; diff --git a/src/fireedge/src/public/containers/Login/FormUser.js b/src/fireedge/src/public/containers/Login/FormUser.js index cc1303c4b0c..6c367a05346 100644 --- a/src/fireedge/src/public/containers/Login/FormUser.js +++ b/src/fireedge/src/public/containers/Login/FormUser.js @@ -1,18 +1,3 @@ -/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */ -/* */ -/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ -/* not use this file except in compliance with the License. You may obtain */ -/* a copy of the License at */ -/* */ -/* http://www.apache.org/licenses/LICENSE-2.0 */ -/* */ -/* Unless required by applicable law or agreed to in writing, software */ -/* distributed under the License is distributed on an "AS IS" BASIS, */ -/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ -/* See the License for the specific language governing permissions and */ -/* limitations under the License. */ -/* -------------------------------------------------------------------------- */ - import React from 'react'; import { func, string } from 'prop-types'; import { Box, Checkbox, TextField, FormControlLabel } from '@material-ui/core'; diff --git a/src/fireedge/src/public/containers/Login/index.js b/src/fireedge/src/public/containers/Login/index.js index aabba9cedde..05be257a783 100644 --- a/src/fireedge/src/public/containers/Login/index.js +++ b/src/fireedge/src/public/containers/Login/index.js @@ -24,7 +24,6 @@ import { } from '@material-ui/core'; import useAuth from 'client/hooks/useAuth'; -import useOpennebula from 'client/hooks/useOpennebula'; import FormUser from 'client/containers/Login/FormUser'; import Form2fa from 'client/containers/Login/Form2fa'; @@ -51,7 +50,6 @@ function Login() { getAuthInfo, setPrimaryGroup } = useAuth(); - const { groups } = useOpennebula(); const handleSubmitUser = dataForm => { login({ ...user, ...dataForm }).then(data => { @@ -122,11 +120,7 @@ function Login() { unmountOnExit > - + diff --git a/src/fireedge/src/public/hooks/useAuth.js b/src/fireedge/src/public/hooks/useAuth.js index 3ff2b49190d..514fb9e242a 100644 --- a/src/fireedge/src/public/hooks/useAuth.js +++ b/src/fireedge/src/public/hooks/useAuth.js @@ -27,7 +27,6 @@ export default function useAuth() { filterPool, user: authUser } = useSelector(state => state?.Authenticated, shallowEqual); - const baseURL = useSelector(state => state?.System?.baseURL, shallowEqual); const dispatch = useDispatch(); useEffect(() => { @@ -43,7 +42,7 @@ export default function useAuth() { dispatch(startAuth()); return serviceAuth - .login(user, baseURL) + .login(user) .then(data => { const { id, token } = data; dispatch(successAuth()); @@ -67,7 +66,7 @@ export default function useAuth() { dispatch(failureAuth({ error: err })); }); }, - [dispatch, baseURL, jwtName] + [dispatch, jwtName] ); const logout = useCallback(() => { @@ -79,22 +78,22 @@ export default function useAuth() { dispatch(startAuth()); return serviceAuth - .getUser(baseURL) + .getUser() .then(user => dispatch(successAuth({ user }))) .then(serviceGroups.getGroups) .then(groups => dispatch(setGroups(groups))) .catch(err => dispatch(failureAuth({ error: err }))); - }, [dispatch, baseURL, jwtName, authUser]); + }, [dispatch, jwtName, authUser]); const setPrimaryGroup = useCallback( - values => { - if (values?.group === FILTER_POOL.ALL_RESOURCES) { + ({ group }) => { + if (group === FILTER_POOL.ALL_RESOURCES) { dispatch(selectFilterGroup({ filterPool: FILTER_POOL.ALL_RESOURCES })); } else { dispatch(startAuth()); serviceUsers - .changeGroup({ id: authUser.ID, ...values }) + .changeGroup({ id: authUser.ID, group }) .then(() => dispatch( selectFilterGroup({ @@ -102,10 +101,11 @@ export default function useAuth() { }) ) ) + .then(getAuthInfo) .catch(err => dispatch(failureAuth({ error: err }))); } }, - [dispatch, authUser, jwtName] + [dispatch, authUser] ); return { diff --git a/src/fireedge/src/public/services/auth.js b/src/fireedge/src/public/services/auth.js index 32bd77546b0..23a378a3e65 100644 --- a/src/fireedge/src/public/services/auth.js +++ b/src/fireedge/src/public/services/auth.js @@ -2,9 +2,8 @@ import { httpCodes } from 'server/utils/constants'; import { jwtName, endpointsRoutes } from 'client/constants'; import { requestData, removeStoreData } from 'client/utils'; -export const login = (user, baseURL = '') => +export const login = user => requestData(endpointsRoutes.login, { - baseURL, data: user, method: 'POST', authenticate: false, @@ -21,9 +20,8 @@ export const login = (user, baseURL = '') => return res?.data; }); -export const getUser = (baseURL = '') => +export const getUser = () => requestData(endpointsRoutes.userInfo, { - baseURL, error: err => { removeStoreData(jwtName); return err?.message; diff --git a/src/fireedge/src/public/utils/request.js b/src/fireedge/src/public/utils/request.js index 2dca36e1127..ab94c6fb608 100644 --- a/src/fireedge/src/public/utils/request.js +++ b/src/fireedge/src/public/utils/request.js @@ -37,7 +37,7 @@ export const requestParams = (data, command) => { const resources = getResources(mappedParams); const body = getDataBody(mappedParams); - const url = `api/${name.replace('.', '/')}`; + const url = `/api/${name.replace('.', '/')}`; return { url: `${url}/${resources}?${queries}`,