Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,27 @@ export class TimeEntriesComponent implements OnInit {
}

saveEntry(entry): void {
const entryDateAsIso = new Date(entry.start_date).toISOString();
const entryDateAsLocalDate = new Date(entryDateAsIso);
const activeEntryAsLocaldate = new Date(this.activeTimeEntry.start_date);
const isEditingActiveEntry = this.entryId === this.activeTimeEntry.id;
if (!isEditingActiveEntry && entryDateAsLocalDate > activeEntryAsLocaldate) {
this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.');
} else {
if (this.entryId) {
entry.id = this.entryId;
this.store.dispatch(new entryActions.UpdateActiveEntry(entry));
if (this.activeTimeEntry !== null) {
const entryDateAsIso = new Date(entry.start_date).toISOString();
const entryDateAsLocalDate = new Date(entryDateAsIso);
const activeEntryAsLocaldate = new Date(this.activeTimeEntry.start_date);
const isEditingActiveEntry = this.entryId === this.activeTimeEntry.id;
if (!isEditingActiveEntry && entryDateAsLocalDate > activeEntryAsLocaldate) {
this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.');
} else {
this.store.dispatch(new entryActions.CreateEntry(entry));
this.doSave(entry);
}
} else {
this.doSave(entry);
}
}

doSave(entry) {
if (this.entryId) {
entry.id = this.entryId;
this.store.dispatch(new entryActions.UpdateActiveEntry(entry));
} else {
this.store.dispatch(new entryActions.CreateEntry(entry));
}
}

Expand Down