@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,249 +1,258 @@
1
- import JsonURL from "@jsonurl/jsonurl";
2
- import { Gender } from "@qite/tide-client";
3
- import {
4
- BookingPackageAddress,
5
- BookingPackageBookRequest,
6
- BookingPackagePax,
7
- BookingPackageRequest,
8
- } from "@qite/tide-client/build/types/offer";
9
- import { createSelector } from "@reduxjs/toolkit";
10
- import { format, parseISO } from "date-fns";
11
- import { omit } from "lodash";
12
- import { RootState } from "../../store";
13
- import { Room, Traveler } from "../../types";
14
- import { selectNotifications } from "../price-details/price-details-slice";
15
- import {
16
- selectAgentId,
17
- selectTravelersFormValues,
18
- } from "../travelers-form/travelers-form-slice";
19
-
20
- export const selectGeneratePaymentUrl = (state: RootState) =>
21
- state.booking.generatePaymentUrl;
22
-
23
- export const selectSkipPaymentWithAgent = (state: RootState) =>
24
- state.booking.skipPaymentWithAgent;
25
-
26
- export const selectIsFetchingProductOptions = (state: RootState) =>
27
- state.booking.isBusy;
28
-
29
- export const selectDepartureFlight = (state: RootState) =>
30
- state.booking.package?.outwardFlights?.find((x) => x.isSelected);
31
-
32
- export const selectReturnFlight = (state: RootState) =>
33
- state.booking.package?.returnFlights?.find((x) => x.isSelected);
34
-
35
- export const selectPackageRooms = (state: RootState) =>
36
- state.booking.package?.options.find((x) => x.isSelected)?.rooms;
37
-
38
- export const selectPackageOptionUnits = (state: RootState) =>
39
- state.booking.package?.options.find((x) => x.isSelected)?.optionUnits;
40
-
41
- export const selectPackageOptionPax = (state: RootState) =>
42
- state.booking.package?.options.find((x) => x.isSelected)?.optionPax;
43
-
44
- export const selectPackageGroups = (state: RootState) =>
45
- state.booking.package?.options.find((x) => x.isSelected)?.groups;
46
-
47
- export const selectPackageDetails = (state: RootState) => state.booking.package;
48
-
49
- export const selectActiveOption = (state: RootState) =>
50
- state.booking.package?.options.find((x) => x.isSelected);
51
-
52
- export const selectIsUnavailable = (state: RootState) =>
53
- state.booking.isUnavailable;
54
-
55
- export const selectRequestRooms = (state: RootState) =>
56
- state.booking.package?.options.find((x) => x.isSelected)?.requestRooms;
57
-
58
- export const selectOfficeId = (state: RootState) => state.booking.officeId;
59
-
60
- export const selectEntryStatus = (state: RootState) =>
61
- state.booking.entryStatus;
62
-
63
- export const selectCustomEntryStatusId = (state: RootState) =>
64
- state.booking.customEntryStatusId;
65
-
66
- export const selectProductAttributes = (state: RootState) =>
67
- state.booking.productAttributes;
68
-
69
- export const selectBookingAttributes = (state: RootState) =>
70
- state.booking.bookingAttributes;
71
-
72
- export const selectBookingNumber = (state: RootState) =>
73
- state.booking.bookingNumber;
74
-
75
- export const selectBookingRooms = (state: RootState) =>
76
- state.booking.bookingAttributes?.rooms;
77
-
78
- export const selectCalculateDeposit = (state: RootState) =>
79
- state.booking.calculateDeposit;
80
-
81
- export const selectIsRetry = (state: RootState) => state.booking.isRetry;
82
-
83
- export const selectStartDate = (state: RootState) =>
84
- state.booking.package?.options.find((x) => x.isSelected)?.fromDate;
85
-
86
- export const selectAgents = (state: RootState) => state.booking.agents;
87
-
88
- export const selectBookingQuery = (state: RootState) => {
89
- const bookingAttributes = state.booking.bookingAttributes;
90
-
91
- if (!bookingAttributes) {
92
- return undefined;
93
- }
94
-
95
- const params: Record<string, string> = {};
96
- Object.entries(bookingAttributes).forEach(([key, value]) => {
97
- if (key === "startDate" || key === "endDate") {
98
- value = format(parseISO(value), "yyyy-MM-dd");
99
- }
100
- if (key === "rooms") {
101
- value = JsonURL.stringify(
102
- (value as Room[]).map((room) => omit(room, ["children"])),
103
- {
104
- AQF: true,
105
- }
106
- );
107
- }
108
- params[key] = value;
109
- });
110
-
111
- return params;
112
- };
113
-
114
- export const selectBookingQueryString = createSelector(
115
- selectBookingQuery,
116
- (params) => {
117
- if (!params) {
118
- return undefined;
119
- }
120
-
121
- return Object.keys(params)
122
- .filter((key) => typeof params[key] !== "undefined")
123
- .map((key) => `${key}=${params[key]}`)
124
- .join("&");
125
- }
126
- );
127
-
128
- export const selectMainBookerId = createSelector(
129
- selectTravelersFormValues,
130
- (formValues) => formValues?.mainBookerId
131
- );
132
-
133
- export const selectBookingPackagePax = createSelector(
134
- selectTravelersFormValues,
135
- (formValues) => {
136
- var pax: BookingPackagePax[] = [];
137
-
138
- formValues?.adults.forEach((x) => {
139
- const adultPax = buildPax(x, formValues?.mainBookerId);
140
-
141
- if (adultPax.isMainBooker) {
142
- adultPax.mobilePhone = formValues?.phone;
143
- adultPax.email = formValues?.email;
144
- }
145
-
146
- pax.push(adultPax);
147
- });
148
-
149
- formValues?.children.forEach((x) => {
150
- pax.push(buildPax(x));
151
- });
152
-
153
- return pax;
154
- }
155
- );
156
-
157
- export const selectBookingAddress = createSelector(
158
- selectTravelersFormValues,
159
- selectBookingPackagePax,
160
- (formValues, pax) => {
161
- const mainBooker = pax.find((x) => x.isMainBooker);
162
- if (!mainBooker) return undefined;
163
-
164
- return {
165
- name: `${mainBooker.firstName} ${mainBooker.lastName}`,
166
- street: formValues?.street,
167
- number: formValues?.houseNumber,
168
- box: formValues?.box,
169
- postalCode: formValues?.zipCode,
170
- location: formValues?.place,
171
- country: formValues?.country,
172
- mobilePhone: formValues?.phone,
173
- email: formValues?.email,
174
- } as BookingPackageAddress;
175
- }
176
- );
177
-
178
- export const selectBookingPackageBookRequest = createSelector(
179
- selectOfficeId,
180
- selectEntryStatus,
181
- selectCustomEntryStatusId,
182
- selectBookingPackagePax,
183
- selectBookingAddress,
184
- selectPackageDetails,
185
- selectCalculateDeposit,
186
- selectAgentId,
187
- selectGeneratePaymentUrl,
188
- selectSkipPaymentWithAgent,
189
- selectNotifications,
190
- (
191
- officeId,
192
- entryStatus,
193
- customEntryStatusId,
194
- pax,
195
- address,
196
- packageDetails,
197
- calculateDeposit,
198
- agentId,
199
- generatePaymentUrl,
200
- skipPaymentWithAgent,
201
- notifications
202
- ) => {
203
- if (!packageDetails || pax?.length == 0) return null;
204
-
205
- let returnPaymentUrl = false;
206
-
207
- if (generatePaymentUrl && (!skipPaymentWithAgent || (agentId ?? 0) == 0)) {
208
- returnPaymentUrl = true;
209
- }
210
-
211
- return {
212
- officeId: officeId,
213
- agentId: (agentId ?? 0) > 0 ? agentId : null,
214
- payload: {
215
- package: packageDetails,
216
- status: entryStatus,
217
- customStatusId: customEntryStatusId,
218
- address: address,
219
- pax: pax,
220
- calculateDeposit: calculateDeposit,
221
- returnPaymentUrl: returnPaymentUrl,
222
- notifications: notifications,
223
- },
224
- } as BookingPackageRequest<BookingPackageBookRequest>;
225
- }
226
- );
227
-
228
- const buildPax = (traveler: Traveler, mainBookerId?: number) => {
229
- return {
230
- id: traveler.id,
231
- gender: parseGender(traveler.gender),
232
- firstName: traveler.firstName,
233
- lastName: traveler.lastName,
234
- dateOfBirth: traveler.birthDate,
235
- isMainBooker: traveler.id == mainBookerId,
236
- } as BookingPackagePax;
237
- };
238
-
239
- const parseGender = (gender: string): number => {
240
- switch (gender) {
241
- case "m":
242
- return Gender.male;
243
- case "f":
244
- return Gender.female;
245
- case "x":
246
- default:
247
- return Gender.other;
248
- }
249
- };
1
+ import JsonURL from "@jsonurl/jsonurl";
2
+ import { Gender } from "@qite/tide-client";
3
+ import {
4
+ BookingPackageAddress,
5
+ BookingPackageBookRequest,
6
+ BookingPackagePax,
7
+ BookingPackageRequest,
8
+ } from "@qite/tide-client/build/types/offer";
9
+ import { createSelector } from "@reduxjs/toolkit";
10
+ import { format, parseISO } from "date-fns";
11
+ import { omit } from "lodash";
12
+ import { RootState } from "../../store";
13
+ import { Room, Traveler } from "../../types";
14
+ import { selectNotifications } from "../price-details/price-details-slice";
15
+ import {
16
+ selectAgentId,
17
+ selectTravelersFormValues,
18
+ } from "../travelers-form/travelers-form-slice";
19
+
20
+ export const selectGeneratePaymentUrl = (state: RootState) =>
21
+ state.booking.generatePaymentUrl;
22
+
23
+ export const selectSkipPaymentWithAgent = (state: RootState) =>
24
+ state.booking.skipPaymentWithAgent;
25
+
26
+ export const selectIsFetchingProductOptions = (state: RootState) =>
27
+ state.booking.isBusy;
28
+
29
+ export const selectDepartureFlight = (state: RootState) =>
30
+ state.booking.package?.outwardFlights?.find((x) => x.isSelected);
31
+
32
+ export const selectReturnFlight = (state: RootState) =>
33
+ state.booking.package?.returnFlights?.find((x) => x.isSelected);
34
+
35
+ export const selectPackageRooms = (state: RootState) =>
36
+ state.booking.package?.options.find((x) => x.isSelected)?.rooms;
37
+
38
+ export const selectPackageOptionUnits = (state: RootState) =>
39
+ state.booking.package?.options.find((x) => x.isSelected)?.optionUnits;
40
+
41
+ export const selectPackageOptionPax = (state: RootState) =>
42
+ state.booking.package?.options.find((x) => x.isSelected)?.optionPax;
43
+
44
+ export const selectPackageGroups = (state: RootState) =>
45
+ state.booking.package?.options.find((x) => x.isSelected)?.groups;
46
+
47
+ export const selectPackageDetails = (state: RootState) => state.booking.package;
48
+
49
+ export const selectActiveOption = (state: RootState) =>
50
+ state.booking.package?.options.find((x) => x.isSelected);
51
+
52
+ export const selectIsUnavailable = (state: RootState) =>
53
+ state.booking.isUnavailable;
54
+
55
+ export const selectRequestRooms = (state: RootState) =>
56
+ state.booking.package?.options.find((x) => x.isSelected)?.requestRooms;
57
+
58
+ export const selectOfficeId = (state: RootState) => state.booking.officeId;
59
+
60
+ export const selectEntryStatus = (state: RootState) =>
61
+ state.booking.entryStatus;
62
+
63
+ export const selectCustomEntryStatusId = (state: RootState) =>
64
+ state.booking.customEntryStatusId;
65
+
66
+ export const selectTagIds = (state: RootState) => state.booking.tagIds;
67
+ export const selectAgentAdressId = (state: RootState) =>
68
+ state.booking.agentAdressId;
69
+
70
+ export const selectProductAttributes = (state: RootState) =>
71
+ state.booking.productAttributes;
72
+
73
+ export const selectBookingAttributes = (state: RootState) =>
74
+ state.booking.bookingAttributes;
75
+
76
+ export const selectBookingNumber = (state: RootState) =>
77
+ state.booking.bookingNumber;
78
+
79
+ export const selectBookingRooms = (state: RootState) =>
80
+ state.booking.bookingAttributes?.rooms;
81
+
82
+ export const selectCalculateDeposit = (state: RootState) =>
83
+ state.booking.calculateDeposit;
84
+
85
+ export const selectIsRetry = (state: RootState) => state.booking.isRetry;
86
+
87
+ export const selectStartDate = (state: RootState) =>
88
+ state.booking.package?.options.find((x) => x.isSelected)?.fromDate;
89
+
90
+ export const selectAgents = (state: RootState) => state.booking.agents;
91
+
92
+ export const selectBookingQuery = (state: RootState) => {
93
+ const bookingAttributes = state.booking.bookingAttributes;
94
+
95
+ if (!bookingAttributes) {
96
+ return undefined;
97
+ }
98
+
99
+ const params: Record<string, string> = {};
100
+ Object.entries(bookingAttributes).forEach(([key, value]) => {
101
+ if (key === "startDate" || key === "endDate") {
102
+ value = format(parseISO(value), "yyyy-MM-dd");
103
+ }
104
+ if (key === "rooms") {
105
+ value = JsonURL.stringify(
106
+ (value as Room[]).map((room) => omit(room, ["children"])),
107
+ {
108
+ AQF: true,
109
+ }
110
+ );
111
+ }
112
+ params[key] = value;
113
+ });
114
+
115
+ return params;
116
+ };
117
+
118
+ export const selectBookingQueryString = createSelector(
119
+ selectBookingQuery,
120
+ (params) => {
121
+ if (!params) {
122
+ return undefined;
123
+ }
124
+
125
+ return Object.keys(params)
126
+ .filter((key) => typeof params[key] !== "undefined")
127
+ .map((key) => `${key}=${params[key]}`)
128
+ .join("&");
129
+ }
130
+ );
131
+
132
+ export const selectMainBookerId = createSelector(
133
+ selectTravelersFormValues,
134
+ (formValues) => formValues?.mainBookerId
135
+ );
136
+
137
+ export const selectBookingPackagePax = createSelector(
138
+ selectTravelersFormValues,
139
+ (formValues) => {
140
+ var pax: BookingPackagePax[] = [];
141
+
142
+ formValues?.adults.forEach((x) => {
143
+ const adultPax = buildPax(x, formValues?.mainBookerId);
144
+
145
+ if (adultPax.isMainBooker) {
146
+ adultPax.mobilePhone = formValues?.phone;
147
+ adultPax.email = formValues?.email;
148
+ }
149
+
150
+ pax.push(adultPax);
151
+ });
152
+
153
+ formValues?.children.forEach((x) => {
154
+ pax.push(buildPax(x));
155
+ });
156
+
157
+ return pax;
158
+ }
159
+ );
160
+
161
+ export const selectBookingAddress = createSelector(
162
+ selectTravelersFormValues,
163
+ selectBookingPackagePax,
164
+ (formValues, pax) => {
165
+ const mainBooker = pax.find((x) => x.isMainBooker);
166
+ if (!mainBooker) return undefined;
167
+
168
+ return {
169
+ name: `${mainBooker.firstName} ${mainBooker.lastName}`,
170
+ street: formValues?.street,
171
+ number: formValues?.houseNumber,
172
+ box: formValues?.box,
173
+ postalCode: formValues?.zipCode,
174
+ location: formValues?.place,
175
+ country: formValues?.country,
176
+ mobilePhone: formValues?.phone,
177
+ email: formValues?.email,
178
+ } as BookingPackageAddress;
179
+ }
180
+ );
181
+
182
+ export const selectBookingPackageBookRequest = createSelector(
183
+ selectOfficeId,
184
+ selectEntryStatus,
185
+ selectCustomEntryStatusId,
186
+ selectBookingPackagePax,
187
+ selectBookingAddress,
188
+ selectPackageDetails,
189
+ selectCalculateDeposit,
190
+ selectAgentId,
191
+ selectGeneratePaymentUrl,
192
+ selectSkipPaymentWithAgent,
193
+ selectNotifications,
194
+ selectTagIds,
195
+ selectAgentAdressId,
196
+ (
197
+ officeId,
198
+ entryStatus,
199
+ customEntryStatusId,
200
+ pax,
201
+ address,
202
+ packageDetails,
203
+ calculateDeposit,
204
+ agentId,
205
+ generatePaymentUrl,
206
+ skipPaymentWithAgent,
207
+ notifications,
208
+ tagIds,
209
+ agentAdressId
210
+ ) => {
211
+ if (!packageDetails || pax?.length == 0) return null;
212
+
213
+ let returnPaymentUrl = false;
214
+
215
+ if (generatePaymentUrl && (!skipPaymentWithAgent || (agentId ?? 0) == 0)) {
216
+ returnPaymentUrl = true;
217
+ }
218
+
219
+ return {
220
+ officeId: officeId,
221
+ agentId: (agentId ?? 0) > 0 ? agentId : null,
222
+ payload: {
223
+ package: packageDetails,
224
+ status: entryStatus,
225
+ customStatusId: customEntryStatusId,
226
+ address: address,
227
+ pax: pax,
228
+ calculateDeposit: calculateDeposit,
229
+ returnPaymentUrl: returnPaymentUrl,
230
+ notifications: notifications,
231
+ tagIds: tagIds,
232
+ },
233
+ } as BookingPackageRequest<BookingPackageBookRequest>;
234
+ }
235
+ );
236
+
237
+ const buildPax = (traveler: Traveler, mainBookerId?: number) => {
238
+ return {
239
+ id: traveler.id,
240
+ gender: parseGender(traveler.gender),
241
+ firstName: traveler.firstName,
242
+ lastName: traveler.lastName,
243
+ dateOfBirth: traveler.birthDate,
244
+ isMainBooker: traveler.id == mainBookerId,
245
+ } as BookingPackagePax;
246
+ };
247
+
248
+ const parseGender = (gender: string): number => {
249
+ switch (gender) {
250
+ case "m":
251
+ return Gender.male;
252
+ case "f":
253
+ return Gender.female;
254
+ case "x":
255
+ default:
256
+ return Gender.other;
257
+ }
258
+ };