@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.
- package/build/build-cjs/booking-wizard/features/booking/booking-slice.d.ts +3 -1
- package/build/build-cjs/booking-wizard/features/booking/selectors.d.ts +3 -1
- package/build/build-cjs/booking-wizard/types.d.ts +2 -0
- package/build/build-cjs/index.js +31 -5
- package/build/build-esm/booking-wizard/features/booking/booking-slice.d.ts +3 -1
- package/build/build-esm/booking-wizard/features/booking/selectors.d.ts +3 -1
- package/build/build-esm/booking-wizard/types.d.ts +2 -0
- package/build/build-esm/index.js +31 -5
- package/package.json +71 -71
- package/src/booking-wizard/components/product-card.tsx +1 -1
- package/src/booking-wizard/features/booking/booking-slice.ts +289 -277
- package/src/booking-wizard/features/booking/booking.tsx +291 -283
- package/src/booking-wizard/features/booking/selectors.ts +258 -249
- package/src/booking-wizard/features/travelers-form/travelers-form.tsx +659 -650
- package/src/booking-wizard/settings-context.ts +40 -38
- package/src/booking-wizard/types.ts +105 -103
|
@@ -1,277 +1,289 @@
|
|
|
1
|
-
import { BookingAttributes, ProductAttributes } from "../../types";
|
|
2
|
-
import { PayloadAction, createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
|
3
|
-
|
|
4
|
-
import { RootState } from "../../store";
|
|
5
|
-
import { isNil, range } from "lodash";
|
|
6
|
-
import {
|
|
7
|
-
selectBookingAttributes,
|
|
8
|
-
selectBookingRooms,
|
|
9
|
-
selectOfficeId,
|
|
10
|
-
selectProductAttributes,
|
|
11
|
-
} from "./selectors";
|
|
12
|
-
import {
|
|
13
|
-
BookingOptionGroup,
|
|
14
|
-
BookingOptionPax,
|
|
15
|
-
BookingOptionUnit,
|
|
16
|
-
BookingPackage,
|
|
17
|
-
BookingPackageDetailsRequest,
|
|
18
|
-
BookingPackagePax,
|
|
19
|
-
BookingPackageRequest,
|
|
20
|
-
BookingPackageRequestRoom,
|
|
21
|
-
BookingPackageRoom,
|
|
22
|
-
BookingTravelAgent,
|
|
23
|
-
PerBookingPackageOption,
|
|
24
|
-
} from "@qite/tide-client/build/types";
|
|
25
|
-
import packageApi from "./api";
|
|
26
|
-
import { selectAgentId } from "../travelers-form/travelers-form-slice";
|
|
27
|
-
|
|
28
|
-
export interface BookingState {
|
|
29
|
-
officeId: number;
|
|
30
|
-
entryStatus: number;
|
|
31
|
-
customEntryStatusId?: number;
|
|
32
|
-
productAttributes?: ProductAttributes;
|
|
33
|
-
bookingAttributes?: BookingAttributes;
|
|
34
|
-
calculateDeposit: boolean;
|
|
35
|
-
bookingNumber?: string;
|
|
36
|
-
isRetry: boolean;
|
|
37
|
-
package?: BookingPackage;
|
|
38
|
-
agents?: BookingTravelAgent[];
|
|
39
|
-
isBusy: boolean;
|
|
40
|
-
skipPaymentWithAgent: boolean;
|
|
41
|
-
generatePaymentUrl: boolean;
|
|
42
|
-
isUnavailable?: boolean;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (isNil(
|
|
93
|
-
throw Error("
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (
|
|
97
|
-
throw Error("
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
},
|
|
184
|
-
|
|
185
|
-
const option = getActiveOption(state);
|
|
186
|
-
if (option) option.
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
const option = getActiveOption(state);
|
|
190
|
-
if (option) option.
|
|
191
|
-
},
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
action
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
1
|
+
import { BookingAttributes, ProductAttributes } from "../../types";
|
|
2
|
+
import { PayloadAction, createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
|
3
|
+
|
|
4
|
+
import { RootState } from "../../store";
|
|
5
|
+
import { isNil, range } from "lodash";
|
|
6
|
+
import {
|
|
7
|
+
selectBookingAttributes,
|
|
8
|
+
selectBookingRooms,
|
|
9
|
+
selectOfficeId,
|
|
10
|
+
selectProductAttributes,
|
|
11
|
+
} from "./selectors";
|
|
12
|
+
import {
|
|
13
|
+
BookingOptionGroup,
|
|
14
|
+
BookingOptionPax,
|
|
15
|
+
BookingOptionUnit,
|
|
16
|
+
BookingPackage,
|
|
17
|
+
BookingPackageDetailsRequest,
|
|
18
|
+
BookingPackagePax,
|
|
19
|
+
BookingPackageRequest,
|
|
20
|
+
BookingPackageRequestRoom,
|
|
21
|
+
BookingPackageRoom,
|
|
22
|
+
BookingTravelAgent,
|
|
23
|
+
PerBookingPackageOption,
|
|
24
|
+
} from "@qite/tide-client/build/types";
|
|
25
|
+
import packageApi from "./api";
|
|
26
|
+
import { selectAgentId } from "../travelers-form/travelers-form-slice";
|
|
27
|
+
|
|
28
|
+
export interface BookingState {
|
|
29
|
+
officeId: number;
|
|
30
|
+
entryStatus: number;
|
|
31
|
+
customEntryStatusId?: number;
|
|
32
|
+
productAttributes?: ProductAttributes;
|
|
33
|
+
bookingAttributes?: BookingAttributes;
|
|
34
|
+
calculateDeposit: boolean;
|
|
35
|
+
bookingNumber?: string;
|
|
36
|
+
isRetry: boolean;
|
|
37
|
+
package?: BookingPackage;
|
|
38
|
+
agents?: BookingTravelAgent[];
|
|
39
|
+
isBusy: boolean;
|
|
40
|
+
skipPaymentWithAgent: boolean;
|
|
41
|
+
generatePaymentUrl: boolean;
|
|
42
|
+
isUnavailable?: boolean;
|
|
43
|
+
tagIds?: number[];
|
|
44
|
+
agentAdressId?: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const initialState: BookingState = {
|
|
48
|
+
officeId: 1,
|
|
49
|
+
entryStatus: 0,
|
|
50
|
+
customEntryStatusId: undefined,
|
|
51
|
+
productAttributes: undefined,
|
|
52
|
+
bookingAttributes: undefined,
|
|
53
|
+
calculateDeposit: false,
|
|
54
|
+
bookingNumber: undefined,
|
|
55
|
+
isRetry: false,
|
|
56
|
+
package: undefined,
|
|
57
|
+
isBusy: false,
|
|
58
|
+
skipPaymentWithAgent: false,
|
|
59
|
+
generatePaymentUrl: false,
|
|
60
|
+
tagIds: [],
|
|
61
|
+
agentAdressId: undefined,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const fetchPackage = createAsyncThunk(
|
|
65
|
+
"booking/fetchPackage",
|
|
66
|
+
async (_, { dispatch }) => {
|
|
67
|
+
dispatch(setFetchingPackage(true));
|
|
68
|
+
await dispatch(fetchAgents());
|
|
69
|
+
await dispatch(fetchPackageDetails());
|
|
70
|
+
dispatch(setFetchingPackage(false));
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const fetchAgents = createAsyncThunk(
|
|
75
|
+
"booking/agents",
|
|
76
|
+
async (_, { dispatch, getState, signal }) => {
|
|
77
|
+
return await packageApi.fetchAgents(signal);
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const fetchPackageDetails = createAsyncThunk(
|
|
82
|
+
"booking/details",
|
|
83
|
+
async (_, { dispatch, getState, signal }) => {
|
|
84
|
+
const state = getState() as RootState;
|
|
85
|
+
|
|
86
|
+
const officeId = selectOfficeId(state);
|
|
87
|
+
const productAttributes = selectProductAttributes(state);
|
|
88
|
+
const bookingAttributes = selectBookingAttributes(state);
|
|
89
|
+
const agentId = selectAgentId(state);
|
|
90
|
+
const rooms = selectBookingRooms(state);
|
|
91
|
+
|
|
92
|
+
if (isNil(productAttributes)) {
|
|
93
|
+
throw Error("productAttributes could not be found");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (isNil(bookingAttributes)) {
|
|
97
|
+
throw Error("bookingAttributes could not be found");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!rooms?.length) {
|
|
101
|
+
throw Error("rooms could not be found");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
var requestRooms = rooms?.map((x, i) => {
|
|
105
|
+
var room = { index: i, pax: [] } as BookingPackageRequestRoom;
|
|
106
|
+
range(0, x.adults).forEach(() => {
|
|
107
|
+
room.pax.push({
|
|
108
|
+
age: 30,
|
|
109
|
+
} as BookingPackagePax);
|
|
110
|
+
});
|
|
111
|
+
x.childAges.forEach((x) => {
|
|
112
|
+
room.pax.push({
|
|
113
|
+
age: x,
|
|
114
|
+
} as BookingPackagePax);
|
|
115
|
+
});
|
|
116
|
+
return room;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const isAllotment =
|
|
120
|
+
bookingAttributes.tourCode ||
|
|
121
|
+
bookingAttributes.allotmentName ||
|
|
122
|
+
(bookingAttributes.allotmentIds && bookingAttributes.allotmentIds.length);
|
|
123
|
+
|
|
124
|
+
const request = {
|
|
125
|
+
officeId: officeId,
|
|
126
|
+
agentId: agentId,
|
|
127
|
+
payload: {
|
|
128
|
+
searchType: isAllotment ? 1 : 0,
|
|
129
|
+
catalogueId: bookingAttributes.catalog,
|
|
130
|
+
productCode: productAttributes.productCode,
|
|
131
|
+
fromDate: bookingAttributes.startDate,
|
|
132
|
+
toDate: bookingAttributes.endDate,
|
|
133
|
+
includeFlights: bookingAttributes.includeFlights,
|
|
134
|
+
allotmentName: bookingAttributes.allotmentName,
|
|
135
|
+
allotmentIds: bookingAttributes.allotmentIds ?? [],
|
|
136
|
+
tourCode: bookingAttributes.tourCode,
|
|
137
|
+
rooms: requestRooms,
|
|
138
|
+
} as BookingPackageDetailsRequest,
|
|
139
|
+
} as BookingPackageRequest<BookingPackageDetailsRequest>;
|
|
140
|
+
|
|
141
|
+
return await packageApi.fetchDetails(request, signal);
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const getActiveOption = (state: BookingState) => {
|
|
146
|
+
if (state.package) return state.package.options.find((x) => x.isSelected);
|
|
147
|
+
return null;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const bookingSlice = createSlice({
|
|
151
|
+
name: "booking",
|
|
152
|
+
initialState,
|
|
153
|
+
reducers: {
|
|
154
|
+
setOfficeId(state, action: PayloadAction<number>) {
|
|
155
|
+
state.officeId = action.payload;
|
|
156
|
+
},
|
|
157
|
+
setEntryStatus(state, action: PayloadAction<number>) {
|
|
158
|
+
state.entryStatus = action.payload;
|
|
159
|
+
},
|
|
160
|
+
setCustomEntryStatusId(state, action: PayloadAction<number | undefined>) {
|
|
161
|
+
state.customEntryStatusId = action.payload;
|
|
162
|
+
},
|
|
163
|
+
setProductAttributes(state, action: PayloadAction<ProductAttributes>) {
|
|
164
|
+
state.productAttributes = action.payload;
|
|
165
|
+
},
|
|
166
|
+
setBookingAttributes(state, action: PayloadAction<BookingAttributes>) {
|
|
167
|
+
state.bookingAttributes = action.payload;
|
|
168
|
+
},
|
|
169
|
+
setCalculateDeposit(state, action: PayloadAction<boolean>) {
|
|
170
|
+
state.calculateDeposit = action.payload;
|
|
171
|
+
},
|
|
172
|
+
setBookingNumber(state, action: PayloadAction<string>) {
|
|
173
|
+
state.bookingNumber = action.payload;
|
|
174
|
+
},
|
|
175
|
+
setIsRetry(state, action: PayloadAction<boolean>) {
|
|
176
|
+
state.isRetry = action.payload;
|
|
177
|
+
},
|
|
178
|
+
setFetchingPackage(state, action: PayloadAction<boolean>) {
|
|
179
|
+
state.isBusy = action.payload;
|
|
180
|
+
},
|
|
181
|
+
setPackage(state, action: PayloadAction<BookingPackage>) {
|
|
182
|
+
state.package = action.payload;
|
|
183
|
+
},
|
|
184
|
+
setPackageRooms(state, action: PayloadAction<BookingPackageRoom[]>) {
|
|
185
|
+
const option = getActiveOption(state);
|
|
186
|
+
if (option) option.rooms = action.payload;
|
|
187
|
+
},
|
|
188
|
+
setPackageOptionPax(state, action: PayloadAction<BookingOptionPax[]>) {
|
|
189
|
+
const option = getActiveOption(state);
|
|
190
|
+
if (option) option.optionPax = action.payload;
|
|
191
|
+
},
|
|
192
|
+
setPackageOptionUnits(state, action: PayloadAction<BookingOptionUnit[]>) {
|
|
193
|
+
const option = getActiveOption(state);
|
|
194
|
+
if (option) option.optionUnits = action.payload;
|
|
195
|
+
},
|
|
196
|
+
setSkipPayment(state, action: PayloadAction<boolean>) {
|
|
197
|
+
state.skipPaymentWithAgent = action.payload;
|
|
198
|
+
},
|
|
199
|
+
setGeneratePaymentUrl(state, action: PayloadAction<boolean>) {
|
|
200
|
+
state.generatePaymentUrl = action.payload;
|
|
201
|
+
},
|
|
202
|
+
setPackageGroups(
|
|
203
|
+
state,
|
|
204
|
+
action: PayloadAction<BookingOptionGroup<PerBookingPackageOption>[]>
|
|
205
|
+
) {
|
|
206
|
+
const option = getActiveOption(state);
|
|
207
|
+
if (option) option.groups = action.payload;
|
|
208
|
+
},
|
|
209
|
+
setTagIds(state, action: PayloadAction<number[] | undefined>) {
|
|
210
|
+
state.tagIds = action.payload;
|
|
211
|
+
},
|
|
212
|
+
setAgentAdressId(state, action: PayloadAction<number | undefined>) {
|
|
213
|
+
state.agentAdressId = action.payload;
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
extraReducers: (builder) => {
|
|
217
|
+
builder.addCase(fetchPackageDetails.fulfilled, (state, action) => {
|
|
218
|
+
if (action.payload) {
|
|
219
|
+
if (action.payload.errorCode) {
|
|
220
|
+
console.error(
|
|
221
|
+
action.payload.errorCode,
|
|
222
|
+
action.payload.errorMessage,
|
|
223
|
+
action.payload.errorDetails
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
state.isUnavailable = true;
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (!action.payload.payload) {
|
|
231
|
+
state.isUnavailable = true;
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const bookingRooms = state.bookingAttributes?.rooms;
|
|
236
|
+
const packageDetails = action.payload.payload;
|
|
237
|
+
const activeOption = packageDetails.options.find((x) => x.isSelected);
|
|
238
|
+
|
|
239
|
+
if (
|
|
240
|
+
activeOption &&
|
|
241
|
+
bookingRooms?.some((x) => x.accommodationCode || x.regimeCode)
|
|
242
|
+
) {
|
|
243
|
+
bookingRooms.forEach((room, i) => {
|
|
244
|
+
if (room.accommodationCode || room.regimeCode) {
|
|
245
|
+
activeOption.rooms[i].options = activeOption.rooms[i].options.map(
|
|
246
|
+
(ro) => ({
|
|
247
|
+
...ro,
|
|
248
|
+
isSelected:
|
|
249
|
+
ro.accommodationCode == room.accommodationCode &&
|
|
250
|
+
ro.regimeCode == room.regimeCode,
|
|
251
|
+
})
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
state.package = packageDetails;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
builder.addCase(fetchAgents.fulfilled, (state, action) => {
|
|
261
|
+
if (action.payload) {
|
|
262
|
+
state.agents = action.payload;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
export const {
|
|
269
|
+
setOfficeId,
|
|
270
|
+
setEntryStatus,
|
|
271
|
+
setCustomEntryStatusId,
|
|
272
|
+
setProductAttributes,
|
|
273
|
+
setBookingAttributes,
|
|
274
|
+
setCalculateDeposit,
|
|
275
|
+
setBookingNumber,
|
|
276
|
+
setIsRetry,
|
|
277
|
+
setFetchingPackage,
|
|
278
|
+
setPackage,
|
|
279
|
+
setPackageRooms,
|
|
280
|
+
setPackageOptionPax,
|
|
281
|
+
setPackageOptionUnits,
|
|
282
|
+
setPackageGroups,
|
|
283
|
+
setSkipPayment,
|
|
284
|
+
setGeneratePaymentUrl,
|
|
285
|
+
setTagIds,
|
|
286
|
+
setAgentAdressId,
|
|
287
|
+
} = bookingSlice.actions;
|
|
288
|
+
|
|
289
|
+
export default bookingSlice.reducer;
|