import React from "react"; import { observer } from "mobx-react-lite"; import { Controller, useForm } from "react-hook-form"; // icons import { CircleAlert, XCircle } from "lucide-react"; // types import { IEmailCheckData } from "@plane/types"; // ui import { Button, Input } from "@plane/ui"; // helpers import { checkEmailValidity } from "@/helpers/string.helper"; type Props = { onSubmit: (data: IEmailCheckData) => Promise; defaultEmail: string; }; type TEmailFormValues = { email: string; }; export const AuthEmailForm: React.FC = observer((props) => { const { onSubmit, defaultEmail } = props; // hooks const { control, formState: { errors, isSubmitting, isValid }, handleSubmit, } = useForm({ defaultValues: { email: defaultEmail, }, mode: "onChange", reValidateMode: "onChange", }); const handleFormSubmit = async (data: TEmailFormValues) => { const payload: IEmailCheckData = { email: data.email, }; onSubmit(payload); }; return (
checkEmailValidity(value) || "Email is invalid", }} render={({ field: { value, onChange } }) => ( <>
{value.length > 0 && ( onChange("")} /> )}
{errors.email && (

{errors.email.message}

)} )} />
); });