diff --git a/01-frontend/src/helper/navbar/LoginDialog.tsx b/01-frontend/src/helper/navbar/LoginDialog.tsx new file mode 100644 index 0000000..c0e20bb --- /dev/null +++ b/01-frontend/src/helper/navbar/LoginDialog.tsx @@ -0,0 +1,45 @@ +import { Dialog, DialogTitle, DialogContent, DialogActions, TextField, Button } from "@mui/material"; +import React from "react"; + +type LoginDialogProps = { + open: boolean; + onClose: () => void; + onSubmit: () => void; + loginData: { email: string; password: string }; + setLoginData: React.Dispatch>; +}; + +const LoginDialog: React.FC = ({ open, onClose, onSubmit, loginData, setLoginData }) => ( + + Login + + setLoginData(prev => ({ ...prev, email: e.target.value }))} + /> + setLoginData(prev => ({ ...prev, password: e.target.value }))} + /> + + + + + + +); + +export default LoginDialog; \ No newline at end of file diff --git a/01-frontend/src/helper/navbar/LoginPopUp.tsx b/01-frontend/src/helper/navbar/LoginPopUp.tsx deleted file mode 100644 index 11b81a0..0000000 --- a/01-frontend/src/helper/navbar/LoginPopUp.tsx +++ /dev/null @@ -1,18 +0,0 @@ -export default function LoginPopUp() { - return ( -
-

Login

-
-
- - -
-
- - -
- -
-
- ); -} \ No newline at end of file diff --git a/01-frontend/src/helper/navbar/NavBar.tsx b/01-frontend/src/helper/navbar/NavBar.tsx index 7ce96b6..6af0025 100644 --- a/01-frontend/src/helper/navbar/NavBar.tsx +++ b/01-frontend/src/helper/navbar/NavBar.tsx @@ -1,7 +1,7 @@ import AdbIcon from '@mui/icons-material/Adb'; import MenuIcon from '@mui/icons-material/Menu'; import SearchIcon from '@mui/icons-material/Search'; -import { Autocomplete, Dialog, DialogActions, DialogContent, DialogTitle, TextField } from '@mui/material'; +import { Autocomplete, TextField } from '@mui/material'; import AppBar from '@mui/material/AppBar'; import Avatar from '@mui/material/Avatar'; import Box from '@mui/material/Box'; @@ -18,9 +18,10 @@ import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; import Item from '../../components/Item'; import ThemeToggle from '../../theme/ThemeToggle'; -import { fetchItemList } from '../query/Queries'; -import './NavBar.css'; import { useAccount } from '../AccountProvider'; +import { fetchItemList } from '../query/Queries'; +import LoginDialog from './LoginDialog'; +import './NavBar.css'; export default function NavBar() { const { t } = useTranslation(); @@ -28,7 +29,7 @@ export default function NavBar() { const [anchorElNav, setAnchorElNav] = React.useState(null); const [anchorElUser, setAnchorElUser] = React.useState(null); - const { login } = useAccount(); + const { user, login, logout } = useAccount(); const [loginOpen, setLoginOpen] = React.useState(false); const [loginData, setLoginData] = React.useState({ password: '', email: '' }); @@ -37,10 +38,17 @@ export default function NavBar() { const [itemNames, setItemNames] = React.useState([]); // Für Autocomplete const pageKeys = ['components', 'checkout', 'contact', 'admin']; - const settingKeys = ['account', 'orders', 'login']; const pages = pageKeys.map(key => ({ key, label: t(key) })); - const settings = settingKeys.map(key => ({ key, label: t(key) })); + const settings = user + ? [ + { key: 'account', label: t('account') }, + { key: 'orders', label: t('orders') }, + { key: 'logout', label: t('logout') } + ] + : [ + { key: 'login', label: t('login') } + ]; const handleOpenNavMenu = (event: React.MouseEvent) => { setAnchorElNav(event.currentTarget); @@ -59,6 +67,8 @@ export default function NavBar() { setAnchorElUser(null); if (link === 'login') { setLoginOpen(true); + } else if (link === 'logout') { + logout(); } else { navigate(`/${link.toLowerCase()}`) } @@ -220,36 +230,13 @@ export default function NavBar() { - setLoginOpen(false)}> - Login - - setLoginData({ ...loginData, email: e.target.value })} - /> - setLoginData({ ...loginData, password: e.target.value })} - /> - - - - - - + setLoginOpen(false)} + onSubmit={handleLoginSubmit} + loginData={loginData} + setLoginData={setLoginData} + /> ); }