@@ -32,6 +32,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
32
32
selectedMonth : number ;
33
33
selectedYear : number ;
34
34
selectedMonthAsText : string ;
35
+ isActiveEntryOverlapping = false ;
35
36
constructor ( private store : Store < EntryState > , private toastrService : ToastrService , private actionsSubject$ : ActionsSubject ) {
36
37
this . timeEntriesDataSource$ = this . store . pipe ( delay ( 0 ) , select ( getTimeEntriesDataSource ) ) ;
37
38
}
@@ -104,8 +105,11 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
104
105
const isStartDateGreaterThanActiveEntry = startDateAsLocalDate > activeEntryAsLocalDate ;
105
106
const isEndDateGreaterThanActiveEntry = endDateAsLocalDate > activeEntryAsLocalDate ;
106
107
const isTimeEntryOverlapping = isStartDateGreaterThanActiveEntry || isEndDateGreaterThanActiveEntry ;
107
- if ( ! isEditingEntryEqualToActiveEntry && isTimeEntryOverlapping ) {
108
- this . toastrService . error ( 'You are on the clock and this entry overlaps it, try with earlier times.' ) ;
108
+ this . checkIfActiveEntryOverlapping ( isEditingEntryEqualToActiveEntry , startDateAsLocalDate ) ;
109
+ if ( ! isEditingEntryEqualToActiveEntry && isTimeEntryOverlapping || this . isActiveEntryOverlapping ) {
110
+ const message = this . isActiveEntryOverlapping ? 'try another "Time in"' : 'try with earlier times' ;
111
+ this . toastrService . error ( `You are on the clock and this entry overlaps it, ${ message } .` ) ;
112
+ this . isActiveEntryOverlapping = false ;
109
113
} else {
110
114
this . doSave ( event ) ;
111
115
}
@@ -170,4 +174,16 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
170
174
resetDraggablePosition ( event : any ) : void {
171
175
event . source . _dragRef . reset ( ) ;
172
176
}
177
+
178
+ checkIfActiveEntryOverlapping ( isEditingEntryEqualToActiveEntry : boolean , startDateAsLocalDate : Date ) {
179
+ if ( isEditingEntryEqualToActiveEntry ) {
180
+ this . store . pipe ( select ( getTimeEntriesDataSource ) ) . subscribe ( ds => {
181
+ const overlappingEntry = ds . data . find ( ( item ) => {
182
+ const itemEndDate = new Date ( item . end_date ) ;
183
+ return startDateAsLocalDate < itemEndDate ;
184
+ } ) ;
185
+ this . isActiveEntryOverlapping = overlappingEntry ? true : false ;
186
+ } ) ;
187
+ }
188
+ }
173
189
}
0 commit comments