"use client" import { useEffect, useState } from "react" import { type FieldErrors, type RegisterOptions, useWatch, } from "react-hook-form" import { useIntl } from "react-intl" import Caption from "@scandic-hotels/design-system/Caption" import DateSelect from "@scandic-hotels/design-system/Form/Date" import { useBookingFlowConfig } from "../../../../../bookingFlowConfig/bookingFlowConfigContext" import useLang from "../../../../../hooks/useLang" import BookingFlowInput from "../../../../BookingFlowInput" import { getErrorMessage } from "../../../../BookingFlowInput/errors" import { MembershipNumberInput } from "./MembershipNumberInput" import styles from "./signup.module.css" export default function Signup({ errors, name, registerOptions, refs, }: { errors: FieldErrors name: string registerOptions?: RegisterOptions refs: React.RefObject> }) { const intl = useIntl() const lang = useLang() const config = useBookingFlowConfig() 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]) if (isJoinChecked) return (
{ refs.current.zipCode = el }} >
{ refs.current.dateOfBirth = el }} >
{intl.formatMessage({ id: "common.birthDate", defaultMessage: "Birth date", })}
) if (config.enterDetailsMembershipIdInputLocation === "join-card") return null return (
{ refs.current.membershipNo = el }} >
) }