@qite/tide-booking-component 1.2.3 → 1.2.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 (137) 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-product/components/footer.d.ts +1 -0
  5. package/build/build-cjs/booking-product/components/rooms.d.ts +2 -0
  6. package/build/build-cjs/booking-wizard/features/booking/selectors.d.ts +1 -1
  7. package/build/build-cjs/booking-wizard/features/flight-options/flight-option-flight.d.ts +1 -1
  8. package/build/build-cjs/booking-wizard/features/flight-options/flight-option.d.ts +1 -1
  9. package/build/build-cjs/booking-wizard/types.d.ts +5 -0
  10. package/build/build-cjs/index.js +1453 -735
  11. package/build/build-cjs/shared/utils/localization-util.d.ts +4 -0
  12. package/build/build-esm/booking-product/components/footer.d.ts +1 -0
  13. package/build/build-esm/booking-product/components/rooms.d.ts +2 -0
  14. package/build/build-esm/booking-wizard/features/booking/selectors.d.ts +1 -1
  15. package/build/build-esm/booking-wizard/features/flight-options/flight-option-flight.d.ts +1 -1
  16. package/build/build-esm/booking-wizard/features/flight-options/flight-option.d.ts +1 -1
  17. package/build/build-esm/booking-wizard/types.d.ts +5 -0
  18. package/build/build-esm/index.js +1455 -737
  19. package/build/build-esm/shared/utils/localization-util.d.ts +4 -0
  20. package/package.json +75 -77
  21. package/src/booking-product/components/age-select.tsx +35 -41
  22. package/src/booking-product/components/amount-input.tsx +78 -64
  23. package/src/booking-product/components/date-range-picker/calendar-day.tsx +58 -54
  24. package/src/booking-product/components/date-range-picker/calendar.tsx +178 -176
  25. package/src/booking-product/components/date-range-picker/index.tsx +196 -181
  26. package/src/booking-product/components/dates.tsx +136 -132
  27. package/src/booking-product/components/footer.tsx +69 -64
  28. package/src/booking-product/components/header.tsx +79 -68
  29. package/src/booking-product/components/icon.tsx +251 -208
  30. package/src/booking-product/components/product.tsx +314 -277
  31. package/src/booking-product/components/rooms.tsx +195 -177
  32. package/src/booking-product/index.tsx +30 -30
  33. package/src/booking-product/settings-context.ts +14 -14
  34. package/src/booking-product/types.ts +28 -28
  35. package/src/booking-product/utils/api.ts +25 -25
  36. package/src/booking-product/utils/price.ts +29 -27
  37. package/src/booking-wizard/api-settings-slice.ts +24 -24
  38. package/src/booking-wizard/components/icon.tsx +508 -60
  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/product-card.tsx +37 -37
  42. package/src/booking-wizard/components/step-indicator.tsx +51 -51
  43. package/src/booking-wizard/components/step-route.tsx +27 -27
  44. package/src/booking-wizard/declarations.d.ts +4 -4
  45. package/src/booking-wizard/features/booking/api.ts +49 -45
  46. package/src/booking-wizard/features/booking/booking-self-contained.tsx +384 -357
  47. package/src/booking-wizard/features/booking/booking-slice.ts +662 -603
  48. package/src/booking-wizard/features/booking/booking.tsx +356 -349
  49. package/src/booking-wizard/features/booking/constants.ts +16 -16
  50. package/src/booking-wizard/features/booking/selectors.ts +441 -408
  51. package/src/booking-wizard/features/confirmation/confirmation.tsx +97 -94
  52. package/src/booking-wizard/features/error/error.tsx +78 -75
  53. package/src/booking-wizard/features/flight-options/flight-filter.tsx +432 -344
  54. package/src/booking-wizard/features/flight-options/flight-option-flight.tsx +385 -351
  55. package/src/booking-wizard/features/flight-options/flight-option-modal.tsx +229 -214
  56. package/src/booking-wizard/features/flight-options/flight-option.tsx +81 -66
  57. package/src/booking-wizard/features/flight-options/flight-utils.ts +516 -401
  58. package/src/booking-wizard/features/flight-options/index.tsx +196 -177
  59. package/src/booking-wizard/features/price-details/price-details-api.ts +24 -24
  60. package/src/booking-wizard/features/price-details/price-details-slice.ts +178 -171
  61. package/src/booking-wizard/features/price-details/util.ts +155 -155
  62. package/src/booking-wizard/features/product-options/no-options.tsx +21 -21
  63. package/src/booking-wizard/features/product-options/none-option.tsx +120 -120
  64. package/src/booking-wizard/features/product-options/option-booking-airline-group.tsx +64 -66
  65. package/src/booking-wizard/features/product-options/option-booking-group.tsx +216 -210
  66. package/src/booking-wizard/features/product-options/option-item.tsx +317 -318
  67. package/src/booking-wizard/features/product-options/option-pax-card.tsx +201 -117
  68. package/src/booking-wizard/features/product-options/option-pax-group.tsx +175 -169
  69. package/src/booking-wizard/features/product-options/option-room.tsx +321 -314
  70. package/src/booking-wizard/features/product-options/option-unit-group.tsx +198 -192
  71. package/src/booking-wizard/features/product-options/option-units-card.tsx +185 -102
  72. package/src/booking-wizard/features/product-options/options-form.tsx +459 -437
  73. package/src/booking-wizard/features/room-options/index.tsx +187 -172
  74. package/src/booking-wizard/features/room-options/room-utils.ts +190 -143
  75. package/src/booking-wizard/features/room-options/room.tsx +160 -124
  76. package/src/booking-wizard/features/room-options/traveler-rooms.tsx +75 -63
  77. package/src/booking-wizard/features/sidebar/index.tsx +76 -76
  78. package/src/booking-wizard/features/sidebar/sidebar-flight.tsx +68 -68
  79. package/src/booking-wizard/features/sidebar/sidebar-util.ts +177 -177
  80. package/src/booking-wizard/features/sidebar/sidebar.tsx +364 -346
  81. package/src/booking-wizard/features/summary/summary-booking-option-pax.tsx +25 -25
  82. package/src/booking-wizard/features/summary/summary-booking-option-unit.tsx +25 -25
  83. package/src/booking-wizard/features/summary/summary-flight.tsx +39 -39
  84. package/src/booking-wizard/features/summary/summary-per-booking-option-group.tsx +69 -57
  85. package/src/booking-wizard/features/summary/summary-per-pax-option-group.tsx +63 -51
  86. package/src/booking-wizard/features/summary/summary-per-unit-option-group.tsx +66 -54
  87. package/src/booking-wizard/features/summary/summary-slice.ts +28 -28
  88. package/src/booking-wizard/features/summary/summary.tsx +674 -641
  89. package/src/booking-wizard/features/travelers-form/travelers-form-slice.ts +164 -164
  90. package/src/booking-wizard/features/travelers-form/travelers-form.tsx +754 -755
  91. package/src/booking-wizard/features/travelers-form/type-ahead-input.tsx +101 -101
  92. package/src/booking-wizard/features/travelers-form/validate-form.ts +245 -245
  93. package/src/booking-wizard/index.tsx +36 -36
  94. package/src/booking-wizard/settings-context.ts +60 -60
  95. package/src/booking-wizard/store.ts +31 -31
  96. package/src/booking-wizard/types.ts +276 -271
  97. package/src/index.ts +4 -5
  98. package/src/shared/components/loader.tsx +16 -16
  99. package/src/shared/translations/en-GB.json +232 -0
  100. package/src/shared/translations/fr-BE.json +233 -233
  101. package/src/shared/translations/nl-BE.json +232 -232
  102. package/src/shared/types.ts +4 -4
  103. package/src/shared/utils/localization-util.ts +62 -56
  104. package/src/shared/utils/query-string-util.ts +119 -116
  105. package/src/shared/utils/tide-api-utils.ts +36 -36
  106. package/styles/booking-product-variables.scss +394 -288
  107. package/styles/booking-product.scss +446 -440
  108. package/styles/booking-wizard-variables.scss +871 -0
  109. package/styles/booking-wizard.scss +59 -4
  110. package/styles/components/_animations.scss +39 -39
  111. package/styles/components/_base.scss +107 -106
  112. package/styles/components/_booking.scss +879 -0
  113. package/styles/components/_button.scss +238 -185
  114. package/styles/components/_checkbox.scss +219 -0
  115. package/styles/components/_cta.scss +208 -67
  116. package/styles/components/_date-list.scss +41 -0
  117. package/styles/components/_date-range-picker.scss +225 -224
  118. package/styles/components/_decrement-increment.scss +35 -37
  119. package/styles/components/_dropdown.scss +72 -74
  120. package/styles/components/_flight-option.scss +1429 -0
  121. package/styles/components/_form.scss +1583 -136
  122. package/styles/components/_info-message.scss +71 -0
  123. package/styles/components/_input.scss +25 -0
  124. package/styles/components/_list.scss +187 -0
  125. package/styles/components/_loader.scss +72 -71
  126. package/styles/components/_mixins.scss +550 -518
  127. package/styles/components/_placeholders.scss +166 -166
  128. package/styles/components/_pricing-summary.scss +155 -0
  129. package/styles/components/_qsm.scss +17 -20
  130. package/styles/components/_radiobutton.scss +170 -0
  131. package/styles/components/_select-wrapper.scss +80 -0
  132. package/styles/components/_spinner.scss +29 -0
  133. package/styles/components/_step-indicators.scss +168 -0
  134. package/styles/components/_table.scss +81 -0
  135. package/styles/components/_tree.scss +530 -0
  136. package/styles/components/_typeahead.scss +281 -0
  137. package/styles/components/_variables.scss +89 -89
@@ -1,277 +1,314 @@
1
- import JsonURL from "@jsonurl/jsonurl";
2
- import { BookingPackageDetailsRequest, BookingPackagePax, BookingPackageRequest, BookingPackageRequestRoom } from "@qite/tide-client/build/types";
3
- import { addDays, addMonths, format, formatISO } from "date-fns";
4
- import { omit } from "lodash";
5
- import React, { useContext, useEffect, useState } from "react";
6
- import { ApiSettingsState } from "../../shared/types";
7
- import { getTranslations } from "../../shared/utils/localization-util";
8
- import { getDateAsDateFromParams, getRoomsFromParams } from "../../shared/utils/query-string-util";
9
- import SettingsContext from "../settings-context";
10
- import { DateRange, ProductRoom } from "../types";
11
- import packageApi from "../utils/api";
12
- import { formatPriceByMode } from "../utils/price";
13
- import Dates from "./dates";
14
- import Footer from "./footer";
15
- import Header from "./header";
16
- import Rooms from "./rooms";
17
-
18
- interface ProductProps {
19
- productCode: string;
20
- productName: string;
21
- duration?: number;
22
- rating?: number;
23
- }
24
-
25
- const Product: React.FC<ProductProps> = ({
26
- productCode,
27
- productName,
28
- duration,
29
- rating
30
- }) => {
31
- const {
32
- apiKey,
33
- apiUrl,
34
- officeId,
35
- agentId,
36
- catalogueId,
37
- includeFlights,
38
- language,
39
- basePath,
40
- priceMode,
41
- addProductToQuery,
42
- isOffer
43
- } = useContext(SettingsContext);
44
- const translations = getTranslations(language);
45
-
46
- const [loaded, setLoaded] = useState<boolean>(false);
47
- const [isLoading, setIsLoading] = useState<boolean>(false);
48
- const [price, setPrice] = useState<number>();
49
- const [hasFlight, setHasFlight] = useState<boolean>(false);
50
- const [hasTransfer, setHasTransfer] = useState<boolean>(false);
51
- const [rooms, setRooms] = useState<ProductRoom[]>([{ adults: 2, children: 0, childAges: [] }]);
52
- const [dateRange, setDateRange] = useState<DateRange>();
53
- const [packageProductName, setPackageProductName] = useState<string>(productName);
54
-
55
- const fetchPackage = async (signal: AbortSignal) => {
56
- if (
57
- loaded &&
58
- productCode &&
59
- dateRange?.fromDate &&
60
- dateRange?.toDate &&
61
- rooms
62
- ) {
63
-
64
- const apiSettingsState = (apiKey && apiUrl) ? {
65
- apiKey: apiKey,
66
- apiUrl: apiUrl
67
- } as ApiSettingsState : undefined;
68
-
69
- const startDate = formatISO(dateRange?.fromDate, { representation: "date" }) + "T00:00:00Z";
70
- const endDate = formatISO(dateRange?.toDate, { representation: "date" }) + "T00:00:00Z";
71
-
72
- const requestRooms = rooms.map((room, i) => {
73
- const requestRoom = {
74
- index: i,
75
- pax: []
76
- } as BookingPackageRequestRoom;
77
-
78
- for (var a = 0; a < room.adults; a++) {
79
- requestRoom.pax.push({
80
- age: 30,
81
- } as BookingPackagePax);
82
- }
83
-
84
- for (var c = 0; c < room.children; c++) {
85
- requestRoom.pax.push({
86
- age: room.childAges[c],
87
- } as BookingPackagePax);
88
- }
89
-
90
- return requestRoom;
91
- });
92
-
93
- const request = {
94
- officeId: officeId,
95
- agentId: agentId,
96
- payload: {
97
- searchType: 0,
98
- catalogueId: catalogueId,
99
- productCode: productCode,
100
- fromDate: startDate,
101
- toDate: endDate,
102
- includeFlights: includeFlights,
103
- rooms: requestRooms,
104
- } as BookingPackageDetailsRequest,
105
- } as BookingPackageRequest<BookingPackageDetailsRequest>;
106
-
107
- setIsLoading(true);
108
- const response = await packageApi.fetchDetails(request, signal, language, apiSettingsState);
109
- if (!response.errorCode && response.payload) {
110
- const selectedOption = response.payload.options.find(x => x.isSelected);
111
- if (selectedOption) {
112
- const hasFlight = selectedOption.includedServiceTypes.some(x => x === 7);
113
- const hasTranfer = selectedOption.includedServiceTypes.some(x => x === 13);
114
-
115
- setPrice(selectedOption.price);
116
- setHasFlight(hasFlight);
117
- setHasTransfer(hasTranfer);
118
-
119
- if (!productName) {
120
- setPackageProductName(selectedOption.name);
121
- }
122
- }
123
- } else {
124
- setPrice(undefined);
125
- setHasFlight(false);
126
- setHasTransfer(false);
127
- }
128
-
129
- setIsLoading(false);
130
- }
131
- }
132
-
133
- const handleBookClick = () => {
134
- const params: Record<string, string> = {};
135
-
136
- if (rooms) {
137
- const serialized = JsonURL.stringify(
138
- rooms.map((room) => omit(room, ["children"])),
139
- { AQF: true }
140
- );
141
-
142
- if (serialized) {
143
- params["rooms"] = serialized;
144
- }
145
- }
146
-
147
- if (dateRange?.fromDate) {
148
- params["startDate"] = format(dateRange.fromDate, "yyyy-MM-dd");
149
- }
150
-
151
- if (dateRange?.toDate) {
152
- params["endDate"] = format(dateRange.toDate, "yyyy-MM-dd");
153
- }
154
-
155
- params["catalog"] = catalogueId.toString();
156
-
157
- if (addProductToQuery) {
158
- params["productCode"] = productCode;
159
- params["productName"] = encodeURI(packageProductName)!;
160
- }
161
-
162
- const path = window.location.pathname;
163
- const paramString = Object.keys(params)
164
- .map((key) => `${key}=${params[key]}`)
165
- .join("&");
166
-
167
- window.location.href = basePath.startsWith('/')
168
- ? `${window.location.protocol}//${window.location.host}${basePath}?${paramString}`
169
- : `${path}${path.endsWith("/") ? "" : "/"}${basePath}?${paramString}`
170
- }
171
-
172
- const handleRoomChange = (rooms: ProductRoom[]) => {
173
- setRooms(rooms);
174
- }
175
-
176
- const handleDateChange = (value: DateRange) => {
177
- setDateRange(value);
178
- }
179
-
180
- useEffect(() => {
181
- const controller = new AbortController();
182
- const { signal } = controller;
183
-
184
- (async () => {
185
- fetchPackage(signal);
186
- })();
187
- return () => {
188
- controller.abort();
189
- };
190
- }, [
191
- dateRange?.fromDate?.valueOf(),
192
- dateRange?.toDate?.valueOf(),
193
- JSON.stringify(rooms)
194
- ]);
195
-
196
- useEffect(() => {
197
- const params = new URLSearchParams(location.search);
198
- const rooms = getRoomsFromParams(params, "rooms");
199
- const from = getDateAsDateFromParams(params, "from");
200
- const to = getDateAsDateFromParams(params, "to");
201
-
202
- if (rooms) {
203
- setRooms(rooms);
204
- }
205
-
206
- if (from && duration) {
207
- const durationTo = new Date(
208
- Date.UTC(from.getFullYear(), from.getMonth(), from.getDate() + duration)
209
- );
210
-
211
- setDateRange({ fromDate: from, toDate: durationTo });
212
- } else if (from && to) {
213
- setDateRange({ fromDate: from, toDate: to });
214
- } else if (duration) {
215
- const now = new Date();
216
-
217
- const durationFrom = new Date(Date.UTC(now.getFullYear(), now.getMonth() + 3, now.getDate()));
218
- const durationTo = new Date(
219
- Date.UTC(
220
- durationFrom.getFullYear(),
221
- durationFrom.getMonth(),
222
- durationFrom.getDate() + duration
223
- )
224
- );
225
-
226
- setDateRange({ fromDate: durationFrom, toDate: durationTo });
227
- } else {
228
- const now = new Date();
229
- const startDate = addMonths(now, 1);
230
- const endDate = addDays(startDate, 7);
231
-
232
- setDateRange({ fromDate: startDate, toDate: endDate });
233
- }
234
-
235
- setLoaded(true);
236
- }, [location]);
237
-
238
- const personCount = rooms.reduce((s, r) => s + r.adults + r.children, 0);
239
- const durationCount = 0;
240
- const priceText = formatPriceByMode(
241
- price,
242
- priceMode,
243
- personCount,
244
- durationCount,
245
- translations.PRODUCT.PER_PERSON,
246
- translations.PRODUCT.PER_NIGHT,
247
- translations.PRODUCT.PER_PERSON_PER_NIGHT
248
- );
249
-
250
- return (
251
- <div className="booking-product">
252
- <Header
253
- name={packageProductName}
254
- rating={rating}
255
- priceText={priceText}
256
- isLoading={isLoading}
257
- hasFlight={hasFlight}
258
- hasTransfer={hasTransfer} />
259
- <div className="booking-product__body">
260
- <Rooms
261
- rooms={rooms}
262
- onChange={handleRoomChange} />
263
- <Dates
264
- value={dateRange}
265
- duration={duration}
266
- onChange={handleDateChange} />
267
- </div>
268
- <Footer
269
- priceText={priceText}
270
- isLoading={isLoading}
271
- isOffer={isOffer}
272
- handleBookClick={handleBookClick} />
273
- </div>
274
- );
275
- }
276
-
277
- export default Product;
1
+ import JsonURL from "@jsonurl/jsonurl";
2
+ import {
3
+ BookingPackageDetailsRequest,
4
+ BookingPackagePax,
5
+ BookingPackageRequest,
6
+ BookingPackageRequestRoom,
7
+ } from "@qite/tide-client/build/types";
8
+ import { addDays, addMonths, format, formatISO } from "date-fns";
9
+ import { omit } from "lodash";
10
+ import React, { useContext, useEffect, useState } from "react";
11
+ import { ApiSettingsState } from "../../shared/types";
12
+ import { getTranslations } from "../../shared/utils/localization-util";
13
+ import {
14
+ getDateAsDateFromParams,
15
+ getRoomsFromParams,
16
+ } from "../../shared/utils/query-string-util";
17
+ import SettingsContext from "../settings-context";
18
+ import { DateRange, ProductRoom } from "../types";
19
+ import packageApi from "../utils/api";
20
+ import { formatPriceByMode } from "../utils/price";
21
+ import Dates from "./dates";
22
+ import Footer from "./footer";
23
+ import Header from "./header";
24
+ import Rooms from "./rooms";
25
+
26
+ interface ProductProps {
27
+ productCode: string;
28
+ productName: string;
29
+ duration?: number;
30
+ rating?: number;
31
+ }
32
+
33
+ const Product: React.FC<ProductProps> = ({
34
+ productCode,
35
+ productName,
36
+ duration,
37
+ rating,
38
+ }) => {
39
+ const {
40
+ apiKey,
41
+ apiUrl,
42
+ officeId,
43
+ agentId,
44
+ catalogueId,
45
+ includeFlights,
46
+ language,
47
+ basePath,
48
+ priceMode,
49
+ addProductToQuery,
50
+ isOffer,
51
+ } = useContext(SettingsContext);
52
+ const translations = getTranslations(language);
53
+
54
+ const [loaded, setLoaded] = useState<boolean>(false);
55
+ const [isLoading, setIsLoading] = useState<boolean>(false);
56
+ const [roomsIsDisabled, setRoomsIsDisabled] = useState<boolean>(true);
57
+ const [price, setPrice] = useState<number>();
58
+ const [hasFlight, setHasFlight] = useState<boolean>(false);
59
+ const [hasTransfer, setHasTransfer] = useState<boolean>(false);
60
+ const [rooms, setRooms] = useState<ProductRoom[]>([
61
+ { adults: 2, children: 0, childAges: [] },
62
+ ]);
63
+ const [dateRange, setDateRange] = useState<DateRange>();
64
+ const [packageProductName, setPackageProductName] =
65
+ useState<string>(productName);
66
+
67
+ const fetchPackage = async (signal: AbortSignal) => {
68
+ if (
69
+ loaded &&
70
+ productCode &&
71
+ dateRange?.fromDate &&
72
+ dateRange?.toDate &&
73
+ rooms
74
+ ) {
75
+ const apiSettingsState =
76
+ apiKey && apiUrl
77
+ ? ({
78
+ apiKey: apiKey,
79
+ apiUrl: apiUrl,
80
+ } as ApiSettingsState)
81
+ : undefined;
82
+
83
+ const startDate =
84
+ formatISO(dateRange?.fromDate, { representation: "date" }) +
85
+ "T00:00:00Z";
86
+ const endDate =
87
+ formatISO(dateRange?.toDate, { representation: "date" }) + "T00:00:00Z";
88
+
89
+ const requestRooms = rooms.map((room, i) => {
90
+ const requestRoom = {
91
+ index: i,
92
+ pax: [],
93
+ } as BookingPackageRequestRoom;
94
+
95
+ for (var a = 0; a < room.adults; a++) {
96
+ requestRoom.pax.push({
97
+ age: 30,
98
+ } as BookingPackagePax);
99
+ }
100
+
101
+ for (var c = 0; c < room.children; c++) {
102
+ requestRoom.pax.push({
103
+ age: room.childAges[c],
104
+ } as BookingPackagePax);
105
+ }
106
+
107
+ return requestRoom;
108
+ });
109
+
110
+ const request = {
111
+ officeId: officeId,
112
+ agentId: agentId,
113
+ payload: {
114
+ searchType: 0,
115
+ catalogueId: catalogueId,
116
+ productCode: productCode,
117
+ fromDate: startDate,
118
+ toDate: endDate,
119
+ includeFlights: includeFlights,
120
+ rooms: requestRooms,
121
+ } as BookingPackageDetailsRequest,
122
+ } as BookingPackageRequest<BookingPackageDetailsRequest>;
123
+
124
+ setIsLoading(true);
125
+ const response = await packageApi.fetchDetails(
126
+ request,
127
+ signal,
128
+ language,
129
+ apiSettingsState
130
+ );
131
+ if (!response.errorCode && response.payload) {
132
+ const selectedOption = response.payload.options.find(
133
+ (x) => x.isSelected
134
+ );
135
+ if (selectedOption) {
136
+ const hasFlight = selectedOption.includedServiceTypes.some(
137
+ (x) => x === 7
138
+ );
139
+ const hasTranfer = selectedOption.includedServiceTypes.some(
140
+ (x) => x === 13
141
+ );
142
+
143
+ setPrice(selectedOption.price);
144
+ setHasFlight(hasFlight);
145
+ setHasTransfer(hasTranfer);
146
+
147
+ if (!productName) {
148
+ setPackageProductName(selectedOption.name);
149
+ }
150
+ }
151
+ } else {
152
+ setPrice(undefined);
153
+ setHasFlight(false);
154
+ setHasTransfer(false);
155
+ }
156
+
157
+ setIsLoading(false);
158
+ }
159
+ };
160
+
161
+ const handleBookClick = () => {
162
+ const params: Record<string, string> = {};
163
+
164
+ if (rooms) {
165
+ const serialized = JsonURL.stringify(
166
+ rooms.map((room) => omit(room, ["children"])),
167
+ { AQF: true }
168
+ );
169
+
170
+ if (serialized) {
171
+ params["rooms"] = serialized;
172
+ }
173
+ }
174
+
175
+ if (dateRange?.fromDate) {
176
+ params["startDate"] = format(dateRange.fromDate, "yyyy-MM-dd");
177
+ }
178
+
179
+ if (dateRange?.toDate) {
180
+ params["endDate"] = format(dateRange.toDate, "yyyy-MM-dd");
181
+ }
182
+
183
+ params["catalog"] = catalogueId.toString();
184
+
185
+ if (addProductToQuery) {
186
+ params["productCode"] = productCode;
187
+ params["productName"] = encodeURI(packageProductName)!;
188
+ }
189
+
190
+ const path = window.location.pathname;
191
+ const paramString = Object.keys(params)
192
+ .map((key) => `${key}=${params[key]}`)
193
+ .join("&");
194
+
195
+ window.location.href = basePath.startsWith("/")
196
+ ? `${window.location.protocol}//${window.location.host}${basePath}?${paramString}`
197
+ : `${path}${path.endsWith("/") ? "" : "/"}${basePath}?${paramString}`;
198
+ };
199
+
200
+ const handleRoomChange = (rooms: ProductRoom[]) => {
201
+ setRooms(rooms);
202
+ };
203
+
204
+ const handleDateChange = (value: DateRange) => {
205
+ setDateRange(value);
206
+ };
207
+
208
+ useEffect(() => {
209
+ const controller = new AbortController();
210
+ const { signal } = controller;
211
+
212
+ (async () => {
213
+ fetchPackage(signal);
214
+ })();
215
+ return () => {
216
+ controller.abort();
217
+ };
218
+ }, [
219
+ dateRange?.fromDate?.valueOf(),
220
+ dateRange?.toDate?.valueOf(),
221
+ JSON.stringify(rooms),
222
+ ]);
223
+
224
+ useEffect(() => {
225
+ const params = new URLSearchParams(location.search);
226
+ const rooms = getRoomsFromParams(params, "rooms");
227
+ const from = getDateAsDateFromParams(params, "from");
228
+ const to = getDateAsDateFromParams(params, "to");
229
+
230
+ if (rooms) {
231
+ setRooms(rooms);
232
+ }
233
+
234
+ if (from && duration) {
235
+ const durationTo = new Date(
236
+ Date.UTC(from.getFullYear(), from.getMonth(), from.getDate() + duration)
237
+ );
238
+
239
+ setDateRange({ fromDate: from, toDate: durationTo });
240
+ } else if (from && to) {
241
+ setDateRange({ fromDate: from, toDate: to });
242
+ } else if (duration) {
243
+ const now = new Date();
244
+
245
+ const durationFrom = new Date(
246
+ Date.UTC(now.getFullYear(), now.getMonth() + 3, now.getDate())
247
+ );
248
+ const durationTo = new Date(
249
+ Date.UTC(
250
+ durationFrom.getFullYear(),
251
+ durationFrom.getMonth(),
252
+ durationFrom.getDate() + duration
253
+ )
254
+ );
255
+
256
+ setDateRange({ fromDate: durationFrom, toDate: durationTo });
257
+ } else {
258
+ const now = new Date();
259
+ const startDate = addMonths(now, 1);
260
+ const endDate = addDays(startDate, 7);
261
+
262
+ setDateRange({ fromDate: startDate, toDate: endDate });
263
+ }
264
+
265
+ setLoaded(true);
266
+ }, [location]);
267
+
268
+ const personCount = rooms.reduce((s, r) => s + r.adults + r.children, 0);
269
+ const durationCount = 0;
270
+ const priceText = formatPriceByMode(
271
+ price,
272
+ priceMode,
273
+ personCount,
274
+ durationCount,
275
+ translations.PRODUCT.PER_PERSON,
276
+ translations.PRODUCT.PER_NIGHT,
277
+ translations.PRODUCT.PER_PERSON_PER_NIGHT
278
+ );
279
+
280
+ return (
281
+ <div className="booking-product">
282
+ <Header
283
+ name={packageProductName}
284
+ rating={rating}
285
+ priceText={priceText}
286
+ isLoading={isLoading}
287
+ hasFlight={hasFlight}
288
+ hasTransfer={hasTransfer}
289
+ />
290
+ <div className="booking-product__body">
291
+ <Rooms
292
+ rooms={rooms}
293
+ isDisabled={roomsIsDisabled}
294
+ setIsDisabled={setRoomsIsDisabled}
295
+ onChange={handleRoomChange}
296
+ />
297
+ <Dates
298
+ value={dateRange}
299
+ duration={duration}
300
+ onChange={handleDateChange}
301
+ />
302
+ </div>
303
+ <Footer
304
+ priceText={priceText}
305
+ isLoading={isLoading}
306
+ isOffer={isOffer}
307
+ roomsIsDisabled={roomsIsDisabled}
308
+ handleBookClick={handleBookClick}
309
+ />
310
+ </div>
311
+ );
312
+ };
313
+
314
+ export default Product;