Skip to content

Commit 254f4dc

Browse files
committed
addressed the comments
1 parent 5309f0a commit 254f4dc

File tree

5 files changed

+41
-25
lines changed

5 files changed

+41
-25
lines changed

coderd/notifications/Archive.zip

35.3 KB
Binary file not shown.

coderd/notifications/dispatch/smtp/html.gotmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<div style="border-top: 1px solid #e2e8f0; color: #475569; font-size: 12px; margin-top: 64px; padding-top: 24px; line-height: 1.6;">
2727
<p>&copy;&nbsp;{{ current_year }}&nbsp;Coder. All rights reserved&nbsp;-&nbsp;<a href="{{ base_url }}" style="color: #2563eb; text-decoration: none;">{{ base_url }}</a></p>
2828
<p><a href="{{ base_url }}/settings/notifications" style="color: #2563eb; text-decoration: none;">Click here to manage your notification settings</a></p>
29-
<p><a href="{{ base_url }}/settings/notifications?unsubscribe={{ .NotificationTemplateID }}" style="color: #2563eb; text-decoration: none;">Stop receiving emails like this</a></p>
29+
<p><a href="{{ base_url }}/settings/notifications?disabled={{ .NotificationTemplateID }}" style="color: #2563eb; text-decoration: none;">Stop receiving emails like this</a></p>
3030
</div>
3131
</div>
3232
</body>

coderd/notifications/enqueuer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (s *StoreEnqueuer) Enqueue(ctx context.Context, userID, templateID uuid.UUI
121121
// actions which can be taken by the recipient.
122122
func (s *StoreEnqueuer) buildPayload(metadata database.FetchNewMessageMetadataRow, labels map[string]string) (*types.MessagePayload, error) {
123123
payload := types.MessagePayload{
124-
Version: "1.0",
124+
Version: "1.1",
125125

126126
NotificationName: metadata.NotificationName,
127127
NotificationTemplateID: metadata.NotificationTemplateID.String(),

coderd/notifications/types/payload.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ package types
77
type MessagePayload struct {
88
Version string `json:"_version"`
99

10-
NotificationName string `json:"notification_name"`
11-
NotificationTemplateID string `json:"notification_template_id"`
12-
UserID string `json:"user_id"`
13-
UserEmail string `json:"user_email"`
14-
UserName string `json:"user_name"`
15-
UserUsername string `json:"user_username"`
16-
Actions []TemplateAction `json:"actions"`
17-
Labels map[string]string `json:"labels"`
10+
NotificationName string `json:"notification_name"`
11+
NotificationTemplateID string `json:"notification_template_id"`
12+
13+
UserID string `json:"user_id"`
14+
UserEmail string `json:"user_email"`
15+
UserName string `json:"user_name"`
16+
UserUsername string `json:"user_username"`
17+
18+
Actions []TemplateAction `json:"actions"`
19+
Labels map[string]string `json:"labels"`
1820
}

site/src/pages/UserSettingsPage/NotificationsPage/NotificationsPage.tsx

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {
1818
NotificationPreference,
1919
NotificationTemplate,
2020
} from "api/typesGenerated";
21-
import { displaySuccess } from "components/GlobalSnackbar/utils";
21+
import { displayError, displaySuccess } from "components/GlobalSnackbar/utils";
2222
import { Loader } from "components/Loader/Loader";
2323
import { Stack } from "components/Stack/Stack";
2424
import { useAuthenticated } from "contexts/auth/RequireAuth";
@@ -63,24 +63,38 @@ export const NotificationsPage: FC = () => {
6363
updateUserNotificationPreferences(user.id, queryClient),
6464
);
6565
const [searchParams] = useSearchParams();
66-
const unsubscribeTemplateId = searchParams.get("unsubscribe");
66+
const templateId = searchParams.get("disabled");
6767

6868
useEffect(() => {
69-
if (unsubscribeTemplateId) {
70-
handleUnsubscribe(unsubscribeTemplateId);
69+
if (templateId && templatesByGroup.isSuccess && templatesByGroup.data) {
70+
disableTemplate(templateId);
7171
}
72-
}, [unsubscribeTemplateId]);
72+
}, [templateId, templatesByGroup.isSuccess, templatesByGroup.data]);
7373

74-
const handleUnsubscribe = async (templateId: string) => {
75-
await updatePreferences.mutateAsync({
76-
template_disabled_map: {
77-
[templateId]: true,
78-
},
79-
});
80-
displaySuccess("Notification preferences updated");
81-
queryClient.invalidateQueries(
82-
userNotificationPreferences(user.id).queryKey,
83-
);
74+
const disableTemplate = async (templateId: string) => {
75+
try {
76+
await updatePreferences.mutateAsync({
77+
template_disabled_map: {
78+
[templateId]: true,
79+
},
80+
});
81+
82+
const allTemplates = Object.values(templatesByGroup.data ?? {}).flat();
83+
const template = allTemplates.find((t) => t.id === templateId);
84+
85+
if (!template) {
86+
throw new Error(`Template with ID ${templateId} not found`);
87+
}
88+
89+
displaySuccess(`${template.name} notification has been disabled`);
90+
91+
queryClient.invalidateQueries(
92+
userNotificationPreferences(user.id).queryKey,
93+
);
94+
} catch (error) {
95+
console.error(error);
96+
displayError("Error on disabling notification");
97+
}
8498
};
8599

86100
const ready =

0 commit comments

Comments
 (0)