Fix/mypages clientside menu * feat: move mypages menu to client side * Merge branch 'master' of bitbucket.org:scandic-swap/web into fix/mypages-clientside-menu * wip * wip * wip * refactor: reorganize MyPages navigation logic and improve type definitions * refactor: enhance MyPagesMobileDropdown with loading states and skeletons * refactor: clean up header component and improve myPagesNavigation query structure * Merge branch 'master' of bitbucket.org:scandic-swap/web into fix/mypages-clientside-menu Approved-by: Linus Flood
84 lines
2.0 KiB
TypeScript
84 lines
2.0 KiB
TypeScript
import { cache } from "react"
|
|
|
|
import * as routes from "@/constants/routes/myPages"
|
|
import { env } from "@/env/server"
|
|
|
|
import { getIntl } from "@/i18n"
|
|
import { safeTry } from "@/utils/safeTry"
|
|
|
|
import type { Lang } from "@/constants/languages"
|
|
import type { MyPagesLink } from "./MyPagesLink"
|
|
|
|
export const getPrimaryLinks = cache(
|
|
async ({ lang }: { lang: Lang }): Promise<MyPagesLink[]> => {
|
|
const intl = await getIntl(lang)
|
|
const scandicSasPromise = safeTry(isScandicXSASActive())
|
|
const teamMemberPromise = safeTry(showTeamMemberCard())
|
|
|
|
const [showSASLink] = await scandicSasPromise
|
|
const [showTeamMemberLink] = await teamMemberPromise
|
|
|
|
const menuItems: MyPagesLink[] = [
|
|
{
|
|
type: "link",
|
|
text: intl.formatMessage({ id: "Overview" }),
|
|
href: routes.overview[lang],
|
|
},
|
|
{
|
|
type: "link",
|
|
text: intl.formatMessage({ id: "My Points" }),
|
|
href: routes.points[lang],
|
|
},
|
|
{
|
|
type: "link",
|
|
text: intl.formatMessage({ id: "My Stays" }),
|
|
href: routes.stays[lang],
|
|
},
|
|
{
|
|
type: "link",
|
|
text: intl.formatMessage({ id: "My Benefits" }),
|
|
href: routes.benefits[lang],
|
|
},
|
|
]
|
|
|
|
if (showSASLink) {
|
|
menuItems.push({
|
|
type: "link",
|
|
text: intl.formatMessage({ id: "Scandic ♥ SAS" }),
|
|
href: routes.scandicXSAS[lang],
|
|
})
|
|
}
|
|
|
|
if (showTeamMemberLink) {
|
|
menuItems.push({
|
|
type: "link",
|
|
text: intl.formatMessage({ id: "Team Member Card" }),
|
|
href: "#",
|
|
})
|
|
}
|
|
|
|
return menuItems
|
|
}
|
|
)
|
|
|
|
const isScandicXSASActive = cache(async () => {
|
|
async function checkIfLinked() {
|
|
// TODO: Implement this check
|
|
return true
|
|
}
|
|
|
|
const isLinked = await checkIfLinked()
|
|
|
|
return env.SAS_ENABLED && isLinked
|
|
})
|
|
|
|
const showTeamMemberCard = cache(async () => {
|
|
async function getIsTeamMember() {
|
|
// TODO: Implement this check
|
|
return false
|
|
}
|
|
|
|
const isTeamMember = await getIsTeamMember()
|
|
return isTeamMember
|
|
})
|