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
68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
"use client"
|
|
|
|
import { useEffect, useState } from "react"
|
|
import { type RegisterOptions, useWatch } from "react-hook-form"
|
|
import { useIntl } from "react-intl"
|
|
|
|
import DateSelect from "@/components/TempDesignSystem/Form/Date"
|
|
import Input from "@/components/TempDesignSystem/Form/Input"
|
|
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
|
|
|
import styles from "./signup.module.css"
|
|
|
|
export default function Signup({
|
|
name,
|
|
registerOptions,
|
|
}: {
|
|
name: string
|
|
registerOptions?: RegisterOptions
|
|
}) {
|
|
const intl = useIntl()
|
|
|
|
const [isJoinChecked, setIsJoinChecked] = useState(false)
|
|
|
|
const joinValue = useWatch({ name })
|
|
|
|
useEffect(() => {
|
|
// In order to avoid hydration errors the state needs to be set as side effect,
|
|
// since the join value can come from search params
|
|
setIsJoinChecked(joinValue)
|
|
}, [joinValue])
|
|
|
|
return isJoinChecked ? (
|
|
<div className={styles.additionalFormData}>
|
|
<Input
|
|
name="zipCode"
|
|
label={intl.formatMessage({
|
|
defaultMessage: "Zip code",
|
|
})}
|
|
registerOptions={{ required: true, ...registerOptions }}
|
|
/>
|
|
<div className={styles.dateField}>
|
|
<header>
|
|
<Caption type="bold">
|
|
<span className={styles.required}>
|
|
{intl.formatMessage({
|
|
defaultMessage: "Birth date",
|
|
})}
|
|
</span>
|
|
</Caption>
|
|
</header>
|
|
<DateSelect
|
|
name="dateOfBirth"
|
|
registerOptions={{ required: true, ...registerOptions }}
|
|
/>
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<Input
|
|
label={intl.formatMessage({
|
|
defaultMessage: "Membership no",
|
|
})}
|
|
name="membershipNo"
|
|
type="tel"
|
|
registerOptions={registerOptions}
|
|
/>
|
|
)
|
|
}
|