import { Component, inject, signal } from "@angular/core"; import { FormBuilder, ReactiveFormsModule, Validators } from "@angular/forms"; import { Router, RouterLink } from "@angular/router"; import { MATERIAL } from "../shared/material"; import { ApiService } from "../core/api.service"; @Component({ standalone: true, imports: [ReactiveFormsModule, RouterLink, ...MATERIAL], template: `

Willkommen zurück

Ausbildungsstunden übersichtlich dokumentieren.

E-MailmailPasswortlock @if (error()) {

{{ error() }}

}
`, styles: [ ` .login { min-height: 100%; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at top left, #d9e9ff, transparent 45%), #f5f7fb; } .login mat-card { width: min(430px, 100%); padding: 24px; border-radius: 24px !important; } .logo { width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; background: #155bd7; color: #fff; font-size: 25px; font-weight: 800; } h1 { margin: 22px 0 6px; } .full { margin-top: 10px; } .error { color: #b3261e; } button.full { height: 48px; } .auth-links { display: flex; justify-content: space-between; gap: 16px; margin-top: 20px; } .auth-links a { color: #155bd7; text-decoration: none; font-weight: 500; } .legal { text-align: center; margin-top: 18px; } .legal a { color: #687287; text-decoration: none; font-size: 13px; } `, ], }) export class LoginComponent { private readonly fb = inject(FormBuilder); readonly loading = signal(false); readonly error = signal(""); readonly form = this.fb.nonNullable.group({ email: ["", [Validators.required, Validators.email]], password: ["", Validators.required], }); constructor( private api: ApiService, private router: Router, ) {} submit() { if (this.form.invalid) return; this.loading.set(true); this.error.set(""); this.api .login(this.form.value.email!, this.form.value.password!) .subscribe({ next: () => this.router.navigate(["/dashboard"]), error: (e) => { this.loading.set(false); this.error.set(e.error?.error || "Anmeldung fehlgeschlagen"); }, }); } }