feat(create-link): add create link component and routing

This commit is contained in:
Jan K9f 2025-01-20 15:11:46 +01:00
commit 00a7688ef9
Signed by: jank
GPG key ID: 50620ADD22CD330B
8 changed files with 125 additions and 1 deletions

View file

@ -0,0 +1,37 @@
import { Component } from '@angular/core';
import { NavbarComponent } from '../navbar/navbar.component';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { LinkService } from '../service/link.service';
import { Router } from '@angular/router';
@Component({
selector: 'app-create-link',
imports: [NavbarComponent, ReactiveFormsModule],
templateUrl: './create-link.component.html',
styleUrl: './create-link.component.css'
})
export class CreateLinkComponent {
public createLinkForm!: FormGroup;
public requestFailed: boolean = false;
constructor(private linkService: LinkService, private router: Router) { }
ngOnInit(): void {
this.createLinkForm = new FormGroup({
name: new FormControl(''),
link: new FormControl(''),
});
}
submit() {
this.requestFailed = false;
this.linkService.createLink({
name: this.createLinkForm.get('name')?.value,
link: this.createLinkForm.get('link')?.value,
}).catch(() => this.requestFailed = true).finally(() => {
if (!this.requestFailed) {
this.router.navigate(['dashboard']);
}
});
}
}