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:
@@ -4,9 +4,9 @@ import { autocompleteRouter } from "@scandic-hotels/trpc/routers/autocomplete"
|
||||
import { bookingRouter } from "@scandic-hotels/trpc/routers/booking"
|
||||
import { contentstackRouter } from "@scandic-hotels/trpc/routers/contentstack"
|
||||
import { hotelsRouter } from "@scandic-hotels/trpc/routers/hotels"
|
||||
import { navigationRouter } from "@scandic-hotels/trpc/routers/navigation"
|
||||
import { partnerRouter } from "@scandic-hotels/trpc/routers/partners"
|
||||
|
||||
import { navigationRouter } from "./routers/navigation"
|
||||
import { userRouter } from "./routers/user"
|
||||
|
||||
export const appRouter = router({
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import { router } from "@scandic-hotels/trpc"
|
||||
|
||||
import { myPagesNavigation } from "./mypages/index"
|
||||
|
||||
export const navigationRouter = router({ myPages: myPagesNavigation })
|
||||
@@ -1,10 +0,0 @@
|
||||
type BaseLink = {
|
||||
type: "link" | "withbadge"
|
||||
text: string
|
||||
href: string
|
||||
}
|
||||
|
||||
type NormalLink = BaseLink & { type: "link" }
|
||||
type LinkWithBadge = BaseLink & { type: "withbadge"; number: number }
|
||||
|
||||
export type MyPagesLink = NormalLink | LinkWithBadge
|
||||
@@ -1,99 +0,0 @@
|
||||
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
|
||||
})
|
||||
@@ -1,33 +0,0 @@
|
||||
import * as routes from "@/constants/routes/myPages"
|
||||
|
||||
import { getIntl } from "@/i18n"
|
||||
|
||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
|
||||
import type { MyPagesLink } from "./MyPagesLink"
|
||||
|
||||
export async function getSecondaryLinks({
|
||||
lang,
|
||||
}: {
|
||||
lang: Lang
|
||||
}): Promise<MyPagesLink[]> {
|
||||
const intl = await getIntl({ lang })
|
||||
const menuItems: MyPagesLink[] = [
|
||||
{
|
||||
type: "link",
|
||||
text: intl.formatMessage({
|
||||
defaultMessage: "About Scandic Friends",
|
||||
}),
|
||||
href: routes.scandicFriends[lang],
|
||||
},
|
||||
{
|
||||
type: "link",
|
||||
text: intl.formatMessage({
|
||||
defaultMessage: "My profile",
|
||||
}),
|
||||
href: routes.profile[lang],
|
||||
},
|
||||
]
|
||||
|
||||
return menuItems
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
import { TRPCError } from "@trpc/server"
|
||||
import { z } from "zod"
|
||||
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { safeProtectedProcedure } from "@scandic-hotels/trpc/procedures"
|
||||
import { getVerifiedUser } from "@scandic-hotels/trpc/routers/user/utils"
|
||||
import { isValidSession } from "@scandic-hotels/trpc/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,
|
||||
}
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user