|
1 | 1 | import { Component, OnInit } from '@angular/core'; |
2 | 2 | import { UserPreferencesService } from '@shared/user-preferences.service'; |
3 | 3 | import { UntypedFormBuilder, UntypedFormGroup, UntypedFormControl, FormsModule, ReactiveFormsModule } from '@angular/forms'; |
4 | | -import { MatFormField, MatLabel } from '@angular/material/form-field'; |
5 | | -import { MatInput } from '@angular/material/input'; |
| 4 | +import { MatFormFieldModule } from '@angular/material/form-field'; |
| 5 | +import { MatInputModule } from '@angular/material/input'; |
| 6 | +import { AuthService } from '@shared/auth-services/auth.service'; |
| 7 | +import { MatIconModule } from "@angular/material/icon"; |
| 8 | +import { MatButtonModule } from '@angular/material/button'; |
| 9 | +import { MatSnackBar } from '@angular/material/snack-bar'; |
6 | 10 |
|
7 | 11 | @Component({ |
8 | | - selector: 'app-profile-settings', |
9 | | - templateUrl: './profile-settings.component.html', |
10 | | - styleUrls: ['./profile-settings.component.css'], |
11 | | - imports: [FormsModule, ReactiveFormsModule, MatFormField, MatLabel, MatInput] |
| 12 | + selector: 'app-profile-settings', |
| 13 | + templateUrl: './profile-settings.component.html', |
| 14 | + styleUrls: ['./profile-settings.component.css'], |
| 15 | + imports: [ |
| 16 | + FormsModule, |
| 17 | + ReactiveFormsModule, |
| 18 | + MatFormFieldModule, |
| 19 | + MatInputModule, |
| 20 | + MatButtonModule, |
| 21 | + MatIconModule, |
| 22 | + ], |
12 | 23 | }) |
13 | 24 | export class ProfileSettingsComponent implements OnInit { |
14 | | - |
15 | 25 | formBuilder: UntypedFormBuilder; |
16 | 26 | profileFormGroup: UntypedFormGroup; |
17 | 27 |
|
18 | | - |
19 | 28 | constructor( |
20 | 29 | private userPreferences: UserPreferencesService, |
21 | | - fb: UntypedFormBuilder, |
22 | | - ) { |
| 30 | + private authService: AuthService, |
| 31 | + private snackBar: MatSnackBar, |
| 32 | + fb: UntypedFormBuilder |
| 33 | + ) { |
23 | 34 | this.formBuilder = fb; |
24 | | - |
25 | 35 | } |
26 | 36 |
|
27 | 37 | ngOnInit(): void { |
28 | 38 | this.profileFormGroup = this.formBuilder.group({ |
29 | | - name: new UntypedFormControl({ value: this.userPreferences.userInfo.firstName, disabled: true }), |
30 | | - lastname: new UntypedFormControl({ value: this.userPreferences.userInfo.lastName, disabled: true }), |
31 | | - email: new UntypedFormControl({ value: this.userPreferences.userInfo.email, disabled: true }), |
32 | | - username: new UntypedFormControl({ value: this.userPreferences.userInfo.email, disabled: true }), |
33 | | - |
| 39 | + name: new UntypedFormControl({ |
| 40 | + value: this.userPreferences.userInfo.firstName, |
| 41 | + disabled: true, |
| 42 | + }), |
| 43 | + lastname: new UntypedFormControl({ |
| 44 | + value: this.userPreferences.userInfo.lastName, |
| 45 | + disabled: true, |
| 46 | + }), |
| 47 | + email: new UntypedFormControl({ |
| 48 | + value: this.userPreferences.userInfo.email, |
| 49 | + disabled: true, |
| 50 | + }), |
| 51 | + username: new UntypedFormControl({ |
| 52 | + value: this.userPreferences.userInfo.email, |
| 53 | + disabled: true, |
| 54 | + }), |
| 55 | + token: new UntypedFormControl({ |
| 56 | + value: this.authService.getScilogToken(), |
| 57 | + disabled: true, |
| 58 | + }), |
34 | 59 | }); |
35 | | - console.log(this.userPreferences.userInfo) |
36 | | - |
37 | 60 | } |
38 | 61 |
|
| 62 | + copyToClipboard() { |
| 63 | + const token = this.profileFormGroup.get('token')?.value; |
| 64 | + if (token) { |
| 65 | + navigator.clipboard |
| 66 | + .writeText(token) |
| 67 | + .then(() => { |
| 68 | + this.snackBar.open('Token copied to clipboard', 'Dismiss', { |
| 69 | + duration: 3000, |
| 70 | + verticalPosition: 'top', |
| 71 | + }); |
| 72 | + }) |
| 73 | + .catch((err) => { |
| 74 | + console.error('Failed to copy token: ', err); |
| 75 | + this.snackBar.open('Failed to copy token to clipboard', 'Dismiss', { |
| 76 | + duration: 3000, |
| 77 | + verticalPosition: 'top', |
| 78 | + }); |
| 79 | + }); |
| 80 | + } |
| 81 | + } |
39 | 82 | } |
0 commit comments