@ohhwells/bridge 0.1.34-next.40 → 0.1.34-next.44

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.cjs CHANGED
@@ -110,6 +110,7 @@ var import_react3 = require("react");
110
110
  var import_react2 = require("react");
111
111
  var import_radix_ui = require("radix-ui");
112
112
  var import_jsx_runtime = require("react/jsx-runtime");
113
+ var isValidEmail = (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
113
114
  function Spinner() {
114
115
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
115
116
  "svg",
@@ -143,12 +144,17 @@ function EmailCaptureModal({ title, subtitle, onSubmit, onClose }) {
143
144
  const [error, setError] = (0, import_react2.useState)(null);
144
145
  const isBook = title === "Confirm your spot";
145
146
  const handleSubmit = async () => {
146
- if (!email.trim()) return;
147
+ const trimmed = email.trim();
148
+ if (!trimmed) return;
149
+ if (!isValidEmail(trimmed)) {
150
+ setError("Please enter a valid email address.");
151
+ return;
152
+ }
147
153
  setLoading(true);
148
154
  setError(null);
149
155
  try {
150
- await onSubmit(email.trim());
151
- setSubmittedEmail(email.trim());
156
+ await onSubmit(trimmed);
157
+ setSubmittedEmail(trimmed);
152
158
  setSuccess(true);
153
159
  } catch (e) {
154
160
  setError(e instanceof Error ? e.message : "Something went wrong. Please try again.");
@@ -223,7 +229,10 @@ function EmailCaptureModal({ title, subtitle, onSubmit, onClose }) {
223
229
  {
224
230
  type: "email",
225
231
  value: email,
226
- onChange: (e) => setEmail(e.target.value),
232
+ onChange: (e) => {
233
+ setEmail(e.target.value);
234
+ if (error) setError(null);
235
+ },
227
236
  onKeyDown: handleKeyDown,
228
237
  placeholder: "hello@gmail.com",
229
238
  autoFocus: true,
@@ -639,6 +648,17 @@ function SchedulingWidget({ notifyOnConnect = false, initialScheduleId, insertAf
639
648
  const [isHovered, setIsHovered] = (0, import_react3.useState)(false);
640
649
  const [modalState, setModalState] = (0, import_react3.useState)(null);
641
650
  const switchScheduleIdRef = (0, import_react3.useRef)(null);
651
+ const liveScheduleIdRef = (0, import_react3.useRef)(null);
652
+ const refetchLiveSchedule = (0, import_react3.useCallback)(async () => {
653
+ const id = liveScheduleIdRef.current;
654
+ if (!id) return;
655
+ try {
656
+ const res = await fetch(`${API_URL}/api/schedule/id/${id}`);
657
+ const data = await res.json();
658
+ if (data?.id) setSchedule(data);
659
+ } catch {
660
+ }
661
+ }, []);
642
662
  const dates = (0, import_react3.useMemo)(() => {
643
663
  const today = /* @__PURE__ */ new Date();
644
664
  today.setHours(0, 0, 0, 0);
@@ -658,6 +678,18 @@ function SchedulingWidget({ notifyOnConnect = false, initialScheduleId, insertAf
658
678
  }
659
679
  }
660
680
  }, [schedule, dates]);
681
+ (0, import_react3.useEffect)(() => {
682
+ if (typeof window === "undefined") return;
683
+ const onVisible = () => {
684
+ if (!document.hidden) void refetchLiveSchedule();
685
+ };
686
+ window.addEventListener("focus", refetchLiveSchedule);
687
+ document.addEventListener("visibilitychange", onVisible);
688
+ return () => {
689
+ window.removeEventListener("focus", refetchLiveSchedule);
690
+ document.removeEventListener("visibilitychange", onVisible);
691
+ };
692
+ }, [refetchLiveSchedule]);
661
693
  (0, import_react3.useEffect)(() => {
662
694
  if (typeof window === "undefined") return;
663
695
  const isInEditor = window.self !== window.top;
@@ -719,7 +751,7 @@ function SchedulingWidget({ notifyOnConnect = false, initialScheduleId, insertAf
719
751
  setLoading(false);
720
752
  return;
721
753
  }
722
- ;
754
+ liveScheduleIdRef.current = effectiveId;
723
755
  (async () => {
724
756
  try {
725
757
  const res = await fetch(`${API_URL}/api/schedule/id/${effectiveId}`);
@@ -776,6 +808,7 @@ function SchedulingWidget({ notifyOnConnect = false, initialScheduleId, insertAf
776
808
  const data = await res.json().catch(() => ({}));
777
809
  throw new Error(data?.message ?? "Something went wrong. Please try again.");
778
810
  }
811
+ await refetchLiveSchedule();
779
812
  };
780
813
  const handleReplaceSchedule = () => {
781
814
  setIsHovered(false);