Skip to content

Commit c86c264

Browse files
Update src/app/features/settings/notifications/notifications.component.ts
improve and shorten conditional Co-authored-by: nsemets <nsemets@exoft.net>
1 parent 46b1787 commit c86c264

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,24 +137,14 @@ export class NotificationsComponent implements OnInit {
137137
onSubscriptionChange(event: SubscriptionEvent, frequency: SubscriptionFrequency) {
138138
const user = this.currentUser();
139139
if (!user) return;
140+
const apiEventName = this.FORM_EVENT_TO_API_EVENT[event as string] ?? (event as string);
140141

141-
const eventKey = event as unknown as string;
142+
const id =
143+
event === SubscriptionEvent.GlobalReviews
144+
? this.notificationSubscriptions().find((s) => (s.event as string) === 'new_pending_submissions')?.id
145+
: `${user.id}_${apiEventName}`;
142146

143-
const apiEventName = this.FORM_EVENT_TO_API_EVENT[eventKey] ?? eventKey;
144-
145-
let id: string | undefined;
146-
147-
if (event === SubscriptionEvent.GlobalReviews) {
148-
const subs = this.notificationSubscriptions();
149-
const match = subs.find((s) => (s.event as string) === 'new_pending_submissions');
150-
if (match) {
151-
id = match.id;
152-
} else {
153-
return;
154-
}
155-
} else {
156-
id = `${user.id}_${apiEventName}`;
157-
}
147+
if (!id) return;
158148

159149
this.loaderService.show();
160150
this.actions.updateNotificationSubscription({ id, frequency }).subscribe(() => {

0 commit comments

Comments
 (0)