2024-06-10 09:43:10 +00:00
|
|
|
|
"use client";
|
|
|
|
|
|
2024-05-16 14:12:18 +00:00
|
|
|
|
import React, { FC, useEffect } from "react";
|
2024-01-23 12:19:22 +00:00
|
|
|
|
import { Controller, useForm } from "react-hook-form";
|
2024-03-19 14:38:35 +00:00
|
|
|
|
import { IUserEmailNotificationSettings } from "@plane/types";
|
2024-01-23 12:19:22 +00:00
|
|
|
|
// ui
|
2024-03-06 08:48:41 +00:00
|
|
|
|
import { Button, Checkbox, TOAST_TYPE, setToast } from "@plane/ui";
|
2024-01-23 12:19:22 +00:00
|
|
|
|
// services
|
2024-03-19 14:38:35 +00:00
|
|
|
|
import { UserService } from "@/services/user.service";
|
2024-01-23 12:19:22 +00:00
|
|
|
|
// types
|
|
|
|
|
|
|
|
|
|
interface IEmailNotificationFormProps {
|
|
|
|
|
data: IUserEmailNotificationSettings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// services
|
|
|
|
|
const userService = new UserService();
|
|
|
|
|
|
|
|
|
|
export const EmailNotificationForm: FC<IEmailNotificationFormProps> = (props) => {
|
|
|
|
|
const { data } = props;
|
|
|
|
|
// form data
|
|
|
|
|
const {
|
|
|
|
|
handleSubmit,
|
2024-02-09 11:07:39 +00:00
|
|
|
|
watch,
|
2024-01-23 12:19:22 +00:00
|
|
|
|
control,
|
|
|
|
|
setValue,
|
2024-05-16 14:12:18 +00:00
|
|
|
|
reset,
|
2024-01-23 12:19:22 +00:00
|
|
|
|
formState: { isSubmitting, isDirty, dirtyFields },
|
|
|
|
|
} = useForm<IUserEmailNotificationSettings>({
|
|
|
|
|
defaultValues: {
|
|
|
|
|
...data,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const onSubmit = async (formData: IUserEmailNotificationSettings) => {
|
|
|
|
|
// Get the dirty fields from the form data and create a payload
|
|
|
|
|
let payload = {};
|
|
|
|
|
Object.keys(dirtyFields).forEach((key) => {
|
|
|
|
|
payload = {
|
|
|
|
|
...payload,
|
|
|
|
|
[key]: formData[key as keyof IUserEmailNotificationSettings],
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
await userService
|
|
|
|
|
.updateCurrentUserEmailNotificationSettings(payload)
|
|
|
|
|
.then(() =>
|
2024-03-06 08:48:41 +00:00
|
|
|
|
setToast({
|
2024-05-07 09:33:24 +00:00
|
|
|
|
title: "Success!",
|
2024-03-06 08:48:41 +00:00
|
|
|
|
type: TOAST_TYPE.SUCCESS,
|
2024-01-23 12:19:22 +00:00
|
|
|
|
message: "Email Notification Settings updated successfully",
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
.catch((err) => console.error(err));
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-16 14:12:18 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
reset(data);
|
|
|
|
|
}, [reset, data]);
|
|
|
|
|
|
2024-01-23 12:19:22 +00:00
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className="pt-2 text-lg font-medium text-custom-text-100">Notify me when:</div>
|
|
|
|
|
{/* Notification Settings */}
|
|
|
|
|
<div className="flex flex-col py-2">
|
|
|
|
|
<div className="flex gap-2 items-center pt-6">
|
|
|
|
|
<div className="grow">
|
|
|
|
|
<div className="pb-1 text-base font-medium text-custom-text-100">Property changes</div>
|
|
|
|
|
<div className="text-sm font-normal text-custom-text-300">
|
|
|
|
|
Notify me when issue’s properties like assignees, priority, estimates or anything else changes.
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="shrink-0">
|
|
|
|
|
<Controller
|
|
|
|
|
control={control}
|
|
|
|
|
name="property_change"
|
|
|
|
|
render={({ field: { value, onChange } }) => (
|
2024-05-31 09:35:28 +00:00
|
|
|
|
<Checkbox checked={value} onChange={() => onChange(!value)} containerClassName="mx-2" />
|
2024-01-23 12:19:22 +00:00
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex gap-2 items-center pt-6 pb-2">
|
|
|
|
|
<div className="grow">
|
|
|
|
|
<div className="pb-1 text-base font-medium text-custom-text-100">State Change</div>
|
|
|
|
|
<div className="text-sm font-normal text-custom-text-300">
|
|
|
|
|
Notify me when the issues moves to a different state
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="shrink-0">
|
|
|
|
|
<Controller
|
|
|
|
|
control={control}
|
|
|
|
|
name="state_change"
|
|
|
|
|
render={({ field: { value, onChange } }) => (
|
2024-02-09 11:07:39 +00:00
|
|
|
|
<Checkbox
|
2024-01-23 12:19:22 +00:00
|
|
|
|
checked={value}
|
2024-05-31 09:35:28 +00:00
|
|
|
|
indeterminate={!value && watch("issue_completed")}
|
2024-01-23 12:19:22 +00:00
|
|
|
|
onChange={() => {
|
2024-05-31 06:48:57 +00:00
|
|
|
|
setValue("issue_completed", !value, { shouldDirty: true });
|
2024-01-23 12:19:22 +00:00
|
|
|
|
onChange(!value);
|
|
|
|
|
}}
|
2024-05-31 09:35:28 +00:00
|
|
|
|
containerClassName="mx-2"
|
2024-01-23 12:19:22 +00:00
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex gap-2 items-center border-0 border-l-[3px] border-custom-border-300 pl-3">
|
|
|
|
|
<div className="grow">
|
|
|
|
|
<div className="pb-1 text-base font-medium text-custom-text-100">Issue completed</div>
|
|
|
|
|
<div className="text-sm font-normal text-custom-text-300">Notify me only when an issue is completed</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="shrink-0">
|
|
|
|
|
<Controller
|
|
|
|
|
control={control}
|
|
|
|
|
name="issue_completed"
|
|
|
|
|
render={({ field: { value, onChange } }) => (
|
2024-05-31 09:35:28 +00:00
|
|
|
|
<Checkbox checked={value} onChange={() => onChange(!value)} containerClassName="mx-2" />
|
2024-01-23 12:19:22 +00:00
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex gap-2 items-center pt-6">
|
|
|
|
|
<div className="grow">
|
|
|
|
|
<div className="pb-1 text-base font-medium text-custom-text-100">Comments</div>
|
|
|
|
|
<div className="text-sm font-normal text-custom-text-300">
|
|
|
|
|
Notify me when someone leaves a comment on the issue
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="shrink-0">
|
|
|
|
|
<Controller
|
|
|
|
|
control={control}
|
|
|
|
|
name="comment"
|
|
|
|
|
render={({ field: { value, onChange } }) => (
|
2024-05-31 09:35:28 +00:00
|
|
|
|
<Checkbox checked={value} onChange={() => onChange(!value)} containerClassName="mx-2" />
|
2024-01-23 12:19:22 +00:00
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex gap-2 items-center pt-6">
|
|
|
|
|
<div className="grow">
|
|
|
|
|
<div className="pb-1 text-base font-medium text-custom-text-100">Mentions</div>
|
|
|
|
|
<div className="text-sm font-normal text-custom-text-300">
|
|
|
|
|
Notify me only when someone mentions me in the comments or description
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="shrink-0">
|
|
|
|
|
<Controller
|
|
|
|
|
control={control}
|
|
|
|
|
name="mention"
|
|
|
|
|
render={({ field: { value, onChange } }) => (
|
2024-05-31 09:35:28 +00:00
|
|
|
|
<Checkbox checked={value} onChange={() => onChange(!value)} containerClassName="mx-2" />
|
2024-01-23 12:19:22 +00:00
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center py-12">
|
|
|
|
|
<Button variant="primary" onClick={handleSubmit(onSubmit)} loading={isSubmitting} disabled={!isDirty}>
|
|
|
|
|
{isSubmitting ? "Saving..." : "Save changes"}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|