WIP on notification preferences service

This commit is contained in:
Valentin 2021-10-21 15:11:17 +03:00
parent 4ab4aa6296
commit a389dd96b4
2 changed files with 33 additions and 3 deletions

View File

@ -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<void> {
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);
}
}

View File

@ -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<any> {
constructor(protected readonly _injector: Injector, private readonly _userService: UserService) {
super(_injector, 'notification-preferences');
}
getNotificationPreferences(): Observable<any> {
return super._getOne([this._userService.currentUser.id]);
}
}