From a389dd96b449c26bcba8df7d9d19bf075c5608af Mon Sep 17 00:00:00 2001 From: Valentin Date: Thu, 21 Oct 2021 15:11:17 +0300 Subject: [PATCH] WIP on notification preferences service --- .../notifications-screen.component.ts | 19 ++++++++++++++++--- .../notification-preferences.service.ts | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 apps/red-ui/src/app/services/notification-preferences.service.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 4d2cb0084..17d820d52 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 @@ -1,7 +1,8 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { FormBuilder, FormGroup } from '@angular/forms'; import { notificationsTranslations } from '../../translations/notifications-translations'; import { NotificationPreferences } from '../../../../models/notification-preferences'; +import { NotificationPreferencesService } from '../../../../services/notification-preferences.service'; enum SendSchedule { INSTANT = 'instant', @@ -14,7 +15,7 @@ enum SendSchedule { templateUrl: './notifications-screen.component.html', styleUrls: ['./notifications-screen.component.scss'], }) -export class NotificationsScreenComponent { +export class NotificationsScreenComponent implements OnInit { readonly sendSchedules = ['instant', 'daily', 'weekly']; readonly notificationCategories = ['inAppNotifications', 'emailNotifications']; @@ -22,13 +23,20 @@ export class NotificationsScreenComponent { formGroup: FormGroup; - constructor(private readonly _formBuilder: FormBuilder) { + constructor( + private readonly _formBuilder: FormBuilder, + private readonly _notificationPreferencesService: NotificationPreferencesService, + ) { this.formGroup = this._formBuilder.group({ inAppNotifications: new FormGroup(new NotificationPreferences() as any), emailNotifications: new FormGroup(new NotificationPreferences(SendSchedule.INSTANT) as any), }); } + async ngOnInit(): Promise { + await this._initializeForm(); + } + setSchedule(schedule: string) { this.formGroup.get('emailNotifications').get('sendSchedule').setValue(schedule); } @@ -42,4 +50,9 @@ export class NotificationsScreenComponent { } save() {} + + private async _initializeForm() { + const notificationPreferences = await this._notificationPreferencesService.getNotificationPreferences().toPromise(); + console.log('notificationPreferences: ', notificationPreferences); + } } diff --git a/apps/red-ui/src/app/services/notification-preferences.service.ts b/apps/red-ui/src/app/services/notification-preferences.service.ts new file mode 100644 index 000000000..11c8c0eb2 --- /dev/null +++ b/apps/red-ui/src/app/services/notification-preferences.service.ts @@ -0,0 +1,17 @@ +import { Injectable, Injector } from '@angular/core'; +import { GenericService } from '../../../../../libs/common-ui/src'; +import { Observable } from 'rxjs'; +import { UserService } from './user.service'; + +@Injectable({ + providedIn: 'root', +}) +export class NotificationPreferencesService extends GenericService { + constructor(protected readonly _injector: Injector, private readonly _userService: UserService) { + super(_injector, 'notification-preferences'); + } + + getNotificationPreferences(): Observable { + return super._getOne([this._userService.currentUser.id]); + } +}