Skip to content

Commit c57489f

Browse files
authored
Revert "[ENG-9758] fix(notifications): change settings page to default to cor…" (#780)
Reverts #761 Reason: this breaks notification settings for `Preprint submissions updated` This reverts commit 9aa505d.
1 parent 9aa505d commit c57489f

File tree

4 files changed

+15
-69
lines changed

4 files changed

+15
-69
lines changed

src/app/features/settings/notifications/constants/notifications-constants.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,3 @@ export const SUBSCRIPTION_EVENTS: SubscriptionEventModel[] = [
1212
labelKey: 'settings.notifications.notificationPreferences.items.preprints',
1313
},
1414
];
15-
16-
export const FORM_EVENT_TO_API_EVENT: Record<string, string> = {
17-
new_pending_submissions: 'new_pending_submissions',
18-
files_updated: 'files_updated',
19-
global_file_updated: 'global_file_updated',
20-
};
21-
22-
export const API_EVENT_TO_FORM_EVENT: Record<string, string> = {
23-
new_pending_submissions: 'new_pending_submissions',
24-
files_updated: 'global_file_updated',
25-
};

src/app/features/settings/notifications/notifications.component.spec.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,13 @@ describe('NotificationsComponent', () => {
4141
subscribeOsfHelpEmail: false,
4242
};
4343

44-
// new_pending_submissions → global_reviews
45-
// files_updated → global_file_updated
4644
const mockNotificationSubscriptions = [
45+
{ id: 'id1', event: SubscriptionEvent.GlobalFileUpdated, frequency: SubscriptionFrequency.Daily },
4746
{
48-
id: 'osf_new_pending_submissions',
49-
event: 'new_pending_submissions',
47+
id: 'id2',
48+
event: SubscriptionEvent.GlobalFileUpdated,
5049
frequency: SubscriptionFrequency.Instant,
5150
},
52-
{
53-
id: 'cuzg4_global_file_updated',
54-
event: 'files_updated',
55-
frequency: SubscriptionFrequency.Daily,
56-
},
5751
];
5852

5953
beforeEach(async () => {
@@ -83,7 +77,7 @@ describe('NotificationsComponent', () => {
8377
return signal(null);
8478
});
8579

86-
MOCK_STORE.dispatch.mockReturnValue(of({}));
80+
MOCK_STORE.dispatch.mockImplementation(() => of());
8781

8882
await TestBed.configureTestingModule({
8983
imports: [
@@ -122,9 +116,9 @@ describe('NotificationsComponent', () => {
122116

123117
return signal(null);
124118
});
125-
126119
component.emailPreferencesFormSubmit();
127-
expect(loaderService.hide).toHaveBeenCalledTimes(1);
120+
121+
expect(loaderService.hide).not.toHaveBeenCalled();
128122
});
129123

130124
it('should handle subscription completion correctly', () => {
@@ -142,15 +136,11 @@ describe('NotificationsComponent', () => {
142136
it('should call dispatch only once per subscription change', () => {
143137
const mockDispatch = jest.fn().mockReturnValue(of({}));
144138
MOCK_STORE.dispatch.mockImplementation(mockDispatch);
139+
const event = SubscriptionEvent.GlobalFileUpdated;
140+
const frequency = SubscriptionFrequency.Daily;
145141

146-
component.onSubscriptionChange(SubscriptionEvent.GlobalFileUpdated, SubscriptionFrequency.Daily);
142+
component.onSubscriptionChange(event, frequency);
147143

148144
expect(mockDispatch).toHaveBeenCalledTimes(1);
149145
});
150-
151-
it('should default to API value', () => {
152-
const subs = component.notificationSubscriptionsForm.value;
153-
expect(subs.new_pending_submissions).toBe(SubscriptionFrequency.Instant);
154-
expect(subs.global_file_updated).toBe(SubscriptionFrequency.Daily);
155-
});
156146
});

src/app/features/settings/notifications/notifications.component.ts

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { ToastService } from '@osf/shared/services/toast.service';
2121
import { AccountSettings } from '../account-settings/models';
2222
import { AccountSettingsSelectors, GetAccountSettings, UpdateAccountSettings } from '../account-settings/store';
2323

24-
import { API_EVENT_TO_FORM_EVENT, FORM_EVENT_TO_API_EVENT, SUBSCRIPTION_EVENTS } from './constants';
24+
import { SUBSCRIPTION_EVENTS } from './constants';
2525
import { EmailPreferencesForm, EmailPreferencesFormControls } from './models';
2626
import {
2727
GetAllGlobalNotificationSubscriptions,
@@ -80,9 +80,7 @@ export class NotificationsComponent implements OnInit {
8080
notificationSubscriptionsForm = this.fb.group(
8181
SUBSCRIPTION_EVENTS.reduce(
8282
(control, { event }) => {
83-
control[event as string] = this.fb.control<SubscriptionFrequency>(SubscriptionFrequency.Never, {
84-
nonNullable: true,
85-
});
83+
control[event] = this.fb.control<SubscriptionFrequency>(SubscriptionFrequency.Never, { nonNullable: true });
8684
return control;
8785
},
8886
{} as Record<string, FormControl<SubscriptionFrequency>>
@@ -130,24 +128,7 @@ export class NotificationsComponent implements OnInit {
130128
onSubscriptionChange(event: SubscriptionEvent, frequency: SubscriptionFrequency) {
131129
const user = this.currentUser();
132130
if (!user) return;
133-
134-
const eventKey = event as string;
135-
136-
const apiEventName = FORM_EVENT_TO_API_EVENT[eventKey] ?? eventKey;
137-
138-
let id: string | undefined;
139-
140-
if (event === SubscriptionEvent.GlobalReviews) {
141-
const subs = this.notificationSubscriptions();
142-
const match = subs.find((s) => (s.event as string) === 'new_pending_submissions');
143-
if (match) {
144-
id = match.id;
145-
} else {
146-
return;
147-
}
148-
} else {
149-
id = `${user.id}_${apiEventName}`;
150-
}
131+
const id = `${user.id}_${event}`;
151132

152133
this.loaderService.show();
153134
this.actions.updateNotificationSubscription({ id, frequency }).subscribe(() => {
@@ -164,24 +145,10 @@ export class NotificationsComponent implements OnInit {
164145
}
165146

166147
private updateNotificationSubscriptionsForm() {
167-
const subs = this.notificationSubscriptions();
168-
if (!subs?.length) {
169-
return;
170-
}
171-
172148
const patch: Record<string, SubscriptionFrequency> = {};
173149

174-
for (const sub of subs) {
175-
const apiEvent = sub.event as string | null;
176-
if (!apiEvent) {
177-
continue;
178-
}
179-
180-
const formEventKey = API_EVENT_TO_FORM_EVENT[apiEvent];
181-
182-
if (formEventKey) {
183-
patch[formEventKey] = sub.frequency;
184-
}
150+
for (const sub of this.notificationSubscriptions()) {
151+
patch[sub.event] = sub.frequency;
185152
}
186153

187154
this.notificationSubscriptionsForm.patchValue(patch);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export enum SubscriptionEvent {
22
GlobalFileUpdated = 'global_file_updated',
3-
GlobalReviews = 'new_pending_submissions',
3+
GlobalReviews = 'global_reviews',
44
FileUpdated = 'file_updated',
55
}

0 commit comments

Comments
 (0)