-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsetup.component.ts
More file actions
69 lines (62 loc) · 1.81 KB
/
Copy pathsetup.component.ts
File metadata and controls
69 lines (62 loc) · 1.81 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { CommonModule } from '@angular/common';
import { Component, inject, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { Router } from '@angular/router';
import { EmailValidationDirective } from 'src/app/directives/emailValidator.directive';
import { SelfhostedService } from 'src/app/services/selfhosted.service';
import { AlertComponent } from '../ui-components/alert/alert.component';
import { UserPasswordComponent } from '../ui-components/user-password/user-password.component';
@Component({
selector: 'app-setup',
templateUrl: './setup.component.html',
styleUrls: ['./setup.component.css'],
imports: [
CommonModule,
FormsModule,
MatFormFieldModule,
MatInputModule,
MatButtonModule,
EmailValidationDirective,
AlertComponent,
UserPasswordComponent,
],
})
export class SetupComponent {
private _selfhostedService = inject(SelfhostedService);
private _router = inject(Router);
protected email = signal('');
protected password = signal('');
protected submitting = signal(false);
onEmailChange(value: string): void {
this.email.set(value);
}
onPasswordChange(value: string): void {
this.password.set(value);
}
createAdminAccount(): void {
if (!this.email() || !this.password()) {
return;
}
this.submitting.set(true);
this._selfhostedService
.createInitialUser({
email: this.email(),
password: this.password(),
})
.subscribe({
next: () => {
this.submitting.set(false);
this._router.navigate(['/login']);
},
error: () => {
this.submitting.set(false);
},
complete: () => {
this.submitting.set(false);
},
});
}
}