"use client" import { zodResolver } from "@hookform/resolvers/zod" import { cx } from "class-variance-authority" import { useRouter } from "next/navigation" import { FormProvider, useForm } from "react-hook-form" import { useIntl } from "react-intl" import { membershipTermsAndConditions } from "@scandic-hotels/common/constants/routes/membershipTermsAndConditions" import { privacyPolicyRoutes } from "@scandic-hotels/common/constants/routes/privacyPolicyRoutes" import { logger } from "@scandic-hotels/common/logger" import { formatPhoneNumber, getDefaultCountryFromLang, } from "@scandic-hotels/common/utils/phone" import { Button } from "@scandic-hotels/design-system/Button" import Checkbox from "@scandic-hotels/design-system/Form/Checkbox" import CountrySelect from "@scandic-hotels/design-system/Form/Country" import DateSelect from "@scandic-hotels/design-system/Form/Date" import Phone from "@scandic-hotels/design-system/Form/Phone" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import Link from "@scandic-hotels/design-system/OldDSLink" import { toast } from "@scandic-hotels/design-system/Toast" import { Typography } from "@scandic-hotels/design-system/Typography" import { useFormTracking } from "@scandic-hotels/tracking/useFormTracking" import { trpc } from "@scandic-hotels/trpc/client" import { signupErrors, type SignUpSchema, signUpSchema, } from "@scandic-hotels/trpc/routers/user/schemas" import ProfilingConsentModalReadOnly from "@/components/MyPages/ProfilingConsent/Modal/ReadOnly" import Input from "@/components/TempDesignSystem/Form/Input" import PasswordInput from "@/components/TempDesignSystem/Form/PasswordInput" import useLang from "@/hooks/useLang" import { getFormattedCountryList } from "@/utils/countries" import { getErrorMessage } from "@/utils/getErrorMessage" import { requestOpen } from "@/utils/profilingConsent" import { trackLinkClick } from "@/utils/tracking/profilingConsent" // import { type SignUpSchema, signUpSchema } from "./schema" import styles from "./form.module.css" import type { SignUpFormProps } from "@/types/components/form/signupForm" export default function SignupForm({ title }: SignUpFormProps) { const intl = useIntl() const router = useRouter() const lang = useLang() const signupButtonText = intl.formatMessage({ id: "signUp.joinNow", defaultMessage: "Join now", }) const signup = trpc.user.signup.useMutation({ onSuccess: (data) => { if (data.success && data.redirectUrl) { router.push(data.redirectUrl) } }, onError: (error) => { if (error.data?.code === "CONFLICT") { toast.error( intl.formatMessage({ id: "signUp.accountExistsError", defaultMessage: "An account with this email already exists. Please try signing in instead.", }) ) return } toast.error( intl.formatMessage({ id: "errorMessage.somethingWentWrong", defaultMessage: "Something went wrong!", }) ) logger.error("Component Signup error:", error) }, }) const methods = useForm({ defaultValues: { firstName: "", lastName: "", email: "", phoneNumber: "", phoneNumberCC: getDefaultCountryFromLang(lang), dateOfBirth: "", address: { countryCode: "", zipCode: "", }, password: "", termsAccepted: false, profilingConsent: false, }, mode: "all", criteriaMode: "all", resolver: zodResolver(signUpSchema), reValidateMode: "onChange", shouldFocusError: true, }) const { control, subscribe, formState: { errors }, } = methods const { trackFormSubmit } = useFormTracking("signup", subscribe, control) async function onSubmit(data: SignUpSchema) { const phoneNumber = formatPhoneNumber(data.phoneNumber, data.phoneNumberCC) signup.mutate({ ...data, phoneNumber, language: lang }) trackFormSubmit() } function openPersonalizationModal() { trackLinkClick({ position: "signup", name: "read more about personalization at scandic", }) requestOpen() } return (
{title ? (

{title}

) : null}

{intl.formatMessage({ id: "signUp.contactInformation", defaultMessage: "Contact information", })}

{intl.formatMessage({ id: "common.birthDate", defaultMessage: "Birth date", })}

{intl.formatMessage({ id: "common.password", defaultMessage: "Password", })}

{intl.formatMessage({ id: "signup.UnlockYourPersonalizedExperience", defaultMessage: "Unlock your personalized experience!", })}

{intl.formatMessage({ id: "signup.yesConsent", defaultMessage: "I consent to Scandic using my information to give me even more personalized travel inspiration and offers from Scandic and trusted Scandic Friends partners. This means Scandic may use information about my interactions with Scandic Friends partners, and share details of my interactions with Scandic with those partners, to make the experience even more relevant to me.", })}

{intl.formatMessage({ id: "signup.GetATailoredProfile", defaultMessage: "Get a tailored profile that adapts to your interests.", })}

{intl.formatMessage({ id: "signup.PersonalizedOffersEarlyAccess", defaultMessage: "Personalized offers, early access to campaigns, and deals you won't find anywhere else!", })}

{intl.formatMessage({ id: "signUp.termsAndConditions", defaultMessage: "Terms and conditions", })}

{intl.formatMessage({ id: "signUp.iAccept", defaultMessage: "I accept", })}

{intl.formatMessage( { id: "signUp.termsAndConditionsDescription", defaultMessage: "By accepting the Terms and Conditions for Scandic Friends I understand that my personal data will be processed in accordance with Scandic's Privacy Policy.", }, { termsAndConditionsLink: (str) => ( {str} ), privacyPolicy: (str) => ( {str} ), } )}

{/* This is a manual validation trigger workaround: - The Controller component (which Input uses) doesn't re-render on submit, which prevents automatic error display. - Future fix requires Input component refactoring (out of scope for now). */} {!methods.formState.isValid ? ( ) : ( )}
) }