Skip to content

Commit 86ed023

Browse files
committed
fix: ioet#313 fix bug on entries creation when no clock-in
1 parent c35e0d0 commit 86ed023

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/app/modules/time-entries/pages/time-entries.component.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)