mautourco-components 0.2.171 → 0.2.173
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/dist/components/molecules/BookingPax/BookingPaxClient/BookingPaxClient.js +19 -3
- package/dist/components/organisms/Booking/BookingPaxList.js +8 -3
- package/package.json +1 -1
- package/src/components/molecules/BookingPax/BookingPaxClient/BookingPaxClient.tsx +19 -3
- package/src/components/organisms/Booking/BookingPaxList.tsx +9 -3
|
@@ -23,7 +23,7 @@ import Checkbox from '../../../atoms/Checkbox/Checkbox';
|
|
|
23
23
|
import { Text } from '../../../atoms/Typography/Typography';
|
|
24
24
|
import useBookingPax from '../../../../hooks/useBookingPax';
|
|
25
25
|
import { cn } from '../../../../lib/utils';
|
|
26
|
-
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
26
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
27
27
|
import './BookingPaxClient.css';
|
|
28
28
|
/**
|
|
29
29
|
* BookingPaxClient is a component that allows the user to select the pax for a booking.
|
|
@@ -99,9 +99,25 @@ export function BookingPaxClient(props) {
|
|
|
99
99
|
setSelectedClientsInfoIds(defaultSelectedClientsInfoIds);
|
|
100
100
|
}
|
|
101
101
|
}, [defaultSelectedClientsInfoIds]);
|
|
102
|
+
var prevErrorRef = useRef(undefined);
|
|
102
103
|
useEffect(function () {
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
var _a;
|
|
105
|
+
var selectedError = clients.length === paxCount;
|
|
106
|
+
if (selectedError) {
|
|
107
|
+
if (prevErrorRef.current !== selectedError) {
|
|
108
|
+
prevErrorRef.current = selectedError;
|
|
109
|
+
onError === null || onError === void 0 ? void 0 : onError(false);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
var hasError_1 = ((_a = selectedClientsInfoIds[selectedIndex]) === null || _a === void 0 ? void 0 : _a.length) !== paxCount ||
|
|
114
|
+
clients.length === paxCount;
|
|
115
|
+
if (prevErrorRef.current !== hasError_1) {
|
|
116
|
+
prevErrorRef.current = hasError_1;
|
|
117
|
+
onError === null || onError === void 0 ? void 0 : onError(hasError_1);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}, [selectedClientsInfoIds, selectedIndex, paxCount, onError]);
|
|
105
121
|
return (_jsxs("div", { className: "booking_spacing-y-2", children: [_jsxs(Text, { children: ["Please confirm the pax which applies on this service (", paxCount, " Pax)", ' ', _jsx(Text, { color: "state-error", as: "span", children: "*" })] }), _jsx("div", { className: cn('booking-pax-client', {
|
|
106
122
|
'booking-pax-accom--error': hasError,
|
|
107
123
|
}), children: clients.map(function (client) {
|
|
@@ -19,7 +19,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
19
19
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
20
|
};
|
|
21
21
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
|
-
import
|
|
22
|
+
import isEqual from 'lodash/isEqual';
|
|
23
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
23
24
|
import { BookingPax, } from '../../molecules/BookingPax';
|
|
24
25
|
// Type guards for better type safety
|
|
25
26
|
var isAccommodationData = function (data) {
|
|
@@ -53,6 +54,7 @@ var isTransferData = function (data) {
|
|
|
53
54
|
export function BookingPaxList(props) {
|
|
54
55
|
var data = props.data, isSubmitted = props.isSubmitted, clientsInfo = props.clientsInfo, onPaxChange = props.onPaxChange, onRemarkChange = props.onRemarkChange, onError = props.onError, onTimeChange = props.onTimeChange, onFlightNumberChange = props.onFlightNumberChange, onAutoFilled = props.onAutoFilled, onChange = props.onChange;
|
|
55
56
|
var _a = useState([]), autoFilledData = _a[0], setAutoFilledData = _a[1];
|
|
57
|
+
var autoFilledDataRef = useRef([]);
|
|
56
58
|
// Memoized callback handlers to reduce re-renders
|
|
57
59
|
var handlePaxChange = useCallback(function (type, index, options) {
|
|
58
60
|
onPaxChange === null || onPaxChange === void 0 ? void 0 : onPaxChange(index, type, options);
|
|
@@ -116,8 +118,11 @@ export function BookingPaxList(props) {
|
|
|
116
118
|
});
|
|
117
119
|
}, [data, handleAutoFilled]);
|
|
118
120
|
useEffect(function () {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
+
if (!isEqual(autoFilledData, autoFilledDataRef.current)) {
|
|
122
|
+
autoFilledDataRef.current = autoFilledData;
|
|
123
|
+
onAutoFilled === null || onAutoFilled === void 0 ? void 0 : onAutoFilled(autoFilledData);
|
|
124
|
+
}
|
|
125
|
+
}, [autoFilledData]);
|
|
121
126
|
return (_jsx(BookingPax, { children: data.map(function (item, index) {
|
|
122
127
|
var type = item.type, itemData = item.data;
|
|
123
128
|
var callbacks = {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import Checkbox, { CheckboxProps } from '@/src/components/atoms/Checkbox/Checkbo
|
|
|
2
2
|
import { Text } from '@/src/components/atoms/Typography/Typography';
|
|
3
3
|
import useBookingPax from '@/src/hooks/useBookingPax';
|
|
4
4
|
import { cn } from '@/src/lib/utils';
|
|
5
|
-
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
5
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
6
6
|
import './BookingPaxClient.css';
|
|
7
7
|
|
|
8
8
|
export interface BookingPaxClientInfo {
|
|
@@ -214,9 +214,25 @@ export function BookingPaxClient(props: BookingPaxClientProps) {
|
|
|
214
214
|
}
|
|
215
215
|
}, [defaultSelectedClientsInfoIds]);
|
|
216
216
|
|
|
217
|
+
const prevErrorRef = useRef<boolean | undefined>(undefined);
|
|
218
|
+
|
|
217
219
|
useEffect(() => {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
+
const selectedError = clients.length === paxCount;
|
|
221
|
+
if (selectedError) {
|
|
222
|
+
if (prevErrorRef.current !== selectedError) {
|
|
223
|
+
prevErrorRef.current = selectedError;
|
|
224
|
+
onError?.(false);
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
const hasError =
|
|
228
|
+
selectedClientsInfoIds[selectedIndex]?.length !== paxCount ||
|
|
229
|
+
clients.length === paxCount;
|
|
230
|
+
if (prevErrorRef.current !== hasError) {
|
|
231
|
+
prevErrorRef.current = hasError;
|
|
232
|
+
onError?.(hasError);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}, [selectedClientsInfoIds, selectedIndex, paxCount, onError]);
|
|
220
236
|
|
|
221
237
|
return (
|
|
222
238
|
<div className="booking_spacing-y-2">
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import isEqual from 'lodash/isEqual';
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
3
|
import {
|
|
3
4
|
BookingPax,
|
|
4
5
|
BookingPaxAccomProps,
|
|
@@ -168,6 +169,8 @@ export function BookingPaxList(props: BookingPaxProps) {
|
|
|
168
169
|
}[]
|
|
169
170
|
>([]);
|
|
170
171
|
|
|
172
|
+
const autoFilledDataRef = useRef<BookingPaxAutoFilledData[]>([]);
|
|
173
|
+
|
|
171
174
|
// Memoized callback handlers to reduce re-renders
|
|
172
175
|
const handlePaxChange = useCallback(
|
|
173
176
|
(type: BookingPaxData['type'], index: number, options: BookingPaxClientOptions) => {
|
|
@@ -252,8 +255,11 @@ export function BookingPaxList(props: BookingPaxProps) {
|
|
|
252
255
|
}, [data, handleAutoFilled]);
|
|
253
256
|
|
|
254
257
|
useEffect(() => {
|
|
255
|
-
|
|
256
|
-
|
|
258
|
+
if (!isEqual(autoFilledData, autoFilledDataRef.current)) {
|
|
259
|
+
autoFilledDataRef.current = autoFilledData;
|
|
260
|
+
onAutoFilled?.(autoFilledData);
|
|
261
|
+
}
|
|
262
|
+
}, [autoFilledData]);
|
|
257
263
|
|
|
258
264
|
return (
|
|
259
265
|
<BookingPax>
|