File tree Expand file tree Collapse file tree 1 file changed +19
-11
lines changed
src/app/modules/time-entries/pages Expand file tree Collapse file tree 1 file changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -43,19 +43,27 @@ export class TimeEntriesComponent implements OnInit {
4343 }
4444
4545 saveEntry ( entry ) : void {
46- const entryDateAsIso = new Date ( entry . start_date ) . toISOString ( ) ;
47- const entryDateAsLocalDate = new Date ( entryDateAsIso ) ;
48- const activeEntryAsLocaldate = new Date ( this . activeTimeEntry . start_date ) ;
49- const isEditingActiveEntry = this . entryId === this . activeTimeEntry . id ;
50- if ( ! isEditingActiveEntry && entryDateAsLocalDate > activeEntryAsLocaldate ) {
51- this . toastrService . error ( 'You are on the clock and this entry overlaps it, try with earlier times.' ) ;
52- } else {
53- if ( this . entryId ) {
54- entry . id = this . entryId ;
55- this . store . dispatch ( new entryActions . UpdateActiveEntry ( entry ) ) ;
46+ if ( this . activeTimeEntry !== null ) {
47+ const entryDateAsIso = new Date ( entry . start_date ) . toISOString ( ) ;
48+ const entryDateAsLocalDate = new Date ( entryDateAsIso ) ;
49+ const activeEntryAsLocaldate = new Date ( this . activeTimeEntry . start_date ) ;
50+ const isEditingActiveEntry = this . entryId === this . activeTimeEntry . id ;
51+ if ( ! isEditingActiveEntry && entryDateAsLocalDate > activeEntryAsLocaldate ) {
52+ this . toastrService . error ( 'You are on the clock and this entry overlaps it, try with earlier times.' ) ;
5653 } else {
57- this . store . dispatch ( new entryActions . CreateEntry ( entry ) ) ;
54+ this . doSave ( entry ) ;
5855 }
56+ } else {
57+ this . doSave ( entry ) ;
58+ }
59+ }
60+
61+ doSave ( entry ) {
62+ if ( this . entryId ) {
63+ entry . id = this . entryId ;
64+ this . store . dispatch ( new entryActions . UpdateActiveEntry ( entry ) ) ;
65+ } else {
66+ this . store . dispatch ( new entryActions . CreateEntry ( entry ) ) ;
5967 }
6068 }
6169
You can’t perform that action at this time.
0 commit comments