fix: add login/logout buttons

This commit is contained in:
Christel Westerberg
2024-05-29 17:20:27 +02:00
parent 0ec6d58d6a
commit 37843af507
9 changed files with 191 additions and 12 deletions

View File

@@ -2,9 +2,9 @@ import "@scandic-hotels/design-system/current/style.css"
import styles from "./bookingButton.module.css"
export default function BookingButton() {
export default function BookingButton({ href }: { href: string }) {
return (
<a className={styles.button} href="/">
<a className={styles.button} href={href}>
Book
</a>
)

View File

@@ -1,7 +1,14 @@
"use client"
import { useParams } from "next/navigation"
import { useState } from "react"
import { Lang } from "@/constants/languages"
import { login } from "@/constants/routes/handleAuth"
import { myPages } from "@/constants/routes/myPages"
import { _ } from "@/lib/translation"
import Image from "@/components/Image"
import Link from "@/components/TempDesignSystem/Link"
import BookingButton from "../BookingButton"
@@ -16,9 +23,13 @@ export function MainMenu({
logo,
topMenuMobileLinks,
languageSwitcher,
bookingHref,
isLoggedIn,
}: MainMenuProps) {
const [isOpen, setIsOpen] = useState(false)
const lang = useParams().lang as Lang
function toogleIsOpen() {
setIsOpen((prevIsOpen) => !prevIsOpen)
}
@@ -59,6 +70,52 @@ export function MainMenu({
<ul
className={`${styles.listWrapper} ${isOpen ? styles.isOpen : ""}`}
>
<ul className={styles.linkRow}>
{isLoggedIn ? (
<>
<li>
<div className={styles.loggedInLogo} />
</li>
<li className={styles.mobileLinkRow}>
<Link
className={styles.mobileLinkButton}
href={myPages[lang]}
>
{_("My pages")}
</Link>
</li>
</>
) : (
<>
<li>
<Image
src="/_static/img/icon-scandic-friends.svg"
alt="Scanidc Friends Logo"
height={35}
width={35}
className={styles.scandicFriendsLogo}
/>
</li>
<li className={styles.mobileLinkRow}>
<Link
className={styles.mobileLinkButton}
href={login[lang]}
>
{_("Log in")}
</Link>
</li>
</>
)}
<li className={styles.mobileLinkRow}>
<span className={styles.mobileSeparator} />
</li>
<li className={styles.mobileLinkRow}>
<a className={styles.mobileLinkButton} href="">
{_("Find booking")}
</a>
</li>
</ul>
<ul className={styles.mainLinks}>
{links.map((link, i) => (
<li className={styles.li} key={link.href + i}>
@@ -84,7 +141,7 @@ export function MainMenu({
) : null}
</ul>
<div className={styles.buttonContainer}>
<BookingButton />
<BookingButton href={bookingHref} />
</div>
</nav>
</div>

View File

@@ -8,6 +8,7 @@
top: 0;
width: 100%;
z-index: 99999;
height: 52.39px;
}
.container {
@@ -25,7 +26,8 @@
.navBar {
display: grid;
grid-template-columns: 1fr 80px 1fr;
height: 52.39px;
grid-template-rows: 100%;
height: 100%;
}
.expanderBtn {
@@ -154,6 +156,57 @@
text-decoration: none;
}
.linkRow {
display: flex;
align-items: center;
justify-content: center;
border-bottom: 1px solid #e3e0db;
background-color: #f3f2f1 !important;
list-style: none;
}
.scandicFriendsLogo {
margin-right: 4px;
margin-left: -4px;
}
.mobileLinkRow {
margin: 6px 0;
padding: 15px 15px 15px 5px;
}
.loggedInLogo {
height: 35px;
width: 35px;
border-radius: 50px;
background-color: #000;
margin-right: 4px;
margin-left: -4px;
}
.mobileLinkButton {
font-size: 14px;
font-family:
Helvetica Neue,
Helvetica,
Arial,
sans-serif;
font-weight: 700;
background-color: transparent !important;
text-decoration: none;
color: #000;
outline-color: transparent;
}
.mobileSeparator {
border-left: 1px solid #e3e0db;
height: 35px;
margin-bottom: -12px;
margin-left: -1px;
margin-top: -12px;
display: block;
}
.mobileList {
padding-top: 6px;
}
@@ -187,6 +240,7 @@
background-color: hsla(0, 0%, 100%, 0.95);
position: relative;
z-index: unset;
height: 85.09px;
}
.container {
@@ -201,7 +255,9 @@
.navBar {
grid-template-columns: 132.18px 1fr auto;
align-content: center;
height: 85.09px;
padding-bottom: 2px;
overflow: hidden;
}
.expanderBtn {
@@ -217,9 +273,8 @@
}
.logo {
width: 102.18px;
object-fit: cover;
height: auto;
width: 102.17px;
height: 100%;
}
.listWrapper {
@@ -250,6 +305,10 @@
padding: 30px 15px;
}
.linkRow {
display: none;
}
.mobileList {
display: none;
padding-top: 0px;
@@ -258,12 +317,18 @@
.mobileLi {
display: none;
}
.buttonContainer {
margin-right: 0;
}
}
@media (min-width: 1200px) {
.mainMenu {
height: 82.4px;
}
.navBar {
grid-template-columns: 140px auto 1fr;
height: 82.4px;
}
.logoLink {

View File

@@ -1,3 +1,5 @@
import { login, logout } from "@/constants/routes/handleAuth"
import { auth } from "@/auth"
import styles from "./topMenu.module.css"
@@ -32,11 +34,11 @@ export default async function TopMenu({
))}
<li className={styles.loginContainer}>
{session ? (
<a href={`${lang}/logout`} className={styles.loginLink}>
<a href={logout[lang]} className={styles.loginLink}>
Log out
</a>
) : (
<a href={`${lang}/login`} className={styles.loginLink}>
<a href={login[lang]} className={styles.loginLink}>
Log in
</a>
)}

View File

@@ -24,6 +24,7 @@
.list {
display: flex;
list-style: none;
line-height: 22.4px;
}
.link {
@@ -71,11 +72,27 @@
.loginContainer {
margin-left: 10px;
background-color: #f3f2f1;
height: 100%;
display: flex;
align-items: center;
}
.loginLink {
padding-left: 30px;
padding-right: 30px;
color: #000;
font-family:
Helvetica Neue,
Helvetica,
Arial,
sans-serif;
font-size: 13px;
font-weight: 400;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
cursor: pointer;
text-align: center;
text-decoration: none;
}
}

View File

@@ -2,6 +2,8 @@ import { homeHrefs } from "@/constants/homeHrefs"
import { env } from "@/env/server"
import { serverClient } from "@/lib/trpc/server"
import { auth } from "@/auth"
import { MainMenu } from "./MainMenu"
import OfflineBanner from "./OfflineBanner"
import TopMenu from "./TopMenu"
@@ -15,6 +17,7 @@ export default async function Header({
languageSwitcher,
}: LangParams & { languageSwitcher: React.ReactNode }) {
const data = await serverClient().contentstack.config.header({ lang })
const session = await auth()
const homeHref = homeHrefs[env.NODE_ENV][lang]
const { frontpage_link_text, logo, menu, top_menu } = data
@@ -40,6 +43,8 @@ export default async function Header({
logo={logo}
topMenuMobileLinks={topMenuMobileLinks}
languageSwitcher={languageSwitcher}
bookingHref={homeHref}
isLoggedIn={!!session}
/>
</header>
)