feat(BOOK-414): Added hotel branding themes to hotelpages
Approved-by: Matilda Landström
This commit is contained in:
28
apps/scandic-web/utils/theme/index.ts
Normal file
28
apps/scandic-web/utils/theme/index.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { headers } from "next/headers"
|
||||
|
||||
import { PageContentTypeEnum } from "@scandic-hotels/trpc/enums/contentType"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import { DEFAULT_THEME } from "./types"
|
||||
import { getHotelTheme } from "./utils"
|
||||
|
||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
|
||||
export async function getThemeClass(lang: Lang): Promise<string> {
|
||||
if (!env.HOTEL_BRANDING) {
|
||||
return DEFAULT_THEME
|
||||
}
|
||||
|
||||
const headersList = await headers()
|
||||
const contentType = headersList.get("x-contenttype") || ""
|
||||
|
||||
const isHotelPage =
|
||||
contentType && contentType === PageContentTypeEnum.hotelPage
|
||||
|
||||
if (isHotelPage) {
|
||||
return await getHotelTheme(lang)
|
||||
}
|
||||
|
||||
return DEFAULT_THEME
|
||||
}
|
||||
12
apps/scandic-web/utils/theme/types.ts
Normal file
12
apps/scandic-web/utils/theme/types.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export enum Theme {
|
||||
downtownCamper = "downtown-camper",
|
||||
grandHotel = "grand-hotel",
|
||||
haymarket = "haymarket",
|
||||
hotelNorge = "hotel-norge",
|
||||
marski = "marski",
|
||||
scandic = "scandic",
|
||||
scandicGo = "scandic-go",
|
||||
}
|
||||
|
||||
export const DEFAULT_THEME = Theme.scandic
|
||||
export const THEMES = Object.values(Theme)
|
||||
67
apps/scandic-web/utils/theme/utils.ts
Normal file
67
apps/scandic-web/utils/theme/utils.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { SignatureHotelEnum } from "@scandic-hotels/common/constants/signatureHotels"
|
||||
import { HotelTypeEnum } from "@scandic-hotels/trpc/enums/hotelType"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
import { getHotel, getHotelPage } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import { DEFAULT_THEME, Theme } from "./types"
|
||||
|
||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
|
||||
function getSignatureHotelTheme(hotelId: string) {
|
||||
switch (hotelId) {
|
||||
case SignatureHotelEnum.Haymarket:
|
||||
return Theme.haymarket
|
||||
case SignatureHotelEnum.HotelNorge:
|
||||
return Theme.hotelNorge
|
||||
case SignatureHotelEnum.DowntownCamper:
|
||||
return Theme.downtownCamper
|
||||
case SignatureHotelEnum.GrandHotelOslo:
|
||||
return Theme.grandHotel
|
||||
case SignatureHotelEnum.Marski:
|
||||
return Theme.marski
|
||||
default:
|
||||
return Theme.scandic
|
||||
}
|
||||
}
|
||||
|
||||
function getThemeByHotel(hotelId: string, hotelType: string) {
|
||||
if (hotelType === HotelTypeEnum.ScandicGo) {
|
||||
return Theme.scandicGo
|
||||
}
|
||||
if (hotelType === HotelTypeEnum.Signature) {
|
||||
return getSignatureHotelTheme(hotelId)
|
||||
}
|
||||
|
||||
return DEFAULT_THEME
|
||||
}
|
||||
|
||||
export async function getHotelTheme(language: Lang): Promise<Theme> {
|
||||
if (!env.HOTEL_BRANDING) {
|
||||
return DEFAULT_THEME
|
||||
}
|
||||
|
||||
try {
|
||||
const hotelPageData = await getHotelPage()
|
||||
if (!hotelPageData) {
|
||||
return DEFAULT_THEME
|
||||
}
|
||||
|
||||
const hotelData = await getHotel({
|
||||
hotelId: hotelPageData.hotel_page_id,
|
||||
isCardOnlyPayment: false,
|
||||
language,
|
||||
})
|
||||
|
||||
if (!hotelData) {
|
||||
return DEFAULT_THEME
|
||||
}
|
||||
|
||||
return getThemeByHotel(
|
||||
hotelPageData.hotel_page_id,
|
||||
hotelData.hotel.hotelType
|
||||
)
|
||||
} catch {
|
||||
return DEFAULT_THEME
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user