import { FC, useState } from "react"; import { Controller, useForm } from "react-hook-form"; // ui import { Eye, EyeOff } from "lucide-react"; import { IFormattedInstanceConfiguration } from "@plane/types"; import { Button, Input, ToggleSwitch, TOAST_TYPE, setToast } from "@plane/ui"; // types import { useApplication } from "@/hooks/store"; // hooks export interface IInstanceEmailForm { config: IFormattedInstanceConfiguration; } export interface EmailFormValues { EMAIL_HOST: string; EMAIL_PORT: string; EMAIL_HOST_USER: string; EMAIL_HOST_PASSWORD: string; EMAIL_USE_TLS: string; EMAIL_USE_SSL: string; EMAIL_FROM: string; } export const InstanceEmailForm: FC = (props) => { const { config } = props; // states const [showPassword, setShowPassword] = useState(false); // store hooks const { instance: instanceStore } = useApplication(); // form data const { handleSubmit, watch, control, formState: { errors, isSubmitting }, } = useForm({ defaultValues: { EMAIL_HOST: config["EMAIL_HOST"], EMAIL_PORT: config["EMAIL_PORT"], EMAIL_HOST_USER: config["EMAIL_HOST_USER"], EMAIL_HOST_PASSWORD: config["EMAIL_HOST_PASSWORD"], EMAIL_USE_TLS: config["EMAIL_USE_TLS"], EMAIL_USE_SSL: config["EMAIL_USE_SSL"], EMAIL_FROM: config["EMAIL_FROM"], }, }); const onSubmit = async (formData: EmailFormValues) => { const payload: Partial = { ...formData }; await instanceStore .updateInstanceConfigurations(payload) .then(() => setToast({ title: "Success!", type: TOAST_TYPE.SUCCESS, message: "Email Settings updated successfully", }) ) .catch((err) => console.error(err)); }; return ( <>

Host

( )} />

Port

( )} />

Username

( )} />

Password

( )} /> {showPassword ? ( ) : ( )}

From address

( )} />

This is the email address your users will see when getting emails from this instance. You will need to verify this address.

Turn TLS {Boolean(parseInt(watch("EMAIL_USE_TLS"))) ? "off" : "on"}
Use this if your email domain supports TLS.
( { Boolean(parseInt(value)) === true ? onChange("0") : onChange("1"); }} size="sm" /> )} />
Turn SSL {Boolean(parseInt(watch("EMAIL_USE_SSL"))) ? "off" : "on"}
Most email domains support SSL. Use this to secure comms between this instance and your users.
( { Boolean(parseInt(value)) === true ? onChange("0") : onChange("1"); }} size="sm" /> )} />
); };