@mseva/upyog-ui-module-ads 1.0.96 → 1.0.97

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.
@@ -238,13 +238,6 @@ const transformBookingResponseToBookingData = (apiResponse = {}) => {
238
238
  bookingData
239
239
  };
240
240
  };
241
- const areSlotsEqual = (a = [], b = []) => {
242
- if ((a === null || a === void 0 ? void 0 : a.length) !== (b === null || b === void 0 ? void 0 : b.length)) return false;
243
- const key = s => s === null || s === void 0 ? void 0 : s.bookingDate;
244
- const aKeys = a === null || a === void 0 ? void 0 : a.map(key).sort();
245
- const bKeys = b === null || b === void 0 ? void 0 : b.map(key).sort();
246
- return (JSON === null || JSON === void 0 ? void 0 : JSON.stringify(aKeys)) === (JSON === null || JSON === void 0 ? void 0 : JSON.stringify(bKeys));
247
- };
248
241
  function transformAdsData(adsData) {
249
242
  var _Object$values;
250
243
  const grouped = {};
@@ -24105,8 +24098,7 @@ const AvailabilityModal = ({
24105
24098
  onSelectSlot,
24106
24099
  dateRange,
24107
24100
  t,
24108
- cartSlots,
24109
- onRemoveSlot
24101
+ cartSlots
24110
24102
  }) => {
24111
24103
  var _cartSlots$find;
24112
24104
  const [selectedSlots, setSelectedSlots] = useState([]);
@@ -24160,32 +24152,20 @@ const AvailabilityModal = ({
24160
24152
  addType: ad === null || ad === void 0 ? void 0 : ad.adType,
24161
24153
  amount: ad === null || ad === void 0 ? void 0 : ad.amount,
24162
24154
  bookingDate: dateRange === null || dateRange === void 0 ? void 0 : dateRange.startDate,
24163
- nightLight: (ad === null || ad === void 0 ? void 0 : ad.light) === "With Light",
24155
+ nightLight: (ad === null || ad === void 0 ? void 0 : ad.light) === "With Light" ? true : false,
24164
24156
  bookingStartDate: dateRange === null || dateRange === void 0 ? void 0 : dateRange.startDate,
24165
24157
  bookingEndDate: dateRange === null || dateRange === void 0 ? void 0 : dateRange.endDate
24166
24158
  });
24167
- } else if ((existingForAd === null || existingForAd === void 0 ? void 0 : existingForAd.length) > 0) {
24168
- onRemoveSlot(ad);
24159
+ setSelectedSlots([]);
24160
+ setSelectAll(false);
24161
+ onClose();
24169
24162
  }
24170
- setSelectedSlots([]);
24171
- setSelectAll(false);
24172
- onClose();
24173
24163
  };
24174
24164
  useEffect(() => {
24175
24165
  if (allInCart) {
24176
24166
  setSelectAll(true);
24177
24167
  }
24178
24168
  }, [allInCart]);
24179
- const hasChanges = !areSlotsEqual(selectedSlots, existingForAd);
24180
- useEffect(() => {
24181
- if ((existingForAd === null || existingForAd === void 0 ? void 0 : existingForAd.length) > 0) {
24182
- setSelectAll(true);
24183
- setSelectedSlots(existingForAd);
24184
- } else {
24185
- setSelectAll(false);
24186
- setSelectedSlots([]);
24187
- }
24188
- }, [ad === null || ad === void 0 ? void 0 : ad.id]);
24189
24169
  const columns = [{
24190
24170
  Header: () => /*#__PURE__*/React.createElement("input", {
24191
24171
  type: "checkbox",
@@ -24204,7 +24184,7 @@ const AvailabilityModal = ({
24204
24184
  row
24205
24185
  }) => {
24206
24186
  const slot = row === null || row === void 0 ? void 0 : row.original;
24207
- const isChecked = selectAll && (slot === null || slot === void 0 ? void 0 : slot.slotStaus) === "AVAILABLE";
24187
+ const isChecked = allInCart || selectAll && (slot === null || slot === void 0 ? void 0 : slot.slotStaus) === "AVAILABLE";
24208
24188
  return /*#__PURE__*/React.createElement("input", {
24209
24189
  type: "checkbox",
24210
24190
  checked: isChecked,
@@ -24370,18 +24350,17 @@ const AvailabilityModal = ({
24370
24350
  }
24371
24351
  }, t ? t("Cancel") : "Cancel"), /*#__PURE__*/React.createElement("button", {
24372
24352
  onClick: handleAddToCart,
24373
- disabled: !hasChanges,
24374
24353
  style: {
24375
24354
  padding: "10px 18px",
24376
24355
  borderRadius: "6px",
24377
24356
  border: "none",
24378
- background: hasChanges ? "#2947a3" : "#ccc",
24357
+ background: (selectedSlots === null || selectedSlots === void 0 ? void 0 : selectedSlots.length) > 0 ? "#2947a3" : "#ccc",
24379
24358
  color: "#fff",
24380
24359
  fontWeight: 600,
24381
- cursor: hasChanges ? "pointer" : "not-allowed",
24360
+ cursor: (selectedSlots === null || selectedSlots === void 0 ? void 0 : selectedSlots.length) > 0 ? "pointer" : "not-allowed",
24382
24361
  transition: "background 0.2s"
24383
24362
  }
24384
- }, "\uD83D\uDED2 ", (existingForAd === null || existingForAd === void 0 ? void 0 : existingForAd.length) > 0 ? t("COMMON_REMOVE_LABEL") : t("ADS_ADD_TO_CART")))));
24363
+ }, "\uD83D\uDED2 ", (existingForAd === null || existingForAd === void 0 ? void 0 : existingForAd.length) > 0 ? t("ADS_UPDATE_CART") : t("ADS_ADD_TO_CART")))));
24385
24364
  };
24386
24365
 
24387
24366
  const CartModal = ({
@@ -24867,6 +24846,20 @@ const ADSCitizenSecond = ({
24867
24846
  });
24868
24847
  }
24869
24848
  };
24849
+ const areCartSlotsEqual = (a = [], b = []) => {
24850
+ if (a.length !== b.length) return false;
24851
+ const sortByAd = arr => [...arr].sort((x, y) => String(x.ad.id).localeCompare(String(y.ad.id)));
24852
+ const sortedA = sortByAd(a);
24853
+ const sortedB = sortByAd(b);
24854
+ return sortedA.every((item, idx) => {
24855
+ const other = sortedB[idx];
24856
+ if (String(item.ad.id) !== String(other.ad.id)) return false;
24857
+ const slotsA = item.slots.map(s => s.bookingDate).sort();
24858
+ const slotsB = other.slots.map(s => s.bookingDate).sort();
24859
+ if (slotsA.length !== slotsB.length) return false;
24860
+ return slotsA.every((date, i) => date === slotsB[i]);
24861
+ });
24862
+ };
24870
24863
  const onSubmit = async data => {
24871
24864
  var _currentStepData$ads;
24872
24865
  if ((cartSlots === null || cartSlots === void 0 ? void 0 : cartSlots.length) === 0) {
@@ -25167,8 +25160,7 @@ const ADSCitizenSecond = ({
25167
25160
  onSelectSlot: handleAddToCart,
25168
25161
  cartSlots: cartSlots,
25169
25162
  t: t,
25170
- dateRange: dateRange,
25171
- onRemoveSlot: handleRemoveFromCart
25163
+ dateRange: dateRange
25172
25164
  }), showCart && /*#__PURE__*/React.createElement(CartModal, {
25173
25165
  cartSlots: cartSlots,
25174
25166
  onClose: () => setShowCart(false),