Files
zitadel/console/src/app/modules/project-role-detail-dialog/project-role-detail-dialog.component.ts
T
93e1fe0056 fix(console): better error messages (#5409)
* fix(console): better error messages

* fix: fix i18n error labels

* rollout cnsl-i18n-errors

* move errors to form-field

* fix: form control errors

* rollout validators

* translate

* replace variables

* lint

* self review

* fix confirm validation

* use help observable

* fix validation errors

* cleanup

* custom validator for idp templates

* lint

* validate on blur

* remove element

---------

Co-authored-by: Max Peintner <[email protected]>
2023-03-14 21:29:45 +00:00

64 lines
2.1 KiB
TypeScript

import { Component, Inject } from '@angular/core';
import { AbstractControl, UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import {
MatLegacyDialogRef as MatDialogRef,
MAT_LEGACY_DIALOG_DATA as MAT_DIALOG_DATA,
} from '@angular/material/legacy-dialog';
import { ManagementService } from 'src/app/services/mgmt.service';
import { ToastService } from 'src/app/services/toast.service';
import { requiredValidator } from '../form-field/validators/validators';
@Component({
selector: 'cnsl-project-role-detail-dialog',
templateUrl: './project-role-detail-dialog.component.html',
styleUrls: ['./project-role-detail-dialog.component.scss'],
})
export class ProjectRoleDetailDialogComponent {
public projectId: string = '';
public formGroup!: UntypedFormGroup;
constructor(
private mgmtService: ManagementService,
private toast: ToastService,
public dialogRef: MatDialogRef<ProjectRoleDetailDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
) {
this.projectId = data.projectId;
this.formGroup = new UntypedFormGroup({
key: new UntypedFormControl({ value: '', disabled: true }, [requiredValidator]),
displayName: new UntypedFormControl(''),
group: new UntypedFormControl(''),
});
this.formGroup.patchValue(data.role);
}
submitForm(): void {
if (this.formGroup.valid && this.key?.value && this.group?.value && this.displayName?.value) {
this.mgmtService
.updateProjectRole(this.projectId, this.key.value, this.displayName.value, this.group.value)
.then(() => {
this.toast.showInfo('PROJECT.TOAST.ROLECHANGED', true);
this.dialogRef.close(true);
})
.catch((error) => {
this.toast.showError(error);
});
}
}
public closeDialog(): void {
this.dialogRef.close(false);
}
public get key(): AbstractControl | null {
return this.formGroup.get('key');
}
public get displayName(): AbstractControl | null {
return this.formGroup.get('displayName');
}
public get group(): AbstractControl | null {
return this.formGroup.get('group');
}
}