Merged in chore/SW-3321-move-selectratecontext-to- (pull request #2729)

chore(SW-3321): Moved Select rate context to booking-flow package

* chore(SW-3321): Moved Select rate context to booking-flow package

* chore(SW-3321): Optimised code


Approved-by: Joakim Jäderberg
This commit is contained in:
Hrishikesh Vaipurkar
2025-09-02 07:40:01 +00:00
parent 1804f7b7cd
commit 0a4bf40a15
77 changed files with 127 additions and 148 deletions
@@ -15,8 +15,8 @@ import { isBookingCodeRate } from "./utils"
import styles from "./rateSummary.module.css"
import type { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import type { SelectedRate } from "@/contexts/SelectRate/types"
import type { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import type { SelectedRate } from "@scandic-hotels/booking-flow/contexts/SelectRate/types"
export function DesktopSummary({
input,
@@ -2,6 +2,7 @@
import { cx } from "class-variance-authority"
import { useIntl } from "react-intl"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import { longDateFormat } from "@scandic-hotels/common/constants/dateFormats"
import { dt } from "@scandic-hotels/common/dt"
@@ -13,7 +14,6 @@ import { Typography } from "@scandic-hotels/design-system/Typography"
import PriceDetailsModal from "@/components/HotelReservation/PriceDetailsModal"
import SignupPromoDesktop from "@/components/HotelReservation/SignupPromo/Desktop"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import useRateTitles from "@/hooks/booking/useRateTitles"
import useLang from "@/hooks/useLang"
@@ -22,7 +22,7 @@ import Room from "../Room"
import styles from "./summaryContent.module.css"
import type { Price } from "@/contexts/SelectRate/getTotalPrice"
import type { Price } from "@scandic-hotels/booking-flow/contexts/SelectRate/getTotalPrice"
export type SelectRateSummaryProps = {
isMember: boolean
@@ -4,12 +4,12 @@ import { useEffect, useRef, useState } from "react"
import { Button as ButtonRAC } from "react-aria-components"
import { useIntl } from "react-intl"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { formatPrice } from "@scandic-hotels/common/utils/numberFormatting"
import { Button } from "@scandic-hotels/design-system/Button"
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
import { Typography } from "@scandic-hotels/design-system/Typography"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import { useIsUserLoggedIn } from "@/hooks/useIsUserLoggedIn"
import { isBookingCodeRate } from "../utils"
@@ -1,12 +1,12 @@
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import type { Packages } from "@scandic-hotels/trpc/types/packages"
import type { Price } from "@/types/components/hotelReservation/price"
import type {
Rate,
Room,
} from "@/types/components/hotelReservation/selectRate/selectRate"
} from "@scandic-hotels/booking-flow/types/components/selectRate/selectRate"
import type { Packages } from "@scandic-hotels/trpc/types/packages"
import type { Price } from "@/types/components/hotelReservation/price"
export function mapRate(
room: Rate,
@@ -1,7 +1,8 @@
import type {
Rate,
Room as SelectRateRoom,
} from "@/types/components/hotelReservation/selectRate/selectRate"
} from "@scandic-hotels/booking-flow/types/components/selectRate/selectRate"
import type { Room } from "@/components/HotelReservation/PriceDetailsModal/PriceDetailsTable"
export function mapToPrice(
@@ -3,8 +3,9 @@
import { useRouter, useSearchParams } from "next/navigation"
import { useState, useTransition } from "react"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { ErrorBoundary } from "@/components/ErrorBoundary/ErrorBoundary"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import { DesktopSummary } from "./DesktopSummary"
import { MobileSummary } from "./MobileSummary"
@@ -1,8 +1,8 @@
import { sumPackages } from "@scandic-hotels/booking-flow/utils/SelectRate"
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import { RateTypeEnum } from "@scandic-hotels/common/constants/rateType"
import { sumPackages } from "@/components/HotelReservation/utils"
import type { Rate } from "@scandic-hotels/booking-flow/types/components/selectRate/selectRate"
import type { Packages } from "@scandic-hotels/trpc/types/packages"
import type {
Product,
@@ -10,7 +10,6 @@ import type {
} from "@scandic-hotels/trpc/types/roomAvailability"
import type { Price } from "@/types/components/hotelReservation/price"
import type { Rate } from "@/types/components/hotelReservation/selectRate/selectRate"
export function calculateTotalPrice(
selectedRateSummary: Rate[],
@@ -1,6 +1,7 @@
"use client"
import { useIntl } from "react-intl"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import { RateEnum } from "@scandic-hotels/common/constants/rate"
import { logger } from "@scandic-hotels/common/logger"
@@ -12,7 +13,6 @@ import Image from "@scandic-hotels/design-system/Image"
import { OldDSButton as Button } from "@scandic-hotels/design-system/OldDSButton"
import Subtitle from "@scandic-hotels/design-system/Subtitle"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import { useIsUserLoggedIn } from "@/hooks/useIsUserLoggedIn"
import styles from "./selectedRoomPanel.module.css"
@@ -1,13 +1,12 @@
import { useEffect } from "react"
import { useIntl } from "react-intl"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import useStickyPosition from "@scandic-hotels/common/hooks/useStickyPosition"
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
import { OldDSButton as Button } from "@scandic-hotels/design-system/OldDSButton"
import Subtitle from "@scandic-hotels/design-system/Subtitle"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import { SelectedRoomPanel } from "./SelectedRoomPanel"
import { roomSelectionPanelVariants } from "./variants"
@@ -1,12 +1,12 @@
"use client"
import { useIntl } from "react-intl"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
import { alternativeHotels } from "@scandic-hotels/common/constants/routes/hotelReservation"
import { Alert } from "@scandic-hotels/design-system/Alert"
import { AvailabilityEnum } from "@scandic-hotels/trpc/enums/selectHotel"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import useLang from "@/hooks/useLang"
import styles from "./alert.module.css"
@@ -12,6 +12,7 @@ import {
} from "react-aria-components"
import { useIntl } from "react-intl"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { BookingCodeFilterEnum } from "@scandic-hotels/booking-flow/stores/bookingCode-filter"
import { RateTypeEnum } from "@scandic-hotels/common/constants/rateType"
import { ChipButton } from "@scandic-hotels/design-system/ChipButton"
@@ -19,7 +20,6 @@ import { IconButton } from "@scandic-hotels/design-system/IconButton"
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
import { Typography } from "@scandic-hotels/design-system/Typography"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import { useBreakpoint } from "@/hooks/useBreakpoint"
import styles from "./bookingCodeFilter.module.css"
@@ -1,7 +1,6 @@
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { BookingCodeChip } from "@scandic-hotels/design-system/BookingCodeChip"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
export function RemoveBookingCodeButton() {
const {
input: { bookingCode },
@@ -1,11 +1,11 @@
"use client"
import { Button as ButtonRAC } from "react-aria-components"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
import { Typography } from "@scandic-hotels/design-system/Typography"
import { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import { useBreakpoint } from "@/hooks/useBreakpoint"
import PetRoomMessage from "./Form/Checkboxes/PetRoomMessage"
@@ -1,12 +1,12 @@
"use client"
import { useIntl } from "react-intl"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import SkeletonShimmer from "@scandic-hotels/design-system/SkeletonShimmer"
import { Typography } from "@scandic-hotels/design-system/Typography"
import { AvailabilityEnum } from "@scandic-hotels/trpc/enums/selectHotel"
import { ErrorBoundary } from "@/components/ErrorBoundary/ErrorBoundary"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import { RemoveBookingCodeButton } from "./RemoveBookingCodeButton/RemoveBookingCodeButton"
import { RoomPackageFilter } from "./RoomPackageFilter"
@@ -7,7 +7,7 @@ import RoomSize from "./RoomSize"
import styles from "./details.module.css"
import type { RoomInfo } from "@/contexts/SelectRate/types"
import type { RoomInfo } from "@scandic-hotels/booking-flow/contexts/SelectRate/types"
type Props = {
roomInfo: RoomInfo
@@ -2,11 +2,11 @@
import { useSession } from "next-auth/react"
import { useIntl } from "react-intl"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { BookingCodeFilterEnum } from "@scandic-hotels/booking-flow/stores/bookingCode-filter"
import { Divider } from "@scandic-hotels/design-system/Divider"
import { Typography } from "@scandic-hotels/design-system/Typography"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import { isValidClientSession } from "@/utils/clientSession"
import { getBreakfastMessage } from "./getBreakfastMessage"
@@ -1,15 +1,15 @@
"use client"
import { useIntl } from "react-intl"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { BookingCodeFilterEnum } from "@scandic-hotels/booking-flow/stores/bookingCode-filter"
import CampaignRateCard from "@scandic-hotels/design-system/CampaignRateCard"
import NoRateAvailableCard from "@scandic-hotels/design-system/NoRateAvailableCard"
import {
sumPackages,
sumPackagesRequestedPrice,
} from "@/components/HotelReservation/utils"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
} from "@scandic-hotels/booking-flow/utils/SelectRate"
import CampaignRateCard from "@scandic-hotels/design-system/CampaignRateCard"
import NoRateAvailableCard from "@scandic-hotels/design-system/NoRateAvailableCard"
import useRateTitles from "@/hooks/booking/useRateTitles"
import { useIsUserLoggedIn } from "@/hooks/useIsUserLoggedIn"
@@ -18,7 +18,7 @@ import { calculatePricePerNightPriceProduct } from "./totalPricePerNight"
import type {
AvailabilityWithRoomInfo,
Package,
} from "@/contexts/SelectRate/types"
} from "@scandic-hotels/booking-flow/contexts/SelectRate/types"
type CampaignProps = {
nights: number
@@ -2,21 +2,20 @@
import { useIntl } from "react-intl"
import CodeRateCard from "@scandic-hotels/design-system/CodeRateCard"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import {
sumPackages,
sumPackagesRequestedPrice,
} from "@/components/HotelReservation/utils"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
} from "@scandic-hotels/booking-flow/utils/SelectRate"
import CodeRateCard from "@scandic-hotels/design-system/CodeRateCard"
import useRateTitles from "@/hooks/booking/useRateTitles"
import { calculatePricePerNightPriceProduct } from "./totalPricePerNight"
import type { Package } from "@scandic-hotels/booking-flow/contexts/SelectRate/types"
import type { CodeProduct } from "@scandic-hotels/trpc/types/roomAvailability"
import type { Package } from "@/contexts/SelectRate/types"
type CodeProps = {
nights: number
roomTypeCode: string
@@ -1,17 +1,17 @@
"use client"
import { useIntl } from "react-intl"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { BookingCodeFilterEnum } from "@scandic-hotels/booking-flow/stores/bookingCode-filter"
import { sumPackages } from "@scandic-hotels/booking-flow/utils/SelectRate"
import PointsRateCard from "@scandic-hotels/design-system/PointsRateCard"
import { sumPackages } from "@/components/HotelReservation/utils"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import useRateTitles from "@/hooks/booking/useRateTitles"
import type {
AvailabilityWithRoomInfo,
Package,
} from "@/contexts/SelectRate/types"
} from "@scandic-hotels/booking-flow/contexts/SelectRate/types"
type RedemptionsProps = {
redemptions: AvailabilityWithRoomInfo["redemptions"]
@@ -2,24 +2,23 @@
import { useSession } from "next-auth/react"
import { useIntl } from "react-intl"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { BookingCodeFilterEnum } from "@scandic-hotels/booking-flow/stores/bookingCode-filter"
import NoRateAvailableCard from "@scandic-hotels/design-system/NoRateAvailableCard"
import RegularRateCard from "@scandic-hotels/design-system/RegularRateCard"
import {
sumPackages,
sumPackagesRequestedPrice,
} from "@/components/HotelReservation/utils"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
} from "@scandic-hotels/booking-flow/utils/SelectRate"
import NoRateAvailableCard from "@scandic-hotels/design-system/NoRateAvailableCard"
import RegularRateCard from "@scandic-hotels/design-system/RegularRateCard"
import useRateTitles from "@/hooks/booking/useRateTitles"
import { isValidClientSession } from "@/utils/clientSession"
import { calculatePricePerNightPriceProduct } from "./totalPricePerNight"
import type { AvailabilityWithRoomInfo } from "@scandic-hotels/booking-flow/contexts/SelectRate/types"
import type { Package } from "@scandic-hotels/trpc/types/packages"
import type { AvailabilityWithRoomInfo } from "@/contexts/SelectRate/types"
interface Rate {
label: string
price: string
@@ -1,20 +1,18 @@
"use client"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { BookingCodeFilterEnum } from "@scandic-hotels/booking-flow/stores/bookingCode-filter"
import { Divider } from "@scandic-hotels/design-system/Divider"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import { BreakfastMessage } from "./BreakfastMessage"
import Campaign from "./Campaign"
import Code from "./Code"
import Redemptions from "./Redemptions"
import { RegularRate } from "./Regular"
import type { AvailabilityWithRoomInfo } from "@scandic-hotels/booking-flow/contexts/SelectRate/types"
import type { Package } from "@scandic-hotels/trpc/types/packages"
import type { AvailabilityWithRoomInfo } from "@/contexts/SelectRate/types"
export interface RatesProps {
roomConfiguration: AvailabilityWithRoomInfo
roomIndex: number
@@ -1,11 +1,10 @@
import type { SelectedRate } from "@scandic-hotels/booking-flow/types/stores/rates"
import type {
CorporateChequeProduct,
PriceProduct,
VoucherProduct,
} from "@scandic-hotels/trpc/types/roomAvailability"
import type { SelectedRate } from "@/types/stores/rates"
export function isSelectedPriceProduct(
product: PriceProduct,
selectedRate: SelectedRate | null,
@@ -2,13 +2,13 @@
import { memo } from "react"
import { useIntl } from "react-intl"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { IconForFeatureCode } from "@scandic-hotels/booking-flow/utils/SelectRate"
import ImageGallery from "@scandic-hotels/design-system/ImageGallery"
import { Typography } from "@scandic-hotels/design-system/Typography"
import { getHotelRoom } from "@scandic-hotels/trpc/routers/booking/helpers"
import { IconForFeatureCode } from "@/components/HotelReservation/utils"
import RoomDetailsSidePeek from "@/components/SidePeeks/RoomDetailsSidePeek"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import { mapApiImagesToGalleryImages } from "@/utils/imageGallery"
import styles from "./image.module.css"
@@ -8,10 +8,9 @@ import RoomNotAvailable from "./RoomNotAvailable"
import styles from "./roomListItem.module.css"
import type { AvailabilityWithRoomInfo } from "@scandic-hotels/booking-flow/contexts/SelectRate/types"
import type { Package } from "@scandic-hotels/trpc/types/packages"
import type { AvailabilityWithRoomInfo } from "@/contexts/SelectRate/types"
export type RoomListItemProps = {
room: AvailabilityWithRoomInfo
selectedPackages: Package[]
@@ -1,7 +1,7 @@
"use client"
import { useEffect } from "react"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import styles from "./rooms.module.css"
@@ -1,5 +1,5 @@
"use client"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { RoomListItem } from "./RoomListItem"
import { RoomsListSkeleton } from "./RoomsListSkeleton"
@@ -1,6 +1,6 @@
"use client"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { MultiRoomWrapper } from "./MultiRoomWrapper"
import NoAvailabilityAlert from "./NoAvailabilityAlert"
@@ -3,11 +3,10 @@
import { TRPCClientError } from "@trpc/client"
import { useIntl } from "react-intl"
import { useSelectRateContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
import { Alert } from "@scandic-hotels/design-system/Alert"
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
import { RateSummary } from "./RateSummary"
import Rooms from "./Rooms"
import { RoomsContainerSkeleton } from "./RoomsContainerSkeleton"
@@ -8,10 +8,10 @@ import {
import { ChildBedMapEnum } from "@scandic-hotels/trpc/enums/childBedMapEnum"
import { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
import type { Room } from "@scandic-hotels/booking-flow/types/components/selectRate/selectRate"
import type { Lang } from "@scandic-hotels/common/constants/language"
import type { Child } from "@scandic-hotels/trpc/types/child"
import type { Room } from "@/types/components/hotelReservation/selectRate/selectRate"
type ChildrenInRoom = (Child[] | null)[] | null
@@ -2,6 +2,7 @@ import { cookies } from "next/headers"
import FnFNotAllowedAlert from "@scandic-hotels/booking-flow/components/FnFNotAllowedAlert"
import { HotelDetailsSidePeek } from "@scandic-hotels/booking-flow/components/HotelDetailsSidePeek"
import { hasOverlappingDates } from "@scandic-hotels/booking-flow/utils/SelectRate"
import { FamilyAndFriendsCodes } from "@scandic-hotels/common/constants/familyAndFriends"
import { dt } from "@scandic-hotels/common/dt"
import { HotelInfoCard } from "@scandic-hotels/design-system/HotelInfoCard"
@@ -10,14 +11,12 @@ import { RoomsContainer } from "@/components/HotelReservation/SelectRate/RoomsCo
import { getIntl } from "@/i18n"
import { mapApiImagesToGalleryImages } from "@/utils/imageGallery"
import { hasOverlappingDates } from "../utils"
import AvailabilityError from "./AvailabilityError"
import Tracking from "./Tracking"
import type { SelectRateBooking } from "@scandic-hotels/booking-flow/types/components/selectRate/selectRate"
import type { RouterOutput } from "@scandic-hotels/trpc/client"
import type { SelectRateBooking } from "@/types/components/hotelReservation/selectRate/selectRate"
export default async function SelectRatePage({
booking,
hotelData,