@anker-in/ui 0.1.15 → 0.1.16

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
@@ -12,6 +12,8 @@ import { theme, ConfigProvider, Calendar, Select } from 'antd';
12
12
  import dayLocaleData from 'dayjs/plugin/localeData';
13
13
  import weekday from 'dayjs/plugin/weekday';
14
14
  import weekOfYear from 'dayjs/plugin/weekOfYear';
15
+ import timezone from 'dayjs/plugin/timezone';
16
+ import utc from 'dayjs/plugin/utc';
15
17
 
16
18
  function cn(...inputs) {
17
19
  return twMerge(clsx(inputs));
@@ -1659,7 +1661,8 @@ var QuestionnaireForm = ({
1659
1661
  pageData,
1660
1662
  selectedTimeslotId,
1661
1663
  loading = false,
1662
- className
1664
+ className,
1665
+ error
1663
1666
  }) => {
1664
1667
  const [responses, setResponses] = useState({});
1665
1668
  const [errors, setErrors] = useState({});
@@ -2105,17 +2108,20 @@ var QuestionnaireForm = ({
2105
2108
  ),
2106
2109
  children: loading ? pageData?.submitting || "Submitting..." : pageData?.submit || "Submit Booking"
2107
2110
  }
2108
- )
2111
+ ),
2112
+ error && /* @__PURE__ */ jsx("div", { className: "text-center w-full p-4", children: /* @__PURE__ */ jsx("p", { className: "text-[#FF4D4D] font-bold", children: error.message }) })
2109
2113
  ] })
2110
2114
  ] });
2111
2115
  };
2112
2116
  dayjs.extend(dayLocaleData);
2113
2117
  dayjs.extend(weekday);
2114
2118
  dayjs.extend(weekOfYear);
2119
+ dayjs.extend(utc);
2120
+ dayjs.extend(timezone);
2115
2121
  var DateTimePicker = ({
2116
2122
  apiClient,
2117
2123
  demoRoomCode,
2118
- timezone,
2124
+ timezone: timezone2,
2119
2125
  pageData = {
2120
2126
  scheduleYourVisit: "Schedule Your Visit",
2121
2127
  timeSlot: "Time Slot",
@@ -2169,41 +2175,47 @@ var DateTimePicker = ({
2169
2175
  {
2170
2176
  start_date: startDate,
2171
2177
  end_date: endDate,
2172
- timezone
2178
+ timezone: timezone2
2173
2179
  },
2174
2180
  { enabled: !!demoRoomCode }
2175
2181
  );
2176
2182
  const dayTimeslots = useMemo(() => {
2177
2183
  if (!timeslotsData?.timeslots || !selectedDate) return [];
2184
+ const tz = demoRoom?.timezone || timezone2;
2178
2185
  const selectedDateStr = selectedDate.format("YYYY-MM-DD");
2179
2186
  return timeslotsData.timeslots.filter((slot) => {
2180
- const slotDate = dayjs(slot.start_time).format("YYYY-MM-DD");
2187
+ const slotDate = tz ? dayjs(slot.start_time).tz(tz).format("YYYY-MM-DD") : dayjs(slot.start_time).format("YYYY-MM-DD");
2181
2188
  return slotDate === selectedDateStr;
2182
2189
  });
2183
- }, [timeslotsData, selectedDate]);
2190
+ }, [timeslotsData, selectedDate, demoRoom?.timezone, timezone2]);
2184
2191
  const availableDates = useMemo(() => {
2185
2192
  if (!timeslotsData?.timeslots) return /* @__PURE__ */ new Set();
2193
+ const tz = demoRoom?.timezone || timezone2;
2186
2194
  const dates = /* @__PURE__ */ new Set();
2187
2195
  timeslotsData.timeslots.forEach((slot) => {
2188
2196
  if (slot.status === "available") {
2189
- const dateStr = dayjs(slot.start_time).format("YYYY-MM-DD");
2197
+ const dateStr = tz ? dayjs(slot.start_time).tz(tz).format("YYYY-MM-DD") : dayjs(slot.start_time).format("YYYY-MM-DD");
2190
2198
  dates.add(dateStr);
2191
2199
  }
2192
2200
  });
2193
2201
  return dates;
2194
- }, [timeslotsData]);
2202
+ }, [timeslotsData, demoRoom?.timezone, timezone2]);
2195
2203
  useEffect(() => {
2196
2204
  if (!timeslotsData?.timeslots || isInitialized) return;
2197
- const now2 = dayjs();
2198
- const availableTimeslots = timeslotsData.timeslots.filter(
2199
- (slot) => slot.status === "available" && dayjs(slot.start_time).isAfter(now2)
2200
- );
2205
+ const tz = demoRoom?.timezone || timezone2;
2206
+ const now2 = tz ? dayjs().tz(tz) : dayjs();
2207
+ const availableTimeslots = timeslotsData.timeslots.filter((slot) => {
2208
+ const slotTime = tz ? dayjs(slot.start_time).tz(tz) : dayjs(slot.start_time);
2209
+ return slot.status === "available" && slotTime.isAfter(now2);
2210
+ });
2201
2211
  if (availableTimeslots.length > 0) {
2202
- const sortedSlots = [...availableTimeslots].sort(
2203
- (a, b) => dayjs(a.start_time).unix() - dayjs(b.start_time).unix()
2204
- );
2212
+ const sortedSlots = [...availableTimeslots].sort((a, b) => {
2213
+ const timeA = tz ? dayjs(a.start_time).tz(tz) : dayjs(a.start_time);
2214
+ const timeB = tz ? dayjs(b.start_time).tz(tz) : dayjs(b.start_time);
2215
+ return timeA.unix() - timeB.unix();
2216
+ });
2205
2217
  const nearestSlot = sortedSlots[0];
2206
- const nearestDate = dayjs(nearestSlot.start_time);
2218
+ const nearestDate = tz ? dayjs(nearestSlot.start_time).tz(tz) : dayjs(nearestSlot.start_time);
2207
2219
  setSelectedDate(nearestDate);
2208
2220
  setCalendarValue(nearestDate);
2209
2221
  setSelectedTimeslotId(nearestSlot.id);
@@ -2213,32 +2225,43 @@ var DateTimePicker = ({
2213
2225
  setCalendarValue(now2);
2214
2226
  setIsInitialized(true);
2215
2227
  }
2216
- }, [timeslotsData, isInitialized, selectedDate]);
2228
+ }, [timeslotsData, isInitialized, selectedDate, demoRoom?.timezone, timezone2]);
2217
2229
  useEffect(() => {
2218
2230
  if (!timeslotsData?.timeslots || !isInitialized) return;
2219
2231
  if (selectedDate && selectedDate.isSame(calendarValue, "month")) {
2220
2232
  return;
2221
2233
  }
2234
+ const tz = demoRoom?.timezone || timezone2;
2222
2235
  const currentMonthStart = calendarValue.startOf("month");
2223
2236
  const currentMonthEnd = calendarValue.endOf("month");
2224
- const now2 = dayjs();
2237
+ const now2 = tz ? dayjs().tz(tz) : dayjs();
2225
2238
  const availableTimeslots = timeslotsData.timeslots.filter((slot) => {
2226
- const slotDate = dayjs(slot.start_time);
2239
+ const slotDate = tz ? dayjs(slot.start_time).tz(tz) : dayjs(slot.start_time);
2227
2240
  return slot.status === "available" && slotDate.isAfter(now2) && (slotDate.isAfter(currentMonthStart) || slotDate.isSame(currentMonthStart, "day")) && (slotDate.isBefore(currentMonthEnd) || slotDate.isSame(currentMonthEnd, "day"));
2228
2241
  });
2229
2242
  if (availableTimeslots.length > 0) {
2230
- const sortedSlots = [...availableTimeslots].sort(
2231
- (a, b) => dayjs(a.start_time).unix() - dayjs(b.start_time).unix()
2232
- );
2243
+ const sortedSlots = [...availableTimeslots].sort((a, b) => {
2244
+ const timeA = tz ? dayjs(a.start_time).tz(tz) : dayjs(a.start_time);
2245
+ const timeB = tz ? dayjs(b.start_time).tz(tz) : dayjs(b.start_time);
2246
+ return timeA.unix() - timeB.unix();
2247
+ });
2233
2248
  const firstSlot = sortedSlots[0];
2234
- const firstDate = dayjs(firstSlot.start_time);
2249
+ const firstDate = tz ? dayjs(firstSlot.start_time).tz(tz) : dayjs(firstSlot.start_time);
2235
2250
  setSelectedDate(firstDate);
2236
2251
  setSelectedTimeslotId(firstSlot.id);
2237
2252
  }
2238
- }, [calendarValue, timeslotsData, isInitialized, selectedDate]);
2253
+ }, [
2254
+ calendarValue,
2255
+ timeslotsData,
2256
+ isInitialized,
2257
+ selectedDate,
2258
+ demoRoom?.timezone,
2259
+ timezone2
2260
+ ]);
2239
2261
  const formatTimeslot = (slot) => {
2240
- const start = dayjs(slot.start_time).format("h:mm A");
2241
- const end = dayjs(slot.end_time).format("h:mm A");
2262
+ const tz = demoRoom?.timezone || timezone2;
2263
+ const start = tz ? dayjs(slot.start_time).tz(tz).format("h:mm A") : dayjs(slot.start_time).format("h:mm A");
2264
+ const end = tz ? dayjs(slot.end_time).tz(tz).format("h:mm A") : dayjs(slot.end_time).format("h:mm A");
2242
2265
  return `${start} - ${end}`;
2243
2266
  };
2244
2267
  const wrapperStyle = {
@@ -2653,7 +2676,7 @@ var DateTimePicker = ({
2653
2676
  }) }),
2654
2677
  !timeslotsLoading && dayTimeslots?.length > 0 && /* @__PURE__ */ jsx("div", { className: "pt-[24px] text-[#6d6d6F] text-center", children: pageData?.timezone?.replace(
2655
2678
  "{{timezone}}",
2656
- demoRoom?.timezone || timezone || ""
2679
+ demoRoom?.timezone || timezone2 || ""
2657
2680
  ) })
2658
2681
  ] })
2659
2682
  ] }),
@@ -2666,6 +2689,7 @@ var DateTimePicker = ({
2666
2689
  loading: bookingLoading,
2667
2690
  pageData,
2668
2691
  selectedTimeslotId,
2692
+ error: bookingError,
2669
2693
  onSubmit: async (responses) => {
2670
2694
  if (onQuestionnaireSubmit) {
2671
2695
  await onQuestionnaireSubmit(responses);
@@ -8754,7 +8778,7 @@ var BookingForm = ({
8754
8778
  apiConfig,
8755
8779
  demoRoomCode,
8756
8780
  pageData,
8757
- timezone,
8781
+ timezone: timezone2,
8758
8782
  handleBookingSuccess,
8759
8783
  onQuestionnaireSubmit,
8760
8784
  ...props
@@ -8786,7 +8810,7 @@ var BookingForm = ({
8786
8810
  {
8787
8811
  apiClient,
8788
8812
  demoRoomCode,
8789
- timezone,
8813
+ timezone: timezone2,
8790
8814
  locale: apiConfig.locale,
8791
8815
  onBookingSuccess: handleBookingSuccess,
8792
8816
  onQuestionnaireSubmit,