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 => { 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 })