2023-11-27 11:45:11 +00:00
|
|
|
import { FC, useState } from "react";
|
2023-11-20 15:16:49 +00:00
|
|
|
import { Controller, useForm } from "react-hook-form";
|
|
|
|
// ui
|
|
|
|
import { Button, Input, ToggleSwitch } from "@plane/ui";
|
2023-11-27 11:45:11 +00:00
|
|
|
import { Eye, EyeOff } from "lucide-react";
|
2023-11-20 15:16:49 +00:00
|
|
|
// types
|
|
|
|
import { IFormattedInstanceConfiguration } from "types/instance";
|
|
|
|
// hooks
|
|
|
|
import useToast from "hooks/use-toast";
|
|
|
|
// mobx store
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
|
|
|
|
|
|
|
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;
|
2023-12-06 13:59:45 +00:00
|
|
|
// EMAIL_USE_SSL: string;
|
2023-12-18 08:06:09 +00:00
|
|
|
EMAIL_FROM: string;
|
2023-11-20 15:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const InstanceEmailForm: FC<IInstanceEmailForm> = (props) => {
|
|
|
|
const { config } = props;
|
2023-11-27 14:11:47 +00:00
|
|
|
// states
|
2023-11-27 11:45:11 +00:00
|
|
|
const [showPassword, setShowPassword] = useState(false);
|
2023-11-20 15:16:49 +00:00
|
|
|
// store
|
|
|
|
const { instance: instanceStore } = useMobxStore();
|
|
|
|
// toast
|
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
// form data
|
|
|
|
const {
|
|
|
|
handleSubmit,
|
2023-11-25 15:53:50 +00:00
|
|
|
watch,
|
2023-11-20 15:16:49 +00:00
|
|
|
control,
|
|
|
|
formState: { errors, isSubmitting },
|
|
|
|
} = useForm<EmailFormValues>({
|
|
|
|
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"],
|
2023-12-06 13:59:45 +00:00
|
|
|
// EMAIL_USE_SSL: config["EMAIL_USE_SSL"],
|
2023-12-18 08:06:09 +00:00
|
|
|
EMAIL_FROM: config["EMAIL_FROM"],
|
2023-11-20 15:16:49 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const onSubmit = async (formData: EmailFormValues) => {
|
|
|
|
const payload: Partial<EmailFormValues> = { ...formData };
|
|
|
|
|
|
|
|
await instanceStore
|
|
|
|
.updateInstanceConfigurations(payload)
|
|
|
|
.then(() =>
|
|
|
|
setToastAlert({
|
|
|
|
title: "Success",
|
|
|
|
type: "success",
|
|
|
|
message: "Email Settings updated successfully",
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.catch((err) => console.error(err));
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2023-11-25 15:53:50 +00:00
|
|
|
<>
|
2023-12-21 09:07:26 +00:00
|
|
|
<div className="grid-col grid w-full max-w-4xl grid-cols-1 items-center justify-between gap-x-20 gap-y-10 lg:grid-cols-2">
|
2023-11-20 15:16:49 +00:00
|
|
|
<div className="flex flex-col gap-1">
|
|
|
|
<h4 className="text-sm">Host</h4>
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="EMAIL_HOST"
|
|
|
|
render={({ field: { value, onChange, ref } }) => (
|
|
|
|
<Input
|
|
|
|
id="EMAIL_HOST"
|
|
|
|
name="EMAIL_HOST"
|
|
|
|
type="text"
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
|
|
|
ref={ref}
|
|
|
|
hasError={Boolean(errors.EMAIL_HOST)}
|
2023-11-25 15:53:50 +00:00
|
|
|
placeholder="email.google.com"
|
2023-12-10 10:18:10 +00:00
|
|
|
className="w-full rounded-md font-medium"
|
2023-11-20 15:16:49 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1">
|
|
|
|
<h4 className="text-sm">Port</h4>
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="EMAIL_PORT"
|
|
|
|
render={({ field: { value, onChange, ref } }) => (
|
|
|
|
<Input
|
|
|
|
id="EMAIL_PORT"
|
|
|
|
name="EMAIL_PORT"
|
|
|
|
type="text"
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
|
|
|
ref={ref}
|
|
|
|
hasError={Boolean(errors.EMAIL_PORT)}
|
2023-11-25 15:53:50 +00:00
|
|
|
placeholder="8080"
|
2023-12-10 10:18:10 +00:00
|
|
|
className="w-full rounded-md font-medium"
|
2023-11-20 15:16:49 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-12-21 09:07:26 +00:00
|
|
|
<div className="grid-col grid w-full max-w-4xl grid-cols-1 items-center justify-between gap-x-20 gap-y-10 lg:grid-cols-2">
|
2023-11-20 15:16:49 +00:00
|
|
|
<div className="flex flex-col gap-1">
|
|
|
|
<h4 className="text-sm">Username</h4>
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="EMAIL_HOST_USER"
|
|
|
|
render={({ field: { value, onChange, ref } }) => (
|
|
|
|
<Input
|
|
|
|
id="EMAIL_HOST_USER"
|
|
|
|
name="EMAIL_HOST_USER"
|
|
|
|
type="text"
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
|
|
|
ref={ref}
|
|
|
|
hasError={Boolean(errors.EMAIL_HOST_USER)}
|
2023-11-25 15:53:50 +00:00
|
|
|
placeholder="getitdone@projectplane.so"
|
2023-12-10 10:18:10 +00:00
|
|
|
className="w-full rounded-md font-medium"
|
2023-11-20 15:16:49 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1">
|
|
|
|
<h4 className="text-sm">Password</h4>
|
2023-11-27 11:45:11 +00:00
|
|
|
<div className="relative">
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="EMAIL_HOST_PASSWORD"
|
|
|
|
render={({ field: { value, onChange, ref } }) => (
|
|
|
|
<Input
|
|
|
|
id="EMAIL_HOST_PASSWORD"
|
|
|
|
name="EMAIL_HOST_PASSWORD"
|
|
|
|
type={showPassword ? "text" : "password"}
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
|
|
|
ref={ref}
|
|
|
|
hasError={Boolean(errors.EMAIL_HOST_PASSWORD)}
|
|
|
|
placeholder="Password"
|
2023-12-10 10:18:10 +00:00
|
|
|
className="w-full rounded-md !pr-10 font-medium"
|
2023-11-27 11:45:11 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
{showPassword ? (
|
|
|
|
<button
|
|
|
|
className="absolute right-3 top-2.5 flex items-center justify-center text-custom-text-400"
|
|
|
|
onClick={() => setShowPassword(false)}
|
|
|
|
>
|
|
|
|
<EyeOff className="h-4 w-4" />
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button
|
|
|
|
className="absolute right-3 top-2.5 flex items-center justify-center text-custom-text-400"
|
|
|
|
onClick={() => setShowPassword(true)}
|
|
|
|
>
|
|
|
|
<Eye className="h-4 w-4" />
|
|
|
|
</button>
|
2023-11-20 15:16:49 +00:00
|
|
|
)}
|
2023-11-27 11:45:11 +00:00
|
|
|
</div>
|
2023-11-20 15:16:49 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-12-21 09:07:26 +00:00
|
|
|
<div className="grid-col grid w-full max-w-4xl grid-cols-1 items-center justify-between gap-x-20 gap-y-10 lg:grid-cols-2">
|
2023-12-18 08:06:09 +00:00
|
|
|
<div className="flex flex-col gap-1">
|
|
|
|
<h4 className="text-sm">From address</h4>
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="EMAIL_FROM"
|
|
|
|
render={({ field: { value, onChange, ref } }) => (
|
|
|
|
<Input
|
|
|
|
id="EMAIL_FROM"
|
|
|
|
name="EMAIL_FROM"
|
|
|
|
type="text"
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
|
|
|
ref={ref}
|
|
|
|
hasError={Boolean(errors.EMAIL_FROM)}
|
|
|
|
placeholder="no-reply@projectplane.so"
|
|
|
|
className="w-full rounded-md font-medium"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<p className="text-xs text-custom-text-400">
|
2023-12-21 09:07:26 +00:00
|
|
|
This is the email address your users will see when getting emails from this instance. You will need to
|
|
|
|
verify this address.
|
2023-12-18 08:06:09 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-11-20 15:16:49 +00:00
|
|
|
|
2023-12-21 09:07:26 +00:00
|
|
|
<div className="flex w-full max-w-md flex-col gap-y-10 px-1">
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="mr-8 flex items-center gap-10 pt-4">
|
2023-11-25 15:53:50 +00:00
|
|
|
<div className="grow">
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="text-sm font-medium text-custom-text-100">
|
2023-11-25 15:53:50 +00:00
|
|
|
Turn TLS {Boolean(parseInt(watch("EMAIL_USE_TLS"))) ? "off" : "on"}
|
|
|
|
</div>
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="text-xs font-normal text-custom-text-300">Use this if your email domain supports TLS.</div>
|
2023-11-25 15:53:50 +00:00
|
|
|
</div>
|
|
|
|
<div className="shrink-0">
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="EMAIL_USE_TLS"
|
|
|
|
render={({ field: { value, onChange } }) => (
|
|
|
|
<ToggleSwitch
|
|
|
|
value={Boolean(parseInt(value))}
|
|
|
|
onChange={() => {
|
|
|
|
Boolean(parseInt(value)) === true ? onChange("0") : onChange("1");
|
|
|
|
}}
|
|
|
|
size="sm"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-11-20 15:16:49 +00:00
|
|
|
</div>
|
|
|
|
|
2023-12-06 13:59:45 +00:00
|
|
|
{/* <div className="flex items-center gap-10 pt-4 mr-8">
|
2023-11-25 15:53:50 +00:00
|
|
|
<div className="grow">
|
|
|
|
<div className="text-custom-text-100 font-medium text-sm">
|
|
|
|
Turn SSL {Boolean(parseInt(watch("EMAIL_USE_SSL"))) ? "off" : "on"}
|
|
|
|
</div>
|
|
|
|
<div className="text-custom-text-300 font-normal text-xs">
|
|
|
|
Most email domains support SSL. Use this to secure comms between this instance and your users.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="shrink-0">
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="EMAIL_USE_SSL"
|
|
|
|
render={({ field: { value, onChange } }) => (
|
|
|
|
<ToggleSwitch
|
|
|
|
value={Boolean(parseInt(value))}
|
|
|
|
onChange={() => {
|
|
|
|
Boolean(parseInt(value)) === true ? onChange("0") : onChange("1");
|
|
|
|
}}
|
|
|
|
size="sm"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-12-06 13:59:45 +00:00
|
|
|
</div> */}
|
2023-11-20 15:16:49 +00:00
|
|
|
</div>
|
|
|
|
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="flex max-w-4xl items-center py-1">
|
2023-11-20 15:16:49 +00:00
|
|
|
<Button variant="primary" onClick={handleSubmit(onSubmit)} loading={isSubmitting}>
|
2023-11-27 14:11:47 +00:00
|
|
|
{isSubmitting ? "Saving..." : "Save changes"}
|
2023-11-20 15:16:49 +00:00
|
|
|
</Button>
|
|
|
|
</div>
|
2023-11-25 15:53:50 +00:00
|
|
|
</>
|
2023-11-20 15:16:49 +00:00
|
|
|
);
|
|
|
|
};
|