@anker-in/ui 0.3.4 → 0.3.5

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/index.mjs CHANGED
@@ -11442,6 +11442,10 @@ var DateTimePicker2 = ({
11442
11442
  );
11443
11443
  const [isInitialized, setIsInitialized] = useState(() => !!booking);
11444
11444
  const [hasResolvedBookingSlot, setHasResolvedBookingSlot] = useState(false);
11445
+ const autoSelectLockRef = useRef(false);
11446
+ useEffect(() => {
11447
+ autoSelectLockRef.current = false;
11448
+ }, [demoRoomCode]);
11445
11449
  const {
11446
11450
  createBooking,
11447
11451
  loading: bookingLoading,
@@ -11453,13 +11457,17 @@ var DateTimePicker2 = ({
11453
11457
  error: editError
11454
11458
  } = useEditBooking(apiClient);
11455
11459
  const isManagedByParent = demoRoomLoading !== void 0;
11456
- const { data: fetchedDemoRoom } = useDemoRoom(
11460
+ const {
11461
+ data: fetchedDemoRoom,
11462
+ loading: fetchedDemoRoomLoading
11463
+ } = useDemoRoom(
11457
11464
  apiClient,
11458
11465
  demoRoomCode || "",
11459
11466
  locale,
11460
11467
  { enabled: !isManagedByParent && !demoRoomProp && !!demoRoomCode }
11461
11468
  );
11462
11469
  const demoRoom = demoRoomProp ?? fetchedDemoRoom;
11470
+ const effectiveDemoRoomLoading = !demoRoom && !!(isManagedByParent ? demoRoomLoading : fetchedDemoRoomLoading);
11463
11471
  const isPodPurpose = selectedPurposeType === "pod";
11464
11472
  const effectiveQuestionnaireId = isPodPurpose && demoRoom?.pod_config?.questionnaire_id || demoRoom?.questionnaire_id;
11465
11473
  const { data: questionnaire, loading: questionnaireLoading } = useQuestionnaire(
@@ -11508,7 +11516,8 @@ var DateTimePicker2 = ({
11508
11516
  return dates;
11509
11517
  }, [timeslotsData, demoRoom?.timezone, timezone5]);
11510
11518
  useEffect(() => {
11511
- if (booking || isInitialized || !demoRoom?.timeslots?.length) return;
11519
+ if (booking || isInitialized || autoSelectLockRef.current || !demoRoom?.timeslots?.length)
11520
+ return;
11512
11521
  const tz = demoRoom?.timezone || timezone5;
11513
11522
  const now2 = tz ? dayjs4().tz(tz) : dayjs4();
11514
11523
  const nearestSlot = demoRoom.timeslots.filter((slot) => {
@@ -11520,6 +11529,7 @@ var DateTimePicker2 = ({
11520
11529
  return timeA.unix() - timeB.unix();
11521
11530
  })[0];
11522
11531
  if (!nearestSlot) return;
11532
+ autoSelectLockRef.current = true;
11523
11533
  const nearestDate = tz ? dayjs4(nearestSlot.start_time).tz(tz) : dayjs4(nearestSlot.start_time);
11524
11534
  setSelectedDate(nearestDate);
11525
11535
  setCalendarValue(nearestDate);
@@ -11527,7 +11537,7 @@ var DateTimePicker2 = ({
11527
11537
  setIsInitialized(true);
11528
11538
  }, [booking, isInitialized, demoRoom?.timeslots, demoRoom?.timezone, timezone5]);
11529
11539
  useEffect(() => {
11530
- if (!timeslotsData?.timeslots || isInitialized) return;
11540
+ if (!timeslotsData?.timeslots || isInitialized || autoSelectLockRef.current) return;
11531
11541
  const tz = demoRoom?.timezone || timezone5;
11532
11542
  const now2 = tz ? dayjs4().tz(tz) : dayjs4();
11533
11543
  const availableTimeslots = timeslotsData.timeslots.filter((slot) => {
@@ -11542,16 +11552,25 @@ var DateTimePicker2 = ({
11542
11552
  });
11543
11553
  const nearestSlot = sortedSlots[0];
11544
11554
  const nearestDate = tz ? dayjs4(nearestSlot.start_time).tz(tz) : dayjs4(nearestSlot.start_time);
11555
+ autoSelectLockRef.current = true;
11545
11556
  setSelectedDate(nearestDate);
11546
11557
  setCalendarValue(nearestDate);
11547
11558
  setSelectedTimeslotId(nearestSlot.id);
11548
11559
  setIsInitialized(true);
11549
- } else if (!selectedDate) {
11560
+ } else if (!selectedDate && !effectiveDemoRoomLoading) {
11561
+ autoSelectLockRef.current = true;
11550
11562
  setSelectedDate(now2);
11551
11563
  setCalendarValue(now2);
11552
11564
  setIsInitialized(true);
11553
11565
  }
11554
- }, [timeslotsData, isInitialized, selectedDate, demoRoom?.timezone, timezone5]);
11566
+ }, [
11567
+ timeslotsData,
11568
+ isInitialized,
11569
+ selectedDate,
11570
+ demoRoom?.timezone,
11571
+ timezone5,
11572
+ effectiveDemoRoomLoading
11573
+ ]);
11555
11574
  useEffect(() => {
11556
11575
  if (!timeslotsData?.timeslots || !isInitialized) return;
11557
11576
  if (selectedDate && selectedDate.isSame(calendarValue, "month")) {