diff --git a/actions/registerUser.ts b/actions/registerUser.ts index 11afb22f4..7ce9c2e43 100644 --- a/actions/registerUser.ts +++ b/actions/registerUser.ts @@ -7,7 +7,7 @@ import { signupVerify } from "@/constants/routes/signup" import * as api from "@/lib/api" import { serviceServerActionProcedure } from "@/server/trpc" -import { registerSchema } from "@/components/Forms/Register/schema" +import { signUpSchema } from "@/components/Forms/Signup/schema" import { passwordValidator } from "@/utils/passwordValidator" import { phoneValidator } from "@/utils/phoneValidator" @@ -29,7 +29,7 @@ const registerUserPayload = z.object({ }) export const registerUser = serviceServerActionProcedure - .input(registerSchema) + .input(signUpSchema) .mutation(async function ({ ctx, input }) { const payload = { ...input, diff --git a/components/Blocks/DynamicContent/SignupFormWrapper/index.tsx b/components/Blocks/DynamicContent/SignupFormWrapper/index.tsx index 4c39dafc5..f69637847 100644 --- a/components/Blocks/DynamicContent/SignupFormWrapper/index.tsx +++ b/components/Blocks/DynamicContent/SignupFormWrapper/index.tsx @@ -3,7 +3,7 @@ import { redirect } from "next/navigation" import { overview } from "@/constants/routes/myPages" import { auth } from "@/auth" -import Form from "@/components/Forms/Register" +import Form from "@/components/Forms/Signup" import { getLang } from "@/i18n/serverContext" import { SignupFormWrapperProps } from "@/types/components/blocks/dynamicContent" diff --git a/components/Forms/Register/form.module.css b/components/Forms/Signup/form.module.css similarity index 100% rename from components/Forms/Register/form.module.css rename to components/Forms/Signup/form.module.css diff --git a/components/Forms/Register/index.tsx b/components/Forms/Signup/index.tsx similarity index 94% rename from components/Forms/Register/index.tsx rename to components/Forms/Signup/index.tsx index a8f3f6524..d616d1e5f 100644 --- a/components/Forms/Register/index.tsx +++ b/components/Forms/Signup/index.tsx @@ -1,6 +1,7 @@ "use client" import { zodResolver } from "@hookform/resolvers/zod" +import { useEffect,useState } from "react" import { FormProvider, useForm } from "react-hook-form" import { useIntl } from "react-intl" @@ -22,16 +23,16 @@ import Title from "@/components/TempDesignSystem/Text/Title" import { toast } from "@/components/TempDesignSystem/Toasts" import useLang from "@/hooks/useLang" -import { RegisterSchema, registerSchema } from "./schema" +import { SignUpSchema, signUpSchema } from "./schema" import styles from "./form.module.css" -import type { RegisterFormProps } from "@/types/components/form/registerForm" +import type { SignUpFormProps } from "@/types/components/form/signupForm" -export default function Form({ link, subtitle, title }: RegisterFormProps) { +export default function Form({ link, subtitle, title }: SignUpFormProps) { const intl = useIntl() const lang = useLang() - const methods = useForm({ + const methods = useForm({ defaultValues: { firstName: "", lastName: "", @@ -47,7 +48,7 @@ export default function Form({ link, subtitle, title }: RegisterFormProps) { }, mode: "all", criteriaMode: "all", - resolver: zodResolver(registerSchema), + resolver: zodResolver(signUpSchema), reValidateMode: "onChange", }) const country = intl.formatMessage({ id: "Country" }) @@ -55,7 +56,7 @@ export default function Form({ link, subtitle, title }: RegisterFormProps) { const phoneNumber = intl.formatMessage({ id: "Phone number" }) const zipCode = intl.formatMessage({ id: "Zip code" }) - async function handleSubmit(data: RegisterSchema) { + async function handleSubmit(data: SignUpSchema) { try { const result = await registerUser(data) if (result && !result.success) { diff --git a/components/Forms/Register/schema.ts b/components/Forms/Signup/schema.ts similarity index 67% rename from components/Forms/Register/schema.ts rename to components/Forms/Signup/schema.ts index 2584a02fe..6a8eecc22 100644 --- a/components/Forms/Register/schema.ts +++ b/components/Forms/Signup/schema.ts @@ -4,19 +4,13 @@ import { passwordValidator } from "@/utils/passwordValidator" import { phoneValidator } from "@/utils/phoneValidator" const countryRequiredMsg = "Country is required" -export const registerSchema = z.object({ - firstName: z - .string() - .max(250) - .refine((value) => value.trim().length > 0, { - message: "First name is required", - }), - lastName: z - .string() - .max(250) - .refine((value) => value.trim().length > 0, { - message: "Last name is required", - }), +export const signUpSchema = z.object({ + firstName: z.string().max(250).trim().min(1, { + message: "First name is required", + }), + lastName: z.string().max(250).trim().min(1, { + message: "Last name is required", + }), email: z.string().max(250).email(), phoneNumber: phoneValidator( "Phone is required", @@ -38,4 +32,4 @@ export const registerSchema = z.object({ }), }) -export type RegisterSchema = z.infer +export type SignUpSchema = z.infer diff --git a/types/components/form/registerForm.ts b/types/components/form/signupForm.ts similarity index 69% rename from types/components/form/registerForm.ts rename to types/components/form/signupForm.ts index 41e783dd5..060c8d860 100644 --- a/types/components/form/registerForm.ts +++ b/types/components/form/signupForm.ts @@ -1,4 +1,4 @@ -export type RegisterFormProps = { +export type SignUpFormProps = { link?: { href: string; text: string } subtitle?: string title: string