WIP on notification preferences service
This commit is contained in:
parent
4ab4aa6296
commit
a389dd96b4
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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]);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user