73 lines
2.8 KiB
TypeScript
73 lines
2.8 KiB
TypeScript
import { CommonModule } from '@angular/common';
|
|
import { Component } from '@angular/core';
|
|
import { FormsModule } from '@angular/forms';
|
|
import { RouterModule } from '@angular/router';
|
|
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
|
|
import { User } from '../../../../../bizmatch-server/src/models/db.model';
|
|
import { ErrorResponse, KeycloakUser, MailInfo } from '../../../../../bizmatch-server/src/models/main.model';
|
|
import { AuditService } from '../../services/audit.service';
|
|
import { AuthService } from '../../services/auth.service';
|
|
import { MailService } from '../../services/mail.service';
|
|
import { MessageService } from '../../services/message.service';
|
|
import { SelectOptionsService } from '../../services/select-options.service';
|
|
import { UserService } from '../../services/user.service';
|
|
import { ValidationService } from '../../services/validation.service';
|
|
import { createMailInfo, map2User } from '../../utils/utils';
|
|
|
|
@Component({
|
|
selector: 'app-email-us',
|
|
standalone: true,
|
|
imports: [CommonModule, FormsModule, RouterModule, FontAwesomeModule],
|
|
providers: [],
|
|
templateUrl: './email-us.component.html',
|
|
styleUrl: './email-us.component.scss',
|
|
})
|
|
export class EmailUsComponent {
|
|
mailinfo: MailInfo;
|
|
keycloakUser: KeycloakUser;
|
|
user: User;
|
|
errorResponse: ErrorResponse;
|
|
constructor(
|
|
private mailService: MailService,
|
|
private userService: UserService,
|
|
public validationService: ValidationService,
|
|
private messageService: MessageService,
|
|
public selectOptions: SelectOptionsService,
|
|
private auditService: AuditService,
|
|
private authService: AuthService,
|
|
) {
|
|
this.mailinfo = createMailInfo();
|
|
}
|
|
async ngOnInit() {
|
|
const token = await this.authService.getToken();
|
|
this.keycloakUser = map2User(token);
|
|
if (this.keycloakUser) {
|
|
this.user = await this.userService.getByMail(this.keycloakUser.email);
|
|
this.mailinfo = createMailInfo(this.user);
|
|
}
|
|
}
|
|
ngOnDestroy() {
|
|
this.validationService.clearMessages(); // Löschen Sie alle bestehenden Validierungsnachrichten
|
|
}
|
|
async mail() {
|
|
try {
|
|
this.validationService.clearMessages();
|
|
this.mailinfo.email = 'support@bizmatch.net';
|
|
await this.mailService.mail(this.mailinfo);
|
|
this.messageService.addMessage({ severity: 'success', text: 'Your request has been forwarded to the support team of bizmatch.', duration: 3000 });
|
|
this.auditService.createEvent(null, 'emailus', this.mailinfo.email, this.mailinfo);
|
|
this.mailinfo = createMailInfo(this.user);
|
|
} catch (error) {
|
|
this.messageService.addMessage({
|
|
severity: 'danger',
|
|
text: 'Please check your inputs',
|
|
duration: 5000,
|
|
});
|
|
this.validationService.handleApiError(error.error);
|
|
}
|
|
}
|
|
containsError(fieldname: string) {
|
|
return this.errorResponse?.fields.map(f => f.fieldname).includes(fieldname);
|
|
}
|
|
}
|