mautourco-components 0.2.70 → 0.2.71

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.
@@ -64,14 +64,58 @@ var SearchBarTransfer = function (_a) {
64
64
  { value: "roundtrip", label: "Round trip" },
65
65
  { value: "custom", label: "Custom transfer" },
66
66
  ];
67
+ // Helper function to check if roundtrip data is empty or has data
68
+ var hasRoundtripData = function (data) {
69
+ if (!data)
70
+ return false;
71
+ // Check if at least one field has data (half or full data)
72
+ return !!(data.paxData ||
73
+ data.arrivalDate ||
74
+ data.departureDate ||
75
+ data.pickupDropoffPoint ||
76
+ data.accommodation);
77
+ };
78
+ // Helper function to create prefilled transfer lines from roundtrip data
79
+ var createPrefilledTransferLines = function (data) {
80
+ var lines = [];
81
+ // Create arrival transfer
82
+ var arrivalTransfer = {
83
+ id: generateTransferId(),
84
+ type: "arrival",
85
+ paxData: data.paxData,
86
+ transferDate: data.arrivalDate,
87
+ pickupPoint: data.pickupDropoffPoint,
88
+ dropoffPoint: data.accommodation,
89
+ };
90
+ lines.push(arrivalTransfer);
91
+ // Create departure transfer
92
+ var departureTransfer = {
93
+ id: generateTransferId(),
94
+ type: "departure",
95
+ paxData: data.paxData,
96
+ transferDate: data.departureDate,
97
+ pickupPoint: data.accommodation,
98
+ dropoffPoint: data.pickupDropoffPoint,
99
+ };
100
+ lines.push(departureTransfer);
101
+ return lines;
102
+ };
67
103
  // Handle mode change
68
104
  var handleModeChange = function (newMode) {
69
105
  var transferMode = newMode;
70
106
  if (transferMode === mode)
71
107
  return;
72
108
  if (transferMode === "custom" && mode === "roundtrip") {
73
- // When switching to custom mode, reset transfer lines (will show placeholder)
74
- setTransferLines([]);
109
+ // When switching from roundtrip to custom mode
110
+ if (hasRoundtripData(roundTripData)) {
111
+ // Half/full Roundtrip data → prefilled arrival and departure (2h)
112
+ var prefilledLines = createPrefilledTransferLines(roundTripData);
113
+ setTransferLines(prefilledLines);
114
+ }
115
+ else {
116
+ // Empty Roundtrip data → empty custom transfer (1h)
117
+ setTransferLines([]);
118
+ }
75
119
  setRoundTripData(undefined);
76
120
  }
77
121
  else if (transferMode === "roundtrip" && mode === "custom") {
@@ -88,19 +132,72 @@ var SearchBarTransfer = function (_a) {
88
132
  id: generateTransferId(),
89
133
  type: type,
90
134
  };
135
+ if (transferLines.length > 0) {
136
+ // If adding inter-hotel, set pickup point to the dropoff of latest arrival
137
+ if (type === "inter-hotel") {
138
+ var arrivalTransfers = transferLines.filter(function (line) { return line.type === "arrival"; });
139
+ if (arrivalTransfers.length > 0) {
140
+ var latestArrival = arrivalTransfers[arrivalTransfers.length - 1];
141
+ newTransfer.pickupPoint = latestArrival.dropoffPoint;
142
+ }
143
+ }
144
+ // If adding departure, set pickup point to the dropoff of latest arrival or inter-hotel
145
+ if (type === "departure") {
146
+ var arrivalAndInterHotelTransfers = transferLines.filter(function (line) { return line.type === "arrival" || line.type === "inter-hotel"; });
147
+ if (arrivalAndInterHotelTransfers.length > 0) {
148
+ var latestTransfer = arrivalAndInterHotelTransfers[arrivalAndInterHotelTransfers.length - 1];
149
+ newTransfer.pickupPoint = latestTransfer.dropoffPoint;
150
+ }
151
+ }
152
+ }
91
153
  setTransferLines(__spreadArray(__spreadArray([], transferLines, true), [newTransfer], false));
92
154
  };
93
155
  // Render transfer type buttons
94
156
  var renderTransferTypeButtons = function (onClick) { return (_jsxs("div", { className: "search-bar-transfer__add-buttons", children: [_jsx(Button, { variant: "outline-secondary", size: "sm", leadingIcon: "plus", onClick: function () { return onClick("arrival"); }, children: "Add Arrival" }), _jsx(Button, { variant: "outline-secondary", size: "sm", leadingIcon: "plus", onClick: function () { return onClick("departure"); }, children: "Add Departure" }), _jsx(Button, { variant: "outline-secondary", size: "sm", leadingIcon: "plus", onClick: function () { return onClick("inter-hotel"); }, children: "Add Inter-Hotel" })] })); };
95
157
  // Handle adding transfer from round-trip mode (switches to custom and adds new transfer)
96
158
  var handleAddTransferFromRoundTrip = function (type) {
97
- // Add the new transfer of the clicked type
98
- var newTransfer = {
99
- id: generateTransferId(),
100
- type: type,
101
- };
102
- // Set the transfer and switch to custom mode
103
- setTransferLines([newTransfer]);
159
+ var newTransferLines = [];
160
+ if (hasRoundtripData(roundTripData)) {
161
+ // Half/full Roundtrip data → prefilled arrival & departure + Adding the appropriate transfer type (2h)
162
+ var prefilledLines = createPrefilledTransferLines(roundTripData);
163
+ // Add the new transfer of the clicked type with prefilled data
164
+ var newTransfer = {
165
+ id: generateTransferId(),
166
+ type: type,
167
+ paxData: roundTripData.paxData,
168
+ // Use the appropriate date based on transfer type
169
+ transferDate: type === "arrival"
170
+ ? roundTripData.arrivalDate
171
+ : type === "departure"
172
+ ? roundTripData.departureDate
173
+ : undefined,
174
+ // Use appropriate pickup/dropoff points based on transfer type
175
+ pickupPoint: type === "arrival"
176
+ ? roundTripData.pickupDropoffPoint
177
+ : type === "departure"
178
+ ? roundTripData.accommodation
179
+ : type === "inter-hotel"
180
+ ? roundTripData.accommodation // Inter-hotel pickup = arrival's dropoff (accommodation)
181
+ : undefined,
182
+ dropoffPoint: type === "arrival"
183
+ ? roundTripData.accommodation
184
+ : type === "departure"
185
+ ? roundTripData.pickupDropoffPoint
186
+ : undefined,
187
+ };
188
+ // Combine prefilled lines with the new transfer
189
+ newTransferLines = __spreadArray(__spreadArray([], prefilledLines, true), [newTransfer], false);
190
+ }
191
+ else {
192
+ // Empty Roundtrip data → Adding the appropriate transfer type (1h)
193
+ var newTransfer = {
194
+ id: generateTransferId(),
195
+ type: type,
196
+ };
197
+ newTransferLines = [newTransfer];
198
+ }
199
+ // Set the transfers and switch to custom mode
200
+ setTransferLines(newTransferLines);
104
201
  setRoundTripData(undefined);
105
202
  setMode("custom");
106
203
  setError(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mautourco-components",
3
- "version": "0.2.70",
3
+ "version": "0.2.71",
4
4
  "private": false,
5
5
  "description": "Bibliothèque de composants Mautourco pour le redesign",
6
6
  "main": "dist/index.js",
@@ -102,14 +102,63 @@ const SearchBarTransfer: React.FC<SearchBarTransferProps> = ({
102
102
  { value: "custom", label: "Custom transfer" },
103
103
  ];
104
104
 
105
+ // Helper function to check if roundtrip data is empty or has data
106
+ const hasRoundtripData = (data?: RoundTripData): boolean => {
107
+ if (!data) return false;
108
+ // Check if at least one field has data (half or full data)
109
+ return !!(
110
+ data.paxData ||
111
+ data.arrivalDate ||
112
+ data.departureDate ||
113
+ data.pickupDropoffPoint ||
114
+ data.accommodation
115
+ );
116
+ };
117
+
118
+ // Helper function to create prefilled transfer lines from roundtrip data
119
+ const createPrefilledTransferLines = (data: RoundTripData): TransferLineData[] => {
120
+ const lines: TransferLineData[] = [];
121
+
122
+ // Create arrival transfer
123
+ const arrivalTransfer: TransferLineData = {
124
+ id: generateTransferId(),
125
+ type: "arrival",
126
+ paxData: data.paxData,
127
+ transferDate: data.arrivalDate,
128
+ pickupPoint: data.pickupDropoffPoint,
129
+ dropoffPoint: data.accommodation,
130
+ };
131
+ lines.push(arrivalTransfer);
132
+
133
+ // Create departure transfer
134
+ const departureTransfer: TransferLineData = {
135
+ id: generateTransferId(),
136
+ type: "departure",
137
+ paxData: data.paxData,
138
+ transferDate: data.departureDate,
139
+ pickupPoint: data.accommodation,
140
+ dropoffPoint: data.pickupDropoffPoint,
141
+ };
142
+ lines.push(departureTransfer);
143
+
144
+ return lines;
145
+ };
146
+
105
147
  // Handle mode change
106
148
  const handleModeChange = (newMode: string) => {
107
149
  const transferMode = newMode as TransferMode;
108
150
  if (transferMode === mode) return;
109
151
 
110
152
  if (transferMode === "custom" && mode === "roundtrip") {
111
- // When switching to custom mode, reset transfer lines (will show placeholder)
112
- setTransferLines([]);
153
+ // When switching from roundtrip to custom mode
154
+ if (hasRoundtripData(roundTripData)) {
155
+ // Half/full Roundtrip data → prefilled arrival and departure (2h)
156
+ const prefilledLines = createPrefilledTransferLines(roundTripData!);
157
+ setTransferLines(prefilledLines);
158
+ } else {
159
+ // Empty Roundtrip data → empty custom transfer (1h)
160
+ setTransferLines([]);
161
+ }
113
162
  setRoundTripData(undefined);
114
163
  } else if (transferMode === "roundtrip" && mode === "custom") {
115
164
  // Reset everything when switching to roundtrip
@@ -127,6 +176,29 @@ const SearchBarTransfer: React.FC<SearchBarTransferProps> = ({
127
176
  id: generateTransferId(),
128
177
  type,
129
178
  };
179
+
180
+ if (transferLines.length > 0) {
181
+ // If adding inter-hotel, set pickup point to the dropoff of latest arrival
182
+ if (type === "inter-hotel") {
183
+ const arrivalTransfers = transferLines.filter(line => line.type === "arrival");
184
+ if (arrivalTransfers.length > 0) {
185
+ const latestArrival = arrivalTransfers[arrivalTransfers.length - 1];
186
+ newTransfer.pickupPoint = latestArrival.dropoffPoint;
187
+ }
188
+ }
189
+
190
+ // If adding departure, set pickup point to the dropoff of latest arrival or inter-hotel
191
+ if (type === "departure") {
192
+ const arrivalAndInterHotelTransfers = transferLines.filter(
193
+ line => line.type === "arrival" || line.type === "inter-hotel"
194
+ );
195
+ if (arrivalAndInterHotelTransfers.length > 0) {
196
+ const latestTransfer = arrivalAndInterHotelTransfers[arrivalAndInterHotelTransfers.length - 1];
197
+ newTransfer.pickupPoint = latestTransfer.dropoffPoint;
198
+ }
199
+ }
200
+ }
201
+
130
202
  setTransferLines([...transferLines, newTransfer]);
131
203
  };
132
204
 
@@ -162,14 +234,51 @@ const SearchBarTransfer: React.FC<SearchBarTransferProps> = ({
162
234
 
163
235
  // Handle adding transfer from round-trip mode (switches to custom and adds new transfer)
164
236
  const handleAddTransferFromRoundTrip = (type: TransferType) => {
165
- // Add the new transfer of the clicked type
166
- const newTransfer: TransferLineData = {
167
- id: generateTransferId(),
168
- type,
169
- };
237
+ let newTransferLines: TransferLineData[] = [];
238
+
239
+ if (hasRoundtripData(roundTripData)) {
240
+ // Half/full Roundtrip data → prefilled arrival & departure + Adding the appropriate transfer type (2h)
241
+ const prefilledLines = createPrefilledTransferLines(roundTripData!);
242
+
243
+ // Add the new transfer of the clicked type with prefilled data
244
+ const newTransfer: TransferLineData = {
245
+ id: generateTransferId(),
246
+ type,
247
+ paxData: roundTripData!.paxData,
248
+ // Use the appropriate date based on transfer type
249
+ transferDate: type === "arrival"
250
+ ? roundTripData!.arrivalDate
251
+ : type === "departure"
252
+ ? roundTripData!.departureDate
253
+ : undefined,
254
+ // Use appropriate pickup/dropoff points based on transfer type
255
+ pickupPoint: type === "arrival"
256
+ ? roundTripData!.pickupDropoffPoint
257
+ : type === "departure"
258
+ ? roundTripData!.accommodation
259
+ : type === "inter-hotel"
260
+ ? roundTripData!.accommodation // Inter-hotel pickup = arrival's dropoff (accommodation)
261
+ : undefined,
262
+ dropoffPoint: type === "arrival"
263
+ ? roundTripData!.accommodation
264
+ : type === "departure"
265
+ ? roundTripData!.pickupDropoffPoint
266
+ : undefined,
267
+ };
268
+
269
+ // Combine prefilled lines with the new transfer
270
+ newTransferLines = [...prefilledLines, newTransfer];
271
+ } else {
272
+ // Empty Roundtrip data → Adding the appropriate transfer type (1h)
273
+ const newTransfer: TransferLineData = {
274
+ id: generateTransferId(),
275
+ type,
276
+ };
277
+ newTransferLines = [newTransfer];
278
+ }
170
279
 
171
- // Set the transfer and switch to custom mode
172
- setTransferLines([newTransfer]);
280
+ // Set the transfers and switch to custom mode
281
+ setTransferLines(newTransferLines);
173
282
  setRoundTripData(undefined);
174
283
  setMode("custom");
175
284
  setError(null);