Merged in chore/remove-unused-useRoomContext (pull request #2747)
chore: delete unused useRoomContext * chore: delete unused useRoomContext * merge Approved-by: Matilda Landström
This commit is contained in:
@@ -12,7 +12,6 @@ import type { Room } from "@scandic-hotels/booking-flow/types/components/selectR
|
|||||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||||
import type { Child } from "@scandic-hotels/trpc/types/child"
|
import type { Child } from "@scandic-hotels/trpc/types/child"
|
||||||
|
|
||||||
|
|
||||||
type ChildrenInRoom = (Child[] | null)[] | null
|
type ChildrenInRoom = (Child[] | null)[] | null
|
||||||
|
|
||||||
type SelectRateTrackingInput = {
|
type SelectRateTrackingInput = {
|
||||||
|
|||||||
@@ -1,91 +0,0 @@
|
|||||||
"use client"
|
|
||||||
|
|
||||||
import { RoomContext } from "@scandic-hotels/booking-flow/contexts/SelectRate/Room"
|
|
||||||
import { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
|
|
||||||
import { AvailabilityEnum } from "@scandic-hotels/trpc/enums/selectHotel"
|
|
||||||
import { sortRoomConfigs } from "@scandic-hotels/trpc/utils/sortRoomConfigs"
|
|
||||||
|
|
||||||
import { useRatesStore } from "@/stores/select-rate"
|
|
||||||
|
|
||||||
import type { RoomProviderProps } from "@/types/providers/select-rate/room"
|
|
||||||
|
|
||||||
export default function RoomProvider({
|
|
||||||
children,
|
|
||||||
idx,
|
|
||||||
room,
|
|
||||||
}: RoomProviderProps) {
|
|
||||||
const { activeRoom, rateSummary, roomAvailability, roomPackages } =
|
|
||||||
useRatesStore((state) => ({
|
|
||||||
activeRoom: state.activeRoom,
|
|
||||||
rateSummary: state.rateSummary,
|
|
||||||
roomPackages: state.roomsPackages[idx],
|
|
||||||
roomAvailability: state.roomsAvailability?.[idx],
|
|
||||||
}))
|
|
||||||
const roomNr = idx + 1
|
|
||||||
|
|
||||||
const petRoomPackage = roomPackages.find(
|
|
||||||
(pkg) => pkg.code === RoomPackageCodeEnum.PET_ROOM
|
|
||||||
)
|
|
||||||
|
|
||||||
const selectedRoomsCount = rateSummary.reduce<Record<string, number>>(
|
|
||||||
(roomsCount, selectedRoom) => {
|
|
||||||
if (selectedRoom) {
|
|
||||||
if (!roomsCount[selectedRoom.roomTypeCode]) {
|
|
||||||
roomsCount[selectedRoom.roomTypeCode] = 0
|
|
||||||
}
|
|
||||||
roomsCount[selectedRoom.roomTypeCode] =
|
|
||||||
roomsCount[selectedRoom.roomTypeCode] + 1
|
|
||||||
}
|
|
||||||
return roomsCount
|
|
||||||
},
|
|
||||||
{}
|
|
||||||
)
|
|
||||||
|
|
||||||
const rooms = room.rooms
|
|
||||||
.map((r) => {
|
|
||||||
// Need to copy (shallow) since using immer with
|
|
||||||
// Zustand uses Proxy objects which results in
|
|
||||||
// properties being read-only thus causing errors
|
|
||||||
// when trying to modify roomsLeft etc.
|
|
||||||
const rCopy = { ...r }
|
|
||||||
if (selectedRoomsCount[r.roomTypeCode]) {
|
|
||||||
rCopy.roomsLeft =
|
|
||||||
rCopy.roomsLeft - selectedRoomsCount[rCopy.roomTypeCode]
|
|
||||||
|
|
||||||
const selectedRoom = rateSummary[idx]
|
|
||||||
const isCurrentlySelectedRoom =
|
|
||||||
selectedRoom && selectedRoom.roomTypeCode === rCopy.roomTypeCode
|
|
||||||
if (isCurrentlySelectedRoom) {
|
|
||||||
// Need to add 1 roomsLeft back to tally since
|
|
||||||
// our selectedRoom was included in selectedRoomsCount
|
|
||||||
rCopy.roomsLeft = rCopy.roomsLeft + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rCopy.roomsLeft <= 0) {
|
|
||||||
rCopy.status = AvailabilityEnum.NotAvailable
|
|
||||||
rCopy.roomsLeft = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rCopy
|
|
||||||
})
|
|
||||||
.sort(sortRoomConfigs)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<RoomContext.Provider
|
|
||||||
value={{
|
|
||||||
...room,
|
|
||||||
isActiveRoom: activeRoom === idx,
|
|
||||||
isMainRoom: roomNr === 1,
|
|
||||||
petRoomPackage,
|
|
||||||
roomAvailability,
|
|
||||||
roomPackages,
|
|
||||||
roomNr,
|
|
||||||
rooms,
|
|
||||||
totalRooms: room.rooms.length,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</RoomContext.Provider>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import isEqual from "fast-deep-equal"
|
|
||||||
import { parsePhoneNumberFromString } from "libphonenumber-js"
|
import { parsePhoneNumberFromString } from "libphonenumber-js"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -11,8 +10,6 @@ import { logger } from "@scandic-hotels/common/logger"
|
|||||||
|
|
||||||
import { detailsStorageName } from "."
|
import { detailsStorageName } from "."
|
||||||
|
|
||||||
import type { BookingWidgetSearchData } from "@scandic-hotels/booking-flow/BookingWidget"
|
|
||||||
import type { SelectRateBooking } from "@scandic-hotels/booking-flow/types/components/selectRate/selectRate"
|
|
||||||
import type { Packages } from "@scandic-hotels/trpc/types/packages"
|
import type { Packages } from "@scandic-hotels/trpc/types/packages"
|
||||||
import type {
|
import type {
|
||||||
CorporateChequeProduct,
|
CorporateChequeProduct,
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
import { createContext, useContext } from "react"
|
|
||||||
|
|
||||||
import type { RoomContextValue } from "../../types/contexts/selectRate/room"
|
|
||||||
|
|
||||||
export const RoomContext = createContext<RoomContextValue | null>(null)
|
|
||||||
|
|
||||||
export function useRoomContext() {
|
|
||||||
const ctx = useContext(RoomContext)
|
|
||||||
if (!ctx) {
|
|
||||||
throw new Error("Missing context value [RoomContext]")
|
|
||||||
}
|
|
||||||
return ctx
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import type { Package } from "@scandic-hotels/trpc/types/packages"
|
|
||||||
|
|
||||||
import type { RatesState, SelectedRoom } from "../../stores/rates"
|
|
||||||
|
|
||||||
export interface RoomContextValue extends SelectedRoom {
|
|
||||||
isActiveRoom: boolean
|
|
||||||
isFetchingAdditionalRate: boolean
|
|
||||||
isMainRoom: boolean
|
|
||||||
petRoomPackage: Package | undefined
|
|
||||||
roomAvailability:
|
|
||||||
| NonNullable<RatesState["roomsAvailability"]>[number]
|
|
||||||
| undefined
|
|
||||||
roomPackages: Package[]
|
|
||||||
roomNr: number
|
|
||||||
totalRooms: number
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user