updated request
This commit is contained in:
parent
dd0248e7f5
commit
0a74269d56
@ -11,7 +11,7 @@
|
||||
<div class="dialog-header">
|
||||
<div class="heading-l" translate="notifications-screen.title"></div>
|
||||
</div>
|
||||
<form (submit)="save()" [formGroup]="formGroup">
|
||||
<form (submit)="save()" [formGroup]="formGroup" *ngIf="formGroup">
|
||||
<div class="dialog-content">
|
||||
<div *ngFor="let category of notificationCategories">
|
||||
<div class="iqser-input-group header w-full">
|
||||
@ -35,7 +35,7 @@
|
||||
<div class="statement" translate="notifications-screen.options-title"></div>
|
||||
|
||||
<div class="group" *ngFor="let key of notificationGroupsKeys; let i = index">
|
||||
<div class="group-title" translate="notifications-screen.groups.{{ key }}"></div>
|
||||
<div class="group-title" [translate]="translations[key]"></div>
|
||||
<div class="iqser-input-group">
|
||||
<mat-checkbox
|
||||
*ngFor="let preference of notificationGroupsValues[i]"
|
||||
|
||||
@ -2,7 +2,8 @@ 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';
|
||||
import { LoadingService, Toaster } from '@iqser/common-ui';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-notifications-screen',
|
||||
@ -23,6 +24,7 @@ export class NotificationsScreenComponent implements OnInit {
|
||||
formGroup: FormGroup;
|
||||
|
||||
constructor(
|
||||
private readonly _toaster: Toaster,
|
||||
private readonly _formBuilder: FormBuilder,
|
||||
private readonly _loadingService: LoadingService,
|
||||
private readonly _notificationPreferencesService: NotificationPreferencesService,
|
||||
@ -60,27 +62,19 @@ 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();
|
||||
try {
|
||||
await this._notificationPreferencesService.updateNotificationPreferences(this.formGroup.value).toPromise();
|
||||
} catch (e) {
|
||||
this._toaster.error(_('notifications-screen.error.generic'));
|
||||
}
|
||||
this._loadingService.stop();
|
||||
}
|
||||
|
||||
private async _initializeForm() {
|
||||
this._loadingService.start();
|
||||
// const notificationPreferences = await this._notificationPreferencesService.getNotificationPreferences().toPromise();
|
||||
this._loadingService.stop();
|
||||
|
||||
const notificationPreferences = {
|
||||
emailNotificationType: 'DAILY',
|
||||
emailNotifications: ['documentStatusChanges', 'string'],
|
||||
emailNotificationsEnabled: true,
|
||||
inAppNotifications: ['whenADocumentIsAssignedToAReviewer', 'whenAReviewerIsUnassignedFromADocument'],
|
||||
inAppNotificationsEnabled: true,
|
||||
userId: 'string',
|
||||
};
|
||||
|
||||
const notificationPreferences = await this._notificationPreferencesService.getNotificationPreferences().toPromise();
|
||||
this.formGroup = this._formBuilder.group({
|
||||
inAppNotificationsEnabled: [notificationPreferences.inAppNotificationsEnabled],
|
||||
emailNotificationsEnabled: [notificationPreferences.emailNotificationsEnabled],
|
||||
@ -88,5 +82,7 @@ export class NotificationsScreenComponent implements OnInit {
|
||||
emailNotifications: [notificationPreferences.emailNotifications],
|
||||
inAppNotifications: [notificationPreferences.inAppNotifications],
|
||||
});
|
||||
|
||||
this._loadingService.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,4 +16,7 @@ export const notificationsTranslations: { [key: string]: string } = {
|
||||
whenAReviewerIsUnassignedFromADocument: _('notifications-screen.options.when-a-reviewer-is-unassigned-from-a-document'),
|
||||
whenIAmAssignedOnADocument: _('notifications-screen.options.when-i-am-assigned-on-a-document'),
|
||||
whenIAmUnassignedFromADocument: _('notifications-screen.options.when-i-am-unassigned-from-a-document'),
|
||||
approver: _('notifications-screen.groups.approver'),
|
||||
own: _('notifications-screen.groups.own'),
|
||||
reviewer: _('notifications-screen.groups.reviewer'),
|
||||
} as const;
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import { Injectable, Injector } from '@angular/core';
|
||||
import { GenericService } from '../../../../../libs/common-ui/src';
|
||||
import { Observable } from 'rxjs';
|
||||
import { GenericService } from '@iqser/common-ui';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { UserService } from './user.service';
|
||||
import { INotificationPreferences } from '../../../../../libs/red-domain/src/lib/notifications-preferences/notification-preferences';
|
||||
import { INotificationPreferences } from '@red/domain';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@ -12,11 +13,24 @@ export class NotificationPreferencesService extends GenericService<INotification
|
||||
super(_injector, 'notification-preferences');
|
||||
}
|
||||
|
||||
getNotificationPreferences(): Observable<INotificationPreferences[]> {
|
||||
return super.get();
|
||||
getNotificationPreferences(): Observable<INotificationPreferences> {
|
||||
return super.get().pipe(
|
||||
map(notificationPreferences => (Array.isArray(notificationPreferences) ? notificationPreferences[0] : notificationPreferences)),
|
||||
catchError(() => of(this._defaultPreferences)),
|
||||
);
|
||||
}
|
||||
|
||||
updateNotificationPreferences(notificationPreferences: INotificationPreferences): Observable<void> {
|
||||
return super._post(notificationPreferences);
|
||||
}
|
||||
|
||||
private get _defaultPreferences(): INotificationPreferences {
|
||||
return {
|
||||
emailNotificationType: 'INSTANT',
|
||||
emailNotifications: [],
|
||||
emailNotificationsEnabled: false,
|
||||
inAppNotifications: [],
|
||||
inAppNotificationsEnabled: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1287,6 +1287,9 @@
|
||||
"email-notifications": "Email Notifications",
|
||||
"in-app-notifications": "In-App Notifications"
|
||||
},
|
||||
"error": {
|
||||
"generic": "Something went wrong... Preferences update failed!"
|
||||
},
|
||||
"groups": {
|
||||
"approver": "Dossiers you are approver on",
|
||||
"own": "Dossiers you own",
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 1df1b1ab899e21093eb07c444acf90def933cb02
|
||||
Subproject commit 712178ea34c998098cd2c079a0be1dd863dd266e
|
||||
@ -6,6 +6,7 @@ export * from './lib/users';
|
||||
export * from './lib/pages';
|
||||
export * from './lib/audit';
|
||||
export * from './lib/notifications';
|
||||
export * from './lib/notifications-preferences';
|
||||
export * from './lib/dossier-templates';
|
||||
export * from './lib/dictionaries';
|
||||
export * from './lib/redaction-log';
|
||||
|
||||
@ -0,0 +1 @@
|
||||
export * from './notification-preferences';
|
||||
Loading…
x
Reference in New Issue
Block a user