@@ -32,6 +32,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
3232 selectedMonth : number ;
3333 selectedYear : number ;
3434 selectedMonthAsText : string ;
35+ isActiveEntryOverlapping = false ;
3536 constructor ( private store : Store < EntryState > , private toastrService : ToastrService , private actionsSubject$ : ActionsSubject ) {
3637 this . timeEntriesDataSource$ = this . store . pipe ( delay ( 0 ) , select ( getTimeEntriesDataSource ) ) ;
3738 }
@@ -104,8 +105,11 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
104105 const isStartDateGreaterThanActiveEntry = startDateAsLocalDate > activeEntryAsLocalDate ;
105106 const isEndDateGreaterThanActiveEntry = endDateAsLocalDate > activeEntryAsLocalDate ;
106107 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 ;
109113 } else {
110114 this . doSave ( event ) ;
111115 }
@@ -170,4 +174,16 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
170174 resetDraggablePosition ( event : any ) : void {
171175 event . source . _dragRef . reset ( ) ;
172176 }
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+ }
173189}
0 commit comments