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,13 +1,15 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
import { homeHrefs } from "@/constants/homeHrefs"
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { myBookingPath } from "@/constants/myBooking"
|
||||
import { myStay } from "@/constants/routes/myStay"
|
||||
import { env } from "@/env/server"
|
||||
import * as api from "@/lib/api"
|
||||
|
||||
import { getCurrentWebUrl } from "@/utils/url"
|
||||
|
||||
import { encrypt } from "../utils/encryption"
|
||||
|
||||
import type { Lang } from "@/constants/languages"
|
||||
import type { FriendTransaction, Stay } from "./output"
|
||||
|
||||
const meter = metrics.getMeter("trpc.user")
|
||||
@@ -68,62 +70,23 @@ async function updateStaysBookingUrl(
|
||||
apiJson.data.attributes.lastName
|
||||
const encryptedBookingValue = encrypt(originalString)
|
||||
|
||||
// Construct URL using myStay route and append encrypted value
|
||||
const bookingUrlPath = encryptedBookingValue
|
||||
? `${myStay[lang]}?RefId=${encryptedBookingValue}`
|
||||
: `${myStay[lang]}?bookingId=${d.attributes.confirmationNumber}&lastName=${apiJson.data.attributes.lastName}`
|
||||
// Get base URL with fallback for ephemeral environments (like deploy previews).
|
||||
const baseUrl = env.PUBLIC_URL || "https://www.scandichotels.com"
|
||||
|
||||
// Construct full URL with domain
|
||||
const domain = homeHrefs[env.NODE_ENV][lang]
|
||||
let bookingUrl = new URL(bookingUrlPath, domain)
|
||||
// Construct Booking URL.
|
||||
const bookingUrl = env.HIDE_FOR_NEXT_RELEASE
|
||||
? new URL(getCurrentWebUrl(myBookingPath[lang], lang))
|
||||
: new URL(myStay[lang], baseUrl)
|
||||
|
||||
// Update TLD based on language
|
||||
if (lang !== Lang.en)
|
||||
bookingUrl.host = bookingUrl.host.replace(".com", `.${lang}`)
|
||||
|
||||
if (env.HIDE_FOR_NEXT_RELEASE) {
|
||||
// Temporary Url, domain and lang support for current web
|
||||
bookingUrl = new URL(
|
||||
"/hotelreservation/my-booking",
|
||||
env.PUBLIC_URL || "https://www.scandichotels.com" // fallback to production for ephemeral envs (like deploy previews)
|
||||
// Add search parameters.
|
||||
if (encryptedBookingValue) {
|
||||
bookingUrl.searchParams.set("RefId", encryptedBookingValue)
|
||||
} else {
|
||||
bookingUrl.searchParams.set("lastName", apiJson.data.attributes.lastName)
|
||||
bookingUrl.searchParams.set(
|
||||
"bookingId",
|
||||
d.attributes.confirmationNumber.toString()
|
||||
)
|
||||
switch (lang) {
|
||||
case Lang.sv:
|
||||
bookingUrl.host = bookingUrl.host.replace(".com", ".se")
|
||||
bookingUrl.pathname = "/hotelreservation/din-bokning"
|
||||
break
|
||||
case Lang.no:
|
||||
bookingUrl.host = bookingUrl.host.replace(".com", ".no")
|
||||
bookingUrl.pathname = "/hotelreservation/my-booking"
|
||||
break
|
||||
case Lang.da:
|
||||
bookingUrl.host = bookingUrl.host.replace(".com", ".dk")
|
||||
bookingUrl.pathname = "/hotelreservation/min-booking"
|
||||
break
|
||||
case Lang.fi:
|
||||
bookingUrl.host = bookingUrl.host.replace(".com", ".fi")
|
||||
bookingUrl.pathname = "/varaa-hotelli/varauksesi"
|
||||
break
|
||||
case Lang.de:
|
||||
bookingUrl.host = bookingUrl.host.replace(".com", ".de")
|
||||
bookingUrl.pathname = "/hotelreservation/my-booking"
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
if (!!encryptedBookingValue) {
|
||||
bookingUrl.searchParams.set("RefId", encryptedBookingValue)
|
||||
} else {
|
||||
bookingUrl.searchParams.set(
|
||||
"lastName",
|
||||
apiJson.data.attributes.lastName
|
||||
)
|
||||
bookingUrl.searchParams.set(
|
||||
"bookingId",
|
||||
d.attributes.confirmationNumber
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user