import React, { useEffect } from "react"; import Link from "next/link"; import { Controller, useForm } from "react-hook-form"; import { XCircle } from "lucide-react"; // services import { AuthService } from "services/authentication.service"; // hooks import useToast from "hooks/use-toast"; // ui import { Button, Input } from "@plane/ui"; // helpers import { checkEmailValidity } from "helpers/string.helper"; // types import { IPasswordSignInData } from "types/auth"; type Props = { email: string; updateEmail: (email: string) => void; handleSignInRedirection: () => Promise; }; type TPasswordFormValues = { email: string; password: string; }; const defaultValues: TPasswordFormValues = { email: "", password: "", }; const authService = new AuthService(); export const SelfHostedSignInForm: React.FC = (props) => { const { email, updateEmail, handleSignInRedirection } = props; // toast alert const { setToastAlert } = useToast(); // form info const { control, formState: { dirtyFields, errors, isSubmitting }, handleSubmit, setFocus, } = useForm({ defaultValues: { ...defaultValues, email, }, mode: "onChange", reValidateMode: "onChange", }); const handleFormSubmit = async (formData: TPasswordFormValues) => { const payload: IPasswordSignInData = { email: formData.email, password: formData.password, }; updateEmail(formData.email); await authService .passwordSignIn(payload) .then(async () => await handleSignInRedirection()) .catch((err) => setToastAlert({ type: "error", title: "Error!", message: err?.error ?? "Something went wrong. Please try again.", }) ); }; useEffect(() => { setFocus("email"); }, [setFocus]); return ( <>

Get on your flight deck

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

When you click the button above, you agree with our{" "} terms and conditions of service.

); };