/** * Copyright since 2025 Mifos Initiative * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { Component, OnInit, inject } from '@angular/core'; import { UntypedFormGroup, UntypedFormBuilder, Validators } from '@angular/forms'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { MatCheckbox } from '@angular/material/checkbox'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; import { SettingsService } from 'app/settings/settings.service'; import { Dates } from 'app/core/utils/dates'; export interface NomineeDialogData { title: string; familyMemberOptions: any; member?: any; } @Component({ selector: 'mifosx-nominee-dialog', templateUrl: './nominee-dialog.component.html', styleUrls: ['./nominee-dialog.component.scss'], imports: [ ...STANDALONE_SHARED_IMPORTS, MatCheckbox ] }) export class NomineeDialogComponent implements OnInit { private formBuilder = inject(UntypedFormBuilder); private dialogRef = inject(MatDialogRef); private settingsService = inject(SettingsService); private dateUtils = inject(Dates); data: NomineeDialogData = inject(MAT_DIALOG_DATA); nomineeForm: UntypedFormGroup; maxDate = new Date(); ngOnInit() { this.maxDate = this.settingsService.businessDate; this.createForm(); } createForm() { const member = this.data.member; this.nomineeForm = this.formBuilder.group({ nominationType: [member?.nominationType || 'DA1'], firstName: [ member?.firstName || '', Validators.required ], relationshipId: [ member?.relationshipId || '', Validators.required ], dateOfBirth: [member?.dateOfBirth ? this.dateUtils.formatDate(member.dateOfBirth, 'yyyy-MM-dd') : null], percentageShare: [member?.percentageShare ?? 100], isDependent: [member?.isDependent || false], guardianName: [member?.guardianName || ''], guardianRelationship: [member?.guardianRelationship || ''], remarks: [member?.remarks || ''] }); } onSubmit() { if (this.nomineeForm.valid) { const formValue = { ...this.nomineeForm.value }; const locale = this.settingsService.language.code; const dateFormat = this.settingsService.dateFormat; if (formValue.dateOfBirth) { if (formValue.dateOfBirth instanceof Date) { formValue.dateOfBirth = this.dateUtils.formatDate(formValue.dateOfBirth, dateFormat); } } else { delete formValue.dateOfBirth; } this.dialogRef.close({ ...formValue, dateFormat, locale }); } } onCancel() { this.dialogRef.close(null); } }