Merged in fix/sw-2501-remove-continue-button-light (pull request #1892)

fix(sw-2501): remove the continue buttons on enter details

This removes the continue buttons on the enter details page.

This is only that, not the refactoring of the whole enter details page with changing to one form etc. Since I just didn’t complete that refactor today I decided to do this light variant for now.

A quick explanation is that the continue buttons are removed and instead the form is submitted (meaning saving the form data to the store) on blur on the input elements IF the form is valid. If it’s invalid we change the isComplete flag in the store to false. This will hopefully also fix a bug where you were able to submit old data if the new data is invalid.

When clicking the submit button and a room is incomplete/invalid the browser scrolls to the first invalid room.

Approved-by: Erik Tiekstra
This commit is contained in:
Niclas Edenvin
2025-04-30 08:56:16 +00:00
parent 7070770581
commit 341be43a53
10 changed files with 111 additions and 135 deletions

View File

@@ -19,8 +19,8 @@ import { StepEnum } from "@/types/enums/step"
export default function Multiroom() {
const intl = useIntl()
const { idx, room, roomNr, steps } = useRoomContext()
const { breakfastPackages, rooms } = useEnterDetailsStore((state) => ({
const { room, roomNr } = useRoomContext()
const { breakfastPackages } = useEnterDetailsStore((state) => ({
breakfastPackages: state.breakfastPackages,
rooms: state.rooms,
}))
@@ -28,22 +28,6 @@ export default function Multiroom() {
const showBreakfastStep =
!room.breakfastIncluded && !!breakfastPackages.length
const arePreviousRoomsValid = rooms.slice(0, idx).every((r) => r.isComplete)
const isBreakfastStepValid = showBreakfastStep
? steps[StepEnum.breakfast]?.isValid
: true
const isBreakfastDisabled = !(
arePreviousRoomsValid && steps[StepEnum.selectBed].isValid
)
const isDetailsDisabled = !(
arePreviousRoomsValid &&
steps[StepEnum.selectBed].isValid &&
isBreakfastStepValid
)
const hasChildWithExtraBed = room.childrenInRoom?.some(
(child) => Number(child.bed) === ChildBedMapEnum.IN_EXTRA_BED
)
@@ -55,7 +39,7 @@ export default function Multiroom() {
)
return (
<section>
<section id={`room-${roomNr}`}>
<Header>
<Title level="h2" as="h4">
{intl.formatMessage(
@@ -77,7 +61,6 @@ export default function Multiroom() {
label={intl.formatMessage({ defaultMessage: "Request bedtype" })}
additionalInfo={bedTypeInfoText}
step={StepEnum.selectBed}
disabled={!arePreviousRoomsValid}
>
<BedType />
</Section>
@@ -92,7 +75,6 @@ export default function Multiroom() {
defaultMessage: "Select breakfast options",
})}
step={StepEnum.breakfast}
disabled={isBreakfastDisabled}
>
<Breakfast />
</Section>
@@ -106,7 +88,6 @@ export default function Multiroom() {
label={intl.formatMessage({
defaultMessage: "Enter your details",
})}
disabled={isDetailsDisabled}
>
<Details />
</Section>

View File

@@ -20,7 +20,7 @@ import type { SafeUser } from "@/types/user"
export default function RoomOne({ user }: { user: SafeUser }) {
const intl = useIntl()
const { room, steps } = useRoomContext()
const { room } = useRoomContext()
const { breakfastPackages, isMultiroom } = useEnterDetailsStore((state) => ({
breakfastPackages: state.breakfastPackages,
isMultiroom: state.rooms.length > 1,
@@ -43,7 +43,7 @@ export default function RoomOne({ user }: { user: SafeUser }) {
!room.breakfastIncluded && !!breakfastPackages.length
return (
<section>
<section id="room-1">
{isMultiroom ? (
<Header>
<Title level="h2" as="h4">
@@ -81,7 +81,6 @@ export default function RoomOne({ user }: { user: SafeUser }) {
defaultMessage: "Select breakfast options",
})}
step={StepEnum.breakfast}
disabled={!steps[StepEnum.selectBed].isValid}
>
<Breakfast />
</Section>
@@ -95,12 +94,6 @@ export default function RoomOne({ user }: { user: SafeUser }) {
label={intl.formatMessage({
defaultMessage: "Enter your details",
})}
disabled={
!(
steps[StepEnum.selectBed].isValid &&
steps[StepEnum.breakfast]?.isValid !== false
)
}
>
<Details user={user} />
</Section>