complete forgot password and fix bug
This commit is contained in:
@@ -9,7 +9,7 @@ type Props = {
|
|||||||
export const ErrorComponent: FC<Props> = ({ message, show }) => {
|
export const ErrorComponent: FC<Props> = ({ message, show }) => {
|
||||||
return (
|
return (
|
||||||
show && (
|
show && (
|
||||||
<p className="w-full text-right text-xs text-red-500 font-medium -mt-5">
|
<p className="w-full text-right text-xs text-red-500 font-medium mt-2">
|
||||||
* {message}
|
* {message}
|
||||||
</p>
|
</p>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,9 +1,23 @@
|
|||||||
import { Link } from "react-router-dom"
|
import { Link } from "react-router-dom"
|
||||||
import { Input } from "../common/input"
|
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 = () => {
|
export const ForgotPasswordForm = () => {
|
||||||
|
const {
|
||||||
|
handleSubmit,
|
||||||
|
formState: { errors },
|
||||||
|
control
|
||||||
|
} = useForm<ForgotPasswordInterface>({
|
||||||
|
resolver: yupResolver(forgotPasswordSchema)
|
||||||
|
})
|
||||||
|
const handleForgotSubmit: SubmitHandler<ForgotPasswordInterface> = async (data) => { console.log("data=>", data) }
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<form onSubmit={handleSubmit(handleForgotSubmit)}
|
||||||
className="w-fit xl:w-1/2 xl:p-0 p-10 flex flex-col bg-auth-form justify-center items-center gap-y-[42px] rounded-3xl">
|
className="w-fit xl:w-1/2 xl:p-0 p-10 flex flex-col bg-auth-form justify-center items-center gap-y-[42px] rounded-3xl">
|
||||||
<img src="/svgs/logo/logo.svg" alt="logo" className="auth-logo-size" />
|
<img src="/svgs/logo/logo.svg" alt="logo" className="auth-logo-size" />
|
||||||
<div className="flex flex-col xl:-mr-24">
|
<div className="flex flex-col xl:-mr-24">
|
||||||
@@ -14,7 +28,12 @@ export const ForgotPasswordForm = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-9 mb-[42px]">
|
<div className="mt-9 mb-[42px]">
|
||||||
<Input type="number" placeholder="شماره موبایل" />
|
<Controller control={control} name="phoneNumber" render={({ field }) => (
|
||||||
|
<div>
|
||||||
|
<Input type="number" placeholder="شماره موبایل" field={field} />
|
||||||
|
<ErrorComponent show={errors.phoneNumber} message={errors?.phoneNumber?.message} />
|
||||||
|
</div>
|
||||||
|
)} />
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-y-[27px] items-center">
|
<div className="flex flex-col gap-y-[27px] items-center">
|
||||||
<button>دریافت کد تایید</button>
|
<button>دریافت کد تایید</button>
|
||||||
@@ -23,6 +42,6 @@ export const ForgotPasswordForm = () => {
|
|||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -34,16 +34,16 @@ export const LoginForm = () => {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-y-[25px] mt-9 mb-[42px]">
|
<div className="flex flex-col gap-y-[25px] mt-9 mb-[42px]">
|
||||||
<Controller control={control} name="phoneNumber" render={({ field }) => (
|
<Controller control={control} name="phoneNumber" render={({ field }) => (
|
||||||
<>
|
<div>
|
||||||
<Input type="number" placeholder="شماره تماس" field={field} />
|
<Input type="number" placeholder="شماره تماس" field={field} />
|
||||||
<ErrorComponent show={errors.phoneNumber} message={errors.phoneNumber?.message} />
|
<ErrorComponent show={errors.phoneNumber} message={errors.phoneNumber?.message} />
|
||||||
</>
|
</div>
|
||||||
)} />
|
)} />
|
||||||
<Controller control={control} name="password" render={({ field }) => (
|
<Controller control={control} name="password" render={({ field }) => (
|
||||||
<>
|
<div>
|
||||||
<Input type="password" placeholder="رمز عبور" field={field} />
|
<Input type="password" placeholder="رمز عبور" field={field} />
|
||||||
<ErrorComponent show={errors.password} message={errors.password?.message} />
|
<ErrorComponent show={errors.password} message={errors.password?.message} />
|
||||||
</>
|
</div>
|
||||||
)} />
|
)} />
|
||||||
<Link to="/auth/forgot-password"><p className="font-medium text-sm text-secondary-text-color cursor-pointer">فراموشی رمز عبور</p></Link>
|
<Link to="/auth/forgot-password"><p className="font-medium text-sm text-secondary-text-color cursor-pointer">فراموشی رمز عبور</p></Link>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -34,14 +34,14 @@ export const ResetPasswordForm = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-y-[25px] mt-9 mb-[42px]">
|
<div className="flex flex-col gap-y-[25px] mt-9 mb-[42px]">
|
||||||
<Controller control={control} name="password" render={({ field }) => (<>
|
<Controller control={control} name="password" render={({ field }) => (<div>
|
||||||
<Input type="password" placeholder="رمز عبور" field={field} />
|
<Input type="password" placeholder="رمز عبور" field={field} />
|
||||||
<ErrorComponent show={errors.password} message={errors.password?.message} />
|
<ErrorComponent show={errors.password} message={errors.password?.message} />
|
||||||
</>)} />
|
</div>)} />
|
||||||
<Controller control={control} name="repeatPassword" render={({ field }) => (<>
|
<Controller control={control} name="repeatPassword" render={({ field }) => (<div>
|
||||||
<Input type="password" placeholder="تکرار رمز عبور" field={field} />
|
<Input type="password" placeholder="تکرار رمز عبور" field={field} />
|
||||||
<ErrorComponent show={errors.repeatPassword} message={errors.repeatPassword?.message} />
|
<ErrorComponent show={errors.repeatPassword} message={errors.repeatPassword?.message} />
|
||||||
</>)} />
|
</div>)} />
|
||||||
</div>
|
</div>
|
||||||
<Button type="submit">ذخیره</Button>
|
<Button type="submit">ذخیره</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -16,4 +16,12 @@ export const resetPasswordSchema = yup.object({
|
|||||||
repeatPassword: yup.string()
|
repeatPassword: yup.string()
|
||||||
.oneOf([yup.ref('password')], "رمز عبور و تکرار آن باید یکسان باشند")
|
.oneOf([yup.ref('password')], "رمز عبور و تکرار آن باید یکسان باشند")
|
||||||
.required("تکرار رمز عبور الزامی است"),
|
.required("تکرار رمز عبور الزامی است"),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const forgotPasswordSchema = yup.object({
|
||||||
|
phoneNumber: yup.string()
|
||||||
|
.required("وارد کردن شماره تماس الزامی میباشد")
|
||||||
|
.min(11, "شماره تماس نمیتوند کمتر از 11 رقم باشد")
|
||||||
|
.max(11, "شماره تماس نمیتواند بیشتر از 11 رقم باشد")
|
||||||
|
.matches(/^[0-9]{11}$/, "شماره تماس نامعتبر"),
|
||||||
})
|
})
|
||||||
@@ -6,4 +6,8 @@ export interface LoginFormInterface {
|
|||||||
export interface ResetPasswordInterface {
|
export interface ResetPasswordInterface {
|
||||||
password: string,
|
password: string,
|
||||||
repeatPassword: string
|
repeatPassword: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ForgotPasswordInterface {
|
||||||
|
phoneNumber: string
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user