import React, { useState } from "react"; import Link from "next/link"; import { observer } from "mobx-react-lite"; import { Controller, useForm } from "react-hook-form"; import { XCircle } from "lucide-react"; // services import { AuthService } from "services/auth.service"; // hooks import useToast from "hooks/use-toast"; import { useApplication } from "hooks/store"; // components import { ESignInSteps, ForgotPasswordPopover } from "components/account"; // ui import { Button, Input } from "@plane/ui"; // helpers import { checkEmailValidity } from "helpers/string.helper"; // types import { IPasswordSignInData } from "@plane/types"; type Props = { email: string; handleStepChange: (step: ESignInSteps) => void; handleEmailClear: () => void; onSubmit: () => Promise; }; type TPasswordFormValues = { email: string; password: string; }; const defaultValues: TPasswordFormValues = { email: "", password: "", }; const authService = new AuthService(); export const SignInPasswordForm: React.FC = observer((props) => { const { email, handleStepChange, handleEmailClear, onSubmit } = props; // states const [isSendingUniqueCode, setIsSendingUniqueCode] = useState(false); // toast alert const { setToastAlert } = useToast(); const { config: { envConfig }, } = useApplication(); // derived values const isSmtpConfigured = envConfig?.is_smtp_configured; // form info const { control, formState: { errors, isSubmitting, isValid }, getValues, handleSubmit, setError, } = useForm({ defaultValues: { ...defaultValues, email, }, mode: "onChange", reValidateMode: "onChange", }); const handleFormSubmit = async (formData: TPasswordFormValues) => { const payload: IPasswordSignInData = { email: formData.email, password: formData.password, }; await authService .passwordSignIn(payload) .then(async () => await onSubmit()) .catch((err) => setToastAlert({ type: "error", title: "Error!", message: err?.error ?? "Something went wrong. Please try again.", }) ); }; const handleSendUniqueCode = async () => { const emailFormValue = getValues("email"); const isEmailValid = checkEmailValidity(emailFormValue); if (!isEmailValid) { setError("email", { message: "Email is invalid" }); return; } setIsSendingUniqueCode(true); await authService .generateUniqueCode({ email: emailFormValue }) .then(() => handleStepChange(ESignInSteps.USE_UNIQUE_CODE_FROM_PASSWORD)) .catch((err) => setToastAlert({ type: "error", title: "Error!", message: err?.error ?? "Something went wrong. Please try again.", }) ) .finally(() => setIsSendingUniqueCode(false)); }; return ( <>

Welcome back, let{"'"}s get you on board

Get back to your issues, projects and workspaces.

checkEmailValidity(value) || "Email is invalid", }} render={({ field: { value, onChange } }) => (
{value.length > 0 && ( { if (isSmtpConfigured) handleEmailClear(); else onChange(""); }} /> )}
)} />
( )} />
{isSmtpConfigured ? ( Forgot your password? ) : ( )}
{envConfig && envConfig.is_smtp_configured && ( )}
); });