Merged in feat/sw-2865-move-navigation-router-to-trpc-package (pull request #2427)
feat(SW-2862): Move navigation router to trpc package * 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 * Move partners router to trpc package * Move autocomplete router to trpc package * Move booking router to trpc package * Remove translations from My Pages navigation trpc procedure * Move navigation router to trpc package * Merge branch 'master' into feat/sw-2862-move-booking-router-to-trpc-package * Merge branch 'feat/sw-2862-move-booking-router-to-trpc-package' into feat/sw-2865-move-navigation-router-to-trpc-package * Merge branch 'master' into feat/sw-2865-move-navigation-router-to-trpc-package * Merge branch 'master' into feat/sw-2865-move-navigation-router-to-trpc-package * Merge branch 'master' into feat/sw-2865-move-navigation-router-to-trpc-package Approved-by: Linus Flood
This commit is contained in:
87
packages/common/constants/routes/myPages.ts
Normal file
87
packages/common/constants/routes/myPages.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import type { LangRoute } from "@scandic-hotels/common/constants/routes/langRoute"
|
||||
|
||||
/**
|
||||
* These are routes that define code entries for My pages
|
||||
*/
|
||||
|
||||
export const scandicFriends: LangRoute = {
|
||||
da: "/da/scandic-friends",
|
||||
de: "/de/scandic-friends",
|
||||
en: "/en/scandic-friends",
|
||||
fi: "/fi/scandic-friends",
|
||||
no: "/no/scandic-friends",
|
||||
sv: "/sv/scandic-friends",
|
||||
}
|
||||
|
||||
export const myPages: LangRoute = {
|
||||
da: `${scandicFriends.da}/mine-sider`,
|
||||
de: `${scandicFriends.de}/mein-bereich`,
|
||||
en: `${scandicFriends.en}/my-pages`,
|
||||
fi: `${scandicFriends.fi}/omat-sivut`,
|
||||
no: `${scandicFriends.no}/mine-sider`,
|
||||
sv: `${scandicFriends.sv}/mina-sidor`,
|
||||
}
|
||||
|
||||
export const overview: LangRoute = {
|
||||
da: `${myPages.da}/oversigt`,
|
||||
de: `${myPages.de}/uberblick`,
|
||||
en: `${myPages.en}/overview`,
|
||||
fi: `${myPages.fi}/yleista`,
|
||||
no: `${myPages.no}/oversikt`,
|
||||
sv: `${myPages.sv}/oversikt`,
|
||||
}
|
||||
|
||||
/** TODO: Update to relevant paths */
|
||||
export const profile: LangRoute = {
|
||||
da: `${myPages.da}/profil`,
|
||||
de: `${myPages.de}/profil`,
|
||||
en: `${myPages.en}/profile`,
|
||||
fi: `${myPages.fi}/profiili`,
|
||||
no: `${myPages.no}/profil`,
|
||||
sv: `${myPages.sv}/profil`,
|
||||
}
|
||||
|
||||
export const profileEdit: LangRoute = {
|
||||
da: `${profile.da}/rediger`,
|
||||
de: `${profile.de}/bearbeiten`,
|
||||
en: `${profile.en}/edit`,
|
||||
fi: `${profile.fi}/muokkaa`,
|
||||
no: `${profile.no}/rediger`,
|
||||
sv: `${profile.sv}/redigera`,
|
||||
}
|
||||
|
||||
export const points: LangRoute = {
|
||||
da: `${myPages.da}/point`,
|
||||
de: `${myPages.de}/punkte`,
|
||||
en: `${myPages.en}/points`,
|
||||
fi: `${myPages.fi}/pisteet`,
|
||||
no: `${myPages.no}/poeng`,
|
||||
sv: `${myPages.sv}/poang`,
|
||||
}
|
||||
|
||||
export const benefits: LangRoute = {
|
||||
da: `${myPages.da}/fordele`,
|
||||
de: `${myPages.de}/vorteile`,
|
||||
en: `${myPages.en}/benefits`,
|
||||
fi: `${myPages.fi}/edut`,
|
||||
no: `${myPages.no}/fordeler`,
|
||||
sv: `${myPages.sv}/formaner`,
|
||||
}
|
||||
|
||||
export const stays: LangRoute = {
|
||||
da: `${myPages.da}/ophold`,
|
||||
de: `${myPages.de}/aufenthalte`,
|
||||
en: `${myPages.en}/stays`,
|
||||
fi: `${myPages.fi}/varaukset`,
|
||||
no: `${myPages.no}/opphold`,
|
||||
sv: `${myPages.sv}/vistelser`,
|
||||
}
|
||||
|
||||
export const partnerSas: LangRoute = {
|
||||
da: `${myPages.da}/sas-eurobonus`,
|
||||
de: `${myPages.de}/sas-eurobonus`,
|
||||
en: `${myPages.en}/sas-eurobonus`,
|
||||
fi: `${myPages.fi}/sas-eurobonus`,
|
||||
no: `${myPages.no}/sas-eurobonus`,
|
||||
sv: `${myPages.sv}/sas-eurobonus`,
|
||||
}
|
||||
6
packages/trpc/env/server.ts
vendored
6
packages/trpc/env/server.ts
vendored
@@ -21,6 +21,11 @@ export const env = createEnv({
|
||||
SAS_AUTH_ENDPOINT: z.string().default(""),
|
||||
SAS_OCP_APIM: z.string().default(""),
|
||||
SAS_AUTH_CLIENTID: z.string().default(""),
|
||||
SAS_ENABLED: z
|
||||
.string()
|
||||
.refine((s) => s === "1" || s === "0")
|
||||
.transform((s) => s === "1")
|
||||
.default("0"),
|
||||
CACHE_TIME_HOTELS: z.coerce
|
||||
.number()
|
||||
.default(TWENTYFOUR_HOURS)
|
||||
@@ -53,6 +58,7 @@ export const env = createEnv({
|
||||
SAS_AUTH_ENDPOINT: process.env.SAS_AUTH_ENDPOINT,
|
||||
SAS_OCP_APIM: process.env.SAS_OCP_APIM,
|
||||
SAS_AUTH_CLIENTID: process.env.SAS_AUTH_CLIENTID,
|
||||
SAS_ENABLED: process.env.SAS,
|
||||
CACHE_TIME_HOTELS: process.env.CACHE_TIME_HOTELS,
|
||||
CACHE_TIME_CITY_SEARCH: process.env.CACHE_TIME_CITY_SEARCH,
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
|
||||
4
packages/trpc/lib/routers/navigation/index.ts
Normal file
4
packages/trpc/lib/routers/navigation/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { router } from "../.."
|
||||
import { myPagesNavigation } from "./mypages/index"
|
||||
|
||||
export const navigationRouter = router({ myPages: myPagesNavigation })
|
||||
20
packages/trpc/lib/routers/navigation/mypages/MyPagesLink.ts
Normal file
20
packages/trpc/lib/routers/navigation/mypages/MyPagesLink.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export type MyPagesLinkKey =
|
||||
| "overview"
|
||||
| "points"
|
||||
| "stays"
|
||||
| "benefits"
|
||||
| "partnerSas"
|
||||
| "teamMemberCard"
|
||||
| "scandicFriends"
|
||||
| "profile"
|
||||
|
||||
type BaseLink = {
|
||||
type: "link" | "withbadge"
|
||||
key: MyPagesLinkKey
|
||||
href: string
|
||||
}
|
||||
|
||||
type NormalLink = BaseLink & { type: "link" }
|
||||
type LinkWithBadge = BaseLink & { type: "withbadge"; number: number }
|
||||
|
||||
export type MyPagesLink = NormalLink | LinkWithBadge
|
||||
@@ -0,0 +1,83 @@
|
||||
import { cache } from "react"
|
||||
|
||||
import * as routes from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
||||
|
||||
import { env } from "../../../../env/server"
|
||||
import { getEurobonusMembership } from "../../user/helpers"
|
||||
|
||||
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 showSASLink = userLoyalty ? isScandicXSASActive(userLoyalty) : false
|
||||
const [showTeamMemberLink] = await safeTry(showTeamMemberCard())
|
||||
|
||||
const menuItems: MyPagesLink[] = [
|
||||
{
|
||||
type: "link",
|
||||
key: "overview",
|
||||
href: routes.overview[lang],
|
||||
},
|
||||
{
|
||||
type: "link",
|
||||
key: "points",
|
||||
href: routes.points[lang],
|
||||
},
|
||||
{
|
||||
type: "link",
|
||||
key: "stays",
|
||||
href: routes.stays[lang],
|
||||
},
|
||||
{
|
||||
type: "link",
|
||||
key: "benefits",
|
||||
href: routes.benefits[lang],
|
||||
},
|
||||
]
|
||||
|
||||
if (showSASLink) {
|
||||
menuItems.push({
|
||||
type: "link",
|
||||
key: "partnerSas",
|
||||
href: routes.partnerSas[lang],
|
||||
})
|
||||
}
|
||||
|
||||
if (showTeamMemberLink) {
|
||||
menuItems.push({
|
||||
type: "link",
|
||||
key: "teamMemberCard",
|
||||
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
|
||||
})
|
||||
@@ -0,0 +1,26 @@
|
||||
import * as routes from "@scandic-hotels/common/constants/routes/myPages"
|
||||
|
||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
|
||||
import type { MyPagesLink } from "./MyPagesLink"
|
||||
|
||||
export async function getSecondaryLinks({
|
||||
lang,
|
||||
}: {
|
||||
lang: Lang
|
||||
}): Promise<MyPagesLink[]> {
|
||||
const menuItems: MyPagesLink[] = [
|
||||
{
|
||||
type: "link",
|
||||
key: "scandicFriends",
|
||||
href: routes.scandicFriends[lang],
|
||||
},
|
||||
{
|
||||
type: "link",
|
||||
key: "profile",
|
||||
href: routes.profile[lang],
|
||||
},
|
||||
]
|
||||
|
||||
return menuItems
|
||||
}
|
||||
56
packages/trpc/lib/routers/navigation/mypages/index.ts
Normal file
56
packages/trpc/lib/routers/navigation/mypages/index.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { TRPCError } from "@trpc/server"
|
||||
import { z } from "zod"
|
||||
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
|
||||
import { safeProtectedProcedure } from "../../../procedures"
|
||||
import { getVerifiedUser } from "../../../routers/user/utils"
|
||||
import { isValidSession } from "../../../utils/session"
|
||||
import { getPrimaryLinks } from "./getPrimaryLinks"
|
||||
import { getSecondaryLinks } from "./getSecondaryLinks"
|
||||
|
||||
import type { MyPagesLink } from "./MyPagesLink"
|
||||
|
||||
export const myPagesNavigation = safeProtectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
lang: z.nativeEnum(Lang).optional(),
|
||||
})
|
||||
)
|
||||
.query(
|
||||
async ({
|
||||
ctx,
|
||||
input,
|
||||
}): Promise<{
|
||||
primaryLinks: MyPagesLink[]
|
||||
secondaryLinks: MyPagesLink[]
|
||||
} | null> => {
|
||||
if (!isValidSession(ctx.session)) {
|
||||
return null
|
||||
}
|
||||
|
||||
const lang = input.lang || ctx.lang
|
||||
|
||||
if (!lang) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Language must be provided.",
|
||||
})
|
||||
}
|
||||
|
||||
const user = await getVerifiedUser({ session: ctx.session })
|
||||
if (!user || user.error) {
|
||||
return null
|
||||
}
|
||||
|
||||
const [primaryLinks, secondaryLinks] = await Promise.all([
|
||||
getPrimaryLinks({ lang, userLoyalty: user.data.loyalty }),
|
||||
getSecondaryLinks({ lang }),
|
||||
])
|
||||
|
||||
return {
|
||||
primaryLinks,
|
||||
secondaryLinks,
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -1,4 +1,5 @@
|
||||
import type {
|
||||
EurobonusMembership,
|
||||
Membership,
|
||||
NativeFriendsMembership,
|
||||
UserLoyalty,
|
||||
@@ -45,3 +46,13 @@ export function getFriendsMembership(userLoyalty: UserLoyalty) {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
function isEurobonusMembership(
|
||||
membership: Membership
|
||||
): membership is EurobonusMembership {
|
||||
return membership.type === scandicMembershipTypes.SAS_EB
|
||||
}
|
||||
|
||||
export function getEurobonusMembership(loyalty: UserLoyalty) {
|
||||
return loyalty.memberships?.find(isEurobonusMembership)
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"./routers/user/*": "./lib/routers/user/*.ts",
|
||||
"./routers/partners/*": "./lib/routers/partners/*.ts",
|
||||
"./routers/autocomplete/*": "./lib/routers/autocomplete/*.ts",
|
||||
"./routers/navigation/*": "./lib/routers/navigation/*.ts",
|
||||
"./enums/*": "./lib/enums/*.ts",
|
||||
"./types/*": "./lib/types/*.ts",
|
||||
"./constants/*": "./lib/constants/*.ts",
|
||||
|
||||
Reference in New Issue
Block a user