Skip to content

Commit 752bcd2

Browse files
author
Guido Quezada
committed
feat: #566 Datepicker for Date out
1 parent c1aa529 commit 752bcd2

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272

7373

7474
<div class="form-group row">
75-
<label class="col-12 col-sm-2 col-form-label">Date:</label>
76-
<div class="col-12 col-sm-10">
75+
<label class="col-12 col-sm-2">Date in:</label>
76+
<div class="col-12 col-sm-4">
7777
<input
7878
formControlName="entry_date"
7979
id="entry_date"
@@ -85,6 +85,20 @@
8585
required
8686
/>
8787
</div>
88+
89+
<label class="col-12 col-sm-2" *ngIf="!goingToWorkOnThis">Date out:</label>
90+
<div class="col-12 col-sm-4" *ngIf="!goingToWorkOnThis">
91+
<input
92+
formControlName="departure_date"
93+
id="departure_date"
94+
type="date"
95+
class="form-control"
96+
aria-label="Small"
97+
aria-describedby="inputGroup-sizing-sm"
98+
[class.is-invalid]="departure_date.invalid && departure_date.touched"
99+
required
100+
/>
101+
</div>
88102
</div>
89103

90104

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ describe('DetailsFieldsComponent', () => {
6767
activity_id: '',
6868
uri: '',
6969
entry_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
70+
departure_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
7071
start_hour: '00:00:00',
7172
end_hour: '00:00:00',
7273
description: '',
@@ -109,6 +110,7 @@ describe('DetailsFieldsComponent', () => {
109110
activity_id: 'a1',
110111
uri: 'ticketUri',
111112
entry_date: '',
113+
departure_date: '',
112114
start_hour: '00:00:10',
113115
end_hour: '00:00:11',
114116
description: '',
@@ -177,6 +179,7 @@ describe('DetailsFieldsComponent', () => {
177179
activity_id: '',
178180
uri: '',
179181
entry_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
182+
departure_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
180183
start_hour: '00:00:00',
181184
end_hour: '00:00:00',
182185
description: '',
@@ -213,6 +216,7 @@ describe('DetailsFieldsComponent', () => {
213216
activity_id: 'a1',
214217
uri: '',
215218
entry_date: '2020-02-05',
219+
departure_date: '2020-02-05',
216220
start_hour: '00:00:01',
217221
end_hour: '00:01:01',
218222
description: '',
@@ -287,7 +291,7 @@ describe('DetailsFieldsComponent', () => {
287291
component.goingToWorkOnThis = true;
288292
spyOn(component.saveEntry, 'emit');
289293

290-
component.entryForm.setValue({ ...formValues, entry_date: '2020-06-11' });
294+
component.entryForm.setValue({ ...formValues, entry_date: '2020-06-11', departure_date: '2020-06-11' });
291295

292296
component.onSubmit();
293297

@@ -311,7 +315,7 @@ describe('DetailsFieldsComponent', () => {
311315
spyOn(toastrServiceStub, 'error');
312316

313317
const futureDate = moment().add(1, 'days').format('YYYY-MM-DD');
314-
component.entryForm.setValue({ ...formValues, entry_date: futureDate });
318+
component.entryForm.setValue({ ...formValues, entry_date: futureDate, departure_date: futureDate });
315319
component.onSubmit();
316320

317321
expect(toastrServiceStub.error).toHaveBeenCalled();

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
4949
activity_id: ['', Validators.required],
5050
description: '',
5151
entry_date: '',
52+
departure_date: '',
5253
start_hour: '',
5354
end_hour: '',
5455
uri: '',
@@ -130,6 +131,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
130131
activity_id: this.entryToEdit.activity_id,
131132
description: this.entryToEdit.description,
132133
entry_date: this.entryToEdit.start_date ? formatDate(this.entryToEdit.start_date, 'yyyy-MM-dd', 'en') : '',
134+
departure_date: formatDate(this.entryToEdit.end_date ? this.entryToEdit.end_date : new Date(), 'yyyy-MM-dd', 'en'),
133135
start_hour: this.entryToEdit.start_date ? formatDate(this.entryToEdit.start_date, 'HH:mm:ss', 'en') : '00:00:00',
134136
end_hour: this.entryToEdit.end_date ? formatDate(this.entryToEdit.end_date, 'HH:mm:ss', 'en') : '00:00:00',
135137
uri: this.entryToEdit.uri,
@@ -148,6 +150,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
148150
activity_id: '',
149151
description: '',
150152
entry_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
153+
departure_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
151154
start_hour: '00:00:00',
152155
end_hour: '00:00:00',
153156
uri: '',
@@ -175,6 +178,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
175178
return this.entryForm.get('entry_date');
176179
}
177180

181+
get departure_date() {
182+
return this.entryForm.get('departure_date');
183+
}
184+
178185
get start_hour() {
179186
return this.entryForm.get('start_hour');
180187
}
@@ -195,13 +202,14 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
195202
}
196203
// start&end date same for now
197204
const entryDate = this.entryForm.value.entry_date;
205+
const departureDate = this.entryForm.value.departure_date;
198206
const entry = {
199207
project_id: this.entryForm.value.project_id,
200208
activity_id: this.entryForm.value.activity_id,
201209
technologies: this.selectedTechnologies ? this.selectedTechnologies : [],
202210
description: this.entryForm.value.description,
203211
start_date: new Date(`${entryDate}T${this.entryForm.value.start_hour.trim()}`).toISOString(),
204-
end_date: new Date(`${entryDate}T${this.entryForm.value.end_hour.trim()}`).toISOString(),
212+
end_date: new Date(`${departureDate}T${this.entryForm.value.end_hour.trim()}`).toISOString(),
205213
uri: this.entryForm.value.uri,
206214
timezone_offset: new Date().getTimezoneOffset(),
207215
};

0 commit comments

Comments
 (0)