diff --git a/src/components/Header/AppHeader.tsx b/src/components/Header/AppHeader.tsx index 756272ff..f08f773f 100644 --- a/src/components/Header/AppHeader.tsx +++ b/src/components/Header/AppHeader.tsx @@ -1,188 +1,17 @@ import React, { - Dispatch, MouseEventHandler, SetStateAction, useState, + useState, } from "react"; import { Link, NavLink } from "react-router-dom"; import routes from "../../pages/public/routes"; import MobileMenu from "./MobileMenu"; +import LoginPopup from "./LoginPopup"; +import UserAvatar from "./UserAvatar"; +import LoginButtons from "./LoginButtons"; const activeStyle: React.CSSProperties = { fontWeight: "bold", }; -const UserAvatar = () => { - return ( - - ); -}; - -const LoginButtons = ({ setVisible }: { setVisible: Dispatch> }) => { - return ( -
- - -
- ); -}; - -const LoginPopup = ({ setVisible }: { setVisible: Dispatch> }) => { - const [email, setEmail] = useState(""); - const [password, setPassword] = useState(""); - const [errorMessage, setErrorMessage] = useState(""); - const [imgClassName, setimgClassName] = useState("flex flex-row mt-10 ml-4"); - - const closeOrOpen: MouseEventHandler = (e) => { - const isClose = (e.target as HTMLElement).closest("#popup"); - if (!isClose) { - setVisible(false); - } - }; - - function isValidEmail(): boolean { - const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; - return emailPattern.test(email); - } - - const checkEmailAndPassword = () => { - if (!isValidEmail()) { - setErrorMessage("Email ugyldig, prøv igjen!"); - } else if (password.length < 6) { - setErrorMessage("Passord ugyldig, prøv igjen!"); - } else { - setErrorMessage(""); - } - }; - - // Logs in the mail and password set - const logIn = (e: { preventDefault: () => void; }) => { - e.preventDefault(); - checkEmailAndPassword(); - // do something to loginhere - // .catch((error) => { - // showError(error); - // }); - }; - - function handleEnterLogIn(event: React.KeyboardEvent): void { - if (event.key === "Enter") { - logIn(event); // calling the same function that is called when the "Log in" button is clicked - } - } - - return ( -
{}} - role="button" - tabIndex={-1} - > - - ); -}; - const AppHeader = (): JSX.Element => { const [menuOpen, setMenuOpen] = useState(false); const [loginPopupVisible, setLoginPopupVisible] = useState(false); @@ -190,7 +19,6 @@ const AppHeader = (): JSX.Element => { const linkElements = routes.map((route) => ( (isActive ? activeStyle : {})} @@ -223,6 +51,9 @@ const AppHeader = (): JSX.Element => { links={linkElements} menuOpen={menuOpen} setMenuOpen={setMenuOpen} + isLoggedIn={isLoggedIn} + loginPopupVisible={loginPopupVisible} + setLoginPopupVisible={setLoginPopupVisible} /> ); diff --git a/src/components/Header/LoginButtons.tsx b/src/components/Header/LoginButtons.tsx new file mode 100644 index 00000000..72f3353c --- /dev/null +++ b/src/components/Header/LoginButtons.tsx @@ -0,0 +1,17 @@ +import React, { Dispatch, SetStateAction } from "react"; + +const LoginButtons = ({ setVisible }: { setVisible: Dispatch> }) => { + return ( +
+ +
+ ); +}; + +export default LoginButtons; diff --git a/src/components/Header/LoginPopup.tsx b/src/components/Header/LoginPopup.tsx new file mode 100644 index 00000000..920dc3e1 --- /dev/null +++ b/src/components/Header/LoginPopup.tsx @@ -0,0 +1,125 @@ +import React, { + Dispatch, MouseEventHandler, SetStateAction, useState, +} from "react"; + +const LoginPopup = ({ setVisible }: { setVisible: Dispatch> }) => { + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + const [errorMessage, setErrorMessage] = useState(""); + const [imgClassName, setimgClassName] = useState("flex flex-row mt-10 ml-4"); + + const closeOrOpen: MouseEventHandler = (e) => { + const isClose = (e.target as HTMLElement).closest("#popup"); + if (!isClose) { + setVisible(false); + } + }; + + function isValidEmail(): boolean { + const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; + return emailPattern.test(email); + } + + const checkEmailAndPassword = () => { + if (!isValidEmail()) { + setErrorMessage("Email ugyldig, prøv igjen!"); + } else if (password.length < 6) { + setErrorMessage("Passord ugyldig, prøv igjen!"); + } else { + setErrorMessage(""); + } + }; + + const logIn = (e: { preventDefault: () => void; }) => { + e.preventDefault(); + checkEmailAndPassword(); + // to be implemented + }; + + function handleEnterLogIn(event: React.KeyboardEvent): void { + if (event.key === "Enter") { + logIn(event); + } + } + + return ( +
{}} + role="button" + tabIndex={-1} + > + + ); +}; + +export default LoginPopup; diff --git a/src/components/Header/MobileMenu.tsx b/src/components/Header/MobileMenu.tsx index 3dba07fb..7c51c007 100644 --- a/src/components/Header/MobileMenu.tsx +++ b/src/components/Header/MobileMenu.tsx @@ -1,66 +1,82 @@ -import React from "react"; - -import { Link } from "react-router-dom"; - -import "./mobile.css"; - -interface Props { - menuOpen: boolean, - setMenuOpen: (values: boolean) => void; - links: Array, -} - -const MobileMenu = (props: Props): JSX.Element => { - const { links, menuOpen, setMenuOpen } = props; - return ( -
-
-
{ setMenuOpen(!menuOpen); }} - onClick={() => { setMenuOpen(!menuOpen); }} - className="hamburger" - > - - - -
- { - if (menuOpen) { setMenuOpen(!menuOpen); } - }} - to="/" - > - Vektorprogrammet - -
- { - menuOpen ? ( -
{ setMenuOpen(!menuOpen); }} - onClick={() => { setMenuOpen(!menuOpen); }} - className="md:hidden drawer-content fixed" - > - -
- ) : ( -
- -
- ) - } -
- ); -}; - -export default MobileMenu; +import React, { Dispatch, SetStateAction } from "react"; + +import { Link } from "react-router-dom"; + +import "./mobile.css"; +import LoginPopup from "./LoginPopup"; +import UserAvatar from "./UserAvatar"; +import LoginButtons from "./LoginButtons"; + +interface Props { + menuOpen: boolean, + setMenuOpen: (values: boolean) => void; + links: Array, + isLoggedIn: boolean, + loginPopupVisible: boolean, + setLoginPopupVisible: Dispatch> +} + +const MobileMenu = (props: Props): JSX.Element => { + const { + links, menuOpen, setMenuOpen, isLoggedIn, loginPopupVisible, setLoginPopupVisible, + } = props; + return ( +
+
+
{ setMenuOpen(!menuOpen); }} + onClick={() => { setMenuOpen(!menuOpen); }} + className="hamburger" + > + + + +
+ { + if (menuOpen) { setMenuOpen(!menuOpen); } + }} + to="/" + > + Vektorprogrammet + + +
+ {loginPopupVisible ? : null} +
+
+ { + menuOpen ? ( +
{ setMenuOpen(!menuOpen); }} + onClick={() => { setMenuOpen(!menuOpen); }} + className="md:hidden drawer-content fixed" + > + +
+ + ) : ( +
+ +
+ ) + } +
+ ); +}; + +export default MobileMenu; diff --git a/src/components/Header/UserAvatar.tsx b/src/components/Header/UserAvatar.tsx new file mode 100644 index 00000000..c1e9000c --- /dev/null +++ b/src/components/Header/UserAvatar.tsx @@ -0,0 +1,36 @@ +import { Link } from "react-router-dom"; +import React from "react"; + +const UserAvatar = () => { + return ( + + ); +}; + +export default UserAvatar; diff --git a/src/components/Header/mobile.css b/src/components/Header/mobile.css index c2634a14..5adf018e 100644 --- a/src/components/Header/mobile.css +++ b/src/components/Header/mobile.css @@ -1,73 +1,108 @@ -.vektor-dark-blue{ - color: #023874; -} - -.vektor-font{ - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; -} - -.drawer-content{ - width: 100%; - min-height: 100%; - align-items: center; - padding: 0.5rem; - color: #023874; - background-color: white; - transition: 0.5s; -} - -.closed-drawer{ - margin-left: -100%; -} - -.hamburger{ - position: fixed; - width: 32px; - height: 30px; - margin: 0.5em; - transition: all .2s ease-in-out; -} - -.mobile-link{ - margin-top: 16px; - font-weight: 600; - padding: 4px; -} - -.closeMenu{ - position: fixed; - width: 50px; - height: 50px; - background-color: transparent; -} - -.hamburger-span{ - position: fixed; - width: 32px; - height: 5px; - z-index: -1; - border-radius: 3px; - background-color: black; - content: ''; - transition: all .2s ease-in-out; -} - -.top-bun { - transform: translateY(12px) rotate(135deg); -} - -.patty { - transform: scale(0); -} - -.bottom-bun { - transform: translateY(-12px) rotate(-135deg); -} - -.closed{ - display: none; -} - -.open{ - display: block; +.vektor-dark-blue{ + color: #023874; +} + +.vektor-font{ + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; +} + +.drawer-content{ + width: 100%; + min-height: 100%; + align-items: center; + padding: 0.5rem; + color: #023874; + background-color: white; + transition: 0.5s; +} + +.closed-drawer{ + margin-left: -100%; +} + +.hamburger{ + position: fixed; + width: 32px; + height: 30px; + margin: 0.5em; + transition: all .2s ease-in-out; +} + +.mobile-link{ + margin-top: 16px; + font-weight: 600; + padding: 4px; +} + +.closeMenu{ + position: fixed; + width: 50px; + height: 50px; + background-color: transparent; +} + +.hamburger-span{ + position: fixed; + width: 32px; + height: 5px; + z-index: -1; + border-radius: 3px; + background-color: black; + content: ''; + transition: all .2s ease-in-out; +} + +.top-bun { + transform: translateY(12px) rotate(135deg); +} + +.patty { + transform: scale(0); +} + +.bottom-bun { + transform: translateY(-12px) rotate(-135deg); +} + +.closed{ + display: none; +} + +.open{ + display: block; +} + +@media (max-width: 860px) { + #popup{ + width: 90%; + font-size: small; + } + + .button{ + width: 100%; + } + + .login-buttons { + width: 10rem; + } + + .input{ + width: 100%; + height: 40px; + margin-top: 0; + } + + .tor{ + margin-top: 40px; + height: 100px; + width: 100px; + } + + .error-bubble{ + display: none; + } + + .mob-message{ + display: block; + } } \ No newline at end of file