import React from "react"; // next import Link from "next/link"; import { useRouter } from "next/router"; // react hook form import { useForm } from "react-hook-form"; // ui import { Button, Input } from "ui"; import authenticationService from "lib/services/authentication.service"; // types type SignIn = { email: string; password?: string; medium?: string; }; const EmailPasswordForm = ({ onSuccess }: any) => { const { register, handleSubmit, setError, setValue, getValues, formState: { errors, isSubmitting, dirtyFields, isValid, isDirty }, } = useForm({ defaultValues: { email: "", password: "", medium: "email", }, mode: "onChange", reValidateMode: "onChange", }); const onSubmit = (formData: SignIn) => { authenticationService .emailLogin(formData) .then(async (response) => { await onSuccess(response); }) .catch((error) => { console.log(error); if (!error?.response?.data) return; Object.keys(error.response.data).forEach((key) => { const err = error.response.data[key]; console.log("err", err); setError(key as keyof SignIn, { type: "manual", message: Array.isArray(err) ? err.join(", ") : err, }); }); }); }; return ( <>
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test( value ) || "Email ID is not valid", }} error={errors.email} placeholder="Enter your Email ID" />
Forgot your password?
); }; export default EmailPasswordForm;