diff --git a/src/client/app/components/HeaderButtonsComponent.tsx b/src/client/app/components/HeaderButtonsComponent.tsx index a48b18f56..2ff66fae7 100644 --- a/src/client/app/components/HeaderButtonsComponent.tsx +++ b/src/client/app/components/HeaderButtonsComponent.tsx @@ -6,7 +6,7 @@ import * as React from 'react'; import { useEffect, useState } from 'react'; import { FormattedMessage } from 'react-intl'; import { Link, useLocation } from 'react-router-dom'; -import { DropdownItem, DropdownMenu, DropdownToggle, Nav, NavLink, Navbar, UncontrolledDropdown } from 'reactstrap'; +import { DropdownItem, DropdownMenu, DropdownToggle, Modal, ModalBody, ModalHeader, Nav, NavLink, Navbar, UncontrolledDropdown } from 'reactstrap'; import TooltipHelpComponent from '../components/TooltipHelpComponent'; import { clearGraphHistory } from '../redux/actions/extraActions'; import { authApi } from '../redux/api/authApi'; @@ -19,6 +19,7 @@ import { UserRole } from '../types/items'; import translate from '../utils/translate'; import LanguageSelectorComponent from './LanguageSelectorComponent'; import TooltipMarkerComponent from './TooltipMarkerComponent'; +import LoginComponent from './LoginComponent'; /** * React Component that defines the header buttons at the top of a page @@ -150,6 +151,17 @@ export default function HeaderButtonsComponent() { logout(); } }; + // Handle modal visibility + const [showModal, setShowModal] = useState(false); + + const handleClose = () => { + setShowModal(false); + }; + + const handleShow = () => { + setShowModal(true); + }; + return (
@@ -257,14 +269,11 @@ export default function HeaderButtonsComponent() { + onClick={handleShow}> @@ -281,6 +290,17 @@ export default function HeaderButtonsComponent() { + <> + + + {translate('log.in')} + + + + + + +
); } diff --git a/src/client/app/components/LoginComponent.tsx b/src/client/app/components/LoginComponent.tsx index 538c03d99..e85591cbc 100644 --- a/src/client/app/components/LoginComponent.tsx +++ b/src/client/app/components/LoginComponent.tsx @@ -5,24 +5,28 @@ import * as React from 'react'; import { useRef, useState } from 'react'; import { FormattedMessage } from 'react-intl'; -import { useNavigate } from 'react-router-dom'; import { Button, Form, FormGroup, Input, Label } from 'reactstrap'; import { authApi } from '../redux/api/authApi'; import { showErrorNotification, showSuccessNotification } from '../utils/notifications'; import translate from '../utils/translate'; +interface LoginProp { + handleClose: () => void; +} + /** + * @param handleClose Function to close modal after login + * @param handleClose.handleClose Needed by ESLint see above * @returns The login page for users or admins. */ -export default function LoginComponent() { +export default function LoginComponent({ handleClose }: LoginProp) { // Local State const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); // Html Element Reference used for focus() const inputRef = useRef(null); - const navigate = useNavigate(); // Grab the derived loginMutation from the API // The naming of the returned objects is arbitrary @@ -36,7 +40,7 @@ export default function LoginComponent() { .then(() => { // No error, success! showSuccessNotification(translate('login.success')); - navigate('/'); + handleClose(); }) .catch(() => { // Error on login Mutation @@ -69,16 +73,31 @@ export default function LoginComponent() { innerRef={inputRef} /> - +
+
+ +
+
+ +
+
+ + - + ); } diff --git a/src/client/app/components/RouteComponent.tsx b/src/client/app/components/RouteComponent.tsx index 0a871d5b8..a715dd891 100644 --- a/src/client/app/components/RouteComponent.tsx +++ b/src/client/app/components/RouteComponent.tsx @@ -13,7 +13,6 @@ import LocaleTranslationData from '../translations/data'; import { UserRole } from '../types/items'; import AppLayout from './AppLayout'; import HomeComponent from './HomeComponent'; -import LoginComponent from './LoginComponent'; import AdminComponent from './admin/AdminComponent'; import UsersDetailComponent from './admin/users/UsersDetailComponent'; import ConversionsDetailComponent from './conversion/ConversionsDetailComponent'; @@ -47,7 +46,6 @@ const router = createBrowserRouter([ path: '/', element: , errorElement: , children: [ { index: true, element: }, - { path: 'login', element: }, { path: 'groups', element: }, { path: 'meters', element: }, { path: 'graph', element: },