From 1af5a7ae4d6af869985aef8c53f2a57c6c69f6a2 Mon Sep 17 00:00:00 2001 From: Valentin Date: Wed, 10 Nov 2021 10:46:02 +0200 Subject: [PATCH] solved comments --- .../account/screens/notifications/constants.ts | 13 ++----------- .../notifications-screen.component.scss | 2 +- .../notifications-screen.component.ts | 12 ++++-------- .../services/notification-preferences.service.ts | 11 ++++------- libs/common-ui | 2 +- .../src/lib/notifications-preferences/index.ts | 1 + .../notification-preferences.ts | 2 +- .../src/lib/notifications-preferences/types.ts | 8 ++++++++ 8 files changed, 22 insertions(+), 29 deletions(-) create mode 100644 libs/red-domain/src/lib/notifications-preferences/types.ts diff --git a/apps/red-ui/src/app/modules/account/screens/notifications/constants.ts b/apps/red-ui/src/app/modules/account/screens/notifications/constants.ts index 9f2eb7f6b..3c98f33b1 100644 --- a/apps/red-ui/src/app/modules/account/screens/notifications/constants.ts +++ b/apps/red-ui/src/app/modules/account/screens/notifications/constants.ts @@ -1,12 +1,3 @@ -export const EmailNotificationScheduleTypes = { - INSTANT: 'INSTANT', - DAILY: 'DAILY', - WEEKLY: 'WEEKLY', -} as const; - -export type EmailNotificationScheduleType = keyof typeof EmailNotificationScheduleTypes; -export const EmailNotificationScheduleTypesValues = Object.values(EmailNotificationScheduleTypes); - export const NotificationCategories = { inAppNotifications: 'inAppNotifications', emailNotifications: 'emailNotifications', @@ -39,9 +30,9 @@ export const ApproverOnDossiersNotificationsTypes = { export const ApproverOnDossiersNotificationsTypesValues = Object.values(ApproverOnDossiersNotificationsTypes); -export const NotificationGroupsKeys = ['own', 'reviewer', 'approver']; +export const NotificationGroupsKeys = ['own', 'reviewer', 'approver'] as const; export const NotificationGroupsValues = [ OwnDossiersNotificationsTypesValues, ReviewerOnDossiersNotificationsTypesValues, ApproverOnDossiersNotificationsTypesValues, -]; +] as const; diff --git a/apps/red-ui/src/app/modules/account/screens/notifications/notifications-screen/notifications-screen.component.scss b/apps/red-ui/src/app/modules/account/screens/notifications/notifications-screen/notifications-screen.component.scss index 0556bd0c0..82f2afa68 100644 --- a/apps/red-ui/src/app/modules/account/screens/notifications/notifications-screen/notifications-screen.component.scss +++ b/apps/red-ui/src/app/modules/account/screens/notifications/notifications-screen/notifications-screen.component.scss @@ -1,4 +1,4 @@ -@use 'apps/red-ui/src/assets/styles/variables'; +@use 'variables'; @use 'libs/common-ui/src/assets/styles/common-mixins'; .dialog-content { diff --git a/apps/red-ui/src/app/modules/account/screens/notifications/notifications-screen/notifications-screen.component.ts b/apps/red-ui/src/app/modules/account/screens/notifications/notifications-screen/notifications-screen.component.ts index 0c810a54e..e6b8f4a2a 100644 --- a/apps/red-ui/src/app/modules/account/screens/notifications/notifications-screen/notifications-screen.component.ts +++ b/apps/red-ui/src/app/modules/account/screens/notifications/notifications-screen/notifications-screen.component.ts @@ -4,12 +4,8 @@ import { notificationsTranslations } from '../../../translations/notifications-t import { NotificationPreferencesService } from '../../../services/notification-preferences.service'; import { LoadingService, Toaster } from '@iqser/common-ui'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; -import { - EmailNotificationScheduleTypesValues, - NotificationCategoriesValues, - NotificationGroupsKeys, - NotificationGroupsValues, -} from '../constants'; +import { NotificationCategoriesValues, NotificationGroupsKeys, NotificationGroupsValues } from '../constants'; +import { EmailNotificationScheduleTypesValues } from '@red/domain'; @Component({ selector: 'redaction-notifications-screen', @@ -75,7 +71,7 @@ export class NotificationsScreenComponent implements OnInit { async save() { this._loadingService.start(); try { - await this._notificationPreferencesService.updateNotificationPreferences(this.formGroup.value).toPromise(); + await this._notificationPreferencesService.update(this.formGroup.value).toPromise(); } catch (e) { this._toaster.error(_('notifications-screen.error.generic')); } @@ -85,7 +81,7 @@ export class NotificationsScreenComponent implements OnInit { private async _initializeForm() { this._loadingService.start(); - const notificationPreferences = await this._notificationPreferencesService.getNotificationPreferences().toPromise(); + const notificationPreferences = await this._notificationPreferencesService.get().toPromise(); this.formGroup.patchValue(notificationPreferences); this._loadingService.stop(); diff --git a/apps/red-ui/src/app/modules/account/services/notification-preferences.service.ts b/apps/red-ui/src/app/modules/account/services/notification-preferences.service.ts index d4d44a9d5..acd23a718 100644 --- a/apps/red-ui/src/app/modules/account/services/notification-preferences.service.ts +++ b/apps/red-ui/src/app/modules/account/services/notification-preferences.service.ts @@ -2,23 +2,20 @@ import { Injectable, Injector } from '@angular/core'; import { GenericService } from '@iqser/common-ui'; import { Observable, of } from 'rxjs'; import { UserService } from '../../../services/user.service'; -import { INotificationPreferences } from '@red/domain'; +import { EmailNotificationScheduleTypes, INotificationPreferences } from '@red/domain'; import { catchError } from 'rxjs/operators'; -import { EmailNotificationScheduleTypes } from '../screens/notifications/constants'; -@Injectable({ - providedIn: 'root', -}) +@Injectable() export class NotificationPreferencesService extends GenericService { constructor(protected readonly _injector: Injector, private readonly _userService: UserService) { super(_injector, 'notification-preferences'); } - getNotificationPreferences(): Observable { + get(): Observable { return super.get().pipe(catchError(() => of(this._defaultPreferences))); } - updateNotificationPreferences(notificationPreferences: INotificationPreferences): Observable { + update(notificationPreferences: INotificationPreferences): Observable { return super._post(notificationPreferences); } diff --git a/libs/common-ui b/libs/common-ui index 64bf1b270..ca957326b 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit 64bf1b270deb96f399b1ab603cf9cd00ff700f36 +Subproject commit ca957326b3514c7bc158fd80c9f65d1967d431d0 diff --git a/libs/red-domain/src/lib/notifications-preferences/index.ts b/libs/red-domain/src/lib/notifications-preferences/index.ts index 8a3478f79..f2fedd47f 100644 --- a/libs/red-domain/src/lib/notifications-preferences/index.ts +++ b/libs/red-domain/src/lib/notifications-preferences/index.ts @@ -1 +1,2 @@ export * from './notification-preferences'; +export * from './types'; diff --git a/libs/red-domain/src/lib/notifications-preferences/notification-preferences.ts b/libs/red-domain/src/lib/notifications-preferences/notification-preferences.ts index 8577fb137..394af0193 100644 --- a/libs/red-domain/src/lib/notifications-preferences/notification-preferences.ts +++ b/libs/red-domain/src/lib/notifications-preferences/notification-preferences.ts @@ -1,4 +1,4 @@ -import { EmailNotificationScheduleType } from '../../../../../apps/red-ui/src/app/modules/account/screens/notifications/constants'; +import { EmailNotificationScheduleType } from './types'; export interface INotificationPreferences { emailNotificationType: EmailNotificationScheduleType; diff --git a/libs/red-domain/src/lib/notifications-preferences/types.ts b/libs/red-domain/src/lib/notifications-preferences/types.ts new file mode 100644 index 000000000..1b7068c38 --- /dev/null +++ b/libs/red-domain/src/lib/notifications-preferences/types.ts @@ -0,0 +1,8 @@ +export const EmailNotificationScheduleTypes = { + INSTANT: 'INSTANT', + DAILY: 'DAILY', + WEEKLY: 'WEEKLY', +} as const; + +export type EmailNotificationScheduleType = keyof typeof EmailNotificationScheduleTypes; +export const EmailNotificationScheduleTypesValues = Object.values(EmailNotificationScheduleTypes);