From fbcb575a363a9af00c89bf35bd5c673c24d9d540 Mon Sep 17 00:00:00 2001 From: Rafi Arrafif Date: Thu, 16 Oct 2025 00:28:20 +0700 Subject: [PATCH] :construction: (wip) create form provider --- features/auth/models/registerForm.schema.ts | 2 +- features/auth/ui/cards/Signup.tsx | 4 +- features/auth/ui/components/FullNameInput.tsx | 38 ------------------- .../auth/ui/components/provision/main.tsx | 33 +++++++++++++++- .../auth/ui/components/provision/step1.tsx | 38 +++++++++++++++++-- 5 files changed, 69 insertions(+), 46 deletions(-) delete mode 100644 features/auth/ui/components/FullNameInput.tsx diff --git a/features/auth/models/registerForm.schema.ts b/features/auth/models/registerForm.schema.ts index 8061864..f68cb5d 100644 --- a/features/auth/models/registerForm.schema.ts +++ b/features/auth/models/registerForm.schema.ts @@ -2,7 +2,7 @@ import { z } from "zod"; export const registerFormSchema = z .object({ - fullname: z.string().min(1, "Full name is required"), + fullname: z.string().min(4, "Full name must be at least 4 characters long"), email: z.email("Invalid email address"), password: z .string() diff --git a/features/auth/ui/cards/Signup.tsx b/features/auth/ui/cards/Signup.tsx index 7cf8566..378ce56 100644 --- a/features/auth/ui/cards/Signup.tsx +++ b/features/auth/ui/cards/Signup.tsx @@ -4,7 +4,7 @@ import React from "react"; import { Divider, Link } from "@heroui/react"; import { routes } from "@/shared/config/routes"; import OAuthProviders from "../components/OAuthProviders"; -import FullNameInput from "../components/FullNameInput"; +import ProvisionRegister from "../components/provision/main"; type Props = { changeCurrentPage: React.Dispatch>; @@ -17,7 +17,7 @@ const Signup = ({ changeCurrentPage }: Props) => { {/* Email form */}
- +
{/* Sign up link */} diff --git a/features/auth/ui/components/FullNameInput.tsx b/features/auth/ui/components/FullNameInput.tsx deleted file mode 100644 index 048336e..0000000 --- a/features/auth/ui/components/FullNameInput.tsx +++ /dev/null @@ -1,38 +0,0 @@ -"use client"; - -import React, { useState } from "react"; -import { Button, Input } from "@heroui/react"; -import Provision from "../cards/Provision"; - -type Props = { - changeCurrentPage: React.Dispatch>; -}; - -const FullNameInput = ({ changeCurrentPage }: Props) => { - const [fullName, setFullName] = useState(""); - - return ( - <> - setFullName(e.target.value)} - classNames={{ - input: "text-md font-light pt-4", - inputWrapper: "flex gap-10", - }} - /> - - - ); -}; - -export default FullNameInput; diff --git a/features/auth/ui/components/provision/main.tsx b/features/auth/ui/components/provision/main.tsx index cbd2541..d7d5f1e 100644 --- a/features/auth/ui/components/provision/main.tsx +++ b/features/auth/ui/components/provision/main.tsx @@ -1,5 +1,12 @@ +"use client"; + import React, { JSX, useState } from "react"; import Step1ProvisionRegister from "./step1"; +import { Form } from "@heroui/react"; +import { FormProvider, SubmitHandler, useForm } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { registerFormSchema } from "@/features/auth/models/registerForm.schema"; +import Step2ProvisionRegister from "./step2"; export type RegisterInputs = { fullname: string; @@ -9,10 +16,32 @@ export type RegisterInputs = { }; const ProvisionRegister = () => { + const formMethods = useForm({ + resolver: zodResolver(registerFormSchema), + }); + + const { handleSubmit } = formMethods; + + const sendProvisionData: SubmitHandler = (data) => {}; + + const NextToStep2 = () => { + setCurrentComponent(); + }; + const [currentComponent, setCurrentComponent] = useState( - + + ); + + return ( + +
+ {currentComponent} +
+
); - return
ProvisionRegister
; }; export default ProvisionRegister; diff --git a/features/auth/ui/components/provision/step1.tsx b/features/auth/ui/components/provision/step1.tsx index 5d9f6ef..9e86213 100644 --- a/features/auth/ui/components/provision/step1.tsx +++ b/features/auth/ui/components/provision/step1.tsx @@ -1,7 +1,39 @@ -import React from "react"; +"use client"; -const Step1ProvisionRegister = () => { - return
Step1ProvisionRegister
; +import { Button, Input } from "@heroui/react"; +import React from "react"; +import { useFormContext } from "react-hook-form"; + +const Step1ProvisionRegister = ({ NextStep }: { NextStep: () => void }) => { + const { + register, + formState: { errors }, + } = useFormContext(); + return ( +
+ + +
+ ); }; export default Step1ProvisionRegister;