Files
web/apps/scandic-web/components/HotelReservation/MyStay/utils/ancillaries.ts
Christel Westerberg 6b08d5a113 Merged in fix/STAY-135 (pull request #3368)
Fix/STAY-135 & STAY-127

* fix: make quantity and delivery separate steps in mobile

* fix: update design for delivery step in ancillary flow

* fix: add error state for missing time

* fix: only allow points or cash payment for ancillaries

* fix: break out stepper to design system

* fix: update design of select quantity step in add ancillaries flow

* fix: add error states for quantity

* fix: handle insufficient points case

* fix: update stepper to include optional disabledMessage tooltip

* fix: handle validations

* fix: change name to camel case


Approved-by: Bianca Widstam
Approved-by: Chuma Mcphoy (We Ahead)
2025-12-18 13:31:43 +00:00

116 lines
2.8 KiB
TypeScript

import { logger } from "@scandic-hotels/common/logger"
import {
type AncillaryFormData,
PaymentChoiceEnum,
} from "@/components/HotelReservation/MyStay/Ancillaries/AddAncillaryFlow/schema"
import type {
Ancillary,
SelectedAncillary,
} from "@/types/components/myPages/myStay/ancillaries"
import type { BreakfastData } from "@/stores/my-stay/add-ancillary-flow"
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.paymentChoice === PaymentChoiceEnum.Card) {
packages.push({
code: ancillary.id,
quantity: data.quantity,
comment: data.optionalText || undefined,
})
}
if (
ancillary?.loyaltyCode &&
data.paymentChoice === PaymentChoiceEnum.Points
) {
packages.push({
code: ancillary.loyaltyCode,
quantity: data.quantity,
comment: data.optionalText || undefined,
})
}
return packages
}
const ancillarySessionKey = "ancillarySessionData"
export const getAncillarySessionData = ():
| {
formData?: AncillaryFormData
selectedAncillary?: Ancillary["ancillaryContent"][number] | null
packages: {
code: string
quantity: number
comment: string | undefined
}[]
isBreakfast: boolean
breakfastData: BreakfastData | null
}
| undefined => {
if (typeof window === "undefined") return undefined
try {
const storedData = sessionStorage.getItem(ancillarySessionKey)
return storedData ? JSON.parse(storedData) : undefined
} catch (error) {
logger.error("Error reading from session storage:", error)
return undefined
}
}
export function setAncillarySessionData({
formData,
selectedAncillary,
packages,
isBreakfast,
breakfastData,
}: {
formData?: AncillaryFormData
selectedAncillary?: Ancillary["ancillaryContent"][number] | null
packages: {
code: string
quantity: number
comment: string | undefined
}[]
isBreakfast: boolean
breakfastData: BreakfastData | null
}) {
if (typeof window === "undefined") return
try {
const currentData = getAncillarySessionData() || {}
sessionStorage.setItem(
ancillarySessionKey,
JSON.stringify({
...currentData,
formData,
selectedAncillary,
packages,
isBreakfast,
breakfastData,
})
)
} catch (error) {
logger.error("Error writing to session storage:", error)
}
}
export function clearAncillarySessionData() {
if (typeof window === "undefined") return
sessionStorage.removeItem(ancillarySessionKey)
}