Merged in feat(SW-1944)-update-url-to-mystay (pull request #1566)

feat(SW-1944) Update to correct URL to my stay (for my pages/my stays and confirmation page)

* feat(SW-1944) Update to correct URL to my stay (for my pages/my stays and confirmation page)

* feat(SW-1944) updated to RefId

* feat(SW-1944) updated myStay path

* feat(SW-1944) updated refId check


Approved-by: Christian Andolf
This commit is contained in:
Pontus Dreij
2025-03-20 09:55:24 +00:00
parent e0b7c3be7b
commit 8f9e268802
13 changed files with 93 additions and 65 deletions

View File

@@ -1,6 +1,8 @@
import { metrics } from "@opentelemetry/api"
import { homeHrefs } from "@/constants/homeHrefs"
import { Lang } from "@/constants/languages"
import { myStay } from "@/constants/routes/myStay"
import { env } from "@/env/server"
import * as api from "@/lib/api"
@@ -41,35 +43,6 @@ async function updateStaysBookingUrl(
Authorization: `Bearer ${token}`,
},
})
// Temporary Url, domain and lang support for current web
const bookingUrl = new URL(
"/hotelreservation/my-booking",
env.PUBLIC_URL || "https://www.scandichotels.com" // fallback to production for ephemeral envs (like deploy previews)
)
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 (!apiResponse.ok) {
getProfileFailCounter.add(1, { error: JSON.stringify(apiResponse) })
@@ -94,12 +67,20 @@ async function updateStaysBookingUrl(
"," +
apiJson.data.attributes.lastName
const encryptedBookingValue = encrypt(originalString)
if (!!encryptedBookingValue) {
bookingUrl.searchParams.set("RefId", encryptedBookingValue)
} else {
bookingUrl.searchParams.set("lastName", apiJson.data.attributes.lastName)
bookingUrl.searchParams.set("bookingId", d.attributes.confirmationNumber)
}
// 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}`
// Construct full URL with domain
const domain = homeHrefs[env.NODE_ENV][lang]
const bookingUrl = new URL(bookingUrlPath, domain)
// Update TLD based on language
if (lang !== Lang.en)
bookingUrl.host = bookingUrl.host.replace(".com", `.${lang}`)
return {
...d,
attributes: {