57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
import {Component, OnInit} from '@angular/core';
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
import {TuiAlertService, TuiButton} from '@taiga-ui/core';
|
|
import {NgIf} from '@angular/common';
|
|
import {CompanyService} from '../../services/company.service';
|
|
import {Company} from '../../models/company';
|
|
import {AgendaService} from '../../services/agenda.service';
|
|
import {InviteEntity} from '../../models/invite-entity';
|
|
import {CompanyDTO} from '../../models/app-user-dto';
|
|
import {UserService} from '../../services/user.service';
|
|
|
|
@Component({
|
|
selector: 'app-agenda-invite',
|
|
imports: [
|
|
TuiButton,
|
|
NgIf
|
|
],
|
|
templateUrl: './agenda-invite.component.html',
|
|
styleUrl: './agenda-invite.component.scss'
|
|
})
|
|
export class AgendaInviteComponent implements OnInit {
|
|
token: string = '';
|
|
agendaName: string = '...';
|
|
company: CompanyDTO;
|
|
inviteEntity: InviteEntity;
|
|
inviteExpired: boolean = false;
|
|
|
|
constructor(private route: ActivatedRoute, private router: Router, private companyService: CompanyService, private agendaService: AgendaService, private userService: UserService, private alerts: TuiAlertService) {
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.token = this.route.snapshot.queryParamMap.get('token');
|
|
this.agendaService.verifyInvite(this.token).subscribe({
|
|
next: (invite: InviteEntity) => {
|
|
this.inviteEntity = invite
|
|
this.companyService.getCompany(invite.company_id).subscribe(companyResponse => {
|
|
this.company = companyResponse;
|
|
})
|
|
},
|
|
error: (error) => {
|
|
if (error.status === 410) {
|
|
this.inviteExpired = true;
|
|
}
|
|
},
|
|
});
|
|
}
|
|
|
|
acceptInvite(): void {
|
|
this.companyService.linkCompany(this.userService.userValue.id, this.inviteEntity.token).subscribe(
|
|
() => {
|
|
this.alerts.open(`Agenda ${this.company.name} is toegevoegd.`).subscribe();
|
|
this.router.navigate(['home/agenda']);
|
|
}
|
|
)
|
|
}
|
|
}
|