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