@qite/tide-booking-component 1.3.4 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/build/build-cjs/booking-wizard/features/sidebar/sidebar-util.d.ts +3 -3
  2. package/build/build-cjs/booking-wizard/features/travelers-form/travelers-form-slice.d.ts +5 -5
  3. package/build/build-cjs/booking-wizard/types.d.ts +6 -0
  4. package/build/build-cjs/index.js +223 -147
  5. package/build/build-cjs/shared/utils/localization-util.d.ts +2 -0
  6. package/build/build-esm/booking-wizard/features/sidebar/sidebar-util.d.ts +3 -3
  7. package/build/build-esm/booking-wizard/features/travelers-form/travelers-form-slice.d.ts +5 -5
  8. package/build/build-esm/booking-wizard/types.d.ts +6 -0
  9. package/build/build-esm/index.js +223 -147
  10. package/build/build-esm/shared/utils/localization-util.d.ts +2 -0
  11. package/package.json +75 -75
  12. package/src/booking-wizard/components/print-offer-button.tsx +63 -63
  13. package/src/booking-wizard/features/booking/booking-self-contained.tsx +389 -389
  14. package/src/booking-wizard/features/booking/booking-slice.ts +663 -663
  15. package/src/booking-wizard/features/booking/booking.tsx +361 -361
  16. package/src/booking-wizard/features/flight-options/flight-utils.ts +522 -522
  17. package/src/booking-wizard/features/product-options/options-form.tsx +481 -481
  18. package/src/booking-wizard/features/sidebar/sidebar-util.ts +177 -177
  19. package/src/booking-wizard/features/summary/summary-booking-option-pax.tsx +25 -25
  20. package/src/booking-wizard/features/summary/summary.tsx +674 -674
  21. package/src/booking-wizard/features/travelers-form/travelers-form-slice.ts +164 -164
  22. package/src/booking-wizard/features/travelers-form/travelers-form.tsx +888 -754
  23. package/src/booking-wizard/settings-context.ts +62 -62
  24. package/src/booking-wizard/types.ts +286 -279
  25. package/src/booking-wizard/use-offer-printer.ts +117 -117
  26. package/src/shared/translations/en-GB.json +239 -237
  27. package/src/shared/translations/fr-BE.json +239 -238
  28. package/src/shared/translations/nl-BE.json +239 -237
  29. package/src/shared/utils/tide-api-utils.ts +36 -36
  30. package/styles/booking-wizard-variables.scss +873 -873
  31. package/styles/components/_booking.scss +879 -879
  32. package/styles/components/_dropdown.scss +72 -72
  33. package/styles/components/_form.scss +1583 -1583
@@ -1,522 +1,522 @@
1
- import {
2
- BookingPackageFlight,
3
- BookingPackageFlightMetaDataLine,
4
- } from "@qite/tide-client/build/types";
5
- import { differenceInMinutes, isEqual, parseISO } from "date-fns";
6
- import {
7
- FlightDirectionFilter,
8
- FlightFilterOption,
9
- FlightFilterOptions,
10
- GroupedFlightDetails,
11
- GroupedFlights,
12
- } from "../../types";
13
-
14
- /*interface FlightGroup {
15
- code: string;
16
- startDate: Date,
17
- endDate: Date;
18
- options: BookingPackageFlight[];
19
- }*/
20
-
21
- export const buildGroupedFlights = (
22
- outwardFlights: BookingPackageFlight[] | undefined,
23
- returnFlights: BookingPackageFlight[] | undefined
24
- ) => {
25
- if (!outwardFlights || !returnFlights) return [] as GroupedFlights[];
26
-
27
- // let outwardGroups = groupFlights(outwardFlights);
28
- // let returnGroups = groupFlights(returnFlights);
29
-
30
- const pairs: {
31
- outward: BookingPackageFlight;
32
- return: BookingPackageFlight;
33
- }[] = [];
34
- outwardFlights.forEach((outwardFlight) => {
35
- if (outwardFlight.externalGuid) {
36
- const returnFlight = returnFlights.find(
37
- (x) => x.externalGuid === outwardFlight.externalGuid
38
- );
39
- if (!returnFlight) return;
40
-
41
- pairs.push({ outward: outwardFlight, return: returnFlight });
42
- } else {
43
- const outwardCode = outwardFlight.code.substring(0, 7);
44
- const returnCode = outwardCode.split(" ").reduce((a, b) => `${b} ${a}`);
45
-
46
- returnFlights
47
- .filter((x) => x.code.startsWith(returnCode))
48
- .forEach((returnFlight) => {
49
- pairs.push({ outward: outwardFlight, return: returnFlight });
50
- });
51
- }
52
- });
53
-
54
- const results: GroupedFlights[] = [];
55
- pairs.forEach((x) => {
56
- const outwardFlightDetails = getFlightDetails(x.outward);
57
- const returnFlightDetails = getFlightDetails(x.return);
58
-
59
- if (!outwardFlightDetails || !returnFlightDetails) return;
60
-
61
- results.push({
62
- isSelected: x.outward.isSelected && x.return.isSelected,
63
- price: x.outward.price + x.return.price,
64
- outward: outwardFlightDetails,
65
- return: returnFlightDetails,
66
- selectedOutward: x.outward,
67
- selectedReturn: x.return,
68
- } as GroupedFlights);
69
- });
70
-
71
- return results;
72
- };
73
-
74
- export const buildFilterOptions = (
75
- outwardFlights: BookingPackageFlight[] | undefined,
76
- returnFlights: BookingPackageFlight[] | undefined,
77
- translations: any
78
- ) => {
79
- if (!outwardFlights || !returnFlights) return undefined;
80
-
81
- const airports: FlightFilterOption[] = [];
82
- const airlines: FlightFilterOption[] = [];
83
- const numberOfStops: FlightFilterOption[] = [];
84
- const outwardDeparturePeriods: FlightFilterOption[] = [];
85
- const returnDeparturePeriods: FlightFilterOption[] = [];
86
-
87
- let lowestDepartureTravelDuration = 9999;
88
- let highestDepartureTravelDuration = 0;
89
- let lowestDepartureChangeDuration = 9999;
90
- let highestDepartureChangeDuration = 0;
91
-
92
- outwardFlights.forEach((flight) => {
93
- const airlineCode = flight.code.split("/")[1];
94
-
95
- if (flight.flightMetaData.flightLines?.length) {
96
- const firstLine = flight.flightMetaData.flightLines[0];
97
-
98
- if (!airports.some((x) => x.value === firstLine.departureAirport)) {
99
- airports.push({
100
- value: firstLine?.departureAirport,
101
- label: firstLine.departureAirportDescription,
102
- count: 0,
103
- isSelected: false,
104
- });
105
- }
106
- }
107
-
108
- if (!airlines.some((x) => x.value === airlineCode)) {
109
- airlines.push({
110
- value: airlineCode,
111
- label: flight.airlineDescription,
112
- count: 0,
113
- isSelected: false,
114
- });
115
- }
116
-
117
- const stopCount = flight.flightMetaData.flightLines.length - 1;
118
- if (!numberOfStops.some((x) => x.value === stopCount + "")) {
119
- numberOfStops.push({
120
- value: stopCount + "",
121
- label:
122
- stopCount === 0
123
- ? translations.FLIGHTS_FORM.DIRECT_FLIGHT
124
- : stopCount == 1
125
- ? `${stopCount} ${translations.FLIGHTS_FORM.STOP}`
126
- : `${stopCount} ${translations.FLIGHTS_FORM.STOPS}`,
127
- count: 0,
128
- isSelected: false,
129
- });
130
- }
131
-
132
- const departureTime = flight.flightMetaData.flightLines[0].departureTime;
133
- const timeBracket = determineTimeBracket(departureTime);
134
- if (!outwardDeparturePeriods.some((x) => x.value === timeBracket)) {
135
- outwardDeparturePeriods.push({
136
- value: timeBracket,
137
- label: getBracketTranslation(timeBracket, translations),
138
- count: 0,
139
- isSelected: false,
140
- });
141
- }
142
-
143
- const travelDurationInMinutes = minutesFromTicks(
144
- flight.flightMetaData.durationInTicks
145
- );
146
- if (travelDurationInMinutes > highestDepartureTravelDuration)
147
- highestDepartureTravelDuration = travelDurationInMinutes;
148
- if (travelDurationInMinutes < lowestDepartureTravelDuration)
149
- lowestDepartureTravelDuration = travelDurationInMinutes;
150
-
151
- const changeDurationInMinutes = getTotalChangeDuration(flight);
152
- if (changeDurationInMinutes > highestDepartureChangeDuration)
153
- highestDepartureChangeDuration = changeDurationInMinutes;
154
- if (changeDurationInMinutes < lowestDepartureChangeDuration)
155
- lowestDepartureChangeDuration = changeDurationInMinutes;
156
- });
157
-
158
- let lowestReturnTravelDuration = 9999;
159
- let highestReturnTravelDuration = 0;
160
- let lowestReturnChangeDuration = 9999;
161
- let highestReturnChangeDuration = 0;
162
-
163
- returnFlights.forEach((flight) => {
164
- const durationInMinutes = minutesFromTicks(
165
- flight.flightMetaData.durationInTicks
166
- );
167
- if (durationInMinutes > highestReturnTravelDuration)
168
- highestReturnTravelDuration = durationInMinutes;
169
- if (durationInMinutes < lowestReturnTravelDuration)
170
- lowestReturnTravelDuration = durationInMinutes;
171
-
172
- const changeDurationInMinutes = getTotalChangeDuration(flight);
173
- if (changeDurationInMinutes > highestReturnChangeDuration)
174
- highestReturnChangeDuration = changeDurationInMinutes;
175
- if (changeDurationInMinutes < lowestReturnChangeDuration)
176
- lowestReturnChangeDuration = changeDurationInMinutes;
177
-
178
- const departureTime = flight.flightMetaData.flightLines[0].departureTime;
179
- const timeBracket = determineTimeBracket(departureTime);
180
- if (!returnDeparturePeriods.some((x) => x.value === timeBracket)) {
181
- returnDeparturePeriods.push({
182
- value: timeBracket,
183
- label: getBracketTranslation(timeBracket, translations),
184
- count: 0,
185
- isSelected: false,
186
- });
187
- }
188
- });
189
-
190
- return {
191
- airports: airports,
192
- airlines: airlines,
193
- numberOfStops: numberOfStops,
194
- outward: {
195
- departurePeriod: outwardDeparturePeriods,
196
- travelDuration: {
197
- min: lowestDepartureTravelDuration,
198
- max: highestDepartureTravelDuration,
199
- selectedMin: lowestDepartureTravelDuration,
200
- selectedMax: highestDepartureTravelDuration,
201
- },
202
- changeDuration: {
203
- min: lowestDepartureChangeDuration,
204
- max: highestDepartureChangeDuration,
205
- selectedMin: lowestDepartureChangeDuration,
206
- selectedMax: highestDepartureChangeDuration,
207
- },
208
- },
209
- return: {
210
- departurePeriod: returnDeparturePeriods,
211
- travelDuration: {
212
- min: lowestReturnTravelDuration,
213
- max: highestReturnTravelDuration,
214
- selectedMin: lowestReturnTravelDuration,
215
- selectedMax: highestReturnTravelDuration,
216
- },
217
- changeDuration: {
218
- min: lowestReturnChangeDuration,
219
- max: highestReturnChangeDuration,
220
- selectedMin: lowestReturnChangeDuration,
221
- selectedMax: highestReturnChangeDuration,
222
- },
223
- },
224
- } as FlightFilterOptions;
225
- };
226
-
227
- export const filterGroupedFlights = (
228
- groups: GroupedFlights[],
229
- filterOptions: FlightFilterOptions | undefined
230
- ) => {
231
- if (!groups.length || !filterOptions) return [];
232
-
233
- let filteredGroups = groups;
234
- if (filterOptions.airlines.some((x) => x.isSelected)) {
235
- const selectedAirlineCodes = filterOptions.airlines.filter(
236
- (x) => x.isSelected
237
- );
238
- filteredGroups = filteredGroups.filter((x) =>
239
- selectedAirlineCodes.some((y) => y.value === x.outward.airlineCode)
240
- );
241
- }
242
-
243
- if (filterOptions.airports.some((x) => x.isSelected)) {
244
- const selectedAirlineCodes = filterOptions.airports.filter(
245
- (x) => x.isSelected
246
- );
247
- filteredGroups = filteredGroups.filter((x) =>
248
- selectedAirlineCodes.some(
249
- (y) => y.value === x.outward.departureAirportCode
250
- )
251
- );
252
- }
253
-
254
- if (filterOptions.numberOfStops.some((x) => x.isSelected)) {
255
- const selectedNumberOfStops = filterOptions.numberOfStops.filter(
256
- (x) => x.isSelected
257
- );
258
- filteredGroups = filteredGroups.filter((x) =>
259
- selectedNumberOfStops.some(
260
- (y) => parseInt(y.value) === x.outward.flightLines.length - 1
261
- )
262
- );
263
- }
264
-
265
- filteredGroups = filterGroupedFlightByDirection(
266
- filteredGroups,
267
- true,
268
- filterOptions.outward
269
- );
270
- filteredGroups = filterGroupedFlightByDirection(
271
- filteredGroups,
272
- false,
273
- filterOptions.return
274
- );
275
-
276
- return filteredGroups;
277
- };
278
-
279
- const filterGroupedFlightByDirection = (
280
- groups: GroupedFlights[],
281
- isOutward: boolean,
282
- directionFilter: FlightDirectionFilter
283
- ) => {
284
- let filteredGroups = groups;
285
-
286
- if (directionFilter.departurePeriod.some((x) => x.isSelected)) {
287
- const selectedDeparturePeriods = directionFilter.departurePeriod.filter(
288
- (x) => x.isSelected
289
- );
290
- filteredGroups = filteredGroups.filter((x) =>
291
- selectedDeparturePeriods.some(
292
- (y) =>
293
- y.value ===
294
- determineTimeBracket((isOutward ? x.outward : x.return).departureTime)
295
- )
296
- );
297
- }
298
-
299
- filteredGroups = filteredGroups.filter(
300
- (x) =>
301
- directionFilter.travelDuration.selectedMin <=
302
- (isOutward ? x.outward : x.return).travelDurationMinutes &&
303
- (isOutward ? x.outward : x.return).travelDurationMinutes <=
304
- directionFilter.travelDuration.selectedMax
305
- );
306
- return filteredGroups.filter(
307
- (x) =>
308
- directionFilter.changeDuration.selectedMin <=
309
- (isOutward ? x.outward : x.return).changeDurationMinutes &&
310
- (isOutward ? x.outward : x.return).changeDurationMinutes <=
311
- directionFilter.changeDuration.selectedMax
312
- );
313
- };
314
-
315
- export const formatMinutes = (minutes: number) => {
316
- var hh = Math.floor(minutes / 60);
317
- var mm = Math.floor(minutes % 60);
318
- return pad(hh, 2) + ":" + pad(mm, 2);
319
- };
320
-
321
- const getFlightDetails = (flight: BookingPackageFlight) => {
322
- if (flight.flightMetaData == null) return;
323
- const firstLine = flight.flightMetaData.flightLines[0];
324
- const lastLine =
325
- flight.flightMetaData.flightLines[
326
- flight.flightMetaData.flightLines.length - 1
327
- ];
328
-
329
- const airlineCode = flight.code.split("/")[1];
330
- const waitDurations = getWaitDurations(flight.flightMetaData.flightLines);
331
-
332
- return {
333
- airline: flight.airlineDescription,
334
- airlineCode: airlineCode,
335
- departureDate: firstLine.departureDate,
336
- departureTime: firstLine.departureTime,
337
- departureAirportCode: firstLine.departureAirport,
338
- departureAirport: firstLine.departureAirportDescription,
339
- arrivalDate: lastLine.arrivalDate,
340
- arrivalTime: lastLine.arrivalTime,
341
- arrivalAirport: lastLine.arrivalAirportDescription,
342
- travelDuration: formatDuration(flight.flightMetaData.durationInTicks),
343
- travelDurationMinutes: minutesFromTicks(
344
- flight.flightMetaData.durationInTicks
345
- ),
346
- changeDurationMinutes: getTotalChangeDuration(flight),
347
- numberOfStops: flight.flightMetaData.flightLines.length - 1,
348
- isNextDay: isNextDay(firstLine.departureDate, lastLine.arrivalDate),
349
- travelClass: firstLine.travelClass,
350
- flightLines: flight.flightMetaData.flightLines.map((x, i) => ({
351
- airline: x.operatingAirlineDescription,
352
- departureDate: x.departureDate,
353
- departureTime: x.departureTime,
354
- departureAirport: x.departureAirportDescription,
355
- arrivalDate: x.arrivalDate,
356
- arrivalTime: x.arrivalTime,
357
- arrivalAirport: x.arrivalAirportDescription,
358
- number: `${x.airlineCode} ${x.number}`,
359
- travelDuration: formatDuration(x.durationInTicks),
360
- waitDuration:
361
- waitDurations.length - 1 <= i ? waitDurations[i] : undefined,
362
- })),
363
- } as GroupedFlightDetails;
364
- };
365
-
366
- const isNextDay = (startDateString: string, endDateString: string) => {
367
- const startDate = parseISO(startDateString);
368
- const endDate = parseISO(endDateString);
369
-
370
- return !isEqual(startDate, endDate);
371
- };
372
-
373
- const getWaitDurations = (lines: BookingPackageFlightMetaDataLine[]) => {
374
- if (lines.length <= 1) return [];
375
- let arrivalDate = lines[0].arrivalDate;
376
- let arrivalTime = lines[0].arrivalTime;
377
-
378
- const waitDurations: string[] = [];
379
- for (var i = 1; i < lines.length; i++) {
380
- const line = lines[i];
381
-
382
- const waitDuration = getWaitDuration(
383
- arrivalDate,
384
- arrivalTime,
385
- line.departureDate,
386
- line.departureTime
387
- );
388
- waitDurations.push(waitDuration);
389
-
390
- arrivalDate = line.arrivalDate;
391
- arrivalTime = line.arrivalTime;
392
- }
393
-
394
- return waitDurations;
395
- };
396
-
397
- const getWaitDuration = (
398
- arrivalDateString: string,
399
- arrivalTime: string,
400
- departureDateString: string,
401
- departureTime: string
402
- ) => {
403
- const minutes = getWaitDurationInMinutes(
404
- arrivalDateString,
405
- arrivalTime,
406
- departureDateString,
407
- departureTime
408
- );
409
-
410
- var hh = Math.floor(minutes / 60);
411
- var mm = Math.floor(minutes % 60);
412
- return pad(hh, 2) + ":" + pad(mm, 2);
413
- };
414
-
415
- const getWaitDurationInMinutes = (
416
- arrivalDateString: string,
417
- arrivalTime: string,
418
- departureDateString: string,
419
- departureTime: string
420
- ) => {
421
- const arrivalDate = parseISO(arrivalDateString);
422
- const arrivalTimeParts = arrivalTime.split(":");
423
-
424
- arrivalDate.setHours(parseInt(arrivalTimeParts[0]));
425
- arrivalDate.setMinutes(parseInt(arrivalTimeParts[1]));
426
-
427
- const departureDate = parseISO(departureDateString);
428
- const departureTimeParts = departureTime.split(":");
429
-
430
- departureDate.setHours(parseInt(departureTimeParts[0]));
431
- departureDate.setMinutes(parseInt(departureTimeParts[1]));
432
-
433
- return differenceInMinutes(departureDate, arrivalDate);
434
- };
435
-
436
- /*const groupFlights = (flights: BookingPackageFlight[]) => {
437
- let flightsPool = [...flights];
438
- let groups = [] as FlightGroup[];
439
- for (var i = 0; i < flightsPool.length; i++) {
440
- const flight = flightsPool[i];
441
-
442
- const relatedFlights = flightsPool.filter(x => x != flight
443
- && x.code === flight.code
444
- && isDateEqual(x.startDateTime, flight.startDateTime)
445
- && isDateEqual(x.endDateTime, flight.endDateTime)
446
- );
447
-
448
- flightsPool = flightsPool.filter(x => x != flight
449
- && relatedFlights.some(y => y != x));
450
-
451
- groups.push({
452
- code: flight.code,
453
- startDate: parseISO(flight.startDateTime),
454
- endDate: parseISO(flight.endDateTime),
455
- options: [flight, ...relatedFlights]
456
- });
457
- }
458
- }
459
-
460
- const isDateEqual = (first: string, second: string) => {
461
- const firstDate = parseISO(first);
462
- const secondDate = parseISO(second);
463
-
464
- return isEqual(firstDate, secondDate);
465
- }*/
466
-
467
- const minutesFromTicks = (ticks: number) => {
468
- const totalSeconds = ticks / 10_000_000;
469
- return Math.floor(totalSeconds / 60);
470
- };
471
-
472
- const formatDuration = (ticks: number) => {
473
- if (!ticks) return "";
474
-
475
- const totalSeconds = ticks / 10_000_000;
476
- var hh = Math.floor(totalSeconds / 3600);
477
- var mm = Math.floor((totalSeconds % 3600) / 60);
478
- return pad(hh, 2) + ":" + pad(mm, 2);
479
- };
480
-
481
- const pad = (input: number, width: number) => {
482
- const n = input + "";
483
- return n.length >= width ? n : new Array(width - n.length + 1).join("0") + n;
484
- };
485
-
486
- const determineTimeBracket = (input: string) => {
487
- const time = parseInt(input.replace(":", ""));
488
- if (time <= 500) return "0000-0500";
489
- if (time > 500 && time <= 1200) return "0500-1200";
490
- if (time > 1200 && time <= 1800) return "1201-1800";
491
- return "1800-2400";
492
- };
493
-
494
- const getBracketTranslation = (input: string, translations: any) => {
495
- if (input === "0000-0500") return translations.FLIGHTS_FORM.NIGHT_DEPARTURE;
496
- if (input === "0500-1200") return translations.FLIGHTS_FORM.MORNING_DEPARTURE;
497
- if (input === "1200-1800")
498
- return translations.FLIGHTS_FORM.AFTERNOON_DEPARTURE;
499
- return translations.FLIGHTS_FORM.EVENING_DEPARTURE;
500
- };
501
-
502
- const getTotalChangeDuration = (flight: BookingPackageFlight) => {
503
- const lines = flight.flightMetaData.flightLines;
504
-
505
- if (lines.length <= 1) return 0;
506
- let arrivalDate = lines[0].arrivalDate;
507
- let arrivalTime = lines[0].arrivalTime;
508
-
509
- let waitDuration = 0;
510
- for (var i = 1; i < lines.length; i++) {
511
- const line = lines[i];
512
-
513
- waitDuration += getWaitDurationInMinutes(
514
- arrivalDate,
515
- arrivalTime,
516
- line.departureDate,
517
- line.departureTime
518
- );
519
- }
520
-
521
- return waitDuration;
522
- };
1
+ import {
2
+ BookingPackageFlight,
3
+ BookingPackageFlightMetaDataLine,
4
+ } from "@qite/tide-client/build/types";
5
+ import { differenceInMinutes, isEqual, parseISO } from "date-fns";
6
+ import {
7
+ FlightDirectionFilter,
8
+ FlightFilterOption,
9
+ FlightFilterOptions,
10
+ GroupedFlightDetails,
11
+ GroupedFlights,
12
+ } from "../../types";
13
+
14
+ /*interface FlightGroup {
15
+ code: string;
16
+ startDate: Date,
17
+ endDate: Date;
18
+ options: BookingPackageFlight[];
19
+ }*/
20
+
21
+ export const buildGroupedFlights = (
22
+ outwardFlights: BookingPackageFlight[] | undefined,
23
+ returnFlights: BookingPackageFlight[] | undefined
24
+ ) => {
25
+ if (!outwardFlights || !returnFlights) return [] as GroupedFlights[];
26
+
27
+ // let outwardGroups = groupFlights(outwardFlights);
28
+ // let returnGroups = groupFlights(returnFlights);
29
+
30
+ const pairs: {
31
+ outward: BookingPackageFlight;
32
+ return: BookingPackageFlight;
33
+ }[] = [];
34
+ outwardFlights.forEach((outwardFlight) => {
35
+ if (outwardFlight.externalGuid) {
36
+ const returnFlight = returnFlights.find(
37
+ (x) => x.externalGuid === outwardFlight.externalGuid
38
+ );
39
+ if (!returnFlight) return;
40
+
41
+ pairs.push({ outward: outwardFlight, return: returnFlight });
42
+ } else {
43
+ const outwardCode = outwardFlight.code.substring(0, 7);
44
+ const returnCode = outwardCode.split(" ").reduce((a, b) => `${b} ${a}`);
45
+
46
+ returnFlights
47
+ .filter((x) => x.code.startsWith(returnCode))
48
+ .forEach((returnFlight) => {
49
+ pairs.push({ outward: outwardFlight, return: returnFlight });
50
+ });
51
+ }
52
+ });
53
+
54
+ const results: GroupedFlights[] = [];
55
+ pairs.forEach((x) => {
56
+ const outwardFlightDetails = getFlightDetails(x.outward);
57
+ const returnFlightDetails = getFlightDetails(x.return);
58
+
59
+ if (!outwardFlightDetails || !returnFlightDetails) return;
60
+
61
+ results.push({
62
+ isSelected: x.outward.isSelected && x.return.isSelected,
63
+ price: x.outward.price + x.return.price,
64
+ outward: outwardFlightDetails,
65
+ return: returnFlightDetails,
66
+ selectedOutward: x.outward,
67
+ selectedReturn: x.return,
68
+ } as GroupedFlights);
69
+ });
70
+
71
+ return results;
72
+ };
73
+
74
+ export const buildFilterOptions = (
75
+ outwardFlights: BookingPackageFlight[] | undefined,
76
+ returnFlights: BookingPackageFlight[] | undefined,
77
+ translations: any
78
+ ) => {
79
+ if (!outwardFlights || !returnFlights) return undefined;
80
+
81
+ const airports: FlightFilterOption[] = [];
82
+ const airlines: FlightFilterOption[] = [];
83
+ const numberOfStops: FlightFilterOption[] = [];
84
+ const outwardDeparturePeriods: FlightFilterOption[] = [];
85
+ const returnDeparturePeriods: FlightFilterOption[] = [];
86
+
87
+ let lowestDepartureTravelDuration = 9999;
88
+ let highestDepartureTravelDuration = 0;
89
+ let lowestDepartureChangeDuration = 9999;
90
+ let highestDepartureChangeDuration = 0;
91
+
92
+ outwardFlights.forEach((flight) => {
93
+ const airlineCode = flight.code.split("/")[1];
94
+
95
+ if (flight.flightMetaData.flightLines?.length) {
96
+ const firstLine = flight.flightMetaData.flightLines[0];
97
+
98
+ if (!airports.some((x) => x.value === firstLine.departureAirport)) {
99
+ airports.push({
100
+ value: firstLine?.departureAirport,
101
+ label: firstLine.departureAirportDescription,
102
+ count: 0,
103
+ isSelected: false,
104
+ });
105
+ }
106
+ }
107
+
108
+ if (!airlines.some((x) => x.value === airlineCode)) {
109
+ airlines.push({
110
+ value: airlineCode,
111
+ label: flight.airlineDescription,
112
+ count: 0,
113
+ isSelected: false,
114
+ });
115
+ }
116
+
117
+ const stopCount = flight.flightMetaData.flightLines.length - 1;
118
+ if (!numberOfStops.some((x) => x.value === stopCount + "")) {
119
+ numberOfStops.push({
120
+ value: stopCount + "",
121
+ label:
122
+ stopCount === 0
123
+ ? translations.FLIGHTS_FORM.DIRECT_FLIGHT
124
+ : stopCount == 1
125
+ ? `${stopCount} ${translations.FLIGHTS_FORM.STOP}`
126
+ : `${stopCount} ${translations.FLIGHTS_FORM.STOPS}`,
127
+ count: 0,
128
+ isSelected: false,
129
+ });
130
+ }
131
+
132
+ const departureTime = flight.flightMetaData.flightLines[0].departureTime;
133
+ const timeBracket = determineTimeBracket(departureTime);
134
+ if (!outwardDeparturePeriods.some((x) => x.value === timeBracket)) {
135
+ outwardDeparturePeriods.push({
136
+ value: timeBracket,
137
+ label: getBracketTranslation(timeBracket, translations),
138
+ count: 0,
139
+ isSelected: false,
140
+ });
141
+ }
142
+
143
+ const travelDurationInMinutes = minutesFromTicks(
144
+ flight.flightMetaData.durationInTicks
145
+ );
146
+ if (travelDurationInMinutes > highestDepartureTravelDuration)
147
+ highestDepartureTravelDuration = travelDurationInMinutes;
148
+ if (travelDurationInMinutes < lowestDepartureTravelDuration)
149
+ lowestDepartureTravelDuration = travelDurationInMinutes;
150
+
151
+ const changeDurationInMinutes = getTotalChangeDuration(flight);
152
+ if (changeDurationInMinutes > highestDepartureChangeDuration)
153
+ highestDepartureChangeDuration = changeDurationInMinutes;
154
+ if (changeDurationInMinutes < lowestDepartureChangeDuration)
155
+ lowestDepartureChangeDuration = changeDurationInMinutes;
156
+ });
157
+
158
+ let lowestReturnTravelDuration = 9999;
159
+ let highestReturnTravelDuration = 0;
160
+ let lowestReturnChangeDuration = 9999;
161
+ let highestReturnChangeDuration = 0;
162
+
163
+ returnFlights.forEach((flight) => {
164
+ const durationInMinutes = minutesFromTicks(
165
+ flight.flightMetaData.durationInTicks
166
+ );
167
+ if (durationInMinutes > highestReturnTravelDuration)
168
+ highestReturnTravelDuration = durationInMinutes;
169
+ if (durationInMinutes < lowestReturnTravelDuration)
170
+ lowestReturnTravelDuration = durationInMinutes;
171
+
172
+ const changeDurationInMinutes = getTotalChangeDuration(flight);
173
+ if (changeDurationInMinutes > highestReturnChangeDuration)
174
+ highestReturnChangeDuration = changeDurationInMinutes;
175
+ if (changeDurationInMinutes < lowestReturnChangeDuration)
176
+ lowestReturnChangeDuration = changeDurationInMinutes;
177
+
178
+ const departureTime = flight.flightMetaData.flightLines[0].departureTime;
179
+ const timeBracket = determineTimeBracket(departureTime);
180
+ if (!returnDeparturePeriods.some((x) => x.value === timeBracket)) {
181
+ returnDeparturePeriods.push({
182
+ value: timeBracket,
183
+ label: getBracketTranslation(timeBracket, translations),
184
+ count: 0,
185
+ isSelected: false,
186
+ });
187
+ }
188
+ });
189
+
190
+ return {
191
+ airports: airports,
192
+ airlines: airlines,
193
+ numberOfStops: numberOfStops,
194
+ outward: {
195
+ departurePeriod: outwardDeparturePeriods,
196
+ travelDuration: {
197
+ min: lowestDepartureTravelDuration,
198
+ max: highestDepartureTravelDuration,
199
+ selectedMin: lowestDepartureTravelDuration,
200
+ selectedMax: highestDepartureTravelDuration,
201
+ },
202
+ changeDuration: {
203
+ min: lowestDepartureChangeDuration,
204
+ max: highestDepartureChangeDuration,
205
+ selectedMin: lowestDepartureChangeDuration,
206
+ selectedMax: highestDepartureChangeDuration,
207
+ },
208
+ },
209
+ return: {
210
+ departurePeriod: returnDeparturePeriods,
211
+ travelDuration: {
212
+ min: lowestReturnTravelDuration,
213
+ max: highestReturnTravelDuration,
214
+ selectedMin: lowestReturnTravelDuration,
215
+ selectedMax: highestReturnTravelDuration,
216
+ },
217
+ changeDuration: {
218
+ min: lowestReturnChangeDuration,
219
+ max: highestReturnChangeDuration,
220
+ selectedMin: lowestReturnChangeDuration,
221
+ selectedMax: highestReturnChangeDuration,
222
+ },
223
+ },
224
+ } as FlightFilterOptions;
225
+ };
226
+
227
+ export const filterGroupedFlights = (
228
+ groups: GroupedFlights[],
229
+ filterOptions: FlightFilterOptions | undefined
230
+ ) => {
231
+ if (!groups.length || !filterOptions) return [];
232
+
233
+ let filteredGroups = groups;
234
+ if (filterOptions.airlines.some((x) => x.isSelected)) {
235
+ const selectedAirlineCodes = filterOptions.airlines.filter(
236
+ (x) => x.isSelected
237
+ );
238
+ filteredGroups = filteredGroups.filter((x) =>
239
+ selectedAirlineCodes.some((y) => y.value === x.outward.airlineCode)
240
+ );
241
+ }
242
+
243
+ if (filterOptions.airports.some((x) => x.isSelected)) {
244
+ const selectedAirlineCodes = filterOptions.airports.filter(
245
+ (x) => x.isSelected
246
+ );
247
+ filteredGroups = filteredGroups.filter((x) =>
248
+ selectedAirlineCodes.some(
249
+ (y) => y.value === x.outward.departureAirportCode
250
+ )
251
+ );
252
+ }
253
+
254
+ if (filterOptions.numberOfStops.some((x) => x.isSelected)) {
255
+ const selectedNumberOfStops = filterOptions.numberOfStops.filter(
256
+ (x) => x.isSelected
257
+ );
258
+ filteredGroups = filteredGroups.filter((x) =>
259
+ selectedNumberOfStops.some(
260
+ (y) => parseInt(y.value) === x.outward.flightLines.length - 1
261
+ )
262
+ );
263
+ }
264
+
265
+ filteredGroups = filterGroupedFlightByDirection(
266
+ filteredGroups,
267
+ true,
268
+ filterOptions.outward
269
+ );
270
+ filteredGroups = filterGroupedFlightByDirection(
271
+ filteredGroups,
272
+ false,
273
+ filterOptions.return
274
+ );
275
+
276
+ return filteredGroups;
277
+ };
278
+
279
+ const filterGroupedFlightByDirection = (
280
+ groups: GroupedFlights[],
281
+ isOutward: boolean,
282
+ directionFilter: FlightDirectionFilter
283
+ ) => {
284
+ let filteredGroups = groups;
285
+
286
+ if (directionFilter.departurePeriod.some((x) => x.isSelected)) {
287
+ const selectedDeparturePeriods = directionFilter.departurePeriod.filter(
288
+ (x) => x.isSelected
289
+ );
290
+ filteredGroups = filteredGroups.filter((x) =>
291
+ selectedDeparturePeriods.some(
292
+ (y) =>
293
+ y.value ===
294
+ determineTimeBracket((isOutward ? x.outward : x.return).departureTime)
295
+ )
296
+ );
297
+ }
298
+
299
+ filteredGroups = filteredGroups.filter(
300
+ (x) =>
301
+ directionFilter.travelDuration.selectedMin <=
302
+ (isOutward ? x.outward : x.return).travelDurationMinutes &&
303
+ (isOutward ? x.outward : x.return).travelDurationMinutes <=
304
+ directionFilter.travelDuration.selectedMax
305
+ );
306
+ return filteredGroups.filter(
307
+ (x) =>
308
+ directionFilter.changeDuration.selectedMin <=
309
+ (isOutward ? x.outward : x.return).changeDurationMinutes &&
310
+ (isOutward ? x.outward : x.return).changeDurationMinutes <=
311
+ directionFilter.changeDuration.selectedMax
312
+ );
313
+ };
314
+
315
+ export const formatMinutes = (minutes: number) => {
316
+ var hh = Math.floor(minutes / 60);
317
+ var mm = Math.floor(minutes % 60);
318
+ return pad(hh, 2) + ":" + pad(mm, 2);
319
+ };
320
+
321
+ const getFlightDetails = (flight: BookingPackageFlight) => {
322
+ if (flight.flightMetaData == null) return;
323
+ const firstLine = flight.flightMetaData.flightLines[0];
324
+ const lastLine =
325
+ flight.flightMetaData.flightLines[
326
+ flight.flightMetaData.flightLines.length - 1
327
+ ];
328
+
329
+ const airlineCode = flight.code.split("/")[1];
330
+ const waitDurations = getWaitDurations(flight.flightMetaData.flightLines);
331
+
332
+ return {
333
+ airline: flight.airlineDescription,
334
+ airlineCode: airlineCode,
335
+ departureDate: firstLine.departureDate,
336
+ departureTime: firstLine.departureTime,
337
+ departureAirportCode: firstLine.departureAirport,
338
+ departureAirport: firstLine.departureAirportDescription,
339
+ arrivalDate: lastLine.arrivalDate,
340
+ arrivalTime: lastLine.arrivalTime,
341
+ arrivalAirport: lastLine.arrivalAirportDescription,
342
+ travelDuration: formatDuration(flight.flightMetaData.durationInTicks),
343
+ travelDurationMinutes: minutesFromTicks(
344
+ flight.flightMetaData.durationInTicks
345
+ ),
346
+ changeDurationMinutes: getTotalChangeDuration(flight),
347
+ numberOfStops: flight.flightMetaData.flightLines.length - 1,
348
+ isNextDay: isNextDay(firstLine.departureDate, lastLine.arrivalDate),
349
+ travelClass: firstLine.travelClass,
350
+ flightLines: flight.flightMetaData.flightLines.map((x, i) => ({
351
+ airline: x.operatingAirlineDescription,
352
+ departureDate: x.departureDate,
353
+ departureTime: x.departureTime,
354
+ departureAirport: x.departureAirportDescription,
355
+ arrivalDate: x.arrivalDate,
356
+ arrivalTime: x.arrivalTime,
357
+ arrivalAirport: x.arrivalAirportDescription,
358
+ number: `${x.airlineCode} ${x.number}`,
359
+ travelDuration: formatDuration(x.durationInTicks),
360
+ waitDuration:
361
+ waitDurations.length - 1 <= i ? waitDurations[i] : undefined,
362
+ })),
363
+ } as GroupedFlightDetails;
364
+ };
365
+
366
+ const isNextDay = (startDateString: string, endDateString: string) => {
367
+ const startDate = parseISO(startDateString);
368
+ const endDate = parseISO(endDateString);
369
+
370
+ return !isEqual(startDate, endDate);
371
+ };
372
+
373
+ const getWaitDurations = (lines: BookingPackageFlightMetaDataLine[]) => {
374
+ if (lines.length <= 1) return [];
375
+ let arrivalDate = lines[0].arrivalDate;
376
+ let arrivalTime = lines[0].arrivalTime;
377
+
378
+ const waitDurations: string[] = [];
379
+ for (var i = 1; i < lines.length; i++) {
380
+ const line = lines[i];
381
+
382
+ const waitDuration = getWaitDuration(
383
+ arrivalDate,
384
+ arrivalTime,
385
+ line.departureDate,
386
+ line.departureTime
387
+ );
388
+ waitDurations.push(waitDuration);
389
+
390
+ arrivalDate = line.arrivalDate;
391
+ arrivalTime = line.arrivalTime;
392
+ }
393
+
394
+ return waitDurations;
395
+ };
396
+
397
+ const getWaitDuration = (
398
+ arrivalDateString: string,
399
+ arrivalTime: string,
400
+ departureDateString: string,
401
+ departureTime: string
402
+ ) => {
403
+ const minutes = getWaitDurationInMinutes(
404
+ arrivalDateString,
405
+ arrivalTime,
406
+ departureDateString,
407
+ departureTime
408
+ );
409
+
410
+ var hh = Math.floor(minutes / 60);
411
+ var mm = Math.floor(minutes % 60);
412
+ return pad(hh, 2) + ":" + pad(mm, 2);
413
+ };
414
+
415
+ const getWaitDurationInMinutes = (
416
+ arrivalDateString: string,
417
+ arrivalTime: string,
418
+ departureDateString: string,
419
+ departureTime: string
420
+ ) => {
421
+ const arrivalDate = parseISO(arrivalDateString);
422
+ const arrivalTimeParts = arrivalTime.split(":");
423
+
424
+ arrivalDate.setHours(parseInt(arrivalTimeParts[0]));
425
+ arrivalDate.setMinutes(parseInt(arrivalTimeParts[1]));
426
+
427
+ const departureDate = parseISO(departureDateString);
428
+ const departureTimeParts = departureTime.split(":");
429
+
430
+ departureDate.setHours(parseInt(departureTimeParts[0]));
431
+ departureDate.setMinutes(parseInt(departureTimeParts[1]));
432
+
433
+ return differenceInMinutes(departureDate, arrivalDate);
434
+ };
435
+
436
+ /*const groupFlights = (flights: BookingPackageFlight[]) => {
437
+ let flightsPool = [...flights];
438
+ let groups = [] as FlightGroup[];
439
+ for (var i = 0; i < flightsPool.length; i++) {
440
+ const flight = flightsPool[i];
441
+
442
+ const relatedFlights = flightsPool.filter(x => x != flight
443
+ && x.code === flight.code
444
+ && isDateEqual(x.startDateTime, flight.startDateTime)
445
+ && isDateEqual(x.endDateTime, flight.endDateTime)
446
+ );
447
+
448
+ flightsPool = flightsPool.filter(x => x != flight
449
+ && relatedFlights.some(y => y != x));
450
+
451
+ groups.push({
452
+ code: flight.code,
453
+ startDate: parseISO(flight.startDateTime),
454
+ endDate: parseISO(flight.endDateTime),
455
+ options: [flight, ...relatedFlights]
456
+ });
457
+ }
458
+ }
459
+
460
+ const isDateEqual = (first: string, second: string) => {
461
+ const firstDate = parseISO(first);
462
+ const secondDate = parseISO(second);
463
+
464
+ return isEqual(firstDate, secondDate);
465
+ }*/
466
+
467
+ const minutesFromTicks = (ticks: number) => {
468
+ const totalSeconds = ticks / 10_000_000;
469
+ return Math.floor(totalSeconds / 60);
470
+ };
471
+
472
+ const formatDuration = (ticks: number) => {
473
+ if (!ticks) return "";
474
+
475
+ const totalSeconds = ticks / 10_000_000;
476
+ var hh = Math.floor(totalSeconds / 3600);
477
+ var mm = Math.floor((totalSeconds % 3600) / 60);
478
+ return pad(hh, 2) + ":" + pad(mm, 2);
479
+ };
480
+
481
+ const pad = (input: number, width: number) => {
482
+ const n = input + "";
483
+ return n.length >= width ? n : new Array(width - n.length + 1).join("0") + n;
484
+ };
485
+
486
+ const determineTimeBracket = (input: string) => {
487
+ const time = parseInt(input.replace(":", ""));
488
+ if (time <= 500) return "0000-0500";
489
+ if (time > 500 && time <= 1200) return "0500-1200";
490
+ if (time > 1200 && time <= 1800) return "1201-1800";
491
+ return "1800-2400";
492
+ };
493
+
494
+ const getBracketTranslation = (input: string, translations: any) => {
495
+ if (input === "0000-0500") return translations.FLIGHTS_FORM.NIGHT_DEPARTURE;
496
+ if (input === "0500-1200") return translations.FLIGHTS_FORM.MORNING_DEPARTURE;
497
+ if (input === "1200-1800")
498
+ return translations.FLIGHTS_FORM.AFTERNOON_DEPARTURE;
499
+ return translations.FLIGHTS_FORM.EVENING_DEPARTURE;
500
+ };
501
+
502
+ const getTotalChangeDuration = (flight: BookingPackageFlight) => {
503
+ const lines = flight.flightMetaData.flightLines;
504
+
505
+ if (lines.length <= 1) return 0;
506
+ let arrivalDate = lines[0].arrivalDate;
507
+ let arrivalTime = lines[0].arrivalTime;
508
+
509
+ let waitDuration = 0;
510
+ for (var i = 1; i < lines.length; i++) {
511
+ const line = lines[i];
512
+
513
+ waitDuration += getWaitDurationInMinutes(
514
+ arrivalDate,
515
+ arrivalTime,
516
+ line.departureDate,
517
+ line.departureTime
518
+ );
519
+ }
520
+
521
+ return waitDuration;
522
+ };