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