feat(create-link): add create link component and routing
This commit is contained in:
parent
9bc5ed62ff
commit
00a7688ef9
8 changed files with 125 additions and 1 deletions
37
src/app/create-link/create-link.component.ts
Normal file
37
src/app/create-link/create-link.component.ts
Normal 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']);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue