diff --git a/web/core/components/profile/notification/email-notification-form.tsx b/web/core/components/profile/notification/email-notification-form.tsx index d3e9049e72a..02bbe19f1b9 100644 --- a/web/core/components/profile/notification/email-notification-form.tsx +++ b/web/core/components/profile/notification/email-notification-form.tsx @@ -4,7 +4,7 @@ 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"; +import { ToggleSwitch, TOAST_TYPE, setToast } from "@plane/ui"; // services import { UserService } from "@/services/user.service"; // types @@ -20,35 +20,32 @@ export const EmailNotificationForm: FC = (props) => const { data } = props; // form data const { - handleSubmit, control, reset, - formState: { isSubmitting, 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)); + const handleSettingChange = async (key: keyof IUserEmailNotificationSettings, value: boolean) => { + try { + await userService.updateCurrentUserEmailNotificationSettings({ + [key]: value, + }); + setToast({ + title: "Success!", + type: TOAST_TYPE.SUCCESS, + message: "Email notification setting updated successfully", + }); + } catch (err) { + console.error(err); + setToast({ + title: "Error!", + type: TOAST_TYPE.ERROR, + message: "Failed to update email notification setting", + }); + } }; useEffect(() => { @@ -64,7 +61,7 @@ export const EmailNotificationForm: FC = (props) =>
Property changes
- Notify me when issue’s properties like assignees, priority, estimates or anything else changes. + Notify me when issue's properties like assignees, priority, estimates or anything else changes.
@@ -72,7 +69,14 @@ export const EmailNotificationForm: FC = (props) => control={control} name="property_change" render={({ field: { value, onChange } }) => ( - onChange(!value)} containerClassName="mx-2" /> + { + onChange(newValue); + handleSettingChange("property_change", newValue); + }} + size="sm" + /> )} />
@@ -89,12 +93,13 @@ export const EmailNotificationForm: FC = (props) => control={control} name="state_change" render={({ field: { value, onChange } }) => ( - { - onChange(!value); + { + onChange(newValue); + handleSettingChange("state_change", newValue); }} - containerClassName="mx-2" + size="sm" /> )} /> @@ -110,7 +115,14 @@ export const EmailNotificationForm: FC = (props) => control={control} name="issue_completed" render={({ field: { value, onChange } }) => ( - onChange(!value)} containerClassName="mx-2" /> + { + onChange(newValue); + handleSettingChange("issue_completed", newValue); + }} + size="sm" + /> )} /> @@ -127,7 +139,14 @@ export const EmailNotificationForm: FC = (props) => control={control} name="comment" render={({ field: { value, onChange } }) => ( - onChange(!value)} containerClassName="mx-2" /> + { + onChange(newValue); + handleSettingChange("comment", newValue); + }} + size="sm" + /> )} /> @@ -144,17 +163,19 @@ export const EmailNotificationForm: FC = (props) => control={control} name="mention" render={({ field: { value, onChange } }) => ( - onChange(!value)} containerClassName="mx-2" /> + { + onChange(newValue); + handleSettingChange("mention", newValue); + }} + size="sm" + /> )} /> -
- -
); };