All files / src/app/features/user/user-form user-form.component.ts

71.42% Statements 35/49
25% Branches 3/12
52.38% Functions 11/21
100% Lines 32/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 8012x 12x 12x 12x 12x 12x 12x 12x 12x   12x               12x   5x 5x 5x 5x 5x 5x       5x 5x     7x 7x 1x         7x 1x             80x       48x       48x       80x       25x       7x       1x       1x      
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { MatFormField, MatHint, MatLabel } from '@angular/material/form-field';
import { MatInput } from '@angular/material/input';
import { StatusIconComponent } from '@layout/shared/status-icon/status-icon.component';
import { InputBackendErrorsComponent } from "@layout/shared/input-backend-errors/input-backend-errors.component";
import { MatButton } from '@angular/material/button';
import { LocaleService } from '@core/services/locale.service';
import { PasswordValidator } from '@core/validators/password-validator';
import { User } from '@core/model/user.interface';
import { RouterLink } from '@angular/router';
 
@Component({
  selector: 'app-user-form',
  imports: [ReactiveFormsModule, MatButton, MatFormField, MatInput, MatLabel, MatHint, StatusIconComponent, InputBackendErrorsComponent, RouterLink],
  templateUrl: './user-form.component.html',
  styleUrl: './user-form.component.scss'
})
export class UserFormComponent implements OnInit {
  @Input() form!: FormGroup;
  @Input() user: User | null = null;
  @Input() isSubmitting = false;
  @Input() showPassword = false;
  @Input() showJobFollowUpReminderDays = false;
  @Input() submitLabel: 'Register' | 'Save' = 'Save';
  @Output() submitted = new EventEmitter<void>();
 
  public currentLang: string;
  
  constructor(private localeService: LocaleService) {
    this.currentLang = this.localeService.currentLocale.toUpperCase();
  }
  ngOnInit(): void {
    this.form.addControl('lang', new FormControl(this.currentLang, []));
    if(this.showPassword) {
      this.form.addControl('password', new FormControl('', [
        Validators.required,
        PasswordValidator
      ]));
    }
    if(this.showJobFollowUpReminderDays) {
      this.form.addControl('jobFollowUpReminderDays', new FormControl((this.user ? this.user.jobFollowUpReminderDays : 7), [
        Validators.required
      ]));
    }
  }
 
  get email() {
    return this.form.get('email');
  }
 
  get firstName() {
    return this.form.get('firstName');
  }
 
  get lastName() {
    return this.form.get('lastName');
  }
 
  get username() {
    return this.form.get('username');
  }
 
  get password() {
    return this.form.get('password');
  }
 
  get jobFollowUpReminderDays() {
    return this.form.get('jobFollowUpReminderDays');
  }
 
  get lang() {
    return this.form.get('lang');
  }
 
  submit() :void {
      this.submitted.emit();
  }
}