]>
Commit | Line | Data |
---|---|---|
cb0eda56 AG |
1 | import { Subject } from 'rxjs' |
2 | import { Component, Input, OnInit } from '@angular/core' | |
3 | import { Notifier, UserService } from '@app/core' | |
4 | import { FormReactive, FormReactiveService } from '@app/shared/shared-forms' | |
5 | import { User, UserUpdateMe } from '@shared/models' | |
6 | ||
7 | @Component({ | |
8 | selector: 'my-account-email-preferences', | |
9 | templateUrl: './my-account-email-preferences.component.html', | |
10 | styleUrls: [ './my-account-email-preferences.component.scss' ] | |
11 | }) | |
12 | export class MyAccountEmailPreferencesComponent extends FormReactive implements OnInit { | |
13 | @Input() user: User = null | |
14 | @Input() userInformationLoaded: Subject<any> | |
15 | ||
16 | constructor ( | |
17 | protected formReactiveService: FormReactiveService, | |
18 | private userService: UserService, | |
19 | private notifier: Notifier | |
20 | ) { | |
21 | super() | |
22 | } | |
23 | ||
24 | ngOnInit () { | |
25 | this.buildForm({ | |
26 | 'email-public': null | |
27 | }) | |
28 | ||
29 | this.userInformationLoaded.subscribe(() => { | |
30 | this.form.patchValue({ 'email-public': this.user.emailPublic }) | |
31 | }) | |
32 | } | |
33 | ||
34 | updateEmailPublic () { | |
35 | const details: UserUpdateMe = { | |
36 | emailPublic: this.form.value['email-public'] | |
37 | } | |
38 | ||
39 | this.userService.updateMyProfile(details) | |
40 | .subscribe({ | |
41 | next: () => { | |
42 | if (details.emailPublic) this.notifier.success($localize`Email is now public`) | |
43 | else this.notifier.success($localize`Email is now private`) | |
44 | ||
45 | this.user.emailPublic = details.emailPublic | |
46 | }, | |
47 | ||
98eacc80 | 48 | error: err => this.notifier.error(err.message) |
cb0eda56 AG |
49 | }) |
50 | } | |
51 | } |