eeg_portal/eeg_frontend/src/app/pages/register/register.ts
Bernhard Müller a90b7ecc7e fix(frontend): replace alert() with ToastService, remove console.*, fix UI bugs
- Replace alert() with ToastService in admin-user-approval and admin-energy-community
- Remove all console.error/console.warn statements from components and guards
- Fix admin-energy-community modal title (now shows 'Bearbeiten' in edit mode)
- Fix admin-user-approval table header ('Zählpunkt' -> 'Status')
- Remove broken header nav links (#so-gehts, #faq) that pointed to non-existent sections
2026-07-22 09:25:50 +02:00

88 lines
2.8 KiB
TypeScript

import {Component, inject} from '@angular/core';
import {FormBuilder, ReactiveFormsModule, Validators} from '@angular/forms';
import {MatFormFieldModule} from '@angular/material/form-field';
import {MatInputModule} from '@angular/material/input';
import {MatButtonModule} from '@angular/material/button';
import {MatIconModule} from '@angular/material/icon';
import {MatButtonToggleModule} from '@angular/material/button-toggle';
import {AuthenticationService, RegistrationRequest, UserProfileResponse} from '../../api';
import {RouterLink} from '@angular/router';
import ParticipantTypeEnum = UserProfileResponse.ParticipantTypeEnum;
@Component({
selector: 'app-register',
standalone: true,
imports: [
ReactiveFormsModule,
MatFormFieldModule,
MatInputModule,
MatButtonModule,
MatIconModule,
MatButtonToggleModule,
RouterLink
],
templateUrl: './register.html',
styleUrls: ['./register.scss']
})
export class Register {
private fb = inject(FormBuilder);
private authService = inject(AuthenticationService);
// Für die Toggle-Buttons im Template
readonly ParticipantType = RegistrationRequest.ParticipantTypeEnum;
registeredSuccessfully = false;
accountForm = this.fb.group({
participantType: this.fb.control<ParticipantTypeEnum>(
RegistrationRequest.ParticipantTypeEnum.Private,
{nonNullable: true, validators: Validators.required}
),
organizationName: [''],
firstName: ['', Validators.required],
lastName: ['', Validators.required],
email: ['', [Validators.required, Validators.email]],
password: ['', [Validators.required, Validators.minLength(8)]]
});
constructor() {
this.accountForm.get('participantType')!.valueChanges.subscribe(type => {
const orgControl = this.accountForm.get('organizationName')!;
if (type === RegistrationRequest.ParticipantTypeEnum.Company) {
orgControl.setValidators([Validators.required]);
} else {
orgControl.clearValidators();
}
orgControl.updateValueAndValidity();
});
}
get isCompany(): boolean {
return this.accountForm.value.participantType === RegistrationRequest.ParticipantTypeEnum.Company;
}
onSubmit() {
if (this.accountForm.invalid) {
this.accountForm.markAllAsTouched();
return;
}
const registrationData: RegistrationRequest = {
participantType: this.accountForm.value.participantType!,
firstName: this.accountForm.value.firstName!,
lastName: this.accountForm.value.lastName!,
organizationName: this.accountForm.value.organizationName || undefined,
email: this.accountForm.value.email!,
password: this.accountForm.value.password!
};
this.authService.register(registrationData).subscribe({
next: () => {
this.registeredSuccessfully = true;
},
error: () => {
}
});
}
}