/** * Copyright (c) 2023-present Plane Software, Inc. and contributors * SPDX-License-Identifier: AGPL-3.0-only * See the LICENSE file for details. */ import type { FormEvent } from "react"; import { useMemo, useRef, useState } from "react"; import { observer } from "mobx-react"; // icons import { CircleAlert, XCircle } from "lucide-react"; // types import { Button } from "@plane/propel/button"; import type { IEmailCheckData } from "@plane/types"; // ui import { Input, Spinner } from "@plane/ui"; // helpers import { cn } from "@plane/utils"; import { checkEmailValidity } from "@/helpers/string.helper"; type TAuthEmailForm = { defaultEmail: string; onSubmit: (data: IEmailCheckData) => Promise; }; export const AuthEmailForm = observer(function AuthEmailForm(props: TAuthEmailForm) { const { onSubmit, defaultEmail } = props; // states const [isSubmitting, setIsSubmitting] = useState(false); const [email, setEmail] = useState(defaultEmail); 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; const [isFocused, setIsFocused] = useState(true); const inputRef = useRef(null); return (
{ setIsFocused(true); }} onBlur={() => { setIsFocused(false); }} > setEmail(e.target.value)} placeholder="name@company.com" className={`h-10 w-full border-0 disable-autofill-style placeholder:text-placeholder autofill:bg-danger-subtle focus:bg-none active:bg-transparent`} autoComplete="off" autoFocus ref={inputRef} /> {email.length > 0 && ( )}
{emailError?.email && !isFocused && (

{emailError.email}

)}
); });