1
1
import { Component , Inject } from '@angular/core' ;
2
2
import { MAT_DIALOG_DATA , MatDialogRef } from '@angular/material/dialog' ;
3
+ import {
4
+ ApplicationDecisionConditionTypeDto ,
5
+ DateLabel ,
6
+ } from '../../../../services/application/decision/application-decision-v2/application-decision-v2.dto' ;
3
7
import { ApplicationDecisionConditionTypesService } from '../../../../services/application/application-decision-condition-types/application-decision-condition-types.service' ;
8
+ import { FormControl , FormGroup , Validators } from '@angular/forms' ;
4
9
import { DecisionDialogDataInterface } from '../decision-dialog-data.interface' ;
5
10
import { NoticeofIntentDecisionConditionTypesService } from '../../../../services/notice-of-intent/notice-of-intent-decision-condition-types/notice-of-intent-decision-condition-types.service' ;
6
11
@@ -10,37 +15,91 @@ import { NoticeofIntentDecisionConditionTypesService } from '../../../../service
10
15
styleUrls : [ './decision-condition-types-dialog.component.scss' ] ,
11
16
} )
12
17
export class DecisionConditionTypesDialogComponent {
13
- description = '' ;
14
- label = '' ;
15
- code = '' ;
18
+ conditionTypeForm : FormGroup ;
16
19
17
20
isLoading = false ;
18
21
isEdit = false ;
22
+ showWarning = false ;
23
+
19
24
service : ApplicationDecisionConditionTypesService | NoticeofIntentDecisionConditionTypesService | undefined ;
25
+
20
26
constructor (
21
27
@Inject ( MAT_DIALOG_DATA ) public data : DecisionDialogDataInterface | undefined ,
22
28
private dialogRef : MatDialogRef < DecisionConditionTypesDialogComponent > ,
23
29
) {
24
30
this . service = data ?. service ;
25
- if ( data ?. content ) {
26
- this . description = data . content . description ;
27
- this . label = data . content . label ;
28
- this . code = data . content . code ;
29
- }
30
31
this . isEdit = ! ! data ?. content ;
32
+ this . conditionTypeForm = new FormGroup ( {
33
+ description : new FormControl ( this . data ?. content ?. description ? this . data . content . description : '' , [
34
+ Validators . required ,
35
+ ] ) ,
36
+ label : new FormControl ( this . data ?. content ?. label ? this . data . content . label : '' , [ Validators . required ] ) ,
37
+ code : new FormControl ( this . data ?. content ?. code ? this . data . content . code : '' , [ Validators . required ] ) ,
38
+ isComponentToConditionChecked : new FormControl (
39
+ this . data ?. content ?. isComponentToConditionChecked ? this . data . content . isComponentToConditionChecked : true ,
40
+ ) ,
41
+ isDescriptionChecked : new FormControl (
42
+ this . data ?. content ?. isDescriptionChecked ? this . data . content . isDescriptionChecked : true ,
43
+ ) ,
44
+ isAdministrativeFeeAmountChecked : new FormControl (
45
+ this . data ?. content ?. isAdministrativeFeeAmountChecked
46
+ ? this . data . content . isAdministrativeFeeAmountChecked
47
+ : false ,
48
+ ) ,
49
+ isAdministrativeFeeAmountRequired : new FormControl (
50
+ this . data ?. content ?. isAdministrativeFeeAmountRequired
51
+ ? this . data . content . isAdministrativeFeeAmountRequired
52
+ : false ,
53
+ ) ,
54
+ administrativeFeeAmount : new FormControl (
55
+ this . data ?. content ?. administrativeFeeAmount ? this . data . content . administrativeFeeAmount : '' ,
56
+ ) ,
57
+ isSingleDateChecked : new FormControl (
58
+ this . data ?. content ?. isSingleDateChecked ? this . data . content . isSingleDateChecked : false ,
59
+ ) ,
60
+ isSingleDateRequired : new FormControl (
61
+ this . data ?. content ?. isSingleDateRequired ? this . data . content . isSingleDateRequired : false ,
62
+ ) ,
63
+ singleDateLabel : new FormControl (
64
+ this . data ?. content ?. singleDateLabel ? this . data . content . singleDateLabel : DateLabel . DUE_DATE ,
65
+ ) ,
66
+ isSecurityAmountChecked : new FormControl (
67
+ this . data ?. content ?. isSecurityAmountChecked ? this . data . content . isSecurityAmountChecked : false ,
68
+ ) ,
69
+ isSecurityAmountRequired : new FormControl (
70
+ this . data ?. content ?. isSecurityAmountRequired ? this . data . content . isSecurityAmountRequired : false ,
71
+ ) ,
72
+ } ) ;
73
+
74
+ this . conditionTypeForm . get ( 'isComponentToConditionChecked' ) ?. disable ( ) ;
75
+ this . conditionTypeForm . get ( 'isDescriptionChecked' ) ?. disable ( ) ;
76
+ }
77
+
78
+ ngOnInit ( ) : void {
79
+ this . conditionTypeForm . valueChanges . subscribe ( ( ) => {
80
+ this . showWarning = this . isEdit ? true : false ;
81
+ } ) ;
31
82
}
32
83
33
84
async onSubmit ( ) {
34
85
this . isLoading = true ;
35
86
36
- const dto = {
37
- code : this . code ,
38
- label : this . label ,
39
- description : this . description ,
87
+ const dto : ApplicationDecisionConditionTypeDto | NoticeofIntentDecisionConditionTypesService = {
88
+ code : this . conditionTypeForm . get ( 'code' ) ?. value ,
89
+ label : this . conditionTypeForm . get ( 'label' ) ?. value ,
90
+ description : this . conditionTypeForm . get ( 'description' ) ?. value ,
91
+ isAdministrativeFeeAmountChecked : this . conditionTypeForm . get ( 'isAdministrativeFeeAmountChecked' ) ?. value ,
92
+ isAdministrativeFeeAmountRequired : this . conditionTypeForm . get ( 'isAdministrativeFeeAmountRequired' ) ?. value ,
93
+ administrativeFeeAmount : this . conditionTypeForm . get ( 'administrativeFeeAmount' ) ?. value ,
94
+ isSingleDateChecked : this . conditionTypeForm . get ( 'isSingleDateChecked' ) ?. value ,
95
+ isSingleDateRequired : this . conditionTypeForm . get ( 'isSingleDateRequired' ) ?. value ,
96
+ singleDateLabel : this . conditionTypeForm . get ( 'singleDateLabel' ) ?. value ,
97
+ isSecurityAmountChecked : this . conditionTypeForm . get ( 'isSecurityAmountChecked' ) ?. value ,
98
+ isSecurityAmountRequired : this . conditionTypeForm . get ( 'isSecurityAmountRequired' ) ?. value ,
40
99
} ;
41
100
if ( ! this . service ) return ;
42
101
if ( this . isEdit ) {
43
- await this . service . update ( this . code , dto ) ;
102
+ await this . service . update ( dto . code , dto ) ;
44
103
} else {
45
104
await this . service . create ( dto ) ;
46
105
}
0 commit comments