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:
@@ -3,6 +3,7 @@ import { z } from "zod"
|
||||
import { baseUrls } from "@/constants/routes/baseUrls"
|
||||
import { findMyBooking } from "@/constants/routes/findMyBooking"
|
||||
import { hotelreservation } from "@/constants/routes/hotelReservation"
|
||||
import { myStay } from "@/constants/routes/myStay"
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import { attributesSchema as hotelAttributesSchema } from "../../hotels/schemas/hotel"
|
||||
@@ -142,6 +143,14 @@ export function getNonContentstackUrls(lang: Lang, pathName: string) {
|
||||
}, urls)
|
||||
}
|
||||
|
||||
if (Object.values(myStay).includes(pathName)) {
|
||||
const urls: LanguageSwitcherData = {}
|
||||
return Object.entries(myStay).reduce((acc, [lang, url]) => {
|
||||
acc[lang as Lang] = { url }
|
||||
return urls
|
||||
}, urls)
|
||||
}
|
||||
|
||||
if (pathName.startsWith(hotelreservation(lang))) {
|
||||
return baseUrls
|
||||
}
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user