import { FC, FormEvent, useMemo, useState } from "react"; import { observer } from "mobx-react-lite"; // icons import { CircleAlert, XCircle } from "lucide-react"; // types import { IEmailCheckData } from "@plane/types"; // ui import { Button, Input, Spinner } from "@plane/ui"; // helpers import { cn } from "@/helpers/common.helper"; import { checkEmailValidity } from "@/helpers/string.helper"; type TAuthEmailForm = { defaultEmail: string; onSubmit: (data: IEmailCheckData) => Promise; }; export const AuthEmailForm: FC = observer((props) => { const { onSubmit, defaultEmail } = props; // states const [isSubmitting, setIsSubmitting] = useState(false); const [email, setEmail] = useState(defaultEmail); const [isFocused, setFocused] = useState(false); const emailError = useMemo( () => (email && !checkEmailValidity(email) ? { email: "Email is invalid" } : undefined), [email] ); const handleFormSubmit = async (event: FormEvent) => { event.preventDefault(); setIsSubmitting(true); const payload: IEmailCheckData = { email: email, }; await onSubmit(payload); setIsSubmitting(false); }; const isButtonDisabled = email.length === 0 || Boolean(emailError?.email) || isSubmitting; return (
setEmail(e.target.value)} placeholder="name@example.com" className={`disable-autofill-style h-[46px] w-full placeholder:text-onboarding-text-400 autofill:bg-red-500 border-0 focus:bg-none active:bg-transparent`} onFocus={() => setFocused(true)} onBlur={() => setFocused(false)} autoFocus /> {email.length > 0 && (
setEmail("")} />
)}
{emailError?.email && !isFocused && (

{emailError.email}

)}
); });