Skip to content

Commit d2a4d5f

Browse files
committed
TT-52 fix: date out takes date in when goingToWorkOnThis is false
1 parent df0ae39 commit d2a4d5f

File tree

2 files changed

+43
-32
lines changed

2 files changed

+43
-32
lines changed

src/app/modules/shared/components/details-fields/details-fields.component.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,19 +245,25 @@ describe('DetailsFieldsComponent', () => {
245245
expect(component.saveEntry.emit).toHaveBeenCalledWith(data);
246246
});
247247

248-
it('when the current entry is not running, then the end hour input should be rendered', () => {
248+
it('when the current entry is not running, then the end date and end hour inputs should be rendered', () => {
249249
component.goingToWorkOnThis = false;
250250
fixture.detectChanges();
251251

252+
const endDateInput = fixture.debugElement.nativeElement.querySelector('#end_date');
252253
const endHourInput = fixture.debugElement.nativeElement.querySelector('#end_hour');
254+
255+
expect(endDateInput).toBeDefined();
253256
expect(endHourInput).toBeDefined();
254257
});
255258

256-
it('when the current entry is running, then the end hour input should not be rendered', () => {
259+
it('when the current entry is running, then the end date and end hour inputs should not be rendered', () => {
257260
component.goingToWorkOnThis = true;
258261
fixture.detectChanges();
259262

263+
const endDateInput = fixture.debugElement.nativeElement.querySelector('#end_date');
260264
const endHourInput = fixture.debugElement.nativeElement.querySelector('#end_hour');
265+
266+
expect(endDateInput).toBeNull();
261267
expect(endHourInput).toBeNull();
262268
});
263269

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ import { ProjectSelectedEvent } from './project-selected-event';
2020
import { get } from 'lodash';
2121
import { DATE_FORMAT } from 'src/environments/environment';
2222

23-
2423
type Merged = TechnologyState & ProjectState & ActivityState & EntryState;
2524
@Component({
2625
selector: 'app-details-fields',
2726
templateUrl: './details-fields.component.html',
2827
styleUrls: ['./details-fields.component.scss'],
2928
})
3029
export class DetailsFieldsComponent implements OnChanges, OnInit {
31-
3230
keyword = 'search_field';
3331
@Input() entryToEdit: Entry;
3432
@Input() canMarkEntryAsWIP: boolean;
@@ -43,8 +41,12 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
4341
goingToWorkOnThis = false;
4442
shouldRestartEntry = false;
4543

46-
constructor(private formBuilder: FormBuilder, private store: Store<Merged>,
47-
private actionsSubject$: ActionsSubject, private toastrService: ToastrService) {
44+
constructor(
45+
private formBuilder: FormBuilder,
46+
private store: Store<Merged>,
47+
private actionsSubject$: ActionsSubject,
48+
private toastrService: ToastrService
49+
) {
4850
this.entryForm = this.formBuilder.group({
4951
project_id: ['', Validators.required],
5052
project_name: ['', Validators.required],
@@ -66,11 +68,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
6668
if (projects) {
6769
this.listProjects = [];
6870
projects.forEach((project) => {
69-
const projectWithSearchField = {...project};
70-
projectWithSearchField.search_field = `${project.customer_name} - ${project.name}`;
71-
this.listProjects.push(projectWithSearchField);
72-
}
73-
);
71+
const projectWithSearchField = { ...project };
72+
projectWithSearchField.search_field = `${project.customer_name} - ${project.name}`;
73+
this.listProjects.push(projectWithSearchField);
74+
});
7475
}
7576
});
7677

@@ -95,31 +96,32 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
9596
}
9697
});
9798

98-
this.actionsSubject$.pipe(
99-
filter((action: any) => (
100-
action.type === EntryActionTypes.CREATE_ENTRY_SUCCESS ||
101-
action.type === EntryActionTypes.UPDATE_ENTRY_SUCCESS
102-
))
103-
).subscribe(() => {
104-
this.cleanForm();
105-
});
99+
this.actionsSubject$
100+
.pipe(
101+
filter(
102+
(action: any) =>
103+
action.type === EntryActionTypes.CREATE_ENTRY_SUCCESS ||
104+
action.type === EntryActionTypes.UPDATE_ENTRY_SUCCESS
105+
)
106+
)
107+
.subscribe(() => {
108+
this.cleanForm();
109+
});
106110
}
107111

108112
onClearedComponent(event) {
109-
this.entryForm.patchValue(
110-
{
111-
project_id: '',
112-
project_name: '',
113-
});
113+
this.entryForm.patchValue({
114+
project_id: '',
115+
project_name: '',
116+
});
114117
}
115118

116119
onSelectedProject(item) {
117-
this.projectSelected.emit({ projectId : item.id});
118-
this.entryForm.patchValue(
119-
{
120-
project_id: item.id,
121-
project_name: item.search_field,
122-
});
120+
this.projectSelected.emit({ projectId: item.id });
121+
this.entryForm.patchValue({
122+
project_id: item.id,
123+
project_name: item.search_field,
124+
});
123125
}
124126

125127
ngOnChanges(): void {
@@ -197,7 +199,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
197199
this.closeModal?.nativeElement?.click();
198200
}
199201

200-
dateToSubmit(date, hour){
202+
dateToSubmit(date, hour) {
201203
const entryFormDate = this.entryForm.value[date];
202204
const updatedHour = this.entryForm.value[hour];
203205
const initialDate = this.entryToEdit[date];
@@ -246,7 +248,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
246248
onGoingToWorkOnThisChange(event: any) {
247249
this.goingToWorkOnThis = event.currentTarget.checked;
248250
if (!this.goingToWorkOnThis) {
249-
this.entryForm.patchValue({ end_hour: formatDate(new Date(), 'HH:mm:ss', 'en') });
251+
this.entryForm.patchValue({
252+
end_date: formatDate(get(this.entryToEdit, 'start_date', ''), DATE_FORMAT, 'en'),
253+
end_hour: formatDate(get(this.entryToEdit, 'start_date', '00:00'), 'HH:mm', 'en'),
254+
});
250255
}
251256
this.shouldRestartEntry = !this.entryToEdit?.running && this.goingToWorkOnThis;
252257
}

0 commit comments

Comments
 (0)