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:
@@ -1,8 +1,9 @@
|
||||
import { getEurobonusMembership } from "@scandic-hotels/trpc/routers/user/helpers"
|
||||
|
||||
import { getProfileSafely } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import { SASLevelUpgradeCheck } from "@/components/MyPages/SASLevelUpgradeCheck"
|
||||
import Surprises from "@/components/MyPages/Surprises"
|
||||
import { getEurobonusMembership } from "@/utils/user"
|
||||
|
||||
import styles from "./layout.module.css"
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { headers } from "next/headers"
|
||||
import { notFound, redirect } from "next/navigation"
|
||||
|
||||
import { overview } from "@/constants/routes/myPages"
|
||||
import { overview } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
|
||||
import { isSignupPage } from "@/constants/routes/signup"
|
||||
import { env } from "@/env/server"
|
||||
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
import Link from "next/link"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { partnerSas } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
|
||||
import { partnerSas } from "@/constants/routes/myPages"
|
||||
|
||||
import Button from "@/components/TempDesignSystem/Button"
|
||||
import useLang from "@/hooks/useLang"
|
||||
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
import { Link } from "react-aria-components"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { profile } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
|
||||
import { profile } from "@/constants/routes/myPages"
|
||||
|
||||
import Button from "@/components/TempDesignSystem/Button"
|
||||
import useLang from "@/hooks/useLang"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ArrowLeft } from "react-feather"
|
||||
|
||||
import { overview as profileOverview } from "@/constants/routes/myPages"
|
||||
import { overview as profileOverview } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
|
||||
import Image from "@/components/Image"
|
||||
import Link from "@/components/TempDesignSystem/Link"
|
||||
@@ -13,12 +13,12 @@ import type { PropsWithChildren } from "react"
|
||||
|
||||
import type { LangParams, LayoutArgs } from "@/types/params"
|
||||
|
||||
export default async function SasXScandicLayout(props: PropsWithChildren<LayoutArgs<LangParams>>) {
|
||||
const params = await props.params;
|
||||
export default async function SasXScandicLayout(
|
||||
props: PropsWithChildren<LayoutArgs<LangParams>>
|
||||
) {
|
||||
const params = await props.params
|
||||
|
||||
const {
|
||||
children
|
||||
} = props;
|
||||
const { children } = props
|
||||
|
||||
const intl = await getIntl()
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ import { useTransition } from "react"
|
||||
import { FormProvider, useForm } from "react-hook-form"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { profileEdit } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
|
||||
import { profileEdit } from "@/constants/routes/myPages"
|
||||
import { sasPartnershipTermsAndConditions } from "@/constants/webHrefs"
|
||||
|
||||
import Image from "@/components/Image"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { redirect } from "next/navigation"
|
||||
import React from "react"
|
||||
|
||||
import { getProfileSafely } from "@/lib/trpc/memoizedRequests"
|
||||
import { getEurobonusMembership } from "@scandic-hotels/trpc/routers/user/helpers"
|
||||
|
||||
import { getEurobonusMembership } from "@/utils/user"
|
||||
import { getProfileSafely } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import { SASModal } from "../components/SASModal"
|
||||
import { LinkAccountForm } from "./LinkAccountForm"
|
||||
@@ -11,7 +11,7 @@ import { LinkAccountForm } from "./LinkAccountForm"
|
||||
import type { LangParams, PageArgs } from "@/types/params"
|
||||
|
||||
export default async function SASxScandicLinkPage(props: PageArgs<LangParams>) {
|
||||
const params = await props.params;
|
||||
const params = await props.params
|
||||
const profile = await getProfileSafely()
|
||||
|
||||
if (!profile || !profile.loyalty) return null
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import React from "react"
|
||||
|
||||
import { partnerSas } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
|
||||
import { partnerSas } from "@/constants/routes/myPages"
|
||||
|
||||
import { Redirect } from "@/components/Redirect"
|
||||
import { getIntl } from "@/i18n"
|
||||
|
||||
@@ -13,7 +12,7 @@ import { SASModal } from "../../components/SASModal"
|
||||
import type { LangParams, PageArgs } from "@/types/params"
|
||||
|
||||
export default async function SASxScandicLinkPage(props: PageArgs<LangParams>) {
|
||||
const params = await props.params;
|
||||
const params = await props.params
|
||||
const intl = await getIntl()
|
||||
|
||||
return (
|
||||
|
||||
@@ -2,13 +2,13 @@ import { cookies } from "next/headers"
|
||||
import { redirect } from "next/navigation"
|
||||
import { z } from "zod"
|
||||
|
||||
import { myPages } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
||||
import {
|
||||
SAS_TOKEN_STORAGE_KEY,
|
||||
SAS_TRANSFER_POINT_KEY,
|
||||
} from "@scandic-hotels/trpc/constants/partnerSAS"
|
||||
|
||||
import { myPages } from "@/constants/routes/myPages"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import { getIntl } from "@/i18n"
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import Link from "next/link"
|
||||
import React, { Suspense } from "react"
|
||||
|
||||
import { partnerSas } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
|
||||
import { hotelreservation } from "@/constants/routes/hotelReservation"
|
||||
import { partnerSas } from "@/constants/routes/myPages"
|
||||
import { getProfileSafely } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import Image from "@/components/Image"
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import React from "react"
|
||||
|
||||
import { overview } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
|
||||
import { overview } from "@/constants/routes/myPages"
|
||||
|
||||
import { Redirect } from "@/components/Redirect"
|
||||
import { getIntl } from "@/i18n"
|
||||
|
||||
@@ -12,8 +11,10 @@ import { SASModal } from "../../components/SASModal"
|
||||
|
||||
import type { LangParams, PageArgs } from "@/types/params"
|
||||
|
||||
export default async function SASxScandicUnlinkSuccessPage(props: PageArgs<LangParams>) {
|
||||
const params = await props.params;
|
||||
export default async function SASxScandicUnlinkSuccessPage(
|
||||
props: PageArgs<LangParams>
|
||||
) {
|
||||
const params = await props.params
|
||||
const intl = await getIntl()
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { profile } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
|
||||
import { profile } from "@/constants/routes/myPages"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
import { getPublicURL } from "@/server/utils"
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { type NextRequest, NextResponse } from "next/server"
|
||||
|
||||
import { overview } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { isValidSession } from "@scandic-hotels/trpc/utils/session"
|
||||
|
||||
import { DTMC_SUCCESS_BANNER_KEY } from "@/constants/dtmc"
|
||||
import { linkEmploymentError } from "@/constants/routes/dtmc"
|
||||
import { overview } from "@/constants/routes/myPages"
|
||||
import { internalServerError } from "@/server/errors/next"
|
||||
import { getPublicURL } from "@/server/utils"
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { type ReactNode, Suspense } from "react"
|
||||
import DiamondAddIcon from "@scandic-hotels/design-system/Icons/DiamondAddIcon"
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
import { getEurobonusMembership } from "@scandic-hotels/trpc/routers/user/helpers"
|
||||
|
||||
import {
|
||||
SAS_EUROBONUS_TIER_TO_NAME_MAP,
|
||||
@@ -17,7 +18,6 @@ import SectionHeader from "@/components/Section/Header"
|
||||
import SectionLink from "@/components/Section/Link"
|
||||
import SkeletonShimmer from "@/components/SkeletonShimmer"
|
||||
import { getIntl } from "@/i18n"
|
||||
import { getEurobonusMembership } from "@/utils/user"
|
||||
|
||||
import { UnlinkSAS } from "./UnlinkSAS"
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
import { getEurobonusMembership } from "@scandic-hotels/trpc/routers/user/helpers"
|
||||
|
||||
import { getProfileWithExtendedPartnerData } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import Image from "@/components/Image"
|
||||
import SkeletonShimmer from "@/components/SkeletonShimmer"
|
||||
import { getIntl } from "@/i18n"
|
||||
import { getEurobonusMembership } from "@/utils/user"
|
||||
|
||||
import { TransferPointsFormClient } from "./TransferPointsFormClient"
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ import { usePathname } from "next/navigation"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { findMyBookingCurrentWebPath } from "@scandic-hotels/common/constants/routes/findMyBooking"
|
||||
import { myPages } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
|
||||
import { logout } from "@/constants/routes/handleAuth"
|
||||
import { myPages } from "@/constants/routes/myPages"
|
||||
import { env } from "@/env/client"
|
||||
import useDropdownStore from "@/stores/main-menu"
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ import { useIntl } from "react-intl"
|
||||
import { Divider } from "@scandic-hotels/design-system/Divider"
|
||||
|
||||
import { logout } from "@/constants/routes/handleAuth"
|
||||
import { trpc } from "@/lib/trpc/client"
|
||||
import useDropdownStore from "@/stores/main-menu"
|
||||
|
||||
import { useMyPagesNavigation } from "@/components/Header/MainMenu/MyPagesMenuContent"
|
||||
import SkeletonShimmer from "@/components/SkeletonShimmer"
|
||||
import Link from "@/components/TempDesignSystem/Link"
|
||||
import Title from "@/components/TempDesignSystem/Text/Title"
|
||||
@@ -143,8 +143,3 @@ function Skeletons({ count }: { count: number }) {
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function useMyPagesNavigation() {
|
||||
const lang = useLang()
|
||||
return trpc.navigation.myPages.useQuery({ lang })
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { overview } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
|
||||
import { logout } from "@/constants/routes/handleAuth"
|
||||
import { overview } from "@/constants/routes/myPages"
|
||||
import { getName } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import LoginButton from "@/components/LoginButton"
|
||||
|
||||
@@ -5,11 +5,11 @@ import { useEffect, useState } from "react"
|
||||
import { FormProvider, useForm } from "react-hook-form"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { profile } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { langToApiLang } from "@scandic-hotels/trpc/constants/apiLang"
|
||||
|
||||
import { getDefaultCountryFromLang } from "@/constants/languages"
|
||||
import { logout } from "@/constants/routes/handleAuth"
|
||||
import { profile } from "@/constants/routes/myPages"
|
||||
import { trpc } from "@/lib/trpc/client"
|
||||
|
||||
import { editProfile } from "@/actions/editProfile"
|
||||
|
||||
@@ -16,6 +16,8 @@ import useLang from "@/hooks/useLang"
|
||||
|
||||
import styles from "./myPagesMenuContent.module.css"
|
||||
|
||||
import type { MyPagesLinkKey } from "@scandic-hotels/trpc/routers/navigation/mypages/MyPagesLink"
|
||||
|
||||
import type { MyPagesMenuProps } from "../MyPagesMenu"
|
||||
|
||||
type Props = MyPagesMenuProps & { toggleOpenStateFn: () => void }
|
||||
@@ -165,7 +167,51 @@ function SecondaryLinks({
|
||||
|
||||
export const useMyPagesNavigation = () => {
|
||||
const lang = useLang()
|
||||
return trpc.navigation.myPages.useQuery({
|
||||
const intl = useIntl()
|
||||
|
||||
const MyPagesLinkTranslationMap: Record<MyPagesLinkKey, string> = {
|
||||
overview: intl.formatMessage({
|
||||
defaultMessage: "Overview",
|
||||
}),
|
||||
points: intl.formatMessage({
|
||||
defaultMessage: "My points",
|
||||
}),
|
||||
stays: intl.formatMessage({
|
||||
defaultMessage: "My stays",
|
||||
}),
|
||||
benefits: intl.formatMessage({
|
||||
defaultMessage: "My benefits",
|
||||
}),
|
||||
partnerSas: intl.formatMessage({
|
||||
defaultMessage: "Scandic ♥ SAS",
|
||||
}),
|
||||
teamMemberCard: intl.formatMessage({
|
||||
defaultMessage: "Team Member Card",
|
||||
}),
|
||||
scandicFriends: intl.formatMessage({
|
||||
defaultMessage: "About Scandic Friends",
|
||||
}),
|
||||
profile: intl.formatMessage({
|
||||
defaultMessage: "My profile",
|
||||
}),
|
||||
}
|
||||
|
||||
const result = trpc.navigation.myPages.useQuery({
|
||||
lang: lang,
|
||||
})
|
||||
|
||||
if (result.data) {
|
||||
const primaryLinks = result.data.primaryLinks.map((link) => ({
|
||||
...link,
|
||||
text: MyPagesLinkTranslationMap[link.key],
|
||||
}))
|
||||
const secondaryLinks = result.data.secondaryLinks.map((link) => ({
|
||||
...link,
|
||||
text: MyPagesLinkTranslationMap[link.key],
|
||||
}))
|
||||
|
||||
return { ...result, data: { primaryLinks, secondaryLinks } }
|
||||
}
|
||||
|
||||
return { ...result, data: null }
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import { Dialog } from "react-aria-components"
|
||||
import { FormProvider, useForm } from "react-hook-form"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { profileEdit } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
|
||||
import { profileEdit } from "@/constants/routes/myPages"
|
||||
import { isWebview } from "@/constants/routes/webviews"
|
||||
import { trpc } from "@/lib/trpc/client"
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { profileEdit } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { isValidLang } from "@scandic-hotels/common/utils/languages"
|
||||
import { Divider } from "@scandic-hotels/design-system/Divider"
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
@@ -6,7 +7,6 @@ import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
import { countriesMap } from "@scandic-hotels/trpc/constants/countries"
|
||||
|
||||
import { languages } from "@/constants/languages"
|
||||
import { profileEdit } from "@/constants/routes/myPages"
|
||||
import { getProfile } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import ButtonLink from "@/components/ButtonLink"
|
||||
|
||||
@@ -4,8 +4,9 @@ import { usePathname, useRouter } from "next/navigation"
|
||||
import { useEffect, useRef } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { partnerSas } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
|
||||
import { TIER_TO_FRIEND_MAP } from "@/constants/membershipLevels"
|
||||
import { partnerSas } from "@/constants/routes/myPages"
|
||||
import { trpc } from "@/lib/trpc/client"
|
||||
|
||||
import { toast } from "@/components/TempDesignSystem/Toasts"
|
||||
|
||||
@@ -6,9 +6,9 @@ import React, { useState } from "react"
|
||||
import { Dialog, Modal, ModalOverlay } from "react-aria-components"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { benefits } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
|
||||
import { benefits } from "@/constants/routes/myPages"
|
||||
import {
|
||||
benefits as webviewBenefits,
|
||||
myPagesWebviews,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { headers } from "next/headers"
|
||||
import { redirect } from "next/navigation"
|
||||
|
||||
import { overview } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { isValidSession } from "@scandic-hotels/trpc/utils/session"
|
||||
|
||||
import { overview } from "@/constants/routes/myPages"
|
||||
import { getProfile } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
profile,
|
||||
profileEdit,
|
||||
stays,
|
||||
} from "./myPages"
|
||||
} from "@scandic-hotels/common/constants/routes/myPages"
|
||||
|
||||
/**
|
||||
* These are routes in code we know requires auth
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { type NextMiddleware, NextResponse } from "next/server"
|
||||
|
||||
import { findLang } from "@scandic-hotels/common/utils/languages"
|
||||
import { resolve as resolveEntry } from "@scandic-hotels/trpc/utils/entry"
|
||||
|
||||
import {
|
||||
myPages,
|
||||
overview,
|
||||
profile,
|
||||
profileEdit,
|
||||
} from "@/constants/routes/myPages"
|
||||
} from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { findLang } from "@scandic-hotels/common/utils/languages"
|
||||
import { resolve as resolveEntry } from "@scandic-hotels/trpc/utils/entry"
|
||||
|
||||
import { internalServerError, notFound } from "@/server/errors/next"
|
||||
import { getPublicNextURL } from "@/server/utils"
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@ import * as Sentry from "@sentry/nextjs"
|
||||
import createJiti from "jiti"
|
||||
|
||||
import { findMyBooking } from "@scandic-hotels/common/constants/routes/findMyBooking"
|
||||
import { myPages } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import {
|
||||
myStay,
|
||||
preliminaryReceipt,
|
||||
} from "@scandic-hotels/common/constants/routes/myStay"
|
||||
|
||||
import { login, logout } from "./constants/routes/handleAuth.js"
|
||||
import { myPages } from "./constants/routes/myPages.js"
|
||||
import {
|
||||
myStay as myStayWebview,
|
||||
preliminaryReceipt as preliminaryReceiptWebview,
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -4,22 +4,7 @@ import {
|
||||
} from "@scandic-hotels/common/constants/membershipLevels"
|
||||
import { scandicMembershipTypes } from "@scandic-hotels/trpc/routers/user/helpers"
|
||||
|
||||
import type {
|
||||
EurobonusMembership,
|
||||
Membership,
|
||||
User,
|
||||
UserLoyalty,
|
||||
} from "@scandic-hotels/trpc/types/user"
|
||||
|
||||
function isEurobonusMembership(
|
||||
membership: Membership
|
||||
): membership is EurobonusMembership {
|
||||
return membership.type === scandicMembershipTypes.SAS_EB
|
||||
}
|
||||
|
||||
export function getEurobonusMembership(loyalty: UserLoyalty) {
|
||||
return loyalty.memberships?.find(isEurobonusMembership)
|
||||
}
|
||||
import type { User, UserLoyalty } from "@scandic-hotels/trpc/types/user"
|
||||
|
||||
export function getMembershipCards(userLoyalty: UserLoyalty) {
|
||||
return userLoyalty.memberships
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
/**
|
||||
* @file Due to these records being used in next.config.js, and that is required
|
||||
* to be a js file, we use jsdoc to type these.
|
||||
*/
|
||||
import type { LangRoute } from "@scandic-hotels/common/constants/routes/langRoute"
|
||||
|
||||
/**
|
||||
* These are routes that define code entries for My pages
|
||||
*/
|
||||
|
||||
/** @type {import('@scandic-hotels/common/constants/routes/langRoute').LangRoute} */
|
||||
export const scandicFriends = {
|
||||
export const scandicFriends: LangRoute = {
|
||||
da: "/da/scandic-friends",
|
||||
de: "/de/scandic-friends",
|
||||
en: "/en/scandic-friends",
|
||||
@@ -17,8 +13,7 @@ export const scandicFriends = {
|
||||
sv: "/sv/scandic-friends",
|
||||
}
|
||||
|
||||
/** @type {import('@scandic-hotels/common/constants/routes/langRoute').LangRoute} */
|
||||
export const myPages = {
|
||||
export const myPages: LangRoute = {
|
||||
da: `${scandicFriends.da}/mine-sider`,
|
||||
de: `${scandicFriends.de}/mein-bereich`,
|
||||
en: `${scandicFriends.en}/my-pages`,
|
||||
@@ -27,8 +22,7 @@ export const myPages = {
|
||||
sv: `${scandicFriends.sv}/mina-sidor`,
|
||||
}
|
||||
|
||||
/** @type {import('@scandic-hotels/common/constants/routes/langRoute').LangRoute} */
|
||||
export const overview = {
|
||||
export const overview: LangRoute = {
|
||||
da: `${myPages.da}/oversigt`,
|
||||
de: `${myPages.de}/uberblick`,
|
||||
en: `${myPages.en}/overview`,
|
||||
@@ -38,8 +32,7 @@ export const overview = {
|
||||
}
|
||||
|
||||
/** TODO: Update to relevant paths */
|
||||
/** @type {import('@scandic-hotels/common/constants/routes/langRoute').LangRoute} */
|
||||
export const profile = {
|
||||
export const profile: LangRoute = {
|
||||
da: `${myPages.da}/profil`,
|
||||
de: `${myPages.de}/profil`,
|
||||
en: `${myPages.en}/profile`,
|
||||
@@ -48,8 +41,7 @@ export const profile = {
|
||||
sv: `${myPages.sv}/profil`,
|
||||
}
|
||||
|
||||
/** @type {import('@scandic-hotels/common/constants/routes/langRoute').LangRoute} */
|
||||
export const profileEdit = {
|
||||
export const profileEdit: LangRoute = {
|
||||
da: `${profile.da}/rediger`,
|
||||
de: `${profile.de}/bearbeiten`,
|
||||
en: `${profile.en}/edit`,
|
||||
@@ -58,8 +50,7 @@ export const profileEdit = {
|
||||
sv: `${profile.sv}/redigera`,
|
||||
}
|
||||
|
||||
/** @type {import('@scandic-hotels/common/constants/routes/langRoute').LangRoute} */
|
||||
export const points = {
|
||||
export const points: LangRoute = {
|
||||
da: `${myPages.da}/point`,
|
||||
de: `${myPages.de}/punkte`,
|
||||
en: `${myPages.en}/points`,
|
||||
@@ -68,8 +59,7 @@ export const points = {
|
||||
sv: `${myPages.sv}/poang`,
|
||||
}
|
||||
|
||||
/** @type {import('@scandic-hotels/common/constants/routes/langRoute').LangRoute} */
|
||||
export const benefits = {
|
||||
export const benefits: LangRoute = {
|
||||
da: `${myPages.da}/fordele`,
|
||||
de: `${myPages.de}/vorteile`,
|
||||
en: `${myPages.en}/benefits`,
|
||||
@@ -78,8 +68,7 @@ export const benefits = {
|
||||
sv: `${myPages.sv}/formaner`,
|
||||
}
|
||||
|
||||
/** @type {import('@scandic-hotels/common/constants/routes/langRoute').LangRoute} */
|
||||
export const stays = {
|
||||
export const stays: LangRoute = {
|
||||
da: `${myPages.da}/ophold`,
|
||||
de: `${myPages.de}/aufenthalte`,
|
||||
en: `${myPages.en}/stays`,
|
||||
@@ -88,8 +77,7 @@ export const stays = {
|
||||
sv: `${myPages.sv}/vistelser`,
|
||||
}
|
||||
|
||||
/** @type {import('@scandic-hotels/common/constants/routes/langRoute').LangRoute} */
|
||||
export const partnerSas = {
|
||||
export const partnerSas: LangRoute = {
|
||||
da: `${myPages.da}/sas-eurobonus`,
|
||||
de: `${myPages.de}/sas-eurobonus`,
|
||||
en: `${myPages.en}/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,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { router } from "@scandic-hotels/trpc"
|
||||
|
||||
import { router } from "../.."
|
||||
import { myPagesNavigation } from "./mypages/index"
|
||||
|
||||
export const navigationRouter = router({ myPages: myPagesNavigation })
|
||||
@@ -1,6 +1,16 @@
|
||||
export type MyPagesLinkKey =
|
||||
| "overview"
|
||||
| "points"
|
||||
| "stays"
|
||||
| "benefits"
|
||||
| "partnerSas"
|
||||
| "teamMemberCard"
|
||||
| "scandicFriends"
|
||||
| "profile"
|
||||
|
||||
type BaseLink = {
|
||||
type: "link" | "withbadge"
|
||||
text: string
|
||||
key: MyPagesLinkKey
|
||||
href: string
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { cache } from "react"
|
||||
|
||||
import * as routes from "@scandic-hotels/common/constants/routes/myPages"
|
||||
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 { 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"
|
||||
@@ -21,38 +19,28 @@ export const getPrimaryLinks = cache(
|
||||
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",
|
||||
}),
|
||||
key: "overview",
|
||||
href: routes.overview[lang],
|
||||
},
|
||||
{
|
||||
type: "link",
|
||||
text: intl.formatMessage({
|
||||
defaultMessage: "My points",
|
||||
}),
|
||||
key: "points",
|
||||
href: routes.points[lang],
|
||||
},
|
||||
{
|
||||
type: "link",
|
||||
text: intl.formatMessage({
|
||||
defaultMessage: "My stays",
|
||||
}),
|
||||
key: "stays",
|
||||
href: routes.stays[lang],
|
||||
},
|
||||
{
|
||||
type: "link",
|
||||
text: intl.formatMessage({
|
||||
defaultMessage: "My benefits",
|
||||
}),
|
||||
key: "benefits",
|
||||
href: routes.benefits[lang],
|
||||
},
|
||||
]
|
||||
@@ -60,9 +48,7 @@ export const getPrimaryLinks = cache(
|
||||
if (showSASLink) {
|
||||
menuItems.push({
|
||||
type: "link",
|
||||
text: intl.formatMessage({
|
||||
defaultMessage: "Scandic ♥ SAS",
|
||||
}),
|
||||
key: "partnerSas",
|
||||
href: routes.partnerSas[lang],
|
||||
})
|
||||
}
|
||||
@@ -70,9 +56,7 @@ export const getPrimaryLinks = cache(
|
||||
if (showTeamMemberLink) {
|
||||
menuItems.push({
|
||||
type: "link",
|
||||
text: intl.formatMessage({
|
||||
defaultMessage: "Team Member Card",
|
||||
}),
|
||||
key: "teamMemberCard",
|
||||
href: "#",
|
||||
})
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
import * as routes from "@/constants/routes/myPages"
|
||||
|
||||
import { getIntl } from "@/i18n"
|
||||
import * as routes from "@scandic-hotels/common/constants/routes/myPages"
|
||||
|
||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
|
||||
@@ -11,20 +9,15 @@ export async function getSecondaryLinks({
|
||||
}: {
|
||||
lang: Lang
|
||||
}): Promise<MyPagesLink[]> {
|
||||
const intl = await getIntl({ lang })
|
||||
const menuItems: MyPagesLink[] = [
|
||||
{
|
||||
type: "link",
|
||||
text: intl.formatMessage({
|
||||
defaultMessage: "About Scandic Friends",
|
||||
}),
|
||||
key: "scandicFriends",
|
||||
href: routes.scandicFriends[lang],
|
||||
},
|
||||
{
|
||||
type: "link",
|
||||
text: intl.formatMessage({
|
||||
defaultMessage: "My profile",
|
||||
}),
|
||||
key: "profile",
|
||||
href: routes.profile[lang],
|
||||
},
|
||||
]
|
||||
@@ -2,10 +2,10 @@ 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 { safeProtectedProcedure } from "../../../procedures"
|
||||
import { getVerifiedUser } from "../../../routers/user/utils"
|
||||
import { isValidSession } from "../../../utils/session"
|
||||
import { getPrimaryLinks } from "./getPrimaryLinks"
|
||||
import { getSecondaryLinks } from "./getSecondaryLinks"
|
||||
|
||||
@@ -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