Merged in feat/SW-1889 (pull request #1670)

Feat/SW-1889

* fix: remove download invoice from confirmation page

* feat: remove EnterDetails Accordions


Approved-by: Simon.Emanuelsson
This commit is contained in:
Arvid Norlin
2025-03-31 13:14:11 +00:00
parent 93aafe5525
commit 5cff2e5f36
22 changed files with 205 additions and 513 deletions

View File

@@ -15,10 +15,8 @@ import {
calculateVoucherPrice,
checkRoomProgress,
extractGuestFromUser,
findNextInvalidStep,
getRoomPrice,
getTotalPrice,
handleStepProgression,
writeToSessionStorage,
} from "./helpers"
@@ -114,7 +112,6 @@ export function createDetailsStore(
})
return create<DetailsState>()((set) => ({
activeRoom: 0,
booking: initialState.booking,
breakfastPackages,
canProceedToPayment: false,
@@ -141,72 +138,8 @@ export function createDetailsStore(
delete steps[StepEnum.breakfast]
}
const currentStep =
Object.values(steps).find((step) => !step.isValid)?.step ??
StepEnum.selectBed
return {
actions: {
setStep(step) {
return set(
produce((state: DetailsState) => {
const isSameRoom = idx === state.activeRoom
const room = state.rooms[idx]
if (isSameRoom) {
// Closed same accordion as was open
if (step === room.currentStep) {
if (room.isComplete) {
// Room is complete, move to next room or payment
const nextRoomIdx = state.rooms.findIndex(
(r) => !r.isComplete
)
state.activeRoom = nextRoomIdx
// Done, proceed to payment
if (nextRoomIdx === -1) {
room.currentStep = null
} else {
const nextRoom = state.rooms[nextRoomIdx]
const nextInvalidStep = findNextInvalidStep(nextRoom)
nextRoom.currentStep = nextInvalidStep
}
} else {
room.currentStep = findNextInvalidStep(room)
}
} else {
if (room.steps[step]?.isValid) {
room.currentStep = step
} else {
room.currentStep = findNextInvalidStep(room)
}
}
} else {
const arePreviousRoomsCompleted = state.rooms
.slice(0, idx)
.every((room) => room.isComplete)
if (arePreviousRoomsCompleted) {
state.activeRoom = idx
if (room.steps[step]?.isValid) {
room.currentStep = step
} else {
room.currentStep = findNextInvalidStep(room)
}
} else {
const firstIncompleteRoom = state.rooms.findIndex(
(r) => !r.isComplete
)
state.activeRoom = firstIncompleteRoom
if (firstIncompleteRoom === -1) {
// All rooms are done, proceed to payment
room.currentStep = null
} else {
const nextRoom = state.rooms[firstIncompleteRoom]
nextRoom.currentStep = findNextInvalidStep(nextRoom)
}
}
}
})
)
},
updateBedType(bedType) {
return set(
produce((state: DetailsState) => {
@@ -220,10 +153,7 @@ export function createDetailsStore(
state.rooms[idx].isComplete = true
}
handleStepProgression(state.rooms[idx], state)
writeToSessionStorage({
activeRoom: state.activeRoom,
booking: state.booking,
rooms: state.rooms,
})
@@ -340,10 +270,7 @@ export function createDetailsStore(
state.rooms[idx].isComplete = true
}
handleStepProgression(currentRoom, state)
writeToSessionStorage({
activeRoom: state.activeRoom,
booking: state.booking,
rooms: state.rooms,
})
@@ -408,10 +335,7 @@ export function createDetailsStore(
state.rooms[idx].isComplete = true
}
handleStepProgression(state.rooms[idx], state)
writeToSessionStorage({
activeRoom: state.activeRoom,
booking: state.booking,
rooms: state.rooms,
})
@@ -461,10 +385,7 @@ export function createDetailsStore(
state.rooms[idx].isComplete = true
}
handleStepProgression(state.rooms[idx], state)
writeToSessionStorage({
activeRoom: state.activeRoom,
booking: state.booking,
rooms: state.rooms,
})
@@ -490,8 +411,6 @@ export function createDetailsStore(
comment: "",
},
},
currentStep,
isComplete: false,
steps,
}