@qite/tide-booking-component 1.3.2 → 1.3.4

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 (133) hide show
  1. package/.vs/ProjectSettings.json +3 -3
  2. package/.vs/VSWorkspaceState.json +5 -5
  3. package/README.md +8 -8
  4. package/build/build-cjs/booking-wizard/types.d.ts +1 -5
  5. package/build/build-cjs/index.js +58 -101
  6. package/build/build-esm/booking-wizard/types.d.ts +1 -5
  7. package/build/build-esm/index.js +58 -101
  8. package/package.json +75 -75
  9. package/rollup.config.js +23 -23
  10. package/src/booking-product/components/age-select.tsx +35 -35
  11. package/src/booking-product/components/amount-input.tsx +78 -78
  12. package/src/booking-product/components/date-range-picker/calendar-day.tsx +58 -58
  13. package/src/booking-product/components/date-range-picker/calendar.tsx +178 -178
  14. package/src/booking-product/components/date-range-picker/index.tsx +196 -196
  15. package/src/booking-product/components/dates.tsx +136 -136
  16. package/src/booking-product/components/footer.tsx +69 -69
  17. package/src/booking-product/components/header.tsx +79 -79
  18. package/src/booking-product/components/icon.tsx +251 -251
  19. package/src/booking-product/components/product.tsx +314 -314
  20. package/src/booking-product/components/rating.tsx +21 -21
  21. package/src/booking-product/components/rooms.tsx +195 -195
  22. package/src/booking-product/index.tsx +30 -30
  23. package/src/booking-product/settings-context.ts +14 -14
  24. package/src/booking-product/types.ts +28 -28
  25. package/src/booking-product/utils/api.ts +25 -25
  26. package/src/booking-product/utils/price.ts +29 -29
  27. package/src/booking-wizard/api-settings-slice.ts +24 -24
  28. package/src/booking-wizard/components/icon.tsx +508 -508
  29. package/src/booking-wizard/components/labeled-input.tsx +64 -64
  30. package/src/booking-wizard/components/labeled-select.tsx +69 -69
  31. package/src/booking-wizard/components/message.tsx +34 -34
  32. package/src/booking-wizard/components/multi-range-filter.tsx +113 -113
  33. package/src/booking-wizard/components/print-offer-button.tsx +63 -66
  34. package/src/booking-wizard/components/product-card.tsx +37 -37
  35. package/src/booking-wizard/components/step-indicator.tsx +51 -51
  36. package/src/booking-wizard/components/step-route.tsx +27 -27
  37. package/src/booking-wizard/declarations.d.ts +4 -4
  38. package/src/booking-wizard/features/booking/api.ts +49 -49
  39. package/src/booking-wizard/features/booking/booking-self-contained.tsx +389 -389
  40. package/src/booking-wizard/features/booking/booking-slice.ts +663 -663
  41. package/src/booking-wizard/features/booking/booking.tsx +361 -361
  42. package/src/booking-wizard/features/booking/constants.ts +16 -16
  43. package/src/booking-wizard/features/booking/selectors.ts +441 -441
  44. package/src/booking-wizard/features/confirmation/confirmation.tsx +97 -97
  45. package/src/booking-wizard/features/error/error.tsx +78 -78
  46. package/src/booking-wizard/features/flight-options/flight-filter.tsx +432 -432
  47. package/src/booking-wizard/features/flight-options/flight-option-flight.tsx +385 -385
  48. package/src/booking-wizard/features/flight-options/flight-option-modal.tsx +229 -229
  49. package/src/booking-wizard/features/flight-options/flight-option.tsx +81 -81
  50. package/src/booking-wizard/features/flight-options/flight-utils.ts +522 -516
  51. package/src/booking-wizard/features/flight-options/index.tsx +196 -196
  52. package/src/booking-wizard/features/price-details/price-details-api.ts +24 -24
  53. package/src/booking-wizard/features/price-details/price-details-slice.ts +178 -178
  54. package/src/booking-wizard/features/price-details/util.ts +155 -155
  55. package/src/booking-wizard/features/product-options/no-options.tsx +21 -21
  56. package/src/booking-wizard/features/product-options/none-option.tsx +120 -120
  57. package/src/booking-wizard/features/product-options/option-booking-airline-group.tsx +64 -64
  58. package/src/booking-wizard/features/product-options/option-booking-group.tsx +216 -216
  59. package/src/booking-wizard/features/product-options/option-item.tsx +317 -317
  60. package/src/booking-wizard/features/product-options/option-pax-card.tsx +201 -201
  61. package/src/booking-wizard/features/product-options/option-pax-group.tsx +175 -175
  62. package/src/booking-wizard/features/product-options/option-room.tsx +321 -321
  63. package/src/booking-wizard/features/product-options/option-unit-group.tsx +198 -198
  64. package/src/booking-wizard/features/product-options/option-units-card.tsx +185 -185
  65. package/src/booking-wizard/features/product-options/options-form.tsx +481 -563
  66. package/src/booking-wizard/features/room-options/index.tsx +187 -187
  67. package/src/booking-wizard/features/room-options/room-utils.ts +190 -190
  68. package/src/booking-wizard/features/room-options/room.tsx +160 -160
  69. package/src/booking-wizard/features/room-options/traveler-rooms.tsx +75 -75
  70. package/src/booking-wizard/features/sidebar/index.tsx +76 -76
  71. package/src/booking-wizard/features/sidebar/sidebar-flight.tsx +68 -68
  72. package/src/booking-wizard/features/sidebar/sidebar-util.ts +177 -177
  73. package/src/booking-wizard/features/sidebar/sidebar.tsx +364 -364
  74. package/src/booking-wizard/features/summary/summary-booking-option-pax.tsx +25 -25
  75. package/src/booking-wizard/features/summary/summary-booking-option-unit.tsx +25 -25
  76. package/src/booking-wizard/features/summary/summary-flight.tsx +39 -39
  77. package/src/booking-wizard/features/summary/summary-per-booking-option-group.tsx +69 -69
  78. package/src/booking-wizard/features/summary/summary-per-pax-option-group.tsx +63 -63
  79. package/src/booking-wizard/features/summary/summary-per-unit-option-group.tsx +66 -66
  80. package/src/booking-wizard/features/summary/summary-slice.ts +28 -28
  81. package/src/booking-wizard/features/summary/summary.tsx +674 -674
  82. package/src/booking-wizard/features/travelers-form/travelers-form-slice.ts +164 -164
  83. package/src/booking-wizard/features/travelers-form/travelers-form.tsx +754 -754
  84. package/src/booking-wizard/features/travelers-form/type-ahead-input.tsx +101 -101
  85. package/src/booking-wizard/features/travelers-form/validate-form.ts +245 -245
  86. package/src/booking-wizard/index.tsx +36 -36
  87. package/src/booking-wizard/settings-context.ts +62 -62
  88. package/src/booking-wizard/store.ts +31 -31
  89. package/src/booking-wizard/types.ts +279 -279
  90. package/src/booking-wizard/use-offer-printer.ts +117 -136
  91. package/src/index.ts +4 -4
  92. package/src/shared/components/loader.tsx +16 -16
  93. package/src/shared/translations/en-GB.json +237 -237
  94. package/src/shared/translations/fr-BE.json +238 -238
  95. package/src/shared/translations/nl-BE.json +237 -237
  96. package/src/shared/types.ts +4 -4
  97. package/src/shared/utils/class-util.ts +9 -9
  98. package/src/shared/utils/localization-util.ts +62 -62
  99. package/src/shared/utils/query-string-util.ts +119 -119
  100. package/src/shared/utils/tide-api-utils.ts +36 -36
  101. package/styles/booking-product-variables.scss +394 -394
  102. package/styles/booking-product.scss +446 -446
  103. package/styles/booking-wizard-variables.scss +873 -873
  104. package/styles/booking-wizard.scss +59 -59
  105. package/styles/components/_animations.scss +39 -39
  106. package/styles/components/_base.scss +107 -107
  107. package/styles/components/_booking.scss +879 -879
  108. package/styles/components/_button.scss +238 -238
  109. package/styles/components/_checkbox.scss +219 -219
  110. package/styles/components/_cta.scss +208 -208
  111. package/styles/components/_date-list.scss +41 -41
  112. package/styles/components/_date-range-picker.scss +225 -225
  113. package/styles/components/_decrement-increment.scss +35 -35
  114. package/styles/components/_dropdown.scss +72 -72
  115. package/styles/components/_flight-option.scss +1429 -1429
  116. package/styles/components/_form.scss +1583 -1583
  117. package/styles/components/_info-message.scss +71 -71
  118. package/styles/components/_input.scss +25 -25
  119. package/styles/components/_list.scss +187 -187
  120. package/styles/components/_loader.scss +72 -72
  121. package/styles/components/_mixins.scss +550 -550
  122. package/styles/components/_placeholders.scss +166 -166
  123. package/styles/components/_pricing-summary.scss +155 -155
  124. package/styles/components/_qsm.scss +17 -17
  125. package/styles/components/_radiobutton.scss +170 -170
  126. package/styles/components/_select-wrapper.scss +80 -80
  127. package/styles/components/_spinner.scss +29 -29
  128. package/styles/components/_step-indicators.scss +168 -168
  129. package/styles/components/_table.scss +81 -81
  130. package/styles/components/_tree.scss +530 -530
  131. package/styles/components/_typeahead.scss +281 -281
  132. package/styles/components/_variables.scss +89 -89
  133. package/tsconfig.json +24 -24
@@ -1,432 +1,432 @@
1
- import React, { useState, useEffect, useRef } from "react";
2
- import { useSelector } from "react-redux";
3
- import { buildClassName } from "../../../shared/utils/class-util";
4
- import Icon from "../../components/icon";
5
- import MultiRangeFilter from "../../components/multi-range-filter";
6
- import { FlightFilterOptions } from "../../types";
7
- import { selectTranslations } from "../booking/selectors";
8
- import { formatMinutes } from "./flight-utils";
9
-
10
- interface FlightFilterProps {
11
- filterOptions: FlightFilterOptions;
12
- resultCount: number;
13
-
14
- applyFilter: (options: FlightFilterOptions) => void;
15
- }
16
-
17
- const FlightFilter: React.FC<FlightFilterProps> = ({
18
- filterOptions,
19
- resultCount,
20
- applyFilter,
21
- }) => {
22
- const translations = useSelector(selectTranslations);
23
-
24
- const [filtersVisible, setFiltersVisible] = useState<boolean>(false);
25
- const filterRef = useRef<HTMLDivElement>(null);
26
-
27
- useEffect(() => {
28
- function handleClickOutside(event: MouseEvent) {
29
- if (
30
- filterRef.current &&
31
- !filterRef.current.contains(event.target as Node)
32
- ) {
33
- setFiltersVisible(false);
34
- }
35
- }
36
- document.addEventListener("mousedown", handleClickOutside);
37
- return () => {
38
- document.removeEventListener("mousedown", handleClickOutside);
39
- };
40
- }, []);
41
-
42
- const updateAirportFilter = (code: string) => {
43
- const updatedFilterOptions = {
44
- ...filterOptions,
45
- airports: filterOptions.airports.map((x) => {
46
- if (x.value !== code) return x;
47
-
48
- return {
49
- ...x,
50
- isSelected: !x.isSelected,
51
- };
52
- }),
53
- };
54
-
55
- applyFilter(updatedFilterOptions);
56
- };
57
-
58
- const updateAirlineFilter = (code: string) => {
59
- const updatedFilterOptions = {
60
- ...filterOptions,
61
- airlines: filterOptions.airlines.map((x) => {
62
- if (x.value !== code) return x;
63
-
64
- return {
65
- ...x,
66
- isSelected: !x.isSelected,
67
- };
68
- }),
69
- };
70
-
71
- applyFilter(updatedFilterOptions);
72
- };
73
-
74
- const updateStopsFilter = (count: string) => {
75
- const updatedFilterOptions = {
76
- ...filterOptions,
77
- numberOfStops: filterOptions.numberOfStops.map((x) => {
78
- if (x.value !== count) return x;
79
-
80
- return {
81
- ...x,
82
- isSelected: !x.isSelected,
83
- };
84
- }),
85
- };
86
-
87
- applyFilter(updatedFilterOptions);
88
- };
89
-
90
- const updateOutwardDeparture = (period: string) => {
91
- const updatedFilterOptions = {
92
- ...filterOptions,
93
- outward: {
94
- ...filterOptions.outward,
95
- departurePeriod: filterOptions.outward.departurePeriod.map((x) => {
96
- if (x.value !== period) return x;
97
-
98
- return {
99
- ...x,
100
- isSelected: !x.isSelected,
101
- };
102
- }),
103
- },
104
- };
105
-
106
- applyFilter(updatedFilterOptions);
107
- };
108
-
109
- const updateOutwardTravelDuration = (min: number, max: number) => {
110
- const updatedFilterOptions = {
111
- ...filterOptions,
112
- outward: {
113
- ...filterOptions.outward,
114
- travelDuration: {
115
- ...filterOptions.outward.travelDuration,
116
- selectedMin: min,
117
- selectedMax: max,
118
- },
119
- },
120
- };
121
-
122
- applyFilter(updatedFilterOptions);
123
- };
124
-
125
- const updateOutwardChangeDuration = (min: number, max: number) => {
126
- const updatedFilterOptions = {
127
- ...filterOptions,
128
- outward: {
129
- ...filterOptions.outward,
130
- changeDuration: {
131
- ...filterOptions.outward.changeDuration,
132
- selectedMin: min,
133
- selectedMax: max,
134
- },
135
- },
136
- };
137
-
138
- applyFilter(updatedFilterOptions);
139
- };
140
-
141
- const updateReturnDeparture = (period: string) => {
142
- const updatedFilterOptions = {
143
- ...filterOptions,
144
- return: {
145
- ...filterOptions.return,
146
- departurePeriod: filterOptions.return.departurePeriod.map((x) => {
147
- if (x.value !== period) return x;
148
-
149
- return {
150
- ...x,
151
- isSelected: !x.isSelected,
152
- };
153
- }),
154
- },
155
- };
156
-
157
- applyFilter(updatedFilterOptions);
158
- };
159
-
160
- const updateReturnTravelDuration = (min: number, max: number) => {
161
- const updatedFilterOptions = {
162
- ...filterOptions,
163
- return: {
164
- ...filterOptions.return,
165
- travelDuration: {
166
- ...filterOptions.return.travelDuration,
167
- selectedMin: min,
168
- selectedMax: max,
169
- },
170
- },
171
- };
172
-
173
- applyFilter(updatedFilterOptions);
174
- };
175
-
176
- const updateReturnChangeDuration = (min: number, max: number) => {
177
- const updatedFilterOptions = {
178
- ...filterOptions,
179
- return: {
180
- ...filterOptions.return,
181
- changeDuration: {
182
- ...filterOptions.return.changeDuration,
183
- selectedMin: min,
184
- selectedMax: max,
185
- },
186
- },
187
- };
188
-
189
- applyFilter(updatedFilterOptions);
190
- };
191
-
192
- return (
193
- <>
194
- <button
195
- type="button"
196
- className="cta cta--filter"
197
- onClick={() => setFiltersVisible(!filtersVisible)}
198
- >
199
- <Icon name="ui-filter" width={11} height={10} />
200
- <span>{translations.FLIGHTS_FORM.FILTER_OPTIONS}</span>
201
- </button>
202
-
203
- <div
204
- ref={filterRef}
205
- className={buildClassName([
206
- "flight__filter",
207
- filtersVisible && "flight__filter--active",
208
- ])}
209
- >
210
- <div className="flight__filter__header">
211
- <div className="flight__filter__header__title">
212
- <h3>{translations.FLIGHTS_FORM.FILTER_OPTIONS}</h3>
213
- <p>
214
- {translations.FLIGHTS_FORM.FLIGHTS_FOUND_1}{" "}
215
- <strong>
216
- {resultCount} {translations.FLIGHTS_FORM.FLIGHTS_FOUND_2}
217
- </strong>{" "}
218
- {translations.FLIGHTS_FORM.FLIGHTS_FOUND_3}
219
- </p>
220
- </div>
221
- <button
222
- type="button"
223
- className="cta cta--close"
224
- onClick={() => setFiltersVisible(false)}
225
- >
226
- <Icon name="ui-close" width={25} height={25} />
227
- </button>
228
- </div>
229
- <div className="flight__filter__body">
230
- <div className="flight__filter__group">
231
- <div className="flight__filter__group__title">
232
- {translations.FLIGHTS_FORM.AIRLINES}
233
- </div>
234
- <div className="flight__filter__group__wrapper">
235
- {filterOptions.airlines.map((option, k) => (
236
- <div className="tree" key={k}>
237
- <div className="checkbox flight__filter__checkbox">
238
- <label
239
- htmlFor={"airline_" + option.value}
240
- className="checkbox__label"
241
- >
242
- <input
243
- type="checkbox"
244
- id={"airline_" + option.value}
245
- className="checkbox__input checkbox__input--parent"
246
- onClick={() => updateAirlineFilter(option.value)}
247
- />
248
- <span className="radiobutton__label-text">
249
- {option.label}{" "}
250
- {option.count > 0 && (
251
- <span className="amount">({option.count})</span>
252
- )}
253
- </span>
254
- </label>
255
- </div>
256
- </div>
257
- ))}
258
- </div>
259
- </div>
260
- <div className="flight__filter__group">
261
- <div className="flight__filter__group__title">
262
- {translations.FLIGHTS_FORM.AIRPORTS}
263
- </div>
264
- <div className="flight__filter__group__wrapper">
265
- {filterOptions.airports.map((option, k) => (
266
- <div className="tree" key={k}>
267
- <div className="checkbox flight__filter__checkbox">
268
- <label
269
- htmlFor={"airport_" + option.value}
270
- className="checkbox__label"
271
- >
272
- <input
273
- type="checkbox"
274
- id={"airport_" + option.value}
275
- className="checkbox__input checkbox__input--parent"
276
- onClick={() => updateAirportFilter(option.value)}
277
- />
278
- <span className="radiobutton__label-text">
279
- {option.label}{" "}
280
- {option.count > 0 && (
281
- <span className="amount">({option.count})</span>
282
- )}
283
- </span>
284
- </label>
285
- </div>
286
- </div>
287
- ))}
288
- </div>
289
- </div>
290
- <div className="flight__filter__group">
291
- <div className="flight__filter__group__title">
292
- {translations.FLIGHTS_FORM.NUMBER_OF_STOPS}
293
- </div>
294
- <div className="flight__filter__group__wrapper">
295
- {filterOptions.numberOfStops.map((option, k) => (
296
- <div className="tree" key={k}>
297
- <div className="checkbox flight__filter__checkbox">
298
- <label
299
- htmlFor={"stops_" + option.value}
300
- className="checkbox__label"
301
- >
302
- <input
303
- type="checkbox"
304
- id={"stops_" + option.value}
305
- className="checkbox__input checkbox__input--parent"
306
- onClick={() => updateStopsFilter(option.value)}
307
- />
308
- <span className="radiobutton__label-text">
309
- {option.label}{" "}
310
- {option.count > 0 && (
311
- <span className="amount">({option.count})</span>
312
- )}
313
- </span>
314
- </label>
315
- </div>
316
- </div>
317
- ))}
318
- </div>
319
- </div>
320
- <div className="flight__filter__group">
321
- <div className="flight__filter__group__title">
322
- {translations.FLIGHTS_FORM.FLIGHT_OUTWARD}
323
- </div>
324
- <div className="flight__filter__group__wrapper">
325
- <p>{translations.FLIGHTS_FORM.DEPARTURE_TIME}</p>
326
- {filterOptions.outward.departurePeriod.map((option, k) => (
327
- <div className="tree" key={k}>
328
- <div className="checkbox flight__filter__checkbox">
329
- <label
330
- htmlFor={"outward_time_" + option.value}
331
- className="checkbox__label"
332
- >
333
- <input
334
- type="checkbox"
335
- id={"outward_time_" + option.value}
336
- className="checkbox__input checkbox__input--parent"
337
- onClick={() => updateOutwardDeparture(option.value)}
338
- />
339
- <span className="radiobutton__label-text">
340
- {option.label}{" "}
341
- {option.count > 0 && (
342
- <span className="amount">({option.count})</span>
343
- )}
344
- </span>
345
- </label>
346
- </div>
347
- </div>
348
- ))}
349
- </div>
350
- <div className="flight__filter__group__wrapper">
351
- <p>{translations.FLIGHTS_FORM.TRAVEL_DURATION}</p>
352
- <MultiRangeFilter
353
- min={filterOptions.outward.travelDuration.min}
354
- max={filterOptions.outward.travelDuration.max}
355
- selectedMin={filterOptions.outward.travelDuration.selectedMin}
356
- selectedMax={filterOptions.outward.travelDuration.selectedMax}
357
- valueFormatter={formatMinutes}
358
- onChange={updateOutwardTravelDuration}
359
- />
360
- </div>
361
- <div className="flight__filter__group__wrapper">
362
- <p>{translations.FLIGHTS_FORM.CHANGE_TIME}</p>
363
- <MultiRangeFilter
364
- min={filterOptions.outward.changeDuration.min}
365
- max={filterOptions.outward.changeDuration.max}
366
- selectedMin={filterOptions.outward.changeDuration.selectedMin}
367
- selectedMax={filterOptions.outward.changeDuration.selectedMax}
368
- valueFormatter={formatMinutes}
369
- onChange={updateOutwardChangeDuration}
370
- />
371
- </div>
372
- </div>
373
- <div className="flight__filter__group">
374
- <div className="flight__filter__group__title">
375
- {translations.FLIGHTS_FORM.FLIGHT_RETURN}
376
- </div>
377
- <div className="flight__filter__group__wrapper">
378
- <p>{translations.FLIGHTS_FORM.DEPARTURE_TIME}</p>
379
- {filterOptions.return.departurePeriod.map((option, k) => (
380
- <div className="tree" key={k}>
381
- <div className="checkbox flight__filter__checkbox">
382
- <label
383
- htmlFor={"return_time_" + option.value}
384
- className="checkbox__label"
385
- >
386
- <input
387
- type="checkbox"
388
- id={"return_time_" + option.value}
389
- className="checkbox__input checkbox__input--parent"
390
- onClick={() => updateReturnDeparture(option.value)}
391
- />
392
- <span className="radiobutton__label-text">
393
- {option.label}{" "}
394
- {option.count > 0 && (
395
- <span className="amount">({option.count})</span>
396
- )}
397
- </span>
398
- </label>
399
- </div>
400
- </div>
401
- ))}
402
- </div>
403
- <div className="flight__filter__group__wrapper">
404
- <p>{translations.FLIGHTS_FORM.TRAVEL_DURATION}</p>
405
- <MultiRangeFilter
406
- min={filterOptions.return.travelDuration.min}
407
- max={filterOptions.return.travelDuration.max}
408
- selectedMin={filterOptions.return.travelDuration.selectedMin}
409
- selectedMax={filterOptions.return.travelDuration.selectedMax}
410
- valueFormatter={formatMinutes}
411
- onChange={updateReturnTravelDuration}
412
- />
413
- </div>
414
- <div className="flight__filter__group__wrapper">
415
- <p>{translations.FLIGHTS_FORM.CHANGE_TIME}</p>
416
- <MultiRangeFilter
417
- min={filterOptions.return.changeDuration.min}
418
- max={filterOptions.return.changeDuration.max}
419
- selectedMin={filterOptions.return.changeDuration.selectedMin}
420
- selectedMax={filterOptions.return.changeDuration.selectedMax}
421
- valueFormatter={formatMinutes}
422
- onChange={updateReturnChangeDuration}
423
- />
424
- </div>
425
- </div>
426
- </div>
427
- </div>
428
- </>
429
- );
430
- };
431
-
432
- export default FlightFilter;
1
+ import React, { useState, useEffect, useRef } from "react";
2
+ import { useSelector } from "react-redux";
3
+ import { buildClassName } from "../../../shared/utils/class-util";
4
+ import Icon from "../../components/icon";
5
+ import MultiRangeFilter from "../../components/multi-range-filter";
6
+ import { FlightFilterOptions } from "../../types";
7
+ import { selectTranslations } from "../booking/selectors";
8
+ import { formatMinutes } from "./flight-utils";
9
+
10
+ interface FlightFilterProps {
11
+ filterOptions: FlightFilterOptions;
12
+ resultCount: number;
13
+
14
+ applyFilter: (options: FlightFilterOptions) => void;
15
+ }
16
+
17
+ const FlightFilter: React.FC<FlightFilterProps> = ({
18
+ filterOptions,
19
+ resultCount,
20
+ applyFilter,
21
+ }) => {
22
+ const translations = useSelector(selectTranslations);
23
+
24
+ const [filtersVisible, setFiltersVisible] = useState<boolean>(false);
25
+ const filterRef = useRef<HTMLDivElement>(null);
26
+
27
+ useEffect(() => {
28
+ function handleClickOutside(event: MouseEvent) {
29
+ if (
30
+ filterRef.current &&
31
+ !filterRef.current.contains(event.target as Node)
32
+ ) {
33
+ setFiltersVisible(false);
34
+ }
35
+ }
36
+ document.addEventListener("mousedown", handleClickOutside);
37
+ return () => {
38
+ document.removeEventListener("mousedown", handleClickOutside);
39
+ };
40
+ }, []);
41
+
42
+ const updateAirportFilter = (code: string) => {
43
+ const updatedFilterOptions = {
44
+ ...filterOptions,
45
+ airports: filterOptions.airports.map((x) => {
46
+ if (x.value !== code) return x;
47
+
48
+ return {
49
+ ...x,
50
+ isSelected: !x.isSelected,
51
+ };
52
+ }),
53
+ };
54
+
55
+ applyFilter(updatedFilterOptions);
56
+ };
57
+
58
+ const updateAirlineFilter = (code: string) => {
59
+ const updatedFilterOptions = {
60
+ ...filterOptions,
61
+ airlines: filterOptions.airlines.map((x) => {
62
+ if (x.value !== code) return x;
63
+
64
+ return {
65
+ ...x,
66
+ isSelected: !x.isSelected,
67
+ };
68
+ }),
69
+ };
70
+
71
+ applyFilter(updatedFilterOptions);
72
+ };
73
+
74
+ const updateStopsFilter = (count: string) => {
75
+ const updatedFilterOptions = {
76
+ ...filterOptions,
77
+ numberOfStops: filterOptions.numberOfStops.map((x) => {
78
+ if (x.value !== count) return x;
79
+
80
+ return {
81
+ ...x,
82
+ isSelected: !x.isSelected,
83
+ };
84
+ }),
85
+ };
86
+
87
+ applyFilter(updatedFilterOptions);
88
+ };
89
+
90
+ const updateOutwardDeparture = (period: string) => {
91
+ const updatedFilterOptions = {
92
+ ...filterOptions,
93
+ outward: {
94
+ ...filterOptions.outward,
95
+ departurePeriod: filterOptions.outward.departurePeriod.map((x) => {
96
+ if (x.value !== period) return x;
97
+
98
+ return {
99
+ ...x,
100
+ isSelected: !x.isSelected,
101
+ };
102
+ }),
103
+ },
104
+ };
105
+
106
+ applyFilter(updatedFilterOptions);
107
+ };
108
+
109
+ const updateOutwardTravelDuration = (min: number, max: number) => {
110
+ const updatedFilterOptions = {
111
+ ...filterOptions,
112
+ outward: {
113
+ ...filterOptions.outward,
114
+ travelDuration: {
115
+ ...filterOptions.outward.travelDuration,
116
+ selectedMin: min,
117
+ selectedMax: max,
118
+ },
119
+ },
120
+ };
121
+
122
+ applyFilter(updatedFilterOptions);
123
+ };
124
+
125
+ const updateOutwardChangeDuration = (min: number, max: number) => {
126
+ const updatedFilterOptions = {
127
+ ...filterOptions,
128
+ outward: {
129
+ ...filterOptions.outward,
130
+ changeDuration: {
131
+ ...filterOptions.outward.changeDuration,
132
+ selectedMin: min,
133
+ selectedMax: max,
134
+ },
135
+ },
136
+ };
137
+
138
+ applyFilter(updatedFilterOptions);
139
+ };
140
+
141
+ const updateReturnDeparture = (period: string) => {
142
+ const updatedFilterOptions = {
143
+ ...filterOptions,
144
+ return: {
145
+ ...filterOptions.return,
146
+ departurePeriod: filterOptions.return.departurePeriod.map((x) => {
147
+ if (x.value !== period) return x;
148
+
149
+ return {
150
+ ...x,
151
+ isSelected: !x.isSelected,
152
+ };
153
+ }),
154
+ },
155
+ };
156
+
157
+ applyFilter(updatedFilterOptions);
158
+ };
159
+
160
+ const updateReturnTravelDuration = (min: number, max: number) => {
161
+ const updatedFilterOptions = {
162
+ ...filterOptions,
163
+ return: {
164
+ ...filterOptions.return,
165
+ travelDuration: {
166
+ ...filterOptions.return.travelDuration,
167
+ selectedMin: min,
168
+ selectedMax: max,
169
+ },
170
+ },
171
+ };
172
+
173
+ applyFilter(updatedFilterOptions);
174
+ };
175
+
176
+ const updateReturnChangeDuration = (min: number, max: number) => {
177
+ const updatedFilterOptions = {
178
+ ...filterOptions,
179
+ return: {
180
+ ...filterOptions.return,
181
+ changeDuration: {
182
+ ...filterOptions.return.changeDuration,
183
+ selectedMin: min,
184
+ selectedMax: max,
185
+ },
186
+ },
187
+ };
188
+
189
+ applyFilter(updatedFilterOptions);
190
+ };
191
+
192
+ return (
193
+ <>
194
+ <button
195
+ type="button"
196
+ className="cta cta--filter"
197
+ onClick={() => setFiltersVisible(!filtersVisible)}
198
+ >
199
+ <Icon name="ui-filter" width={11} height={10} />
200
+ <span>{translations.FLIGHTS_FORM.FILTER_OPTIONS}</span>
201
+ </button>
202
+
203
+ <div
204
+ ref={filterRef}
205
+ className={buildClassName([
206
+ "flight__filter",
207
+ filtersVisible && "flight__filter--active",
208
+ ])}
209
+ >
210
+ <div className="flight__filter__header">
211
+ <div className="flight__filter__header__title">
212
+ <h3>{translations.FLIGHTS_FORM.FILTER_OPTIONS}</h3>
213
+ <p>
214
+ {translations.FLIGHTS_FORM.FLIGHTS_FOUND_1}{" "}
215
+ <strong>
216
+ {resultCount} {translations.FLIGHTS_FORM.FLIGHTS_FOUND_2}
217
+ </strong>{" "}
218
+ {translations.FLIGHTS_FORM.FLIGHTS_FOUND_3}
219
+ </p>
220
+ </div>
221
+ <button
222
+ type="button"
223
+ className="cta cta--close"
224
+ onClick={() => setFiltersVisible(false)}
225
+ >
226
+ <Icon name="ui-close" width={25} height={25} />
227
+ </button>
228
+ </div>
229
+ <div className="flight__filter__body">
230
+ <div className="flight__filter__group">
231
+ <div className="flight__filter__group__title">
232
+ {translations.FLIGHTS_FORM.AIRLINES}
233
+ </div>
234
+ <div className="flight__filter__group__wrapper">
235
+ {filterOptions.airlines.map((option, k) => (
236
+ <div className="tree" key={k}>
237
+ <div className="checkbox flight__filter__checkbox">
238
+ <label
239
+ htmlFor={"airline_" + option.value}
240
+ className="checkbox__label"
241
+ >
242
+ <input
243
+ type="checkbox"
244
+ id={"airline_" + option.value}
245
+ className="checkbox__input checkbox__input--parent"
246
+ onClick={() => updateAirlineFilter(option.value)}
247
+ />
248
+ <span className="radiobutton__label-text">
249
+ {option.label}{" "}
250
+ {option.count > 0 && (
251
+ <span className="amount">({option.count})</span>
252
+ )}
253
+ </span>
254
+ </label>
255
+ </div>
256
+ </div>
257
+ ))}
258
+ </div>
259
+ </div>
260
+ <div className="flight__filter__group">
261
+ <div className="flight__filter__group__title">
262
+ {translations.FLIGHTS_FORM.AIRPORTS}
263
+ </div>
264
+ <div className="flight__filter__group__wrapper">
265
+ {filterOptions.airports.map((option, k) => (
266
+ <div className="tree" key={k}>
267
+ <div className="checkbox flight__filter__checkbox">
268
+ <label
269
+ htmlFor={"airport_" + option.value}
270
+ className="checkbox__label"
271
+ >
272
+ <input
273
+ type="checkbox"
274
+ id={"airport_" + option.value}
275
+ className="checkbox__input checkbox__input--parent"
276
+ onClick={() => updateAirportFilter(option.value)}
277
+ />
278
+ <span className="radiobutton__label-text">
279
+ {option.label}{" "}
280
+ {option.count > 0 && (
281
+ <span className="amount">({option.count})</span>
282
+ )}
283
+ </span>
284
+ </label>
285
+ </div>
286
+ </div>
287
+ ))}
288
+ </div>
289
+ </div>
290
+ <div className="flight__filter__group">
291
+ <div className="flight__filter__group__title">
292
+ {translations.FLIGHTS_FORM.NUMBER_OF_STOPS}
293
+ </div>
294
+ <div className="flight__filter__group__wrapper">
295
+ {filterOptions.numberOfStops.map((option, k) => (
296
+ <div className="tree" key={k}>
297
+ <div className="checkbox flight__filter__checkbox">
298
+ <label
299
+ htmlFor={"stops_" + option.value}
300
+ className="checkbox__label"
301
+ >
302
+ <input
303
+ type="checkbox"
304
+ id={"stops_" + option.value}
305
+ className="checkbox__input checkbox__input--parent"
306
+ onClick={() => updateStopsFilter(option.value)}
307
+ />
308
+ <span className="radiobutton__label-text">
309
+ {option.label}{" "}
310
+ {option.count > 0 && (
311
+ <span className="amount">({option.count})</span>
312
+ )}
313
+ </span>
314
+ </label>
315
+ </div>
316
+ </div>
317
+ ))}
318
+ </div>
319
+ </div>
320
+ <div className="flight__filter__group">
321
+ <div className="flight__filter__group__title">
322
+ {translations.FLIGHTS_FORM.FLIGHT_OUTWARD}
323
+ </div>
324
+ <div className="flight__filter__group__wrapper">
325
+ <p>{translations.FLIGHTS_FORM.DEPARTURE_TIME}</p>
326
+ {filterOptions.outward.departurePeriod.map((option, k) => (
327
+ <div className="tree" key={k}>
328
+ <div className="checkbox flight__filter__checkbox">
329
+ <label
330
+ htmlFor={"outward_time_" + option.value}
331
+ className="checkbox__label"
332
+ >
333
+ <input
334
+ type="checkbox"
335
+ id={"outward_time_" + option.value}
336
+ className="checkbox__input checkbox__input--parent"
337
+ onClick={() => updateOutwardDeparture(option.value)}
338
+ />
339
+ <span className="radiobutton__label-text">
340
+ {option.label}{" "}
341
+ {option.count > 0 && (
342
+ <span className="amount">({option.count})</span>
343
+ )}
344
+ </span>
345
+ </label>
346
+ </div>
347
+ </div>
348
+ ))}
349
+ </div>
350
+ <div className="flight__filter__group__wrapper">
351
+ <p>{translations.FLIGHTS_FORM.TRAVEL_DURATION}</p>
352
+ <MultiRangeFilter
353
+ min={filterOptions.outward.travelDuration.min}
354
+ max={filterOptions.outward.travelDuration.max}
355
+ selectedMin={filterOptions.outward.travelDuration.selectedMin}
356
+ selectedMax={filterOptions.outward.travelDuration.selectedMax}
357
+ valueFormatter={formatMinutes}
358
+ onChange={updateOutwardTravelDuration}
359
+ />
360
+ </div>
361
+ <div className="flight__filter__group__wrapper">
362
+ <p>{translations.FLIGHTS_FORM.CHANGE_TIME}</p>
363
+ <MultiRangeFilter
364
+ min={filterOptions.outward.changeDuration.min}
365
+ max={filterOptions.outward.changeDuration.max}
366
+ selectedMin={filterOptions.outward.changeDuration.selectedMin}
367
+ selectedMax={filterOptions.outward.changeDuration.selectedMax}
368
+ valueFormatter={formatMinutes}
369
+ onChange={updateOutwardChangeDuration}
370
+ />
371
+ </div>
372
+ </div>
373
+ <div className="flight__filter__group">
374
+ <div className="flight__filter__group__title">
375
+ {translations.FLIGHTS_FORM.FLIGHT_RETURN}
376
+ </div>
377
+ <div className="flight__filter__group__wrapper">
378
+ <p>{translations.FLIGHTS_FORM.DEPARTURE_TIME}</p>
379
+ {filterOptions.return.departurePeriod.map((option, k) => (
380
+ <div className="tree" key={k}>
381
+ <div className="checkbox flight__filter__checkbox">
382
+ <label
383
+ htmlFor={"return_time_" + option.value}
384
+ className="checkbox__label"
385
+ >
386
+ <input
387
+ type="checkbox"
388
+ id={"return_time_" + option.value}
389
+ className="checkbox__input checkbox__input--parent"
390
+ onClick={() => updateReturnDeparture(option.value)}
391
+ />
392
+ <span className="radiobutton__label-text">
393
+ {option.label}{" "}
394
+ {option.count > 0 && (
395
+ <span className="amount">({option.count})</span>
396
+ )}
397
+ </span>
398
+ </label>
399
+ </div>
400
+ </div>
401
+ ))}
402
+ </div>
403
+ <div className="flight__filter__group__wrapper">
404
+ <p>{translations.FLIGHTS_FORM.TRAVEL_DURATION}</p>
405
+ <MultiRangeFilter
406
+ min={filterOptions.return.travelDuration.min}
407
+ max={filterOptions.return.travelDuration.max}
408
+ selectedMin={filterOptions.return.travelDuration.selectedMin}
409
+ selectedMax={filterOptions.return.travelDuration.selectedMax}
410
+ valueFormatter={formatMinutes}
411
+ onChange={updateReturnTravelDuration}
412
+ />
413
+ </div>
414
+ <div className="flight__filter__group__wrapper">
415
+ <p>{translations.FLIGHTS_FORM.CHANGE_TIME}</p>
416
+ <MultiRangeFilter
417
+ min={filterOptions.return.changeDuration.min}
418
+ max={filterOptions.return.changeDuration.max}
419
+ selectedMin={filterOptions.return.changeDuration.selectedMin}
420
+ selectedMax={filterOptions.return.changeDuration.selectedMax}
421
+ valueFormatter={formatMinutes}
422
+ onChange={updateReturnChangeDuration}
423
+ />
424
+ </div>
425
+ </div>
426
+ </div>
427
+ </div>
428
+ </>
429
+ );
430
+ };
431
+
432
+ export default FlightFilter;