"use client" import { zodResolver } from "@hookform/resolvers/zod" import { useRouter } from "next/navigation" import { FormProvider, useForm } from "react-hook-form" import { useIntl } from "react-intl" import { membershipTermsAndConditions, privacyPolicy, } from "@/constants/currentWebHrefs" import { trpc } from "@/lib/trpc/client" import Button from "@/components/TempDesignSystem/Button" import Checkbox from "@/components/TempDesignSystem/Form/Checkbox" import CountrySelect from "@/components/TempDesignSystem/Form/Country" import DateSelect from "@/components/TempDesignSystem/Form/Date" import Input from "@/components/TempDesignSystem/Form/Input" import NewPassword from "@/components/TempDesignSystem/Form/NewPassword" import Phone from "@/components/TempDesignSystem/Form/Phone" import Link from "@/components/TempDesignSystem/Link" import Body from "@/components/TempDesignSystem/Text/Body" import Caption from "@/components/TempDesignSystem/Text/Caption" import Subtitle from "@/components/TempDesignSystem/Text/Subtitle" import Title from "@/components/TempDesignSystem/Text/Title" import { toast } from "@/components/TempDesignSystem/Toasts" import useLang from "@/hooks/useLang" import { type SignUpSchema, signUpSchema } from "./schema" import styles from "./form.module.css" import type { SignUpFormProps } from "@/types/components/form/signupForm" export default function SignupForm({ link, subtitle, title }: SignUpFormProps) { const intl = useIntl() const router = useRouter() const lang = useLang() const country = intl.formatMessage({ id: "Country" }) const email = intl.formatMessage({ id: "Email address" }) const phoneNumber = intl.formatMessage({ id: "Phone number" }) const zipCode = intl.formatMessage({ id: "Zip code" }) const signupButtonText = intl.formatMessage({ id: "Join now", }) const signup = trpc.user.signup.useMutation({ onSuccess: (data) => { if (data.success && data.redirectUrl) { router.push(data.redirectUrl) } }, onError: (error) => { toast.error(intl.formatMessage({ id: "Something went wrong!" })) console.error("Component Signup error:", error) }, }) const methods = useForm({ defaultValues: { firstName: "", lastName: "", email: "", phoneNumber: "", dateOfBirth: "", address: { countryCode: "", zipCode: "", }, password: "", termsAccepted: false, }, mode: "all", criteriaMode: "all", resolver: zodResolver(signUpSchema), reValidateMode: "onChange", shouldFocusError: true, }) async function onSubmit(data: SignUpSchema) { signup.mutate({ ...data, language: lang }) } return (
{title}
{intl.formatMessage({ id: "Contact information" })}
{intl.formatMessage({ id: "Birth date" })}
{intl.formatMessage({ id: "Password" })}
{intl.formatMessage({ id: "Terms and conditions" })}
{intl.formatMessage({ id: "I accept" })} {/* TODO: Update copy once ready */} {intl.formatMessage( { id: "signupPage.terms" }, { termsAndConditions: (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 ? ( ) : ( )}
) }