@qite/tide-booking-component 1.2.5 → 1.3.0

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 (141) 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/components/print-offer-button.d.ts +17 -0
  5. package/build/build-cjs/booking-wizard/types.d.ts +7 -0
  6. package/build/build-cjs/booking-wizard/use-offer-printer.d.ts +13 -0
  7. package/build/build-cjs/index.js +223 -72
  8. package/build/build-cjs/shared/utils/localization-util.d.ts +5 -0
  9. package/build/build-cjs/shared/utils/tide-api-utils.d.ts +1 -0
  10. package/build/build-esm/booking-wizard/components/print-offer-button.d.ts +17 -0
  11. package/build/build-esm/booking-wizard/types.d.ts +7 -0
  12. package/build/build-esm/booking-wizard/use-offer-printer.d.ts +13 -0
  13. package/build/build-esm/index.js +224 -73
  14. package/build/build-esm/shared/utils/localization-util.d.ts +5 -0
  15. package/build/build-esm/shared/utils/tide-api-utils.d.ts +1 -0
  16. package/package.json +75 -75
  17. package/rollup.config.js +23 -23
  18. package/src/booking-product/components/age-select.tsx +35 -35
  19. package/src/booking-product/components/amount-input.tsx +78 -78
  20. package/src/booking-product/components/date-range-picker/calendar-day.tsx +58 -58
  21. package/src/booking-product/components/date-range-picker/calendar.tsx +178 -178
  22. package/src/booking-product/components/date-range-picker/index.tsx +196 -196
  23. package/src/booking-product/components/dates.tsx +136 -136
  24. package/src/booking-product/components/footer.tsx +69 -69
  25. package/src/booking-product/components/header.tsx +79 -79
  26. package/src/booking-product/components/icon.tsx +251 -251
  27. package/src/booking-product/components/product.tsx +314 -314
  28. package/src/booking-product/components/rating.tsx +21 -21
  29. package/src/booking-product/components/rooms.tsx +195 -195
  30. package/src/booking-product/index.tsx +30 -30
  31. package/src/booking-product/settings-context.ts +14 -14
  32. package/src/booking-product/types.ts +28 -28
  33. package/src/booking-product/utils/api.ts +25 -25
  34. package/src/booking-product/utils/price.ts +29 -29
  35. package/src/booking-wizard/api-settings-slice.ts +24 -24
  36. package/src/booking-wizard/components/icon.tsx +508 -508
  37. package/src/booking-wizard/components/labeled-input.tsx +64 -64
  38. package/src/booking-wizard/components/labeled-select.tsx +69 -69
  39. package/src/booking-wizard/components/message.tsx +34 -34
  40. package/src/booking-wizard/components/multi-range-filter.tsx +113 -113
  41. package/src/booking-wizard/components/print-offer-button.tsx +66 -0
  42. package/src/booking-wizard/components/product-card.tsx +37 -37
  43. package/src/booking-wizard/components/step-indicator.tsx +51 -51
  44. package/src/booking-wizard/components/step-route.tsx +27 -27
  45. package/src/booking-wizard/declarations.d.ts +4 -4
  46. package/src/booking-wizard/features/booking/api.ts +49 -49
  47. package/src/booking-wizard/features/booking/booking-self-contained.tsx +384 -384
  48. package/src/booking-wizard/features/booking/booking-slice.ts +662 -662
  49. package/src/booking-wizard/features/booking/booking.tsx +356 -356
  50. package/src/booking-wizard/features/booking/constants.ts +16 -16
  51. package/src/booking-wizard/features/booking/selectors.ts +441 -441
  52. package/src/booking-wizard/features/confirmation/confirmation.tsx +97 -97
  53. package/src/booking-wizard/features/error/error.tsx +78 -78
  54. package/src/booking-wizard/features/flight-options/flight-filter.tsx +432 -432
  55. package/src/booking-wizard/features/flight-options/flight-option-flight.tsx +385 -385
  56. package/src/booking-wizard/features/flight-options/flight-option-modal.tsx +229 -229
  57. package/src/booking-wizard/features/flight-options/flight-option.tsx +81 -81
  58. package/src/booking-wizard/features/flight-options/flight-utils.ts +516 -516
  59. package/src/booking-wizard/features/flight-options/index.tsx +196 -196
  60. package/src/booking-wizard/features/price-details/price-details-api.ts +24 -24
  61. package/src/booking-wizard/features/price-details/price-details-slice.ts +178 -178
  62. package/src/booking-wizard/features/price-details/util.ts +155 -155
  63. package/src/booking-wizard/features/product-options/no-options.tsx +21 -21
  64. package/src/booking-wizard/features/product-options/none-option.tsx +120 -120
  65. package/src/booking-wizard/features/product-options/option-booking-airline-group.tsx +64 -64
  66. package/src/booking-wizard/features/product-options/option-booking-group.tsx +216 -216
  67. package/src/booking-wizard/features/product-options/option-item.tsx +317 -317
  68. package/src/booking-wizard/features/product-options/option-pax-card.tsx +201 -201
  69. package/src/booking-wizard/features/product-options/option-pax-group.tsx +175 -175
  70. package/src/booking-wizard/features/product-options/option-room.tsx +321 -321
  71. package/src/booking-wizard/features/product-options/option-unit-group.tsx +198 -198
  72. package/src/booking-wizard/features/product-options/option-units-card.tsx +185 -185
  73. package/src/booking-wizard/features/product-options/options-form.tsx +563 -459
  74. package/src/booking-wizard/features/room-options/index.tsx +187 -187
  75. package/src/booking-wizard/features/room-options/room-utils.ts +190 -190
  76. package/src/booking-wizard/features/room-options/room.tsx +160 -160
  77. package/src/booking-wizard/features/room-options/traveler-rooms.tsx +75 -75
  78. package/src/booking-wizard/features/sidebar/index.tsx +76 -76
  79. package/src/booking-wizard/features/sidebar/sidebar-flight.tsx +68 -68
  80. package/src/booking-wizard/features/sidebar/sidebar-util.ts +177 -177
  81. package/src/booking-wizard/features/sidebar/sidebar.tsx +364 -364
  82. package/src/booking-wizard/features/summary/summary-booking-option-pax.tsx +25 -25
  83. package/src/booking-wizard/features/summary/summary-booking-option-unit.tsx +25 -25
  84. package/src/booking-wizard/features/summary/summary-flight.tsx +39 -39
  85. package/src/booking-wizard/features/summary/summary-per-booking-option-group.tsx +69 -69
  86. package/src/booking-wizard/features/summary/summary-per-pax-option-group.tsx +63 -63
  87. package/src/booking-wizard/features/summary/summary-per-unit-option-group.tsx +66 -66
  88. package/src/booking-wizard/features/summary/summary-slice.ts +28 -28
  89. package/src/booking-wizard/features/summary/summary.tsx +674 -674
  90. package/src/booking-wizard/features/travelers-form/travelers-form-slice.ts +164 -164
  91. package/src/booking-wizard/features/travelers-form/travelers-form.tsx +754 -754
  92. package/src/booking-wizard/features/travelers-form/type-ahead-input.tsx +101 -101
  93. package/src/booking-wizard/features/travelers-form/validate-form.ts +245 -245
  94. package/src/booking-wizard/index.tsx +36 -36
  95. package/src/booking-wizard/settings-context.ts +67 -60
  96. package/src/booking-wizard/store.ts +31 -31
  97. package/src/booking-wizard/types.ts +283 -276
  98. package/src/booking-wizard/use-offer-printer.ts +136 -0
  99. package/src/index.ts +4 -4
  100. package/src/shared/components/loader.tsx +16 -16
  101. package/src/shared/translations/en-GB.json +237 -232
  102. package/src/shared/translations/fr-BE.json +238 -233
  103. package/src/shared/translations/nl-BE.json +237 -232
  104. package/src/shared/types.ts +4 -4
  105. package/src/shared/utils/class-util.ts +9 -9
  106. package/src/shared/utils/localization-util.ts +62 -62
  107. package/src/shared/utils/query-string-util.ts +119 -119
  108. package/src/shared/utils/tide-api-utils.ts +36 -36
  109. package/styles/booking-product-variables.scss +394 -394
  110. package/styles/booking-product.scss +446 -446
  111. package/styles/booking-wizard-variables.scss +873 -871
  112. package/styles/booking-wizard.scss +59 -59
  113. package/styles/components/_animations.scss +39 -39
  114. package/styles/components/_base.scss +107 -107
  115. package/styles/components/_booking.scss +879 -879
  116. package/styles/components/_button.scss +238 -238
  117. package/styles/components/_checkbox.scss +219 -219
  118. package/styles/components/_cta.scss +208 -208
  119. package/styles/components/_date-list.scss +41 -41
  120. package/styles/components/_date-range-picker.scss +225 -225
  121. package/styles/components/_decrement-increment.scss +35 -35
  122. package/styles/components/_dropdown.scss +72 -72
  123. package/styles/components/_flight-option.scss +1429 -1429
  124. package/styles/components/_form.scss +1583 -1583
  125. package/styles/components/_info-message.scss +71 -71
  126. package/styles/components/_input.scss +25 -25
  127. package/styles/components/_list.scss +187 -187
  128. package/styles/components/_loader.scss +72 -72
  129. package/styles/components/_mixins.scss +550 -550
  130. package/styles/components/_placeholders.scss +166 -166
  131. package/styles/components/_pricing-summary.scss +155 -155
  132. package/styles/components/_qsm.scss +17 -17
  133. package/styles/components/_radiobutton.scss +170 -170
  134. package/styles/components/_select-wrapper.scss +80 -80
  135. package/styles/components/_spinner.scss +29 -29
  136. package/styles/components/_step-indicators.scss +168 -168
  137. package/styles/components/_table.scss +81 -81
  138. package/styles/components/_tree.scss +530 -530
  139. package/styles/components/_typeahead.scss +281 -281
  140. package/styles/components/_variables.scss +89 -89
  141. package/tsconfig.json +24 -24
@@ -1,196 +1,196 @@
1
- import {
2
- endOfDay,
3
- endOfMonth,
4
- getMonth,
5
- getYear,
6
- isAfter,
7
- isEqual,
8
- isWithinInterval,
9
- startOfDay,
10
- } from "date-fns";
11
-
12
- import { isNil } from "lodash";
13
- import React, { useEffect, useState } from "react";
14
- import Calendar from "./calendar";
15
-
16
- interface DateRangePickerProps {
17
- fromDate?: Date;
18
- toDate?: Date;
19
- focusMonth?: { month: number; year: number };
20
- locale?: Locale;
21
- duration?: number;
22
- disabledDaysFunction?: (date: Date) => boolean;
23
- extraClassNamesFunction?: (date: Date) => string[];
24
- dayContentFunction?: (date: Date) => JSX.Element | null | undefined;
25
- onSelectionChange?: (fromDate: Date, toDate: Date) => void;
26
- onFromDateChange?: (date?: Date) => void;
27
- onToDateChange?: (date?: Date) => void;
28
- onFocusMonthChange?: (focusMonth: { month: number; year: number }) => void;
29
- }
30
-
31
- const DateRangePicker: React.FC<DateRangePickerProps> = (props) => {
32
- const [fromDate, setFromDate] = useState<Date | undefined>(props.fromDate);
33
- const [toDate, setToDate] = useState<Date | undefined>(props.toDate);
34
- const [focusMonth, setFocusMonth] = useState<{ month: number; year: number }>(
35
- props.focusMonth ?? {
36
- year: getYear(new Date()),
37
- month: getMonth(new Date()),
38
- }
39
- );
40
- const [isWaitingForToDate, setWaitingForToDate] = useState<boolean>(false);
41
-
42
- const handleDayClick = (day: Date) => {
43
- const { onSelectionChange } = props;
44
-
45
- if (isWaitingForToDate && !isNil(fromDate) && isAfter(day, fromDate)) {
46
- setToDate(day);
47
- setWaitingForToDate(false);
48
-
49
- if (props.onToDateChange) {
50
- props.onToDateChange(undefined);
51
- }
52
-
53
- if (onSelectionChange) {
54
- onSelectionChange(fromDate, day);
55
- }
56
- } else {
57
- setFromDate(day);
58
-
59
- if (props.duration) {
60
- const to = new Date(
61
- Date.UTC(
62
- day.getFullYear(),
63
- day.getMonth(),
64
- day.getDate() + props.duration
65
- )
66
- );
67
- setToDate(to);
68
-
69
- if (onSelectionChange) {
70
- onSelectionChange(day, to);
71
- }
72
- } else {
73
- setToDate(undefined);
74
- setWaitingForToDate(true);
75
- }
76
-
77
- if (props.onFromDateChange) {
78
- props.onFromDateChange(day);
79
- }
80
- }
81
- };
82
-
83
- const handleDayMouseOver = (day: Date) => {
84
- if (
85
- isWaitingForToDate &&
86
- (isNil(fromDate) || isEqual(day, fromDate) || isAfter(day, fromDate))
87
- ) {
88
- setToDate(day);
89
- }
90
- };
91
-
92
- const handlePreviousClick = () => {
93
- const { month, year } = focusMonth;
94
-
95
- const previousMonth = (month - 1) % 12;
96
- const previousMonthsYear = previousMonth > month ? year - 1 : year;
97
-
98
- const newFocusMonth = { year: previousMonthsYear, month: previousMonth };
99
-
100
- setFocusMonth(newFocusMonth);
101
-
102
- if (props.onFocusMonthChange) {
103
- props.onFocusMonthChange(newFocusMonth);
104
- }
105
- };
106
-
107
- const handleNextClick = () => {
108
- const { month, year } = focusMonth;
109
-
110
- const nextMonth = (month + 1) % 12;
111
- const nextMonthsYear = nextMonth < month ? year + 1 : year;
112
-
113
- const newFocusMonth = { year: nextMonthsYear, month: nextMonth };
114
-
115
- setFocusMonth(newFocusMonth);
116
-
117
- if (props.onFocusMonthChange) {
118
- props.onFocusMonthChange(newFocusMonth);
119
- }
120
- };
121
-
122
- const today = startOfDay(new Date());
123
-
124
- const firstCalendarYear = focusMonth.year;
125
- const firstCalendarMonth = focusMonth.month;
126
-
127
- const secondCalendarMonth = (firstCalendarMonth + 1) % 12;
128
- const secondCalendarYear =
129
- secondCalendarMonth < firstCalendarMonth
130
- ? firstCalendarYear + 1
131
- : firstCalendarYear;
132
-
133
- const checkIfDateIsSelected = (date: Date) =>
134
- isNil(toDate)
135
- ? !isNil(fromDate) && isEqual(date, fromDate)
136
- : !isNil(fromDate) &&
137
- isWithinInterval(date, {
138
- start: startOfDay(fromDate),
139
- end: endOfDay(toDate),
140
- });
141
-
142
- useEffect(() => {
143
- setFromDate(props.fromDate);
144
- setToDate(props.toDate);
145
- }, [props.fromDate?.valueOf(), props.toDate?.valueOf()]);
146
-
147
- useEffect(() => {
148
- if (props.fromDate) {
149
- setFocusMonth({
150
- month: props.fromDate.getMonth(),
151
- year: props.fromDate.getFullYear(),
152
- });
153
- }
154
- }, [props.fromDate?.valueOf()]);
155
-
156
- return (
157
- <div className="date-range-picker">
158
- <div className="date-range-picker__from">
159
- <Calendar
160
- year={firstCalendarYear}
161
- month={firstCalendarMonth}
162
- onDayClick={handleDayClick}
163
- onDayMouseOver={handleDayMouseOver}
164
- onPreviousClick={handlePreviousClick}
165
- hasPreviousButton={isAfter(
166
- new Date(firstCalendarYear, firstCalendarMonth),
167
- endOfMonth(today)
168
- )}
169
- hasNextButton={false}
170
- selectedDaysFunction={checkIfDateIsSelected}
171
- disabledDaysFunction={props.disabledDaysFunction}
172
- extraClassNamesFunction={props.extraClassNamesFunction}
173
- dayContentFunction={props.dayContentFunction}
174
- hasFixedHeight={true}
175
- />
176
- </div>
177
- <div className="date-range-picker__to">
178
- <Calendar
179
- year={secondCalendarYear}
180
- month={secondCalendarMonth}
181
- onDayClick={handleDayClick}
182
- onDayMouseOver={handleDayMouseOver}
183
- onNextClick={handleNextClick}
184
- hasPreviousButton={false}
185
- selectedDaysFunction={checkIfDateIsSelected}
186
- disabledDaysFunction={props.disabledDaysFunction}
187
- extraClassNamesFunction={props.extraClassNamesFunction}
188
- dayContentFunction={props.dayContentFunction}
189
- hasFixedHeight={true}
190
- />
191
- </div>
192
- </div>
193
- );
194
- };
195
-
196
- export default DateRangePicker;
1
+ import {
2
+ endOfDay,
3
+ endOfMonth,
4
+ getMonth,
5
+ getYear,
6
+ isAfter,
7
+ isEqual,
8
+ isWithinInterval,
9
+ startOfDay,
10
+ } from "date-fns";
11
+
12
+ import { isNil } from "lodash";
13
+ import React, { useEffect, useState } from "react";
14
+ import Calendar from "./calendar";
15
+
16
+ interface DateRangePickerProps {
17
+ fromDate?: Date;
18
+ toDate?: Date;
19
+ focusMonth?: { month: number; year: number };
20
+ locale?: Locale;
21
+ duration?: number;
22
+ disabledDaysFunction?: (date: Date) => boolean;
23
+ extraClassNamesFunction?: (date: Date) => string[];
24
+ dayContentFunction?: (date: Date) => JSX.Element | null | undefined;
25
+ onSelectionChange?: (fromDate: Date, toDate: Date) => void;
26
+ onFromDateChange?: (date?: Date) => void;
27
+ onToDateChange?: (date?: Date) => void;
28
+ onFocusMonthChange?: (focusMonth: { month: number; year: number }) => void;
29
+ }
30
+
31
+ const DateRangePicker: React.FC<DateRangePickerProps> = (props) => {
32
+ const [fromDate, setFromDate] = useState<Date | undefined>(props.fromDate);
33
+ const [toDate, setToDate] = useState<Date | undefined>(props.toDate);
34
+ const [focusMonth, setFocusMonth] = useState<{ month: number; year: number }>(
35
+ props.focusMonth ?? {
36
+ year: getYear(new Date()),
37
+ month: getMonth(new Date()),
38
+ }
39
+ );
40
+ const [isWaitingForToDate, setWaitingForToDate] = useState<boolean>(false);
41
+
42
+ const handleDayClick = (day: Date) => {
43
+ const { onSelectionChange } = props;
44
+
45
+ if (isWaitingForToDate && !isNil(fromDate) && isAfter(day, fromDate)) {
46
+ setToDate(day);
47
+ setWaitingForToDate(false);
48
+
49
+ if (props.onToDateChange) {
50
+ props.onToDateChange(undefined);
51
+ }
52
+
53
+ if (onSelectionChange) {
54
+ onSelectionChange(fromDate, day);
55
+ }
56
+ } else {
57
+ setFromDate(day);
58
+
59
+ if (props.duration) {
60
+ const to = new Date(
61
+ Date.UTC(
62
+ day.getFullYear(),
63
+ day.getMonth(),
64
+ day.getDate() + props.duration
65
+ )
66
+ );
67
+ setToDate(to);
68
+
69
+ if (onSelectionChange) {
70
+ onSelectionChange(day, to);
71
+ }
72
+ } else {
73
+ setToDate(undefined);
74
+ setWaitingForToDate(true);
75
+ }
76
+
77
+ if (props.onFromDateChange) {
78
+ props.onFromDateChange(day);
79
+ }
80
+ }
81
+ };
82
+
83
+ const handleDayMouseOver = (day: Date) => {
84
+ if (
85
+ isWaitingForToDate &&
86
+ (isNil(fromDate) || isEqual(day, fromDate) || isAfter(day, fromDate))
87
+ ) {
88
+ setToDate(day);
89
+ }
90
+ };
91
+
92
+ const handlePreviousClick = () => {
93
+ const { month, year } = focusMonth;
94
+
95
+ const previousMonth = (month - 1) % 12;
96
+ const previousMonthsYear = previousMonth > month ? year - 1 : year;
97
+
98
+ const newFocusMonth = { year: previousMonthsYear, month: previousMonth };
99
+
100
+ setFocusMonth(newFocusMonth);
101
+
102
+ if (props.onFocusMonthChange) {
103
+ props.onFocusMonthChange(newFocusMonth);
104
+ }
105
+ };
106
+
107
+ const handleNextClick = () => {
108
+ const { month, year } = focusMonth;
109
+
110
+ const nextMonth = (month + 1) % 12;
111
+ const nextMonthsYear = nextMonth < month ? year + 1 : year;
112
+
113
+ const newFocusMonth = { year: nextMonthsYear, month: nextMonth };
114
+
115
+ setFocusMonth(newFocusMonth);
116
+
117
+ if (props.onFocusMonthChange) {
118
+ props.onFocusMonthChange(newFocusMonth);
119
+ }
120
+ };
121
+
122
+ const today = startOfDay(new Date());
123
+
124
+ const firstCalendarYear = focusMonth.year;
125
+ const firstCalendarMonth = focusMonth.month;
126
+
127
+ const secondCalendarMonth = (firstCalendarMonth + 1) % 12;
128
+ const secondCalendarYear =
129
+ secondCalendarMonth < firstCalendarMonth
130
+ ? firstCalendarYear + 1
131
+ : firstCalendarYear;
132
+
133
+ const checkIfDateIsSelected = (date: Date) =>
134
+ isNil(toDate)
135
+ ? !isNil(fromDate) && isEqual(date, fromDate)
136
+ : !isNil(fromDate) &&
137
+ isWithinInterval(date, {
138
+ start: startOfDay(fromDate),
139
+ end: endOfDay(toDate),
140
+ });
141
+
142
+ useEffect(() => {
143
+ setFromDate(props.fromDate);
144
+ setToDate(props.toDate);
145
+ }, [props.fromDate?.valueOf(), props.toDate?.valueOf()]);
146
+
147
+ useEffect(() => {
148
+ if (props.fromDate) {
149
+ setFocusMonth({
150
+ month: props.fromDate.getMonth(),
151
+ year: props.fromDate.getFullYear(),
152
+ });
153
+ }
154
+ }, [props.fromDate?.valueOf()]);
155
+
156
+ return (
157
+ <div className="date-range-picker">
158
+ <div className="date-range-picker__from">
159
+ <Calendar
160
+ year={firstCalendarYear}
161
+ month={firstCalendarMonth}
162
+ onDayClick={handleDayClick}
163
+ onDayMouseOver={handleDayMouseOver}
164
+ onPreviousClick={handlePreviousClick}
165
+ hasPreviousButton={isAfter(
166
+ new Date(firstCalendarYear, firstCalendarMonth),
167
+ endOfMonth(today)
168
+ )}
169
+ hasNextButton={false}
170
+ selectedDaysFunction={checkIfDateIsSelected}
171
+ disabledDaysFunction={props.disabledDaysFunction}
172
+ extraClassNamesFunction={props.extraClassNamesFunction}
173
+ dayContentFunction={props.dayContentFunction}
174
+ hasFixedHeight={true}
175
+ />
176
+ </div>
177
+ <div className="date-range-picker__to">
178
+ <Calendar
179
+ year={secondCalendarYear}
180
+ month={secondCalendarMonth}
181
+ onDayClick={handleDayClick}
182
+ onDayMouseOver={handleDayMouseOver}
183
+ onNextClick={handleNextClick}
184
+ hasPreviousButton={false}
185
+ selectedDaysFunction={checkIfDateIsSelected}
186
+ disabledDaysFunction={props.disabledDaysFunction}
187
+ extraClassNamesFunction={props.extraClassNamesFunction}
188
+ dayContentFunction={props.dayContentFunction}
189
+ hasFixedHeight={true}
190
+ />
191
+ </div>
192
+ </div>
193
+ );
194
+ };
195
+
196
+ export default DateRangePicker;
@@ -1,136 +1,136 @@
1
- import { format, isBefore, startOfDay } from "date-fns";
2
- import React, { useContext, useEffect, useState } from "react";
3
- import { usePopper } from "react-popper";
4
- import { buildClassName } from "../../shared/utils/class-util";
5
- import { getTranslations } from "../../shared/utils/localization-util";
6
- import SettingsContext from "../settings-context";
7
- import { DateRange } from "../types";
8
- import DateRangePicker from "./date-range-picker";
9
- import Icon from "./icon";
10
-
11
- interface DatesProps {
12
- value?: DateRange;
13
- duration?: number;
14
- onChange?: (value: DateRange) => void;
15
- }
16
-
17
- const Dates: React.FC<DatesProps> = ({ value, duration, onChange }) => {
18
- const { language } = useContext(SettingsContext);
19
- const translations = getTranslations(language);
20
- const mql =
21
- typeof window !== "undefined"
22
- ? window.matchMedia("(min-width: 1200px)")
23
- : undefined;
24
-
25
- const [referenceElement, setReferenceElement] =
26
- useState<HTMLDivElement | null>(null);
27
- const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(
28
- null
29
- );
30
- const [panelActive, setPanelActive] = useState<boolean>(false);
31
-
32
- const { styles, attributes } = usePopper(referenceElement, popperElement, {
33
- placement: "top",
34
- modifiers: [
35
- {
36
- name: "offset",
37
- options: {
38
- offset: [0, -40],
39
- },
40
- },
41
- {
42
- name: "preventOverflow",
43
- options: {
44
- padding: 40,
45
- },
46
- },
47
- ],
48
- });
49
-
50
- const handleInputFocus = () => {
51
- if (!panelActive) setPanelActive(true);
52
- };
53
-
54
- const handleSelectionChange = (fromDate?: Date, toDate?: Date) => {
55
- if (onChange) {
56
- onChange({ fromDate, toDate });
57
- setPanelActive(false);
58
- }
59
- };
60
-
61
- useEffect(() => {
62
- document.addEventListener("mousedown", handleDocumentClick);
63
- return () => {
64
- document.removeEventListener("mousedown", handleDocumentClick);
65
- };
66
- });
67
-
68
- const handleDocumentClick: EventListener = (event) => {
69
- if (referenceElement && !referenceElement.contains(event.target as Node)) {
70
- if (panelActive) setPanelActive(false);
71
- }
72
- };
73
-
74
- return (
75
- <div className="booking-product__dates" ref={setReferenceElement}>
76
- <div className="booking-product__dates-title">
77
- <Icon name="ui-calendar" width={25} height={25} />
78
- {translations.PRODUCT.TRAVEL_PERIOD}
79
- </div>
80
- <div className="form__group form__group--datepicker form__group--icon">
81
- <div className="form__group-input">
82
- <label className="form__label">
83
- {translations.PRODUCT.DEPARTURE}
84
- </label>
85
- <input
86
- type="text"
87
- readOnly
88
- value={value?.fromDate ? format(value.fromDate, "dd/MM/yyyy") : ""}
89
- className="form__input"
90
- placeholder={translations.PRODUCT.DEPARTURE_DATE}
91
- onClick={handleInputFocus}
92
- />
93
- </div>
94
-
95
- <div className="form__group-input">
96
- <label className="form__label">{translations.PRODUCT.RETURN}</label>
97
- <input
98
- type="text"
99
- readOnly
100
- value={value?.toDate ? format(value.toDate, "dd/MM/yyyy") : ""}
101
- className="form__input"
102
- placeholder={translations.PRODUCT.RETURN_DATE}
103
- onClick={handleInputFocus}
104
- />
105
- </div>
106
- <div
107
- ref={setPopperElement}
108
- className={buildClassName([
109
- "qsm__panel qsm__panel--bordered qsm__panel--dates-pricing",
110
- panelActive && "qsm__panel--active",
111
- !mql?.matches && "qsm__panel--mobile",
112
- ])}
113
- style={mql?.matches ? styles.popper : undefined}
114
- {...attributes.popper}
115
- >
116
- <DateRangePicker
117
- fromDate={value?.fromDate}
118
- toDate={value?.toDate}
119
- duration={duration}
120
- disabledDaysFunction={(date) =>
121
- isBefore(date, startOfDay(new Date()))
122
- }
123
- onSelectionChange={handleSelectionChange}
124
- />
125
- {!mql?.matches && (
126
- <div className="qsm__close" onClick={() => setPanelActive(false)}>
127
- <Icon name="ui-close" height={25} width={25} />
128
- </div>
129
- )}
130
- </div>
131
- </div>
132
- </div>
133
- );
134
- };
135
-
136
- export default Dates;
1
+ import { format, isBefore, startOfDay } from "date-fns";
2
+ import React, { useContext, useEffect, useState } from "react";
3
+ import { usePopper } from "react-popper";
4
+ import { buildClassName } from "../../shared/utils/class-util";
5
+ import { getTranslations } from "../../shared/utils/localization-util";
6
+ import SettingsContext from "../settings-context";
7
+ import { DateRange } from "../types";
8
+ import DateRangePicker from "./date-range-picker";
9
+ import Icon from "./icon";
10
+
11
+ interface DatesProps {
12
+ value?: DateRange;
13
+ duration?: number;
14
+ onChange?: (value: DateRange) => void;
15
+ }
16
+
17
+ const Dates: React.FC<DatesProps> = ({ value, duration, onChange }) => {
18
+ const { language } = useContext(SettingsContext);
19
+ const translations = getTranslations(language);
20
+ const mql =
21
+ typeof window !== "undefined"
22
+ ? window.matchMedia("(min-width: 1200px)")
23
+ : undefined;
24
+
25
+ const [referenceElement, setReferenceElement] =
26
+ useState<HTMLDivElement | null>(null);
27
+ const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(
28
+ null
29
+ );
30
+ const [panelActive, setPanelActive] = useState<boolean>(false);
31
+
32
+ const { styles, attributes } = usePopper(referenceElement, popperElement, {
33
+ placement: "top",
34
+ modifiers: [
35
+ {
36
+ name: "offset",
37
+ options: {
38
+ offset: [0, -40],
39
+ },
40
+ },
41
+ {
42
+ name: "preventOverflow",
43
+ options: {
44
+ padding: 40,
45
+ },
46
+ },
47
+ ],
48
+ });
49
+
50
+ const handleInputFocus = () => {
51
+ if (!panelActive) setPanelActive(true);
52
+ };
53
+
54
+ const handleSelectionChange = (fromDate?: Date, toDate?: Date) => {
55
+ if (onChange) {
56
+ onChange({ fromDate, toDate });
57
+ setPanelActive(false);
58
+ }
59
+ };
60
+
61
+ useEffect(() => {
62
+ document.addEventListener("mousedown", handleDocumentClick);
63
+ return () => {
64
+ document.removeEventListener("mousedown", handleDocumentClick);
65
+ };
66
+ });
67
+
68
+ const handleDocumentClick: EventListener = (event) => {
69
+ if (referenceElement && !referenceElement.contains(event.target as Node)) {
70
+ if (panelActive) setPanelActive(false);
71
+ }
72
+ };
73
+
74
+ return (
75
+ <div className="booking-product__dates" ref={setReferenceElement}>
76
+ <div className="booking-product__dates-title">
77
+ <Icon name="ui-calendar" width={25} height={25} />
78
+ {translations.PRODUCT.TRAVEL_PERIOD}
79
+ </div>
80
+ <div className="form__group form__group--datepicker form__group--icon">
81
+ <div className="form__group-input">
82
+ <label className="form__label">
83
+ {translations.PRODUCT.DEPARTURE}
84
+ </label>
85
+ <input
86
+ type="text"
87
+ readOnly
88
+ value={value?.fromDate ? format(value.fromDate, "dd/MM/yyyy") : ""}
89
+ className="form__input"
90
+ placeholder={translations.PRODUCT.DEPARTURE_DATE}
91
+ onClick={handleInputFocus}
92
+ />
93
+ </div>
94
+
95
+ <div className="form__group-input">
96
+ <label className="form__label">{translations.PRODUCT.RETURN}</label>
97
+ <input
98
+ type="text"
99
+ readOnly
100
+ value={value?.toDate ? format(value.toDate, "dd/MM/yyyy") : ""}
101
+ className="form__input"
102
+ placeholder={translations.PRODUCT.RETURN_DATE}
103
+ onClick={handleInputFocus}
104
+ />
105
+ </div>
106
+ <div
107
+ ref={setPopperElement}
108
+ className={buildClassName([
109
+ "qsm__panel qsm__panel--bordered qsm__panel--dates-pricing",
110
+ panelActive && "qsm__panel--active",
111
+ !mql?.matches && "qsm__panel--mobile",
112
+ ])}
113
+ style={mql?.matches ? styles.popper : undefined}
114
+ {...attributes.popper}
115
+ >
116
+ <DateRangePicker
117
+ fromDate={value?.fromDate}
118
+ toDate={value?.toDate}
119
+ duration={duration}
120
+ disabledDaysFunction={(date) =>
121
+ isBefore(date, startOfDay(new Date()))
122
+ }
123
+ onSelectionChange={handleSelectionChange}
124
+ />
125
+ {!mql?.matches && (
126
+ <div className="qsm__close" onClick={() => setPanelActive(false)}>
127
+ <Icon name="ui-close" height={25} width={25} />
128
+ </div>
129
+ )}
130
+ </div>
131
+ </div>
132
+ </div>
133
+ );
134
+ };
135
+
136
+ export default Dates;