feat (SW-2864): Move booking router to trpc package * 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 * WIP first step * update internal imports in trpc * 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 * Merge branch 'master' into feat/sw-2864-move-hotels-router-to-trpc-package Approved-by: Linus Flood
100 lines
2.3 KiB
TypeScript
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 "@scandic-hotels/trpc/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
|
|
})
|