From ea2a96cff51f2d229dae35d65f0335b17d069009 Mon Sep 17 00:00:00 2001 From: Alihaghighattalab Date: Mon, 5 Aug 2024 18:40:53 +0330 Subject: [PATCH] Completing the functionalization of the reset password code page --- .../forms/reset-password-code-form.tsx | 40 +++++++++++++------ src/components/forms/send-code-form.tsx | 40 +++++++++++++------ src/schema/index.ts | 16 ++++++++ src/types/index.ts | 7 ++++ 4 files changed, 77 insertions(+), 26 deletions(-) diff --git a/src/components/forms/reset-password-code-form.tsx b/src/components/forms/reset-password-code-form.tsx index 064f12f..4a3d6d0 100644 --- a/src/components/forms/reset-password-code-form.tsx +++ b/src/components/forms/reset-password-code-form.tsx @@ -1,11 +1,21 @@ -import { useState } from "react"; +import { Button } from "@headlessui/react"; +import { Controller, SubmitHandler, useForm } from "react-hook-form"; import OTPInput from "react-otp-input" import { Link } from "react-router-dom" +import { ResetPasswordCodeInterface } from "../../types"; +import { yupResolver } from "@hookform/resolvers/yup"; +import { ResetPasswordCodeSchema } from "../../schema"; +import { ErrorComponent } from "../common/error"; export const ResetpasswordCodeForm = () => { - const [otp, setOtp] = useState(''); + const { handleSubmit, formState: { errors }, control } = useForm({ + resolver: yupResolver(ResetPasswordCodeSchema) + }) + const submitCode: SubmitHandler = async (data) => { + console.log("data=>", data) + } return ( -
logo
@@ -21,22 +31,26 @@ export const ResetpasswordCodeForm = () => {
- } - inputStyle="otp-inputs" - /> + ( +
+ } + inputStyle="otp-inputs" + /> + +
+ )} />

30 ثانیه دیگر تا دریافت کد

- +

ارسال مجدد

- + ) } \ No newline at end of file diff --git a/src/components/forms/send-code-form.tsx b/src/components/forms/send-code-form.tsx index 2e503a9..5cf7c67 100644 --- a/src/components/forms/send-code-form.tsx +++ b/src/components/forms/send-code-form.tsx @@ -1,11 +1,21 @@ -import { useState } from "react"; import OTPInput from "react-otp-input" import { Link } from "react-router-dom" +import { ErrorComponent } from "../common/error" +import { Controller, SubmitHandler, useForm } from "react-hook-form" +import { Button } from "@headlessui/react" +import { LoginCodeInterface } from "../../types" +import { yupResolver } from "@hookform/resolvers/yup" +import { LoginCodeSchema } from "../../schema" export const SendCodeForm = () => { - const [otp, setOtp] = useState(''); + const { handleSubmit, formState: { errors }, control } = useForm({ + resolver: yupResolver(LoginCodeSchema) + }) + const submitCode: SubmitHandler = async (data) => { + console.log("data=>", data) + } return ( -
logo
@@ -21,22 +31,26 @@ export const SendCodeForm = () => {
- } - inputStyle="otp-inputs" - /> + ( +
+ } + inputStyle="otp-inputs" + /> + +
+ )} />

30 ثانیه دیگر تا دریافت کد

- +

ارسال مجدد

- + ) } \ No newline at end of file diff --git a/src/schema/index.ts b/src/schema/index.ts index ea3356d..7a51858 100644 --- a/src/schema/index.ts +++ b/src/schema/index.ts @@ -32,4 +32,20 @@ export const LoginWithCodeSchema = yup.object({ .min(11, "شماره تماس نمیتوند کمتر از 11 رقم باشد") .max(11, "شماره تماس نمیتواند بیشتر از 11 رقم باشد") .matches(/^[0-9]{11}$/, "شماره تماس نامعتبر"), +}) + +export const ResetPasswordCodeSchema = yup.object({ + code: yup.string() + .required("وارد کردن کد الزامی میباشد") + .min(5, "کد نمیتوند کمتر از 5 رقم باشد") + .max(5, "کد نمیتواند بیشتر از 5 رقم باشد") + .matches(/^[0-9]{5}$/, "کد نامعتبر"), +}) + +export const LoginCodeSchema = yup.object({ + code: yup.string() + .required("وارد کردن کد الزامی میباشد") + .min(5, "کد نمیتوند کمتر از 5 رقم باشد") + .max(5, " کد نمیتواند بیشتر از 5 رقم باشد") + .matches(/^[0-9]{5}$/, "کد نامعتبر"), }) \ No newline at end of file diff --git a/src/types/index.ts b/src/types/index.ts index c8fa616..d2bad1a 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -15,4 +15,11 @@ export interface ForgotPasswordInterface { export interface LoginWithCodeInterface { phoneNumber: string } +export interface ResetPasswordCodeInterface { + code: string +} + +export interface LoginCodeInterface { + code: string +}