Skip to content

Commit 2b5e1a4

Browse files
committed
fix: #203 Update-customer-for-active-clock-ins
1 parent 2563e2b commit 2b5e1a4

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.spec.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ProjectListHoverComponent } from './project-list-hover.component';
77
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
88
import { getCustomerProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
99
import { FilterProjectPipe } from '../../../shared/pipes';
10+
import { CreateEntry, UpdateActiveEntry } from '../../store/entry.actions';
1011

1112
describe('ProjectListHoverComponent', () => {
1213
let component: ProjectListHoverComponent;
@@ -58,12 +59,37 @@ describe('ProjectListHoverComponent', () => {
5859
expect(component).toBeTruthy();
5960
});
6061

61-
it('clock-in dispatchs a new action', () => {
62+
it('clock-in dispatchs a CreateEntry action', () => {
63+
const entry = {
64+
project_id: '2b87372b-3d0d-4dc0-832b-ae5863cd39e5',
65+
start_date: new Date().toISOString(),
66+
};
67+
68+
component.activeEntry = null;
69+
spyOn(store, 'dispatch');
70+
71+
component.clockIn('2b87372b-3d0d-4dc0-832b-ae5863cd39e5');
72+
73+
expect(store.dispatch).toHaveBeenCalledWith(new CreateEntry(entry));
74+
});
75+
76+
it('clock-in dispatchs a UpdateActiveEntry action', () => {
77+
const entry = {
78+
id: '123',
79+
project_id: '2b87372b-3d0d-4dc0-832b-ae5863cd39e5',
80+
start_date: new Date().toISOString(),
81+
};
82+
const updatedEntry = {
83+
id: '123',
84+
project_id: '123372b-3d0d-4dc0-832b-ae5863cd39e5',
85+
};
86+
87+
component.activeEntry = entry;
6288
spyOn(store, 'dispatch');
6389

64-
component.clockIn('id');
90+
component.clockIn('123372b-3d0d-4dc0-832b-ae5863cd39e5');
6591

66-
expect(store.dispatch).toHaveBeenCalled();
92+
expect(store.dispatch).toHaveBeenCalledWith(new UpdateActiveEntry(updatedEntry));
6793
});
6894

6995
});

src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class ProjectListHoverComponent implements OnInit {
2222
showButton = '';
2323
keyword = 'name';
2424
nameActiveProject: string;
25+
activeEntry;
2526

2627
constructor(private store: Store<ProjectState>, private toastr: ToastrService) { }
2728

@@ -33,13 +34,13 @@ export class ProjectListHoverComponent implements OnInit {
3334
this.listProjects = projects;
3435
this.loadActiveTimeEntry();
3536
});
36-
3737
}
3838

3939
private loadActiveTimeEntry() {
4040
this.store.dispatch(new entryActions.LoadActiveEntry());
4141
const activeEntry$ = this.store.pipe(select(getActiveTimeEntry));
4242
activeEntry$.subscribe((activeEntry) => {
43+
this.activeEntry = activeEntry;
4344
if (activeEntry) {
4445
for (const project of this.listProjects) {
4546
if (project.id === activeEntry.project_id) {
@@ -54,8 +55,13 @@ export class ProjectListHoverComponent implements OnInit {
5455
}
5556

5657
clockIn(id: string) {
57-
const newEntry = { project_id: id, start_date: new Date().toISOString() };
58-
this.store.dispatch(new entryActions.CreateEntry(newEntry));
59-
this.toastr.success('You just clocked-in');
58+
if (this.activeEntry) {
59+
const entry = {id: this.activeEntry.id, project_id: id};
60+
this.store.dispatch(new entryActions.UpdateActiveEntry(entry));
61+
} else {
62+
const newEntry = { project_id: id, start_date: new Date().toISOString() };
63+
this.store.dispatch(new entryActions.CreateEntry(newEntry));
64+
this.toastr.success('You just clocked-in');
65+
}
6066
}
6167
}

0 commit comments

Comments
 (0)