@ -1,6 +1,14 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { ChangeDetectionStrategy , Component , input , OnDestroy , OnInit } from "@angular/core" ;
import {
ChangeDetectionStrategy ,
Component ,
effect ,
input ,
OnDestroy ,
OnInit ,
output ,
} from "@angular/core" ;
import { FormControl , FormGroup , Validators } from "@angular/forms" ;
import { SharedModule } from "../../../shared" ;
@ -18,18 +26,45 @@ export class SendAccessEmailComponent implements OnInit, OnDestroy {
protected otp : FormControl ;
readonly loading = input . required < boolean > ( ) ;
readonly backToEmail = output < void > ( ) ;
constructor ( ) { }
ngOnInit() {
this . email = new FormControl ( "" , Validators . required ) ;
this . otp = new FormControl ( "" , Validators . required );
this . otp = new FormControl ( "" );
this . formGroup ( ) . addControl ( "email" , this . email ) ;
this . formGroup ( ) . addControl ( "otp" , this . otp ) ;
}
// Update validators when enterOtp changes
effect ( ( ) = > {
const isOtpMode = this . enterOtp ( ) ;
if ( isOtpMode ) {
// In OTP mode: email is not required (already entered), otp is required
this . email . clearValidators ( ) ;
this . otp . setValidators ( [ Validators . required ] ) ;
} else {
// In email mode: email is required, otp is not required
this . email . setValidators ( [ Validators . required ] ) ;
this . otp . clearValidators ( ) ;
}
this . email . updateValueAndValidity ( ) ;
this . otp . updateValueAndValidity ( ) ;
} ) ;
}
ngOnDestroy() {
this . formGroup ( ) . removeControl ( "email" ) ;
this . formGroup ( ) . removeControl ( "otp" ) ;
}
onBackClick() {
this . backToEmail . emit ( ) ;
if ( this . otp ) {
this . otp . clearValidators ( ) ;
this . otp . setValue ( "" ) ;
this . otp . setErrors ( null ) ;
this . otp . markAsUntouched ( ) ;
this . otp . markAsPristine ( ) ;
}
}
}