import React, { useState } from "react"; import { useRouter } from "next/router"; import Link from "next/link"; // react hook form import { useForm } from "react-hook-form"; // components import { EmailResetPasswordForm } from "components/account"; // ui import { Input, SecondaryButton } from "components/ui"; // types type EmailPasswordFormValues = { email: string; password?: string; medium?: string; }; type Props = { onSubmit: (formData: EmailPasswordFormValues) => Promise; }; export const EmailPasswordForm: React.FC = ({ onSubmit }) => { const [isResettingPassword, setIsResettingPassword] = useState(false); const router = useRouter(); const isSignUpPage = router.pathname === "/sign-up"; const { register, handleSubmit, formState: { errors, isSubmitting, isValid, isDirty }, } = useForm({ defaultValues: { email: "", password: "", medium: "email", }, mode: "onChange", reValidateMode: "onChange", }); return ( <> {isResettingPassword ? ( ) : (
/^(([^<>()[\]\\.,;:\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" />
{isSignUpPage ? ( Already have an account? Sign in. ) : ( )}
{isSignUpPage ? isSubmitting ? "Signing up..." : "Sign Up" : isSubmitting ? "Signing in..." : "Sign In"} {!isSignUpPage && ( Don{"'"}t have an account? Sign up. )}
)} ); };