Merged in fix/handle-bed-reselect-navigation (pull request #1321)

fix: adjust allowed step navigation condition

* fix: adjust allowed step navigation condition


Approved-by: Tobias Johansson
This commit is contained in:
Arvid Norlin
2025-02-13 08:39:43 +00:00
parent 41cb32dd30
commit d46a85a529
4 changed files with 45 additions and 14 deletions

View File

@@ -11,6 +11,7 @@ import type {
PersistedState,
RoomState,
RoomStatus,
RoomStep,
} from "@/types/stores/enter-details"
import type { SafeUser } from "@/types/user"
@@ -242,9 +243,30 @@ export const selectRoomSteps = (state: DetailsState, index?: number) =>
index ?? state.bookingProgress.currentRoomIndex
].steps
export const selectPreviousSteps = (
state: DetailsState,
index?: number
): {
[StepEnum.selectBed]?: RoomStep
[StepEnum.breakfast]?: RoomStep
[StepEnum.details]?: RoomStep
} => {
const roomStatus =
state.bookingProgress.roomStatuses[
index ?? state.bookingProgress.currentRoomIndex
]
const stepKeys = Object.keys(roomStatus.steps)
const currentStepIndex = stepKeys.indexOf(`${roomStatus.currentStep}`)
return Object.entries(roomStatus.steps)
.slice(0, currentStepIndex)
.reduce((acc, [key, value]) => {
return { ...acc, [key]: value }
}, {})
}
export const selectNextStep = (roomStatus: RoomStatus) => {
if (!roomStatus.currentStep) {
throw new Error("getNextStep: currentStep is undefined")
if (roomStatus.currentStep === null) {
throw new Error("getNextStep: currentStep is null")
}
if (!roomStatus.steps[roomStatus.currentStep]?.isValid) {
@@ -307,7 +329,7 @@ export function handleStepProgression(state: DetailsState) {
}
const nextStep = selectNextStep(roomStatus)
if (nextStep && roomStatus.currentStep) {
if (nextStep !== null && roomStatus.currentStep !== null) {
roomStatus.lastCompletedStep = roomStatus.currentStep
roomStatus.currentStep = nextStep
return