diff options
Diffstat (limited to 'client/src/app/+my-account/my-account-settings/my-account-email-preferences/my-account-email-preferences.component.ts')
-rw-r--r-- | client/src/app/+my-account/my-account-settings/my-account-email-preferences/my-account-email-preferences.component.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/client/src/app/+my-account/my-account-settings/my-account-email-preferences/my-account-email-preferences.component.ts b/client/src/app/+my-account/my-account-settings/my-account-email-preferences/my-account-email-preferences.component.ts new file mode 100644 index 000000000..7fd59d7c8 --- /dev/null +++ b/client/src/app/+my-account/my-account-settings/my-account-email-preferences/my-account-email-preferences.component.ts | |||
@@ -0,0 +1,51 @@ | |||
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 | |||
48 | error: err => console.log(err.message) | ||
49 | }) | ||
50 | } | ||
51 | } | ||