From d7b66b11a0ab03c0c3bf0e305ac5fe0101eceb7a Mon Sep 17 00:00:00 2001 From: Alihaghighattalab Date: Mon, 5 Aug 2024 19:58:03 +0330 Subject: [PATCH] complete register form --- src/components/common/combo-box.tsx | 15 +++++-- src/components/forms/register-form.tsx | 58 +++++++++++++++++++++----- src/schema/index.ts | 17 ++++++++ src/types/index.ts | 11 +++++ 4 files changed, 86 insertions(+), 15 deletions(-) diff --git a/src/components/common/combo-box.tsx b/src/components/common/combo-box.tsx index 5ac9f1a..f385459 100644 --- a/src/components/common/combo-box.tsx +++ b/src/components/common/combo-box.tsx @@ -1,6 +1,6 @@ import { Combobox, ComboboxButton, ComboboxInput, ComboboxOption, ComboboxOptions } from '@headlessui/react' import { ArrowDown2 } from 'iconsax-react' -import { useState } from 'react' +import { FC, useState } from 'react' const value = [ { id: 1, name: 'تهران' }, @@ -10,9 +10,13 @@ const value = [ { id: 5, name: 'تبریز' }, ] -export const ComboBox = () => { +type Props = { + field?: any +} + +export const ComboBox: FC = ({ field }) => { const [query, setQuery] = useState('') - const [selected, setSelected] = useState(value[1]) + // const [selected, setSelected] = useState(value[1]) const filteredValue = query === '' @@ -22,12 +26,15 @@ export const ComboBox = () => { }) return ( - setSelected(value)} onClose={() => setQuery('')}> + setQuery('')}>
person?.name} onChange={(event) => setQuery(event.target.value)} + ref={field.ref} + name={field.name} + onBlur={field.onBlur} /> diff --git a/src/components/forms/register-form.tsx b/src/components/forms/register-form.tsx index d092205..54de7a3 100644 --- a/src/components/forms/register-form.tsx +++ b/src/components/forms/register-form.tsx @@ -1,10 +1,22 @@ import { Link } from "react-router-dom" import { ComboBox } from "../common/combo-box" import { Input } from "../common/input" +import { Button } from "@headlessui/react" +import { Controller, SubmitHandler, useForm } from "react-hook-form" +import { RegisterInterface } from "../../types" +import { yupResolver } from "@hookform/resolvers/yup" +import { RegisterSchema } from "../../schema" +import { ErrorComponent } from "../common/error" export const RegisterForm = () => { + const { handleSubmit, formState: { errors }, control } = useForm({ + resolver: yupResolver(RegisterSchema) + }) + const handleRegister: SubmitHandler = async (data) => { + console.log("data=>", data) + } return ( -
logo
@@ -19,20 +31,44 @@ export const RegisterForm = () => {
- - +
+ + +
} /> +
+ + +
} />
- - +
+ + +
} /> +
+ + +
} />
- - - - + (
+ + +
)} /> +
+ + +
} /> +
+ + +
} /> +
+ + +
} />
- +
-
+ ) } \ No newline at end of file diff --git a/src/schema/index.ts b/src/schema/index.ts index 7a51858..a563cf3 100644 --- a/src/schema/index.ts +++ b/src/schema/index.ts @@ -48,4 +48,21 @@ export const LoginCodeSchema = yup.object({ .min(5, "کد نمیتوند کمتر از 5 رقم باشد") .max(5, " کد نمیتواند بیشتر از 5 رقم باشد") .matches(/^[0-9]{5}$/, "کد نامعتبر"), +}) + +export const RegisterSchema = yup.object({ + name: yup.string().required("وارد کردن نام الزامی میباشد").min(3, "نام نمیتواند کمتر از 3 کاراکتر باشد").max(20, "نام نمیتواند بیشتر از 20 کاراکتر باشد"), + family: yup.string().required("وارد کردن نام خانوادگی الزامی میباشد").min(3, "نام خانوادگی نمیتواند کمتر از 3 کاراکتر باشد").max(25, "نام خانوادگی نمیتواند بیشتر از 25 کاراکتر باشد"), + city: yup.object().required("وارد کردن شهر الزامی مباشد"), + capCity: yup.object().required("وارد کردن استان الزامی مباشد"), + marketName: yup.string().required("وارد کردن نام فروشگاه الزامی میباشد").min(2, "نام فروشگاه نمیتواند کمتر از 3 کاراکتر باشد").max(30, "نام فروشگاه نمیتواند بیشتر از 30 کاراکتر باشد"), + phoneNumber: yup.string() + .required("وارد کردن شماره تماس الزامی میباشد") + .min(11, "شماره تماس نمیتوند کمتر از 11 رقم باشد") + .max(11, "شماره تماس نمیتواند بیشتر از 11 رقم باشد") + .matches(/^[0-9]{11}$/, "شماره تماس نامعتبر"), + password: yup.string().min(8, "رمز عبور نمیتواند کمتر از 8 کاراکتر باشد").required("رمز عبور الزامی است"), + repeatPassword: yup.string() + .oneOf([yup.ref('password')], "رمز عبور و تکرار آن باید یکسان باشند") + .required("تکرار رمز عبور الزامی است"), }) \ No newline at end of file diff --git a/src/types/index.ts b/src/types/index.ts index d2bad1a..969e353 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -23,3 +23,14 @@ export interface LoginCodeInterface { code: string } +export interface RegisterInterface { + name: string, + family: string, + city: object, + capCity: object, + marketName: string, + phoneNumber: string, + password: string, + repeatPassword: string, +} +