Files
zitadel/console/src/app/pages/users/user-detail/contact/contact.component.ts
T
b099a26a16 feat(console): MDC components (#6482)
mdc components

---------

Co-authored-by: Elio Bischof <[email protected]>
2023-10-26 08:29:06 +00:00

85 lines
2.7 KiB
TypeScript

import { Component, EventEmitter, Input, Output } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { WarnDialogComponent } from 'src/app/modules/warn-dialog/warn-dialog.component';
import { Human, UserState } from 'src/app/proto/generated/zitadel/user_pb';
import { GrpcAuthService } from 'src/app/services/grpc-auth.service';
import { CodeDialogComponent } from '../auth-user-detail/code-dialog/code-dialog.component';
import { EditDialogType } from '../auth-user-detail/edit-dialog/edit-dialog.component';
@Component({
selector: 'cnsl-contact',
templateUrl: './contact.component.html',
styleUrls: ['./contact.component.scss'],
})
export class ContactComponent {
@Input() disablePhoneCode: boolean = false;
@Input() canWrite: boolean | null = false;
@Input() human?: Human.AsObject;
@Input() username: string = '';
@Input() state!: UserState;
@Output() editType: EventEmitter<EditDialogType> = new EventEmitter<EditDialogType>();
@Output() resendEmailVerification: EventEmitter<void> = new EventEmitter<void>();
@Output() resendPhoneVerification: EventEmitter<void> = new EventEmitter<void>();
@Output() enteredPhoneCode: EventEmitter<string> = new EventEmitter<string>();
@Output() deletedPhone: EventEmitter<void> = new EventEmitter<void>();
public UserState: any = UserState;
public EditDialogType: any = EditDialogType;
constructor(
private dialog: MatDialog,
private authService: GrpcAuthService,
) {}
async emitDeletePhone(): Promise<void> {
const { resultList } = await this.authService.listMyMultiFactors();
const hasSMSOTP = !!resultList.find((mfa) => mfa.otpSms);
const dialogRef = this.dialog.open(WarnDialogComponent, {
data: {
confirmKey: 'ACTIONS.DELETE',
cancelKey: 'ACTIONS.CANCEL',
titleKey: 'USER.LOGINMETHODS.PHONE.DELETETITLE',
descriptionKey: 'USER.LOGINMETHODS.PHONE.DELETEDESC',
warnSectionKey: hasSMSOTP ? 'USER.LOGINMETHODS.PHONE.OTPSMSREMOVALWARNING' : '',
},
width: '400px',
});
dialogRef.afterClosed().subscribe((resp) => {
if (resp) {
this.deletedPhone.emit();
}
});
}
emitEmailVerification(): void {
this.resendEmailVerification.emit();
}
emitPhoneVerification(): void {
this.resendPhoneVerification.emit();
}
public enterCode(): void {
if (this.human) {
const dialogRef = this.dialog.open(CodeDialogComponent, {
data: {
number: this.human.phone,
},
width: '400px',
});
dialogRef.afterClosed().subscribe((code) => {
if (code) {
this.enteredPhoneCode.emit(code);
}
});
}
}
public openEditDialog(type: EditDialogType): void {
this.editType.emit(type);
}
}