Merged in fix/SW-2068-correct-public-url-from-my-stays-overview-page (pull request #1694)
feat(SW-2068): Link to Correct Public URL from within My Stays Overview Page * feat(SW-2068): Link to Correct Public URL from within My Stays Overview Page - Added language parameter to previous and upcoming stays queries. - Updated Client components to utilize the new language hook. - Refactored EmptyUpcomingStays component to dynamically generate links based on the current language. - Adjusted user input validation to include optional language parameter. * refactor(SW-2068): Update EmptyUpcomingStays components to use PUBLIC_URL + add utility to handle TLD based on language * chore(SW-2068): Clarify TLD * feat(SW-2068): documentation for getTldForLanguage * refactor(SW-2068): Simplify booking URL construction in updateStaysBookingUrl * refactor(SW-2068): Remove incorrect TLD update logic from booking URL construction * refactor(SW-2068): Centralize booking URL paths using myBookingPath constant * refactor(SW-2068): Streamline search params in booking URL construction logic in updateStaysBookingUrl Approved-by: Christian Andolf
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import type { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
import type {
|
||||
Child,
|
||||
@@ -164,3 +167,43 @@ export function convertObjToSearchParams<T>(
|
||||
|
||||
return bookingSearchParams
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the TLD (top-level domain) for a given language.
|
||||
* @param lang - The language to get the TLD for
|
||||
* @returns The TLD for the given language
|
||||
*/
|
||||
export function getTldForLanguage(lang: Lang): string {
|
||||
switch (lang) {
|
||||
case Lang.sv:
|
||||
return "se"
|
||||
case Lang.no:
|
||||
return "no"
|
||||
case Lang.da:
|
||||
return "dk"
|
||||
case Lang.fi:
|
||||
return "fi"
|
||||
case Lang.de:
|
||||
return "de"
|
||||
default:
|
||||
return "com"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a URL with the correct TLD (top-level domain) based on lang, for current web.
|
||||
* @param path - The path to append to the URL
|
||||
* @param lang - The language to use for TLD
|
||||
* @returns The complete URL with language-specific TLD
|
||||
*/
|
||||
export function getCurrentWebUrl(path: string, lang: Lang): string {
|
||||
const baseUrl = env.PUBLIC_URL || "https://www.scandichotels.com" // Fallback for ephemeral environments (e.g. deploy previews).
|
||||
const tld = getTldForLanguage(lang)
|
||||
const url = new URL(path, baseUrl)
|
||||
|
||||
if (tld !== "com") {
|
||||
url.host = url.host.replace(".com", `.${tld}`)
|
||||
}
|
||||
|
||||
return url.toString()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user