mautourco-components 0.2.171 → 0.2.172

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.
@@ -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,15 @@ export function BookingPaxClient(props) {
99
99
  setSelectedClientsInfoIds(defaultSelectedClientsInfoIds);
100
100
  }
101
101
  }, [defaultSelectedClientsInfoIds]);
102
+ var prevErrorRef = useRef(undefined);
102
103
  useEffect(function () {
103
- onError === null || onError === void 0 ? void 0 : onError(hasError && clients.length !== paxCount);
104
- }, [hasError]);
104
+ var _a;
105
+ var hasError = ((_a = selectedClientsInfoIds[selectedIndex]) === null || _a === void 0 ? void 0 : _a.length) !== paxCount;
106
+ if (prevErrorRef.current !== hasError) {
107
+ prevErrorRef.current = hasError;
108
+ onError === null || onError === void 0 ? void 0 : onError(hasError);
109
+ }
110
+ }, [selectedClientsInfoIds, selectedIndex, paxCount, onError]);
105
111
  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
112
  'booking-pax-accom--error': hasError,
107
113
  }), 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 { useCallback, useEffect, useState } from 'react';
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
- onAutoFilled === null || onAutoFilled === void 0 ? void 0 : onAutoFilled(autoFilledData);
120
- }, [autoFilledData, onAutoFilled]);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mautourco-components",
3
- "version": "0.2.171",
3
+ "version": "0.2.172",
4
4
  "private": false,
5
5
  "description": "Bibliothèque de composants Mautourco pour le redesign",
6
6
  "main": "dist/index.js",
@@ -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,15 @@ export function BookingPaxClient(props: BookingPaxClientProps) {
214
214
  }
215
215
  }, [defaultSelectedClientsInfoIds]);
216
216
 
217
+ const prevErrorRef = useRef<boolean | undefined>(undefined);
218
+
217
219
  useEffect(() => {
218
- onError?.(hasError && clients.length !== paxCount);
219
- }, [hasError]);
220
+ const hasError = selectedClientsInfoIds[selectedIndex]?.length !== paxCount;
221
+ if (prevErrorRef.current !== hasError) {
222
+ prevErrorRef.current = hasError;
223
+ onError?.(hasError);
224
+ }
225
+ }, [selectedClientsInfoIds, selectedIndex, paxCount, onError]);
220
226
 
221
227
  return (
222
228
  <div className="booking_spacing-y-2">
@@ -1,4 +1,5 @@
1
- import { useCallback, useEffect, useState } from 'react';
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
- onAutoFilled?.(autoFilledData);
256
- }, [autoFilledData, onAutoFilled]);
258
+ if (!isEqual(autoFilledData, autoFilledDataRef.current)) {
259
+ autoFilledDataRef.current = autoFilledData;
260
+ onAutoFilled?.(autoFilledData);
261
+ }
262
+ }, [autoFilledData]);
257
263
 
258
264
  return (
259
265
  <BookingPax>