Feat/SW-1997 tracking gla my stay ancillaries * feat(SW-1996): tracking gla my stay * feat(SW-1996): update gla tracking * feat(SW-1996): fix comment * feat(SW-1997): add tracking for gla my stay and ancillaries * feat(SW-1997): rebase master * feat(SW-1997): fix duplicate import * feat(SW-1997): add hotelId and category for ancillaries, and add more tracking * feat(SW-1997): remove commments and fix spelling mistake * feat(SW-1997): if addAncillary failed, but guarantee is successful, default to card in booking Approved-by: Niclas Edenvin
83 lines
2.1 KiB
TypeScript
83 lines
2.1 KiB
TypeScript
import type {
|
|
Ancillary,
|
|
SelectedAncillary,
|
|
} from "@/types/components/myPages/myStay/ancillaries"
|
|
import type { AncillaryFormData } from "./AddAncillaryFlow/schema"
|
|
|
|
export const generateDeliveryOptions = () => {
|
|
const timeSlots = ["16:00-17:00", "17:00-18:00", "18:00-19:00", "19:00-20:00"]
|
|
|
|
return timeSlots.map((slot) => ({
|
|
label: slot,
|
|
value: slot,
|
|
}))
|
|
}
|
|
|
|
export function buildAncillaryPackages(
|
|
data: AncillaryFormData,
|
|
ancillary: SelectedAncillary | null
|
|
) {
|
|
const packages = []
|
|
|
|
if (ancillary?.id && data.quantityWithCard) {
|
|
packages.push({
|
|
code: ancillary.id,
|
|
quantity: data.quantityWithCard,
|
|
comment: data.optionalText || undefined,
|
|
})
|
|
}
|
|
|
|
if (ancillary?.loyaltyCode && data.quantityWithPoints) {
|
|
packages.push({
|
|
code: ancillary.loyaltyCode,
|
|
quantity: data.quantityWithPoints,
|
|
comment: data.optionalText || undefined,
|
|
})
|
|
}
|
|
|
|
return packages
|
|
}
|
|
|
|
const ancillarySessionKey = "ancillarySessionData"
|
|
export const getAncillarySessionData = ():
|
|
| {
|
|
formData?: AncillaryFormData
|
|
selectedAncillary?: Ancillary["ancillaryContent"][number] | null
|
|
}
|
|
| undefined => {
|
|
if (typeof window === "undefined") return undefined
|
|
|
|
try {
|
|
const storedData = sessionStorage.getItem(ancillarySessionKey)
|
|
return storedData ? JSON.parse(storedData) : undefined
|
|
} catch (error) {
|
|
console.error("Error reading from session storage:", error)
|
|
return undefined
|
|
}
|
|
}
|
|
|
|
export function setAncillarySessionData({
|
|
formData,
|
|
selectedAncillary,
|
|
}: {
|
|
formData?: AncillaryFormData
|
|
selectedAncillary?: Ancillary["ancillaryContent"][number] | null
|
|
}) {
|
|
if (typeof window === "undefined") return
|
|
|
|
try {
|
|
const currentData = getAncillarySessionData() || {}
|
|
sessionStorage.setItem(
|
|
ancillarySessionKey,
|
|
JSON.stringify({ ...currentData, formData, selectedAncillary })
|
|
)
|
|
} catch (error) {
|
|
console.error("Error writing to session storage:", error)
|
|
}
|
|
}
|
|
|
|
export function clearAncillarySessionData() {
|
|
if (typeof window === "undefined") return
|
|
sessionStorage.removeItem(ancillarySessionKey)
|
|
}
|