From dd0248e7f5fc7a0fda359f81df9759cbfa583cc0 Mon Sep 17 00:00:00 2001 From: Valentin Date: Fri, 5 Nov 2021 10:13:18 +0200 Subject: [PATCH] added model --- .../notifications/notifications-screen.component.ts | 6 ++++++ .../src/app/services/notification-preferences.service.ts | 9 +++++---- .../notification-preferences.ts | 7 +++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 libs/red-domain/src/lib/notifications-preferences/notification-preferences.ts diff --git a/apps/red-ui/src/app/modules/account/screens/notifications/notifications-screen.component.ts b/apps/red-ui/src/app/modules/account/screens/notifications/notifications-screen.component.ts index 3a3c8de9d..dffef0425 100644 --- a/apps/red-ui/src/app/modules/account/screens/notifications/notifications-screen.component.ts +++ b/apps/red-ui/src/app/modules/account/screens/notifications/notifications-screen.component.ts @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { FormBuilder, FormGroup } from '@angular/forms'; import { notificationsTranslations } from '../../translations/notifications-translations'; import { NotificationPreferencesService } from '../../../../services/notification-preferences.service'; +import { LoadingService } from '../../../../../../../../libs/common-ui/src'; @Component({ selector: 'redaction-notifications-screen', @@ -23,6 +24,7 @@ export class NotificationsScreenComponent implements OnInit { constructor( private readonly _formBuilder: FormBuilder, + private readonly _loadingService: LoadingService, private readonly _notificationPreferencesService: NotificationPreferencesService, ) {} @@ -60,11 +62,15 @@ export class NotificationsScreenComponent implements OnInit { async save() { console.log('formGroup: ', this.formGroup.value); return; + this._loadingService.start(); await this._notificationPreferencesService.updateNotificationPreferences(this.formGroup.value).toPromise(); + this._loadingService.stop(); } private async _initializeForm() { + this._loadingService.start(); // const notificationPreferences = await this._notificationPreferencesService.getNotificationPreferences().toPromise(); + this._loadingService.stop(); const notificationPreferences = { emailNotificationType: 'DAILY', diff --git a/apps/red-ui/src/app/services/notification-preferences.service.ts b/apps/red-ui/src/app/services/notification-preferences.service.ts index e85a2fc91..f1528b5c2 100644 --- a/apps/red-ui/src/app/services/notification-preferences.service.ts +++ b/apps/red-ui/src/app/services/notification-preferences.service.ts @@ -2,20 +2,21 @@ import { Injectable, Injector } from '@angular/core'; import { GenericService } from '../../../../../libs/common-ui/src'; import { Observable } from 'rxjs'; import { UserService } from './user.service'; +import { INotificationPreferences } from '../../../../../libs/red-domain/src/lib/notifications-preferences/notification-preferences'; @Injectable({ providedIn: 'root', }) -export class NotificationPreferencesService extends GenericService { +export class NotificationPreferencesService extends GenericService { constructor(protected readonly _injector: Injector, private readonly _userService: UserService) { super(_injector, 'notification-preferences'); } - getNotificationPreferences(): Observable { + getNotificationPreferences(): Observable { return super.get(); } - updateNotificationPreferences(body: any): Observable { - return super._post(body); + updateNotificationPreferences(notificationPreferences: INotificationPreferences): Observable { + return super._post(notificationPreferences); } } diff --git a/libs/red-domain/src/lib/notifications-preferences/notification-preferences.ts b/libs/red-domain/src/lib/notifications-preferences/notification-preferences.ts new file mode 100644 index 000000000..a70aa9d87 --- /dev/null +++ b/libs/red-domain/src/lib/notifications-preferences/notification-preferences.ts @@ -0,0 +1,7 @@ +export interface INotificationPreferences { + emailNotificationType: 'INSTANT' | 'DAILY' | 'WEEKLY'; + emailNotifications: string[]; + emailNotificationsEnabled: boolean; + inAppNotifications: string[]; + inAppNotificationsEnabled: boolean; +}