@qite/tide-booking-component 0.0.2-preview.58 → 0.0.2-preview.60

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.
@@ -1,283 +1,291 @@
1
- import React, { useContext } from "react";
2
- import { navigate, Router, useLocation } from "@reach/router";
3
- import {
4
- getDateFromParams,
5
- getNumberFromParams,
6
- getNumbersFromParams,
7
- getRoomsFromParams,
8
- getStringFromParams,
9
- } from "../../utils/query-string-util";
10
- import {
11
- fetchPackage,
12
- setBookingAttributes,
13
- setBookingNumber,
14
- setCalculateDeposit,
15
- setCustomEntryStatusId,
16
- setEntryStatus,
17
- setGeneratePaymentUrl,
18
- setIsRetry,
19
- setOfficeId,
20
- setProductAttributes,
21
- setSkipPayment,
22
- } from "./booking-slice";
23
- import { useSelector } from "react-redux";
24
-
25
- import Confirmation from "../confirmation/confirmation";
26
- import Error from "../error/error";
27
- import OptionsForm from "../product-options/options-form";
28
- import SettingsContext from "../../settings-context";
29
- import Sidebar from "../sidebar";
30
- import StepRoute from "../../components/step-route";
31
- import Summary from "../summary/summary";
32
- import TravelersForm from "../travelers-form/travelers-form";
33
- import translations from "../../translations/translations.json";
34
- import { useEffect } from "react";
35
- import { isNil } from "lodash";
36
- import { useAppDispatch } from "../../store";
37
- import {
38
- selectBookingAttributes,
39
- selectBookingNumber,
40
- selectBookingRooms,
41
- selectIsRetry,
42
- selectIsUnavailable,
43
- selectPackageDetails,
44
- selectProductAttributes,
45
- } from "./selectors";
46
-
47
- interface BookingProps {
48
- productCode: string;
49
- productName: string;
50
- thumbnailUrl?: string;
51
- }
52
-
53
- const Booking: React.FC<BookingProps> = ({
54
- productCode,
55
- productName,
56
- thumbnailUrl,
57
- }) => {
58
- const {
59
- officeId,
60
- entryStatus,
61
- customEntryStatusId,
62
- basePath,
63
- options,
64
- summary,
65
- confirmation,
66
- error,
67
- showSidebarDeposit,
68
- includeFlights,
69
- loaderComponent,
70
- skipPaymentWithAgent,
71
- generatePaymentUrl,
72
- } = useContext(SettingsContext);
73
-
74
- const dispatch = useAppDispatch();
75
- const location = useLocation();
76
-
77
- const productAttributes = useSelector(selectProductAttributes);
78
- const bookingAttributes = useSelector(selectBookingAttributes);
79
- const rooms = useSelector(selectBookingRooms);
80
- const bookingNumber = useSelector(selectBookingNumber);
81
- const isRetry = useSelector(selectIsRetry);
82
- const packageDetails = useSelector(selectPackageDetails);
83
- const isUnvailable = useSelector(selectIsUnavailable);
84
-
85
- useEffect(() => {
86
- dispatch(setSkipPayment(skipPaymentWithAgent ?? false));
87
- dispatch(setGeneratePaymentUrl(generatePaymentUrl ?? false));
88
- }, [skipPaymentWithAgent, generatePaymentUrl]);
89
-
90
- useEffect(() => {
91
- const params = new URLSearchParams(location.search);
92
- const startDate = getDateFromParams(params, "startDate");
93
- const endDate = getDateFromParams(params, "endDate");
94
- const catalog = getNumberFromParams(params, "catalog");
95
- const rooms = getRoomsFromParams(params, "rooms");
96
- const allotmentName = getStringFromParams(params, "allotmentName");
97
- const allotmentIds = getNumbersFromParams(params, "allotementId");
98
- const tourCode = getStringFromParams(params, "tourCode");
99
- const bookingNumber = params.get("bookingNr") ?? undefined;
100
-
101
- if (!isNil(bookingNumber)) {
102
- dispatch(setBookingNumber(bookingNumber));
103
- navigate(
104
- `${basePath}${confirmation.pathSuffix}?bookingNr=${bookingNumber}`
105
- );
106
- }
107
-
108
- if (
109
- !isNil(startDate) &&
110
- !isNil(endDate) &&
111
- !isNil(catalog) &&
112
- !isNil(rooms)
113
- ) {
114
- dispatch(
115
- setBookingAttributes({
116
- startDate,
117
- endDate,
118
- catalog,
119
- rooms,
120
- includeFlights,
121
- allotmentName,
122
- allotmentIds,
123
- tourCode,
124
- })
125
- );
126
- } else {
127
- console.error(
128
- "Failure when setting booking attributes",
129
- startDate,
130
- endDate,
131
- catalog,
132
- rooms
133
- );
134
- }
135
- }, [location.search, setBookingAttributes, setBookingNumber, includeFlights]);
136
-
137
- useEffect(() => {
138
- if (
139
- !productAttributes ||
140
- !bookingAttributes ||
141
- !isNil(bookingNumber) ||
142
- !isRetry
143
- ) {
144
- return;
145
- }
146
-
147
- // Retried
148
- dispatch(setIsRetry(false));
149
-
150
- // Fetch data
151
- const promise = dispatch(fetchPackage());
152
- return () => {
153
- promise.abort();
154
- };
155
- }, [isRetry]);
156
-
157
- useEffect(() => {
158
- if (!isNil(productCode) && !isNil(productName)) {
159
- dispatch(
160
- setProductAttributes({
161
- productCode,
162
- productName,
163
- })
164
- );
165
- } else {
166
- console.error(
167
- "Failure when setting product attributes",
168
- productCode,
169
- productName
170
- );
171
- }
172
- }, [productCode, productName, setProductAttributes]);
173
-
174
- useEffect(() => {
175
- dispatch(setOfficeId(officeId));
176
- dispatch(setEntryStatus(entryStatus));
177
- dispatch(setCustomEntryStatusId(customEntryStatusId ?? undefined));
178
- dispatch(setCalculateDeposit(showSidebarDeposit));
179
- }, [
180
- officeId,
181
- entryStatus,
182
- customEntryStatusId,
183
- showSidebarDeposit,
184
- setOfficeId,
185
- setEntryStatus,
186
- setCustomEntryStatusId,
187
- setCalculateDeposit,
188
- ]);
189
-
190
- useEffect(() => {
191
- if (
192
- !productAttributes ||
193
- !bookingAttributes ||
194
- !rooms?.length ||
195
- !isNil(bookingNumber) ||
196
- !isNil(packageDetails)
197
- ) {
198
- return;
199
- }
200
- // Fetch data
201
- const promise = dispatch(fetchPackage());
202
- return () => {
203
- promise.abort();
204
- };
205
- }, [
206
- productAttributes,
207
- bookingAttributes,
208
- rooms,
209
- bookingNumber,
210
- packageDetails,
211
- ]);
212
-
213
- return (
214
- <>
215
- {((productAttributes && bookingAttributes && packageDetails) ||
216
- bookingNumber) && (
217
- <div className="booking">
218
- <div className="booking__content">
219
- <div className="booking__panel">
220
- <Router basepath={basePath}>
221
- <StepRoute
222
- path="/"
223
- number={1}
224
- title={translations.STEPS.PERSONAL_DETAILS}
225
- component={<TravelersForm />}
226
- />
227
- <StepRoute
228
- path={options.pathSuffix}
229
- number={2}
230
- title={translations.STEPS.TRAVEL_OPTIONS}
231
- component={<OptionsForm />}
232
- />
233
- <StepRoute
234
- path={summary.pathSuffix}
235
- number={3}
236
- title={translations.STEPS.SUMMARY}
237
- component={<Summary />}
238
- />
239
- <StepRoute
240
- path={confirmation.pathSuffix}
241
- number={4}
242
- title={translations.STEPS.CONFIRMATION}
243
- component={<Confirmation />}
244
- />
245
- <StepRoute
246
- path={error.pathSuffix}
247
- number={4}
248
- title={translations.STEPS.ERROR}
249
- component={<Error />}
250
- />
251
- </Router>
252
- </div>
253
- <div className="backdrop" id="backdrop"></div>
254
- {packageDetails && (
255
- <Sidebar productName={productName} thumbnailUrl={thumbnailUrl} />
256
- )}
257
- </div>
258
- </div>
259
- )}
260
- {!packageDetails && !bookingNumber && !isUnvailable && (
261
- <div className="booking">
262
- <div className="booking__loader">
263
- {loaderComponent}
264
- <p className="booking__loader-text">
265
- {translations.MAIN.PREPARING_BOOKING}
266
- </p>
267
- </div>
268
- </div>
269
- )}
270
- {isUnvailable && (
271
- <div className="booking">
272
- <div className="booking__loader">
273
- <p className="booking__loader-text">
274
- {translations.MAIN.PRODUCT_UNAVAILABLE}
275
- </p>
276
- </div>
277
- </div>
278
- )}
279
- </>
280
- );
281
- };
282
-
283
- export default Booking;
1
+ import React, { useContext } from "react";
2
+ import { navigate, Router, useLocation } from "@reach/router";
3
+ import {
4
+ getDateFromParams,
5
+ getNumberFromParams,
6
+ getNumbersFromParams,
7
+ getRoomsFromParams,
8
+ getStringFromParams,
9
+ } from "../../utils/query-string-util";
10
+ import {
11
+ fetchPackage,
12
+ setAgentAdressId,
13
+ setBookingAttributes,
14
+ setBookingNumber,
15
+ setCalculateDeposit,
16
+ setCustomEntryStatusId,
17
+ setEntryStatus,
18
+ setGeneratePaymentUrl,
19
+ setIsRetry,
20
+ setOfficeId,
21
+ setProductAttributes,
22
+ setSkipPayment,
23
+ setTagIds,
24
+ } from "./booking-slice";
25
+ import { useSelector } from "react-redux";
26
+
27
+ import Confirmation from "../confirmation/confirmation";
28
+ import Error from "../error/error";
29
+ import OptionsForm from "../product-options/options-form";
30
+ import SettingsContext from "../../settings-context";
31
+ import Sidebar from "../sidebar";
32
+ import StepRoute from "../../components/step-route";
33
+ import Summary from "../summary/summary";
34
+ import TravelersForm from "../travelers-form/travelers-form";
35
+ import translations from "../../translations/translations.json";
36
+ import { useEffect } from "react";
37
+ import { isNil } from "lodash";
38
+ import { useAppDispatch } from "../../store";
39
+ import {
40
+ selectBookingAttributes,
41
+ selectBookingNumber,
42
+ selectBookingRooms,
43
+ selectIsRetry,
44
+ selectIsUnavailable,
45
+ selectPackageDetails,
46
+ selectProductAttributes,
47
+ } from "./selectors";
48
+
49
+ interface BookingProps {
50
+ productCode: string;
51
+ productName: string;
52
+ thumbnailUrl?: string;
53
+ }
54
+
55
+ const Booking: React.FC<BookingProps> = ({
56
+ productCode,
57
+ productName,
58
+ thumbnailUrl,
59
+ }) => {
60
+ const {
61
+ officeId,
62
+ entryStatus,
63
+ customEntryStatusId,
64
+ basePath,
65
+ options,
66
+ summary,
67
+ confirmation,
68
+ error,
69
+ showSidebarDeposit,
70
+ includeFlights,
71
+ loaderComponent,
72
+ skipPaymentWithAgent,
73
+ generatePaymentUrl,
74
+ tagIds,
75
+ agentAdressId,
76
+ } = useContext(SettingsContext);
77
+
78
+ const dispatch = useAppDispatch();
79
+ const location = useLocation();
80
+
81
+ const productAttributes = useSelector(selectProductAttributes);
82
+ const bookingAttributes = useSelector(selectBookingAttributes);
83
+ const rooms = useSelector(selectBookingRooms);
84
+ const bookingNumber = useSelector(selectBookingNumber);
85
+ const isRetry = useSelector(selectIsRetry);
86
+ const packageDetails = useSelector(selectPackageDetails);
87
+ const isUnvailable = useSelector(selectIsUnavailable);
88
+
89
+ useEffect(() => {
90
+ dispatch(setSkipPayment(skipPaymentWithAgent ?? false));
91
+ dispatch(setGeneratePaymentUrl(generatePaymentUrl ?? false));
92
+ }, [skipPaymentWithAgent, generatePaymentUrl]);
93
+
94
+ useEffect(() => {
95
+ const params = new URLSearchParams(location.search);
96
+ const startDate = getDateFromParams(params, "startDate");
97
+ const endDate = getDateFromParams(params, "endDate");
98
+ const catalog = getNumberFromParams(params, "catalog");
99
+ const rooms = getRoomsFromParams(params, "rooms");
100
+ const allotmentName = getStringFromParams(params, "allotmentName");
101
+ const allotmentIds = getNumbersFromParams(params, "allotementId");
102
+ const tourCode = getStringFromParams(params, "tourCode");
103
+ const bookingNumber = params.get("bookingNr") ?? undefined;
104
+
105
+ if (!isNil(bookingNumber)) {
106
+ dispatch(setBookingNumber(bookingNumber));
107
+ navigate(
108
+ `${basePath}${confirmation.pathSuffix}?bookingNr=${bookingNumber}`
109
+ );
110
+ }
111
+
112
+ if (
113
+ !isNil(startDate) &&
114
+ !isNil(endDate) &&
115
+ !isNil(catalog) &&
116
+ !isNil(rooms)
117
+ ) {
118
+ dispatch(
119
+ setBookingAttributes({
120
+ startDate,
121
+ endDate,
122
+ catalog,
123
+ rooms,
124
+ includeFlights,
125
+ allotmentName,
126
+ allotmentIds,
127
+ tourCode,
128
+ })
129
+ );
130
+ } else {
131
+ console.error(
132
+ "Failure when setting booking attributes",
133
+ startDate,
134
+ endDate,
135
+ catalog,
136
+ rooms
137
+ );
138
+ }
139
+ }, [location.search, setBookingAttributes, setBookingNumber, includeFlights]);
140
+
141
+ useEffect(() => {
142
+ if (
143
+ !productAttributes ||
144
+ !bookingAttributes ||
145
+ !isNil(bookingNumber) ||
146
+ !isRetry
147
+ ) {
148
+ return;
149
+ }
150
+
151
+ // Retried
152
+ dispatch(setIsRetry(false));
153
+
154
+ // Fetch data
155
+ const promise = dispatch(fetchPackage());
156
+ return () => {
157
+ promise.abort();
158
+ };
159
+ }, [isRetry]);
160
+
161
+ useEffect(() => {
162
+ if (!isNil(productCode) && !isNil(productName)) {
163
+ dispatch(
164
+ setProductAttributes({
165
+ productCode,
166
+ productName,
167
+ })
168
+ );
169
+ } else {
170
+ console.error(
171
+ "Failure when setting product attributes",
172
+ productCode,
173
+ productName
174
+ );
175
+ }
176
+ }, [productCode, productName, setProductAttributes]);
177
+
178
+ useEffect(() => {
179
+ dispatch(setOfficeId(officeId));
180
+ dispatch(setEntryStatus(entryStatus));
181
+ dispatch(setCustomEntryStatusId(customEntryStatusId ?? undefined));
182
+ dispatch(setCalculateDeposit(showSidebarDeposit));
183
+ dispatch(setTagIds(tagIds ?? undefined));
184
+ dispatch(setAgentAdressId(agentAdressId ?? undefined));
185
+ }, [
186
+ officeId,
187
+ entryStatus,
188
+ customEntryStatusId,
189
+ showSidebarDeposit,
190
+ setOfficeId,
191
+ setEntryStatus,
192
+ setCustomEntryStatusId,
193
+ setCalculateDeposit,
194
+ tagIds,
195
+ agentAdressId,
196
+ ]);
197
+
198
+ useEffect(() => {
199
+ if (
200
+ !productAttributes ||
201
+ !bookingAttributes ||
202
+ !rooms?.length ||
203
+ !isNil(bookingNumber) ||
204
+ !isNil(packageDetails)
205
+ ) {
206
+ return;
207
+ }
208
+ // Fetch data
209
+ const promise = dispatch(fetchPackage());
210
+ return () => {
211
+ promise.abort();
212
+ };
213
+ }, [
214
+ productAttributes,
215
+ bookingAttributes,
216
+ rooms,
217
+ bookingNumber,
218
+ packageDetails,
219
+ ]);
220
+
221
+ return (
222
+ <>
223
+ {((productAttributes && bookingAttributes && packageDetails) ||
224
+ bookingNumber) && (
225
+ <div className="booking">
226
+ <div className="booking__content">
227
+ <div className="booking__panel">
228
+ <Router basepath={basePath}>
229
+ <StepRoute
230
+ path="/"
231
+ number={1}
232
+ title={translations.STEPS.PERSONAL_DETAILS}
233
+ component={<TravelersForm />}
234
+ />
235
+ <StepRoute
236
+ path={options.pathSuffix}
237
+ number={2}
238
+ title={translations.STEPS.TRAVEL_OPTIONS}
239
+ component={<OptionsForm />}
240
+ />
241
+ <StepRoute
242
+ path={summary.pathSuffix}
243
+ number={3}
244
+ title={translations.STEPS.SUMMARY}
245
+ component={<Summary />}
246
+ />
247
+ <StepRoute
248
+ path={confirmation.pathSuffix}
249
+ number={4}
250
+ title={translations.STEPS.CONFIRMATION}
251
+ component={<Confirmation />}
252
+ />
253
+ <StepRoute
254
+ path={error.pathSuffix}
255
+ number={4}
256
+ title={translations.STEPS.ERROR}
257
+ component={<Error />}
258
+ />
259
+ </Router>
260
+ </div>
261
+ <div className="backdrop" id="backdrop"></div>
262
+ {packageDetails && (
263
+ <Sidebar productName={productName} thumbnailUrl={thumbnailUrl} />
264
+ )}
265
+ </div>
266
+ </div>
267
+ )}
268
+ {!packageDetails && !bookingNumber && !isUnvailable && (
269
+ <div className="booking">
270
+ <div className="booking__loader">
271
+ {loaderComponent}
272
+ <p className="booking__loader-text">
273
+ {translations.MAIN.PREPARING_BOOKING}
274
+ </p>
275
+ </div>
276
+ </div>
277
+ )}
278
+ {isUnvailable && (
279
+ <div className="booking">
280
+ <div className="booking__loader">
281
+ <p className="booking__loader-text">
282
+ {translations.MAIN.PRODUCT_UNAVAILABLE}
283
+ </p>
284
+ </div>
285
+ </div>
286
+ )}
287
+ </>
288
+ );
289
+ };
290
+
291
+ export default Booking;