Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.

Commit 1f61bc2

Browse files
viharnishantPFM
authored andcommitted
fix: changed checkboxes to toggles on notifications settings page (makeplane#6175)
1 parent 486c024 commit 1f61bc2

File tree

1 file changed

+58
-37
lines changed

1 file changed

+58
-37
lines changed

web/core/components/profile/notification/email-notification-form.tsx

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, { FC, useEffect } from "react";
44
import { Controller, useForm } from "react-hook-form";
55
import { IUserEmailNotificationSettings } from "@plane/types";
66
// ui
7-
import { Button, Checkbox, TOAST_TYPE, setToast } from "@plane/ui";
7+
import { ToggleSwitch, TOAST_TYPE, setToast } from "@plane/ui";
88
// services
99
import { UserService } from "@/services/user.service";
1010
// types
@@ -20,35 +20,32 @@ export const EmailNotificationForm: FC<IEmailNotificationFormProps> = (props) =>
2020
const { data } = props;
2121
// form data
2222
const {
23-
handleSubmit,
2423
control,
2524
reset,
26-
formState: { isSubmitting, dirtyFields },
2725
} = useForm<IUserEmailNotificationSettings>({
2826
defaultValues: {
2927
...data,
3028
},
3129
});
3230

33-
const onSubmit = async (formData: IUserEmailNotificationSettings) => {
34-
// Get the dirty fields from the form data and create a payload
35-
let payload = {};
36-
Object.keys(dirtyFields).forEach((key) => {
37-
payload = {
38-
...payload,
39-
[key]: formData[key as keyof IUserEmailNotificationSettings],
40-
};
41-
});
42-
await userService
43-
.updateCurrentUserEmailNotificationSettings(payload)
44-
.then(() =>
45-
setToast({
46-
title: "Success!",
47-
type: TOAST_TYPE.SUCCESS,
48-
message: "Email Notification Settings updated successfully",
49-
})
50-
)
51-
.catch((err) => console.error(err));
31+
const handleSettingChange = async (key: keyof IUserEmailNotificationSettings, value: boolean) => {
32+
try {
33+
await userService.updateCurrentUserEmailNotificationSettings({
34+
[key]: value,
35+
});
36+
setToast({
37+
title: "Success!",
38+
type: TOAST_TYPE.SUCCESS,
39+
message: "Email notification setting updated successfully",
40+
});
41+
} catch (err) {
42+
console.error(err);
43+
setToast({
44+
title: "Error!",
45+
type: TOAST_TYPE.ERROR,
46+
message: "Failed to update email notification setting",
47+
});
48+
}
5249
};
5350

5451
useEffect(() => {
@@ -64,15 +61,22 @@ export const EmailNotificationForm: FC<IEmailNotificationFormProps> = (props) =>
6461
<div className="grow">
6562
<div className="pb-1 text-base font-medium text-custom-text-100">Property changes</div>
6663
<div className="text-sm font-normal text-custom-text-300">
67-
Notify me when issues properties like assignees, priority, estimates or anything else changes.
64+
Notify me when issue's properties like assignees, priority, estimates or anything else changes.
6865
</div>
6966
</div>
7067
<div className="shrink-0">
7168
<Controller
7269
control={control}
7370
name="property_change"
7471
render={({ field: { value, onChange } }) => (
75-
<Checkbox checked={value} onChange={() => onChange(!value)} containerClassName="mx-2" />
72+
<ToggleSwitch
73+
value={value}
74+
onChange={(newValue) => {
75+
onChange(newValue);
76+
handleSettingChange("property_change", newValue);
77+
}}
78+
size="sm"
79+
/>
7680
)}
7781
/>
7882
</div>
@@ -89,12 +93,13 @@ export const EmailNotificationForm: FC<IEmailNotificationFormProps> = (props) =>
8993
control={control}
9094
name="state_change"
9195
render={({ field: { value, onChange } }) => (
92-
<Checkbox
93-
checked={value}
94-
onChange={() => {
95-
onChange(!value);
96+
<ToggleSwitch
97+
value={value}
98+
onChange={(newValue) => {
99+
onChange(newValue);
100+
handleSettingChange("state_change", newValue);
96101
}}
97-
containerClassName="mx-2"
102+
size="sm"
98103
/>
99104
)}
100105
/>
@@ -110,7 +115,14 @@ export const EmailNotificationForm: FC<IEmailNotificationFormProps> = (props) =>
110115
control={control}
111116
name="issue_completed"
112117
render={({ field: { value, onChange } }) => (
113-
<Checkbox checked={value} onChange={() => onChange(!value)} containerClassName="mx-2" />
118+
<ToggleSwitch
119+
value={value}
120+
onChange={(newValue) => {
121+
onChange(newValue);
122+
handleSettingChange("issue_completed", newValue);
123+
}}
124+
size="sm"
125+
/>
114126
)}
115127
/>
116128
</div>
@@ -127,7 +139,14 @@ export const EmailNotificationForm: FC<IEmailNotificationFormProps> = (props) =>
127139
control={control}
128140
name="comment"
129141
render={({ field: { value, onChange } }) => (
130-
<Checkbox checked={value} onChange={() => onChange(!value)} containerClassName="mx-2" />
142+
<ToggleSwitch
143+
value={value}
144+
onChange={(newValue) => {
145+
onChange(newValue);
146+
handleSettingChange("comment", newValue);
147+
}}
148+
size="sm"
149+
/>
131150
)}
132151
/>
133152
</div>
@@ -144,17 +163,19 @@ export const EmailNotificationForm: FC<IEmailNotificationFormProps> = (props) =>
144163
control={control}
145164
name="mention"
146165
render={({ field: { value, onChange } }) => (
147-
<Checkbox checked={value} onChange={() => onChange(!value)} containerClassName="mx-2" />
166+
<ToggleSwitch
167+
value={value}
168+
onChange={(newValue) => {
169+
onChange(newValue);
170+
handleSettingChange("mention", newValue);
171+
}}
172+
size="sm"
173+
/>
148174
)}
149175
/>
150176
</div>
151177
</div>
152178
</div>
153-
<div className="flex items-center py-12">
154-
<Button variant="primary" onClick={handleSubmit(onSubmit)} loading={isSubmitting}>
155-
{isSubmitting ? "Saving..." : "Save changes"}
156-
</Button>
157-
</div>
158179
</>
159180
);
160181
};

0 commit comments

Comments
 (0)