Files
web/apps/scandic-web/components/Current/Header/TopMenu/index.tsx
Anton Gunnarsson 00bcdaaa28 Merged in feat/sw-2865-move-navigation-router-to-trpc-package (pull request #2427)
feat(SW-2862): Move navigation router to trpc package

* Fix most errors in scandic-web

Just 100 left...

* Move Props type out of trpc

* Fix CategorizedFilters types

* Move more schemas in hotel router

* Fix deps

* fix getNonContentstackUrls

* Fix import error

* Fix entry error handling

* Fix generateMetadata metrics

* Fix alertType enum

* Fix duplicated types

* lint:fix

* Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package

* Fix broken imports

* Move booking router to trpc package

* Move partners router to trpc package

* Move autocomplete router to trpc package

* Move booking router to trpc package

* Remove translations from My Pages navigation trpc procedure

* Move navigation router to trpc package

* Merge branch 'master' into feat/sw-2862-move-booking-router-to-trpc-package

* Merge branch 'feat/sw-2862-move-booking-router-to-trpc-package' into feat/sw-2865-move-navigation-router-to-trpc-package

* Merge branch 'master' into feat/sw-2865-move-navigation-router-to-trpc-package

* Merge branch 'master' into feat/sw-2865-move-navigation-router-to-trpc-package

* Merge branch 'master' into feat/sw-2865-move-navigation-router-to-trpc-package


Approved-by: Linus Flood
2025-06-27 06:54:49 +00:00

120 lines
3.5 KiB
TypeScript

import { overview } from "@scandic-hotels/common/constants/routes/myPages"
import { logout } from "@/constants/routes/handleAuth"
import { getName } from "@/lib/trpc/memoizedRequests"
import LoginButton from "@/components/LoginButton"
import SkeletonShimmer from "@/components/SkeletonShimmer"
import Link from "@/components/TempDesignSystem/Link"
import { getIntl } from "@/i18n"
import { getLang } from "@/i18n/serverContext"
import styles from "./topMenu.module.css"
import type { TopMenuProps } from "@/types/components/current/header/topMenu"
function capitalize(str: string) {
return str.charAt(0).toUpperCase().toUpperCase() + str.slice(1).toLowerCase()
}
export default async function TopMenu({
frontpageLinkText,
homeHref,
links,
languageSwitcher,
}: TopMenuProps) {
const intl = await getIntl()
const user = await getName()
const lang = await getLang()
return (
<div className={styles.topMenu}>
<div className={styles.container}>
<a className={styles.homeLink} href={homeHref}>
{frontpageLinkText}
</a>
<ul className={styles.list}>
{languageSwitcher ? (
<li className={styles.langSwitcher}>{languageSwitcher}</li>
) : null}
{links.map(({ link }, i) => (
<li key={link.href + i}>
<a className={styles.link} href={link.href}>
{link.title}
</a>
</li>
))}
<li className={styles.sessionContainer}>
{user ? (
<>
{user ? (
<Link
href={overview[lang]}
className={styles.sessionLink}
prefetch={false}
>
<span data-hj-suppress>{capitalize(user.firstName)}</span>
</Link>
) : null}
<div className={styles.loginSeparator} />
<Link
href={logout[lang]}
className={styles.sessionLink}
prefetch={false}
>
{intl.formatMessage({
defaultMessage: "Log out",
})}
</Link>
</>
) : (
<LoginButton
position="hamburger menu"
trackingId="loginStartTopMenu"
className={`${styles.sessionLink} ${styles.loginLink}`}
size="small"
>
{intl.formatMessage({
defaultMessage: "Log in",
})}
</LoginButton>
)}
</li>
</ul>
</div>
</div>
)
}
export async function TopMenuSkeleton() {
const intl = await getIntl()
const links = new Array(5).fill("")
return (
<div className={styles.topMenu}>
<div className={styles.container}>
<ul className={styles.list}>
{links.map((_link, i) => (
<li key={i} className={styles.skeletonWrapper}>
<SkeletonShimmer width="100px" height="16px" />
</li>
))}
<li className={styles.sessionContainer}>
<LoginButton
position="hamburger menu"
trackingId="loginStartTopMenu"
className={`${styles.sessionLink} ${styles.loginLink}`}
size="small"
>
{intl.formatMessage({
defaultMessage: "Log in",
})}
</LoginButton>
</li>
</ul>
</div>
</div>
)
}