Files
web/components/MyPages/menuItems.ts
Joakim Jäderberg 6f51130e48 Merged in feature/hardcoded-mypages-links (pull request #1325)
Feature/hardcoded mypages links

* feat: wip use hardcoded links

* Merge branch 'master' of bitbucket.org:scandic-swap/web into feature/hardcoded-mypages-links

* feat: use hardcoded links for my pages to support dynamic links

* cleanup

* code fixes

* refactor: restructure MyPagesMobileDropdown component for improved readability

* use util timeout function


Approved-by: Christian Andolf
Approved-by: Linus Flood
2025-02-13 09:28:30 +00:00

102 lines
2.2 KiB
TypeScript

import * as routes from "@/constants/routes/myPages"
import { env } from "@/env/server"
import { getIntl } from "@/i18n"
import { safeTry } from "@/utils/safeTry"
import type { ReactNode } from "react"
import type { Lang } from "../../constants/languages"
export type MyPagesLink = {
text: ReactNode
href: string
}
type Args = {
lang: Lang
}
export async function getPrimaryLinks({ lang }: Args): Promise<MyPagesLink[]> {
const intl = await getIntl()
const scandicSasPromise = safeTry(isScandicXSASActive())
const teamMemberPromise = safeTry(showTeamMemberCard())
const [showSASLink] = await scandicSasPromise
const [showTeamMemberLink] = await teamMemberPromise
const menuItems: MyPagesLink[] = [
{
text: intl.formatMessage({ id: "Overview" }),
href: routes.overview[lang],
},
{
text: intl.formatMessage({ id: "My Points" }),
href: routes.points[lang],
},
{
text: intl.formatMessage({ id: "My Stays" }),
href: routes.stays[lang],
},
{
text: intl.formatMessage({ id: "My Benefits" }),
href: routes.benefits[lang],
},
]
if (showSASLink) {
menuItems.push({
text: intl.formatMessage({ id: "Scandic ♥ SAS" }),
href: routes.scandicXSAS[lang],
})
}
if (showTeamMemberLink) {
menuItems.push({
text: intl.formatMessage({ id: "Team Member Card" }),
href: "#",
})
}
return menuItems
}
export async function getSecondaryLinks({
lang,
}: Args): Promise<MyPagesLink[]> {
const intl = await getIntl()
const menuItems: MyPagesLink[] = [
{
text: intl.formatMessage({ id: "About Scandic Friends" }),
href: routes.scandicFriends[lang],
},
{
text: intl.formatMessage({ id: "My Profile" }),
href: routes.profile[lang],
},
]
return menuItems
}
async function isScandicXSASActive() {
async function checkIfLinked() {
// TODO: Implement this check
return true
}
const isLinked = await checkIfLinked()
return env.SAS_ENABLED && isLinked
}
async function showTeamMemberCard() {
async function getIsTeamMember() {
// TODO: Implement this check
return false
}
const isTeamMember = await getIsTeamMember()
return isTeamMember
}