Skip to content

Commit

Permalink
Clean up navbar code, add logout button (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigridge committed Oct 18, 2023
1 parent 53a8ab4 commit 679f163
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 711 deletions.
4 changes: 0 additions & 4 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
"prettier:ci": "prettier --check . "
},
"dependencies": {
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.14.9",
"@mui/material": "^5.14.10",
"@types/node": "20.5.9",
"@types/react": "18.2.21",
"@types/react-dom": "18.2.7",
Expand Down
File renamed without changes
5 changes: 3 additions & 2 deletions frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "./globals.css";
import Head from "next/head";
import AppProviders from "../components/AppProviders";
import NavBar from "@/components/NavBar/NavBar";

export default function RootLayout({
children,
Expand All @@ -17,7 +17,8 @@ export default function RootLayout({
/>
</Head>
<body>
<AppProviders>{children}</AppProviders>
<NavBar />
{children}
</body>
</html>
);
Expand Down
17 changes: 0 additions & 17 deletions frontend/src/components/AppProviders.tsx

This file was deleted.

23 changes: 23 additions & 0 deletions frontend/src/components/NavBar/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Image from "next/image";
import NavBarLink from "./NavBarLink";
import NavBarUserIcon from "./NavBarUserIcon";

export default function NavBar() {
return (
<div className="bg-primary_default w-full h-[52px] flex flex-row justify-between sticky top-0 px-4">
<div className="flex flex-row">
<NavBarLink text="Bemanning" path="/bemanning" />
</div>
<div className="flex flex-row gap-6 items-center">
<Image
className="variant-logo"
alt="Variant logo"
src="./images/variant-logo.svg"
width="65"
height="16"
/>
<NavBarUserIcon />
</div>
</div>
);
}
40 changes: 40 additions & 0 deletions frontend/src/components/NavBar/NavBarDropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use client";
import React, { useState } from "react";
import { signOut } from "next-auth/react";
import { LogOut, User } from "react-feather";

export default function NavBarDropdown(props: { initials: string }) {
const [isOpen, setIsOpen] = useState<boolean>(false);

return (
<>
<div className="relative">
<button
className={`flex rounded-full border border-white h-9 min-w-[36px] justify-center items-center ${
props.initials.length > 3 && "px-1"
}`}
onClick={() => setIsOpen(!isOpen)}
>
<p className="text-white body-small">{props.initials}</p>
</button>
<div
className={`absolute right-0 top-11 rounded-b text-primary_default bg-white flex flex-col w-[138px] shadow-md ${
!isOpen && "hidden"
}`}
>
<button className="p-2 w-[138px] flex flex-row gap-3 hover:bg-primary_default hover:text-white">
<User className="w-4 h-4" />
<p className="body">Min profil</p>
</button>
<button
className="p-2 w-[138px] rounded-b flex flex-row gap-3 hover:bg-primary_default hover:text-white"
onClick={() => signOut()}
>
<LogOut className="w-4 h-4" />
<p className="body">Logg ut</p>
</button>
</div>
</div>
</>
);
}
20 changes: 20 additions & 0 deletions frontend/src/components/NavBar/NavBarLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use client";
import { usePathname } from "next/navigation";

export default function NavBarLink(props: { text: string; path: string }) {
const pathname = usePathname();
const isCurrentPath = props.path.includes(pathname);

return (
<a
className={`p-4 flex justify-center items-center text-white ${
isCurrentPath
? "body-large-bold border-b-[3px] border-secondary_default"
: "body-large opacity-70 hover:opacity-100"
}`}
href={`${props.path}`}
>
{props.text}
</a>
);
}
23 changes: 23 additions & 0 deletions frontend/src/components/NavBar/NavBarUserIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
authOptions,
getCustomServerSession,
} from "@/app/api/auth/[...nextauth]/route";
import NavBarDropdown from "./NavBarDropdown";

export default async function NavBarUserIcon() {
const session =
!process.env.NEXT_PUBLIC_NO_AUTH &&
(await getCustomServerSession(authOptions));

const initials =
session && session.user && session.user.name
? session.user.name
.split(" ")
.map((name) => name.charAt(0).toUpperCase())
.join("")
: "";

if (session) {
return <NavBarDropdown initials={initials} />;
}
}
15 changes: 0 additions & 15 deletions frontend/src/components/PageLayout.tsx

This file was deleted.

18 changes: 0 additions & 18 deletions frontend/src/components/ThemeRegistry/ThemeRegistry.tsx

This file was deleted.

22 changes: 0 additions & 22 deletions frontend/src/components/ThemeRegistry/theme.ts

This file was deleted.

44 changes: 0 additions & 44 deletions frontend/src/components/VibesNavBar.tsx

This file was deleted.

25 changes: 0 additions & 25 deletions frontend/src/components/VibesNavBarTabs.tsx

This file was deleted.

22 changes: 0 additions & 22 deletions frontend/src/components/vibes-buttons/SignInButton.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions frontend/src/components/vibes-buttons/SignInSignOutButton.tsx

This file was deleted.

64 changes: 0 additions & 64 deletions frontend/src/components/vibes-buttons/SignOutButton.tsx

This file was deleted.

Loading

0 comments on commit 679f163

Please sign in to comment.