@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.
- package/.vs/ProjectSettings.json +3 -3
- package/.vs/VSWorkspaceState.json +5 -5
- package/README.md +8 -8
- package/build/build-cjs/booking-wizard/components/print-offer-button.d.ts +17 -0
- package/build/build-cjs/booking-wizard/types.d.ts +7 -0
- package/build/build-cjs/booking-wizard/use-offer-printer.d.ts +13 -0
- package/build/build-cjs/index.js +223 -72
- package/build/build-cjs/shared/utils/localization-util.d.ts +5 -0
- package/build/build-cjs/shared/utils/tide-api-utils.d.ts +1 -0
- package/build/build-esm/booking-wizard/components/print-offer-button.d.ts +17 -0
- package/build/build-esm/booking-wizard/types.d.ts +7 -0
- package/build/build-esm/booking-wizard/use-offer-printer.d.ts +13 -0
- package/build/build-esm/index.js +224 -73
- package/build/build-esm/shared/utils/localization-util.d.ts +5 -0
- package/build/build-esm/shared/utils/tide-api-utils.d.ts +1 -0
- package/package.json +75 -75
- package/rollup.config.js +23 -23
- package/src/booking-product/components/age-select.tsx +35 -35
- package/src/booking-product/components/amount-input.tsx +78 -78
- package/src/booking-product/components/date-range-picker/calendar-day.tsx +58 -58
- package/src/booking-product/components/date-range-picker/calendar.tsx +178 -178
- package/src/booking-product/components/date-range-picker/index.tsx +196 -196
- package/src/booking-product/components/dates.tsx +136 -136
- package/src/booking-product/components/footer.tsx +69 -69
- package/src/booking-product/components/header.tsx +79 -79
- package/src/booking-product/components/icon.tsx +251 -251
- package/src/booking-product/components/product.tsx +314 -314
- package/src/booking-product/components/rating.tsx +21 -21
- package/src/booking-product/components/rooms.tsx +195 -195
- package/src/booking-product/index.tsx +30 -30
- package/src/booking-product/settings-context.ts +14 -14
- package/src/booking-product/types.ts +28 -28
- package/src/booking-product/utils/api.ts +25 -25
- package/src/booking-product/utils/price.ts +29 -29
- package/src/booking-wizard/api-settings-slice.ts +24 -24
- package/src/booking-wizard/components/icon.tsx +508 -508
- package/src/booking-wizard/components/labeled-input.tsx +64 -64
- package/src/booking-wizard/components/labeled-select.tsx +69 -69
- package/src/booking-wizard/components/message.tsx +34 -34
- package/src/booking-wizard/components/multi-range-filter.tsx +113 -113
- package/src/booking-wizard/components/print-offer-button.tsx +66 -0
- package/src/booking-wizard/components/product-card.tsx +37 -37
- package/src/booking-wizard/components/step-indicator.tsx +51 -51
- package/src/booking-wizard/components/step-route.tsx +27 -27
- package/src/booking-wizard/declarations.d.ts +4 -4
- package/src/booking-wizard/features/booking/api.ts +49 -49
- package/src/booking-wizard/features/booking/booking-self-contained.tsx +384 -384
- package/src/booking-wizard/features/booking/booking-slice.ts +662 -662
- package/src/booking-wizard/features/booking/booking.tsx +356 -356
- package/src/booking-wizard/features/booking/constants.ts +16 -16
- package/src/booking-wizard/features/booking/selectors.ts +441 -441
- package/src/booking-wizard/features/confirmation/confirmation.tsx +97 -97
- package/src/booking-wizard/features/error/error.tsx +78 -78
- package/src/booking-wizard/features/flight-options/flight-filter.tsx +432 -432
- package/src/booking-wizard/features/flight-options/flight-option-flight.tsx +385 -385
- package/src/booking-wizard/features/flight-options/flight-option-modal.tsx +229 -229
- package/src/booking-wizard/features/flight-options/flight-option.tsx +81 -81
- package/src/booking-wizard/features/flight-options/flight-utils.ts +516 -516
- package/src/booking-wizard/features/flight-options/index.tsx +196 -196
- package/src/booking-wizard/features/price-details/price-details-api.ts +24 -24
- package/src/booking-wizard/features/price-details/price-details-slice.ts +178 -178
- package/src/booking-wizard/features/price-details/util.ts +155 -155
- package/src/booking-wizard/features/product-options/no-options.tsx +21 -21
- package/src/booking-wizard/features/product-options/none-option.tsx +120 -120
- package/src/booking-wizard/features/product-options/option-booking-airline-group.tsx +64 -64
- package/src/booking-wizard/features/product-options/option-booking-group.tsx +216 -216
- package/src/booking-wizard/features/product-options/option-item.tsx +317 -317
- package/src/booking-wizard/features/product-options/option-pax-card.tsx +201 -201
- package/src/booking-wizard/features/product-options/option-pax-group.tsx +175 -175
- package/src/booking-wizard/features/product-options/option-room.tsx +321 -321
- package/src/booking-wizard/features/product-options/option-unit-group.tsx +198 -198
- package/src/booking-wizard/features/product-options/option-units-card.tsx +185 -185
- package/src/booking-wizard/features/product-options/options-form.tsx +563 -459
- package/src/booking-wizard/features/room-options/index.tsx +187 -187
- package/src/booking-wizard/features/room-options/room-utils.ts +190 -190
- package/src/booking-wizard/features/room-options/room.tsx +160 -160
- package/src/booking-wizard/features/room-options/traveler-rooms.tsx +75 -75
- package/src/booking-wizard/features/sidebar/index.tsx +76 -76
- package/src/booking-wizard/features/sidebar/sidebar-flight.tsx +68 -68
- package/src/booking-wizard/features/sidebar/sidebar-util.ts +177 -177
- package/src/booking-wizard/features/sidebar/sidebar.tsx +364 -364
- package/src/booking-wizard/features/summary/summary-booking-option-pax.tsx +25 -25
- package/src/booking-wizard/features/summary/summary-booking-option-unit.tsx +25 -25
- package/src/booking-wizard/features/summary/summary-flight.tsx +39 -39
- package/src/booking-wizard/features/summary/summary-per-booking-option-group.tsx +69 -69
- package/src/booking-wizard/features/summary/summary-per-pax-option-group.tsx +63 -63
- package/src/booking-wizard/features/summary/summary-per-unit-option-group.tsx +66 -66
- package/src/booking-wizard/features/summary/summary-slice.ts +28 -28
- package/src/booking-wizard/features/summary/summary.tsx +674 -674
- package/src/booking-wizard/features/travelers-form/travelers-form-slice.ts +164 -164
- package/src/booking-wizard/features/travelers-form/travelers-form.tsx +754 -754
- package/src/booking-wizard/features/travelers-form/type-ahead-input.tsx +101 -101
- package/src/booking-wizard/features/travelers-form/validate-form.ts +245 -245
- package/src/booking-wizard/index.tsx +36 -36
- package/src/booking-wizard/settings-context.ts +67 -60
- package/src/booking-wizard/store.ts +31 -31
- package/src/booking-wizard/types.ts +283 -276
- package/src/booking-wizard/use-offer-printer.ts +136 -0
- package/src/index.ts +4 -4
- package/src/shared/components/loader.tsx +16 -16
- package/src/shared/translations/en-GB.json +237 -232
- package/src/shared/translations/fr-BE.json +238 -233
- package/src/shared/translations/nl-BE.json +237 -232
- package/src/shared/types.ts +4 -4
- package/src/shared/utils/class-util.ts +9 -9
- package/src/shared/utils/localization-util.ts +62 -62
- package/src/shared/utils/query-string-util.ts +119 -119
- package/src/shared/utils/tide-api-utils.ts +36 -36
- package/styles/booking-product-variables.scss +394 -394
- package/styles/booking-product.scss +446 -446
- package/styles/booking-wizard-variables.scss +873 -871
- package/styles/booking-wizard.scss +59 -59
- package/styles/components/_animations.scss +39 -39
- package/styles/components/_base.scss +107 -107
- package/styles/components/_booking.scss +879 -879
- package/styles/components/_button.scss +238 -238
- package/styles/components/_checkbox.scss +219 -219
- package/styles/components/_cta.scss +208 -208
- package/styles/components/_date-list.scss +41 -41
- package/styles/components/_date-range-picker.scss +225 -225
- package/styles/components/_decrement-increment.scss +35 -35
- package/styles/components/_dropdown.scss +72 -72
- package/styles/components/_flight-option.scss +1429 -1429
- package/styles/components/_form.scss +1583 -1583
- package/styles/components/_info-message.scss +71 -71
- package/styles/components/_input.scss +25 -25
- package/styles/components/_list.scss +187 -187
- package/styles/components/_loader.scss +72 -72
- package/styles/components/_mixins.scss +550 -550
- package/styles/components/_placeholders.scss +166 -166
- package/styles/components/_pricing-summary.scss +155 -155
- package/styles/components/_qsm.scss +17 -17
- package/styles/components/_radiobutton.scss +170 -170
- package/styles/components/_select-wrapper.scss +80 -80
- package/styles/components/_spinner.scss +29 -29
- package/styles/components/_step-indicators.scss +168 -168
- package/styles/components/_table.scss +81 -81
- package/styles/components/_tree.scss +530 -530
- package/styles/components/_typeahead.scss +281 -281
- package/styles/components/_variables.scss +89 -89
- package/tsconfig.json +24 -24
|
@@ -1,314 +1,314 @@
|
|
|
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;
|
|
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;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { clamp, range } from "lodash";
|
|
3
|
-
import Icon from "./icon";
|
|
4
|
-
|
|
5
|
-
interface RatingProps {
|
|
6
|
-
rating: number;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const Rating: React.FC<RatingProps> = ({ rating }) => {
|
|
10
|
-
const clampedRating = clamp(rating, 0, 5);
|
|
11
|
-
return (
|
|
12
|
-
<div className="rating">
|
|
13
|
-
{range(0, Math.floor(clampedRating)).map((i) => (
|
|
14
|
-
<Icon name="ui-star" key={`rating-star-${i}`} width={25} height={25} />
|
|
15
|
-
))}
|
|
16
|
-
{rating % 1 > 0 && <Icon name="ui-halfstar" width={25} height={25} />}
|
|
17
|
-
</div>
|
|
18
|
-
);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export default Rating;
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { clamp, range } from "lodash";
|
|
3
|
+
import Icon from "./icon";
|
|
4
|
+
|
|
5
|
+
interface RatingProps {
|
|
6
|
+
rating: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const Rating: React.FC<RatingProps> = ({ rating }) => {
|
|
10
|
+
const clampedRating = clamp(rating, 0, 5);
|
|
11
|
+
return (
|
|
12
|
+
<div className="rating">
|
|
13
|
+
{range(0, Math.floor(clampedRating)).map((i) => (
|
|
14
|
+
<Icon name="ui-star" key={`rating-star-${i}`} width={25} height={25} />
|
|
15
|
+
))}
|
|
16
|
+
{rating % 1 > 0 && <Icon name="ui-halfstar" width={25} height={25} />}
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default Rating;
|