chore: cleaning up select-rate
This commit is contained in:
52
providers/RatesProvider.tsx
Normal file
52
providers/RatesProvider.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
"use client"
|
||||
import { usePathname, useSearchParams } from "next/navigation"
|
||||
import { useRef } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { createRatesStore } from "@/stores/select-rate"
|
||||
|
||||
import { RatesContext } from "@/contexts/Rates"
|
||||
|
||||
import type { RatesStore } from "@/types/contexts/rates"
|
||||
import type { RatesProviderProps } from "@/types/providers/rates"
|
||||
|
||||
export default function RatesProvider({
|
||||
booking,
|
||||
children,
|
||||
hotelType,
|
||||
isUserLoggedIn,
|
||||
packages,
|
||||
roomCategories,
|
||||
roomsAvailability,
|
||||
vat,
|
||||
}: RatesProviderProps) {
|
||||
const storeRef = useRef<RatesStore>()
|
||||
const pathname = usePathname()
|
||||
const searchParams = useSearchParams()
|
||||
const intl = useIntl()
|
||||
|
||||
if (!storeRef.current) {
|
||||
storeRef.current = createRatesStore({
|
||||
booking,
|
||||
hotelType,
|
||||
isUserLoggedIn,
|
||||
labels: {
|
||||
accessibilityRoom: intl.formatMessage({ id: "Accessible room" }),
|
||||
allergyRoom: intl.formatMessage({ id: "Allergy-friendly room" }),
|
||||
petRoom: intl.formatMessage({ id: "Pet room" }),
|
||||
},
|
||||
packages: packages ?? [],
|
||||
pathname,
|
||||
roomCategories,
|
||||
roomsAvailability,
|
||||
searchParams,
|
||||
vat,
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<RatesContext.Provider value={storeRef.current}>
|
||||
{children}
|
||||
</RatesContext.Provider>
|
||||
)
|
||||
}
|
||||
34
providers/RoomProvider.tsx
Normal file
34
providers/RoomProvider.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
"use client"
|
||||
|
||||
import { useRatesStore } from "@/stores/select-rate"
|
||||
|
||||
import { RoomContext } from "@/contexts/Room"
|
||||
|
||||
import type { RoomProviderProps } from "@/types/providers/room"
|
||||
|
||||
export default function RoomProvider({
|
||||
children,
|
||||
idx,
|
||||
room,
|
||||
}: RoomProviderProps) {
|
||||
const activeRoom = useRatesStore((state) => state.activeRoom)
|
||||
const modifyRate = useRatesStore((state) => state.actions.modifyRate(idx))
|
||||
const selectFilter = useRatesStore((state) => state.actions.selectFilter(idx))
|
||||
const selectRate = useRatesStore((state) => state.actions.selectRate(idx))
|
||||
return (
|
||||
<RoomContext.Provider
|
||||
value={{
|
||||
...room,
|
||||
actions: {
|
||||
modifyRate,
|
||||
selectFilter,
|
||||
selectRate,
|
||||
},
|
||||
isActiveRoom: activeRoom === idx,
|
||||
roomNr: idx + 1,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</RoomContext.Provider>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user