fix: reset searchparams after errorcode from planet
This commit is contained in:
@@ -5,10 +5,14 @@ import { useCallback, useEffect } from "react"
|
|||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
import { PaymentErrorCodeEnum } from "@/constants/booking"
|
import { PaymentErrorCodeEnum } from "@/constants/booking"
|
||||||
|
import { useEnterDetailsStore } from "@/stores/enter-details"
|
||||||
|
|
||||||
import { toast } from "@/components/TempDesignSystem/Toasts"
|
import { toast } from "@/components/TempDesignSystem/Toasts"
|
||||||
|
|
||||||
export function usePaymentFailedToast() {
|
export function usePaymentFailedToast() {
|
||||||
|
const updateSearchParams = useEnterDetailsStore(
|
||||||
|
(state) => state.actions.updateSeachParamString
|
||||||
|
)
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
@@ -43,6 +47,15 @@ export function usePaymentFailedToast() {
|
|||||||
|
|
||||||
const queryParams = new URLSearchParams(searchParams.toString())
|
const queryParams = new URLSearchParams(searchParams.toString())
|
||||||
queryParams.delete("errorCode")
|
queryParams.delete("errorCode")
|
||||||
|
|
||||||
|
updateSearchParams(queryParams.toString())
|
||||||
router.push(`${pathname}?${queryParams.toString()}`)
|
router.push(`${pathname}?${queryParams.toString()}`)
|
||||||
}, [searchParams, pathname, errorCode, errorMessage, router])
|
}, [
|
||||||
|
searchParams,
|
||||||
|
pathname,
|
||||||
|
errorCode,
|
||||||
|
errorMessage,
|
||||||
|
router,
|
||||||
|
updateSearchParams,
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ export function createDetailsStore(
|
|||||||
const currentStepIndex = state.steps.indexOf(state.currentStep)
|
const currentStepIndex = state.steps.indexOf(state.currentStep)
|
||||||
const nextStep = state.steps[currentStepIndex + 1]
|
const nextStep = state.steps[currentStepIndex + 1]
|
||||||
state.currentStep = nextStep
|
state.currentStep = nextStep
|
||||||
navigate(nextStep, searchParams)
|
navigate(nextStep, state.searchParamString)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -141,7 +141,7 @@ export function createDetailsStore(
|
|||||||
return set(
|
return set(
|
||||||
produce((state) => {
|
produce((state) => {
|
||||||
state.currentStep = step
|
state.currentStep = step
|
||||||
navigate(step, searchParams)
|
navigate(step, state.searchParamString)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -185,7 +185,7 @@ export function createDetailsStore(
|
|||||||
const currentStepIndex = state.steps.indexOf(state.currentStep)
|
const currentStepIndex = state.steps.indexOf(state.currentStep)
|
||||||
const nextStep = state.steps[currentStepIndex + 1]
|
const nextStep = state.steps[currentStepIndex + 1]
|
||||||
state.currentStep = nextStep
|
state.currentStep = nextStep
|
||||||
navigate(nextStep, searchParams)
|
navigate(nextStep, state.searchParamString)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -266,7 +266,7 @@ export function createDetailsStore(
|
|||||||
const currentStepIndex = state.steps.indexOf(state.currentStep)
|
const currentStepIndex = state.steps.indexOf(state.currentStep)
|
||||||
const nextStep = state.steps[currentStepIndex + 1]
|
const nextStep = state.steps[currentStepIndex + 1]
|
||||||
state.currentStep = nextStep
|
state.currentStep = nextStep
|
||||||
navigate(nextStep, searchParams)
|
navigate(nextStep, state.searchParamString)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -304,11 +304,19 @@ export function createDetailsStore(
|
|||||||
const currentStepIndex = state.steps.indexOf(state.currentStep)
|
const currentStepIndex = state.steps.indexOf(state.currentStep)
|
||||||
const nextStep = state.steps[currentStepIndex + 1]
|
const nextStep = state.steps[currentStepIndex + 1]
|
||||||
state.currentStep = nextStep
|
state.currentStep = nextStep
|
||||||
navigate(nextStep, searchParams)
|
navigate(nextStep, state.searchParamString)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
},
|
||||||
|
updateSeachParamString(searchParamString) {
|
||||||
|
return set(
|
||||||
|
produce((state: DetailsState) => {
|
||||||
|
state.searchParamString = searchParamString
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
searchParamString: searchParams,
|
||||||
bedType: initialState.bedType ?? undefined,
|
bedType: initialState.bedType ?? undefined,
|
||||||
booking: initialState.booking,
|
booking: initialState.booking,
|
||||||
breakfast:
|
breakfast:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import type {
|
|||||||
DetailsSchema,
|
DetailsSchema,
|
||||||
SignedInDetailsSchema,
|
SignedInDetailsSchema,
|
||||||
} from "@/types/components/hotelReservation/enterDetails/details"
|
} from "@/types/components/hotelReservation/enterDetails/details"
|
||||||
import { StepEnum } from "@/types/enums/step"
|
import type { StepEnum } from "@/types/enums/step"
|
||||||
import type { DetailsProviderProps } from "../providers/enter-details"
|
import type { DetailsProviderProps } from "../providers/enter-details"
|
||||||
import type { Packages } from "../requests/packages"
|
import type { Packages } from "../requests/packages"
|
||||||
|
|
||||||
@@ -37,6 +37,7 @@ export interface DetailsState {
|
|||||||
updateBedType: (data: BedTypeSchema) => void
|
updateBedType: (data: BedTypeSchema) => void
|
||||||
updateBreakfast: (data: BreakfastPackage | false) => void
|
updateBreakfast: (data: BreakfastPackage | false) => void
|
||||||
updateDetails: (data: DetailsSchema) => void
|
updateDetails: (data: DetailsSchema) => void
|
||||||
|
updateSeachParamString: (searchParamString: string) => void
|
||||||
}
|
}
|
||||||
bedType: BedTypeSchema | undefined
|
bedType: BedTypeSchema | undefined
|
||||||
booking: BookingData
|
booking: BookingData
|
||||||
@@ -52,6 +53,7 @@ export interface DetailsState {
|
|||||||
roomPrice: Price
|
roomPrice: Price
|
||||||
steps: StepEnum[]
|
steps: StepEnum[]
|
||||||
totalPrice: Price
|
totalPrice: Price
|
||||||
|
searchParamString: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type InitialState = Pick<DetailsState, "booking" | "packages"> &
|
export type InitialState = Pick<DetailsState, "booking" | "packages"> &
|
||||||
|
|||||||
Reference in New Issue
Block a user