fix: trigger memberPrice modal for membership number too
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use client"
|
||||
import deepmerge from "deepmerge"
|
||||
import { useEffect, useRef } from "react"
|
||||
import { useEffect, useRef, useState } from "react"
|
||||
|
||||
import { dt } from "@/lib/dt"
|
||||
import { createDetailsStore } from "@/stores/enter-details"
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
|
||||
import { getMultiroomDetailsSchema } from "@/components/HotelReservation/EnterDetails/Details/Multiroom/schema"
|
||||
import { guestDetailsSchema } from "@/components/HotelReservation/EnterDetails/Details/RoomOne/schema"
|
||||
import LoadingSpinner from "@/components/LoadingSpinner"
|
||||
import { DetailsContext } from "@/contexts/Details"
|
||||
|
||||
import type { DetailsStore } from "@/types/contexts/enter-details"
|
||||
@@ -31,6 +32,11 @@ export default function EnterDetailsProvider({
|
||||
user,
|
||||
vat,
|
||||
}: DetailsProviderProps) {
|
||||
// This state is needed to be able to use defaultValues for
|
||||
// react-hook-form since values needs to be there on mount
|
||||
// and since we read from SessionStorage we need to delay
|
||||
// rendering the form until that has been done.
|
||||
const [hasInitializedStore, setHasInitializedStore] = useState(false)
|
||||
const storeRef = useRef<DetailsStore>()
|
||||
if (!storeRef.current) {
|
||||
const initialData: InitialState = {
|
||||
@@ -74,16 +80,19 @@ export default function EnterDetailsProvider({
|
||||
useEffect(() => {
|
||||
const storedValues = readFromSessionStorage()
|
||||
if (!storedValues) {
|
||||
setHasInitializedStore(true)
|
||||
return
|
||||
}
|
||||
const isSameBooking = checkIsSameBooking(storedValues.booking, booking)
|
||||
if (!isSameBooking) {
|
||||
clearSessionStorage()
|
||||
setHasInitializedStore(true)
|
||||
return
|
||||
}
|
||||
|
||||
const store = storeRef.current?.getState()
|
||||
if (!store) {
|
||||
setHasInitializedStore(true)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -209,11 +218,13 @@ export default function EnterDetailsProvider({
|
||||
rooms: filteredOutMissingRooms,
|
||||
totalPrice,
|
||||
})
|
||||
|
||||
setHasInitializedStore(true)
|
||||
}, [booking, rooms, user])
|
||||
|
||||
return (
|
||||
<DetailsContext.Provider value={storeRef.current}>
|
||||
{children}
|
||||
{hasInitializedStore ? children : <LoadingSpinner fullPage />}
|
||||
</DetailsContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user