import React, { FC, useEffect } from "react"; import { Controller, useForm } from "react-hook-form"; import { IUserEmailNotificationSettings } from "@plane/types"; // ui import { Button, Checkbox, TOAST_TYPE, setToast } from "@plane/ui"; // services import { UserService } from "@/services/user.service"; // types interface IEmailNotificationFormProps { data: IUserEmailNotificationSettings; } // services const userService = new UserService(); export const EmailNotificationForm: FC = (props) => { const { data } = props; // form data const { handleSubmit, watch, control, setValue, reset, formState: { isSubmitting, isDirty, dirtyFields }, } = useForm({ 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(() => setToast({ title: "Success!", type: TOAST_TYPE.SUCCESS, message: "Email Notification Settings updated successfully", }) ) .catch((err) => console.error(err)); }; useEffect(() => { reset(data); }, [reset, data]); return ( <>
Notify me when:
{/* Notification Settings */}
Property changes
Notify me when issue’s properties like assignees, priority, estimates or anything else changes.
( onChange(!value)} containerClassName="mx-2" /> )} />
State Change
Notify me when the issues moves to a different state
( { setValue("issue_completed", !value, { shouldDirty: true }); onChange(!value); }} containerClassName="mx-2" /> )} />
Issue completed
Notify me only when an issue is completed
( onChange(!value)} containerClassName="mx-2" /> )} />
Comments
Notify me when someone leaves a comment on the issue
( onChange(!value)} containerClassName="mx-2" /> )} />
Mentions
Notify me only when someone mentions me in the comments or description
( onChange(!value)} containerClassName="mx-2" /> )} />
); };