import React from "react"; import { observer } from "mobx-react-lite"; import { Controller, useForm } from "react-hook-form"; import { XCircle } from "lucide-react"; // services import { Button, Input, TOAST_TYPE, setToast } from "@plane/ui"; import { checkEmailValidity } from "helpers/string.helper"; import { AuthService } from "services/auth.service"; // ui // helpers // types import { IEmailCheckData } from "@plane/types"; type Props = { onSubmit: () => void; updateEmail: (email: string) => void; }; type TEmailFormValues = { email: string; }; const authService = new AuthService(); export const SignUpEmailForm: React.FC = observer((props) => { const { onSubmit, updateEmail } = props; // hooks const { control, formState: { errors, isSubmitting, isValid }, handleSubmit, } = useForm({ defaultValues: { email: "", }, mode: "onChange", reValidateMode: "onChange", }); const handleFormSubmit = async (data: TEmailFormValues) => { const payload: IEmailCheckData = { email: data.email, }; // update the global email state updateEmail(data.email); await authService .emailCheck(payload) .then(() => onSubmit()) .catch((err) => setToast({ type: TOAST_TYPE.SUCCESS, title: "Error!", message: err?.error ?? "Something went wrong. Please try again.", }) ); }; return ( <>

Get on your flight deck

Create or join a workspace. Start with your e-mail.

checkEmailValidity(value) || "Email is invalid", }} render={({ field: { value, onChange } }) => (
{value.length > 0 && ( onChange("")} /> )}
)} />
); });