Files
web/apps/scandic-web/server/routers/navigation/mypages/getPrimaryLinks.ts
Anton Gunnarsson 846fd904a6 Merged in feat/sw-2859-set-up-shared-trpc-package (pull request #2319)
feat(SW-2859): Create trpc package

* Add isEdge, safeTry and dataCache to new common package

* Add eslint and move prettier config

* Clean up tests

* Create trpc package and move initialization

* Move errors and a few procedures

* Move telemetry to common package

* Move tokenManager to common package

* Add Sentry to procedures

* Clean up procedures

* Fix self-referencing imports

* Add exports to packages and lint rule to prevent relative imports

* Add env to trpc package

* Add eslint to trpc package

* Apply lint rules

* Use direct imports from trpc package

* Add lint-staged config to trpc

* Move lang enum to common

* Restructure trpc package folder structure

* Fix lang imports


Approved-by: Linus Flood
2025-06-18 12:14:20 +00:00

100 lines
2.3 KiB
TypeScript

import { cache } from "react"
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
import * as routes from "@/constants/routes/myPages"
import { env } from "@/env/server"
import { getIntl } from "@/i18n"
import { getEurobonusMembership } from "@/utils/user"
import type { Lang } from "@scandic-hotels/common/constants/language"
import type { UserLoyalty } from "@/types/user"
import type { MyPagesLink } from "./MyPagesLink"
export const getPrimaryLinks = cache(
async ({
lang,
userLoyalty,
}: {
lang: Lang
userLoyalty?: UserLoyalty
}): Promise<MyPagesLink[]> => {
const intl = await getIntl({ lang })
const showSASLink = userLoyalty ? isScandicXSASActive(userLoyalty) : false
const [showTeamMemberLink] = await safeTry(showTeamMemberCard())
const menuItems: MyPagesLink[] = [
{
type: "link",
text: intl.formatMessage({
defaultMessage: "Overview",
}),
href: routes.overview[lang],
},
{
type: "link",
text: intl.formatMessage({
defaultMessage: "My points",
}),
href: routes.points[lang],
},
{
type: "link",
text: intl.formatMessage({
defaultMessage: "My stays",
}),
href: routes.stays[lang],
},
{
type: "link",
text: intl.formatMessage({
defaultMessage: "My benefits",
}),
href: routes.benefits[lang],
},
]
if (showSASLink) {
menuItems.push({
type: "link",
text: intl.formatMessage({
defaultMessage: "Scandic ♥ SAS",
}),
href: routes.partnerSas[lang],
})
}
if (showTeamMemberLink) {
menuItems.push({
type: "link",
text: intl.formatMessage({
defaultMessage: "Team Member Card",
}),
href: "#",
})
}
return menuItems
}
)
const isScandicXSASActive = (loyalty: UserLoyalty) => {
const eurobonusMembership = getEurobonusMembership(loyalty)
const isLinked = Boolean(eurobonusMembership)
return env.SAS_ENABLED && isLinked
}
const showTeamMemberCard = cache(async () => {
async function getIsTeamMember() {
// TODO: Implement this check
return false
}
const isTeamMember = await getIsTeamMember()
return isTeamMember
})