import React, { FC, useEffect, useState } from "react"; import { Dialog, Transition } from "@headlessui/react"; // ui import { Button, Input } from "@plane/ui"; // services import { InstanceService } from "services/instance.service"; type Props = { isOpen: boolean; handleClose: () => void; }; enum ESendEmailSteps { SEND_EMAIL = "SEND_EMAIL", SUCCESS = "SUCCESS", FAILED = "FAILED", } const instanceService = new InstanceService(); export const SendTestEmailModal: FC = (props) => { const { isOpen, handleClose } = props; // state const [receiverEmail, setReceiverEmail] = useState(""); const [sendEmailStep, setSendEmailStep] = useState(ESendEmailSteps.SEND_EMAIL); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(""); // reset state const resetState = () => { setReceiverEmail(""); setSendEmailStep(ESendEmailSteps.SEND_EMAIL); setIsLoading(false); setError(""); }; useEffect(() => { if (!isOpen) { resetState(); } }, [isOpen]); const handleSubmit = async (e: React.MouseEvent) => { e.preventDefault(); setIsLoading(true); await instanceService .sendTestEmail(receiverEmail) .then(() => { setSendEmailStep(ESendEmailSteps.SUCCESS); }) .catch((error) => { setError(error?.message || "Failed to send email"); setSendEmailStep(ESendEmailSteps.FAILED); }) .finally(() => { setIsLoading(false); }); }; return (

{sendEmailStep === ESendEmailSteps.SEND_EMAIL ? "Send test email" : sendEmailStep === ESendEmailSteps.SUCCESS ? "Email send" : "Failed"}{" "}

{sendEmailStep === ESendEmailSteps.SEND_EMAIL && ( setReceiverEmail(e.target.value)} placeholder="Receiver email" className="w-full resize-none text-lg" tabIndex={1} /> )} {sendEmailStep === ESendEmailSteps.SUCCESS && (

We have sent the test email to {receiverEmail}. Please check your spam folder if you cannot find it.

If you still cannot find it, recheck your SMTP configuration and trigger a new test email.

)} {sendEmailStep === ESendEmailSteps.FAILED &&
{error}
}
{sendEmailStep === ESendEmailSteps.SEND_EMAIL && ( )}
); };