From a4e648363fef9367c771c42a6adb09cb3f0735c3 Mon Sep 17 00:00:00 2001 From: Alihaghighattalab Date: Mon, 5 Aug 2024 18:09:37 +0330 Subject: [PATCH] complete forgot password and fix bug --- src/components/common/error.tsx | 2 +- src/components/forms/forgot-password-form.tsx | 25 ++++++++++++++++--- src/components/forms/login-form.tsx | 8 +++--- src/components/forms/reset-password.form.tsx | 8 +++--- src/schema/index.ts | 8 ++++++ src/types/index.ts | 4 +++ 6 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/components/common/error.tsx b/src/components/common/error.tsx index 46332f7..83785c0 100644 --- a/src/components/common/error.tsx +++ b/src/components/common/error.tsx @@ -9,7 +9,7 @@ type Props = { export const ErrorComponent: FC = ({ message, show }) => { return ( show && ( -

+

* {message}

) diff --git a/src/components/forms/forgot-password-form.tsx b/src/components/forms/forgot-password-form.tsx index b99da40..94600f5 100644 --- a/src/components/forms/forgot-password-form.tsx +++ b/src/components/forms/forgot-password-form.tsx @@ -1,9 +1,23 @@ import { Link } from "react-router-dom" import { Input } from "../common/input" +import { Controller, SubmitHandler, useForm } from "react-hook-form" +import { ForgotPasswordInterface } from "../../types" +import { yupResolver } from "@hookform/resolvers/yup" +import { forgotPasswordSchema } from "../../schema" +import { ErrorComponent } from "../common/error" export const ForgotPasswordForm = () => { + const { + handleSubmit, + formState: { errors }, + control + } = useForm({ + resolver: yupResolver(forgotPasswordSchema) + }) + const handleForgotSubmit: SubmitHandler = async (data) => { console.log("data=>", data) } + return ( -
logo
@@ -14,7 +28,12 @@ export const ForgotPasswordForm = () => {
- + ( +
+ + +
+ )} />
@@ -23,6 +42,6 @@ export const ForgotPasswordForm = () => {
- + ) } \ No newline at end of file diff --git a/src/components/forms/login-form.tsx b/src/components/forms/login-form.tsx index c3678e2..06d29c0 100644 --- a/src/components/forms/login-form.tsx +++ b/src/components/forms/login-form.tsx @@ -34,16 +34,16 @@ export const LoginForm = () => {
( - <> +
- +
)} /> ( - <> +
- +
)} />

فراموشی رمز عبور

diff --git a/src/components/forms/reset-password.form.tsx b/src/components/forms/reset-password.form.tsx index d95b12b..8b30324 100644 --- a/src/components/forms/reset-password.form.tsx +++ b/src/components/forms/reset-password.form.tsx @@ -34,14 +34,14 @@ export const ResetPasswordForm = () => {
- (<> + (
- )} /> - (<> +
)} /> + (
- )} /> +
)} />
diff --git a/src/schema/index.ts b/src/schema/index.ts index a3829aa..c83ff7f 100644 --- a/src/schema/index.ts +++ b/src/schema/index.ts @@ -16,4 +16,12 @@ export const resetPasswordSchema = yup.object({ repeatPassword: yup.string() .oneOf([yup.ref('password')], "رمز عبور و تکرار آن باید یکسان باشند") .required("تکرار رمز عبور الزامی است"), +}) + +export const forgotPasswordSchema = yup.object({ + phoneNumber: yup.string() + .required("وارد کردن شماره تماس الزامی میباشد") + .min(11, "شماره تماس نمیتوند کمتر از 11 رقم باشد") + .max(11, "شماره تماس نمیتواند بیشتر از 11 رقم باشد") + .matches(/^[0-9]{11}$/, "شماره تماس نامعتبر"), }) \ No newline at end of file diff --git a/src/types/index.ts b/src/types/index.ts index d474f42..a3abfc2 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -6,4 +6,8 @@ export interface LoginFormInterface { export interface ResetPasswordInterface { password: string, repeatPassword: string +} + +export interface ForgotPasswordInterface { + phoneNumber: string } \ No newline at end of file