feat: make steps of enter details flow dynamic depending on data
This commit is contained in:
30
providers/DetailsProvider.tsx
Normal file
30
providers/DetailsProvider.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
"use client"
|
||||
import { useSearchParams } from "next/navigation"
|
||||
import { useRef } from "react"
|
||||
|
||||
import { createDetailsStore } from "@/stores/details"
|
||||
|
||||
import { getQueryParamsForEnterDetails } from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
||||
import { DetailsContext } from "@/contexts/Details"
|
||||
|
||||
import type { DetailsStore } from "@/types/contexts/details"
|
||||
import type { DetailsProviderProps } from "@/types/providers/details"
|
||||
|
||||
export default function DetailsProvider({
|
||||
children,
|
||||
isMember,
|
||||
}: DetailsProviderProps) {
|
||||
const storeRef = useRef<DetailsStore>()
|
||||
const searchParams = useSearchParams()
|
||||
|
||||
if (!storeRef.current) {
|
||||
const booking = getQueryParamsForEnterDetails(searchParams)
|
||||
storeRef.current = createDetailsStore({ booking }, isMember)
|
||||
}
|
||||
|
||||
return (
|
||||
<DetailsContext.Provider value={storeRef.current}>
|
||||
{children}
|
||||
</DetailsContext.Provider>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user