@@ -31,6 +31,11 @@ import { formatDateForApi } from '../../../../shared/utils/api-date-formatter';
31
31
import { RevertToDraftDialogComponent } from './revert-to-draft-dialog/revert-to-draft-dialog.component' ;
32
32
import { ApplicationConditionWithStatus , getEndDate } from '../../../../shared/utils/decision-methods' ;
33
33
import { openFileInline } from '../../../../shared/utils/file' ;
34
+ import { UserService } from '../../../../services/user/user.service' ;
35
+ import { UserDto } from '../../../../services/user/user.dto' ;
36
+ import { FlagDialogComponent , FlagDialogIO } from '../../../../shared/flag-dialog/flag-dialog.component' ;
37
+ import { UpdateApplicationDecisionDto } from '../../../../services/application/decision/application-decision-v2/application-decision-v2.dto' ;
38
+ import moment from 'moment' ;
34
39
35
40
type LoadingDecision = ApplicationDecisionWithLinkedResolutionDto & {
36
41
loading : boolean ;
@@ -67,6 +72,7 @@ export class DecisionV2Component implements OnInit, OnDestroy {
67
72
isSummary = false ;
68
73
69
74
conditions : Record < string , ApplicationConditionWithStatus [ ] > = { } ;
75
+ profile : UserDto | undefined ;
70
76
71
77
constructor (
72
78
public dialog : MatDialog ,
@@ -78,6 +84,7 @@ export class DecisionV2Component implements OnInit, OnDestroy {
78
84
private router : Router ,
79
85
private activatedRouter : ActivatedRoute ,
80
86
private elementRef : ElementRef ,
87
+ private userService : UserService ,
81
88
) { }
82
89
83
90
ngOnInit ( ) : void {
@@ -90,6 +97,10 @@ export class DecisionV2Component implements OnInit, OnDestroy {
90
97
this . application = application ;
91
98
}
92
99
} ) ;
100
+
101
+ this . userService . $userProfile . pipe ( takeUntil ( this . $destroy ) ) . subscribe ( ( profile ) => {
102
+ this . profile = profile ;
103
+ } ) ;
93
104
}
94
105
95
106
async loadDecisions ( fileNumber : string ) {
@@ -324,4 +335,81 @@ export class DecisionV2Component implements OnInit, OnDestroy {
324
335
return DECISION_CONDITION_ONGOING_LABEL ;
325
336
}
326
337
}
338
+
339
+ async flag ( decision : ApplicationDecisionWithLinkedResolutionDto , isEditing : boolean ) {
340
+ this . dialog
341
+ . open ( FlagDialogComponent , {
342
+ minWidth : '800px' ,
343
+ maxWidth : '800px' ,
344
+ maxHeight : '80vh' ,
345
+ width : '90%' ,
346
+ autoFocus : false ,
347
+ data : {
348
+ isEditing,
349
+ decisionNumber : decision . index ,
350
+ reasonFlagged : decision . reasonFlagged ,
351
+ followUpAt : decision . followUpAt ,
352
+ } ,
353
+ } )
354
+ . beforeClosed ( )
355
+ . subscribe ( async ( { isEditing, reasonFlagged, followUpAt, isSaving } : FlagDialogIO ) => {
356
+ if ( isSaving ) {
357
+ const updateDto : UpdateApplicationDecisionDto = {
358
+ isDraft : decision . isDraft ,
359
+ isFlagged : true ,
360
+ reasonFlagged,
361
+ flagEditedByUuid : this . profile ?. uuid ,
362
+ flagEditedAt : moment ( ) . toDate ( ) . getTime ( ) ,
363
+ } ;
364
+
365
+ if ( ! isEditing ) {
366
+ updateDto . flaggedByUuid = this . profile ?. uuid ;
367
+ }
368
+
369
+ if ( followUpAt !== undefined ) {
370
+ updateDto . followUpAt = followUpAt ;
371
+ }
372
+
373
+ await this . decisionService . update ( decision . uuid , updateDto ) ;
374
+ await this . loadDecisions ( this . fileNumber ) ;
375
+ }
376
+ } ) ;
377
+ }
378
+
379
+ async unflag ( decision : ApplicationDecisionWithLinkedResolutionDto ) {
380
+ this . confirmationDialogService
381
+ . openDialog ( {
382
+ title : `Unflag Decision #${ decision . index } ` ,
383
+ body : `<strong>Warning:</strong> Only remove if flagged in error.
384
+ <br>
385
+ <br>
386
+ This action will also remove the follow-up date and explanatory text
387
+ associated with the flag and cannot be undone.
388
+ <br>
389
+ <br>
390
+ Are you sure you want to remove the flag?` ,
391
+ } )
392
+ . subscribe ( async ( confirmed ) => {
393
+ if ( confirmed ) {
394
+ await this . decisionService . update ( decision . uuid , {
395
+ isDraft : decision . isDraft ,
396
+ isFlagged : false ,
397
+ reasonFlagged : null ,
398
+ followUpAt : null ,
399
+ flaggedByUuid : null ,
400
+ flagEditedByUuid : null ,
401
+ flagEditedAt : null ,
402
+ } ) ;
403
+ await this . loadDecisions ( this . fileNumber ) ;
404
+ }
405
+ } ) ;
406
+ }
407
+
408
+ formatDate ( timestamp ?: number | null , includeTime = false ) : string {
409
+ if ( timestamp === undefined || timestamp === null ) {
410
+ return '' ;
411
+ }
412
+
413
+ return moment ( new Date ( timestamp ) ) . format ( `YYYY-MMM-DD ${ includeTime ? 'hh:mm:ss A' : '' } ` ) ;
414
+ }
327
415
}
0 commit comments