@axiom-lattice/react-sdk 2.1.92 → 2.1.93

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
@@ -31196,25 +31196,30 @@ var PersonalAssistantChannelModal = ({
31196
31196
  const [qrLoading, setQrLoading] = useState74(false);
31197
31197
  const [qrCodeUrl, setQrCodeUrl] = useState74(null);
31198
31198
  const [qrStatus, setQrStatus] = useState74("idle");
31199
+ const [qrCountdown, setQrCountdown] = useState74(0);
31199
31200
  const qrCodeRef = useRef27(null);
31200
- const qrPollRef = useRef27(null);
31201
- const clearQrPoll = useCallback38(() => {
31202
- if (qrPollRef.current) {
31203
- clearInterval(qrPollRef.current);
31204
- qrPollRef.current = null;
31201
+ const qrCountdownRef = useRef27(null);
31202
+ const clearQrCountdown = useCallback38(() => {
31203
+ if (qrCountdownRef.current) {
31204
+ clearInterval(qrCountdownRef.current);
31205
+ qrCountdownRef.current = null;
31205
31206
  }
31206
31207
  }, []);
31207
31208
  const resetQrState = useCallback38(() => {
31208
- clearQrPoll();
31209
+ clearQrCountdown();
31209
31210
  setQrLoading(false);
31210
31211
  setQrCodeUrl(null);
31211
31212
  setQrStatus("idle");
31213
+ setQrCountdown(0);
31212
31214
  qrCodeRef.current = null;
31213
- }, [clearQrPoll]);
31215
+ }, [clearQrCountdown]);
31216
+ const QR_EXPIRY_SECONDS = 300;
31214
31217
  const fetchQrCode = useCallback38(async () => {
31215
31218
  setQrLoading(true);
31216
31219
  setQrStatus("loading");
31217
31220
  setQrCodeUrl(null);
31221
+ clearQrCountdown();
31222
+ setQrCountdown(0);
31218
31223
  try {
31219
31224
  const res = await get(
31220
31225
  "/api/channels/wechat/setup/qrcode"
@@ -31223,32 +31228,17 @@ var PersonalAssistantChannelModal = ({
31223
31228
  qrCodeRef.current = res.data.qrcode;
31224
31229
  setQrCodeUrl(res.data.qrcodeImgUrl);
31225
31230
  setQrStatus("wait");
31226
- clearQrPoll();
31227
- qrPollRef.current = setInterval(async () => {
31228
- try {
31229
- const statusRes = await get(`/api/channels/wechat/setup/status?qrcode=${encodeURIComponent(qrCodeRef.current)}`);
31230
- if (statusRes.success && statusRes.data) {
31231
- const s = statusRes.data.status;
31232
- if (s === "confirmed" && statusRes.data.botToken) {
31233
- setQrStatus("confirmed");
31234
- clearQrPoll();
31235
- form.setFieldsValue({
31236
- botToken: statusRes.data.botToken,
31237
- uin: statusRes.data.uin
31238
- });
31239
- message18.success("WeChat login confirmed!");
31240
- } else if (s === "expired") {
31241
- setQrStatus("expired");
31242
- clearQrPoll();
31243
- } else if (s === "scaned") {
31244
- setQrStatus("scaned");
31245
- } else if (s === "wait") {
31246
- setQrStatus("wait");
31247
- }
31231
+ setQrCountdown(QR_EXPIRY_SECONDS);
31232
+ qrCountdownRef.current = setInterval(() => {
31233
+ setQrCountdown((prev) => {
31234
+ if (prev <= 1) {
31235
+ clearQrCountdown();
31236
+ setQrStatus("expired");
31237
+ return 0;
31248
31238
  }
31249
- } catch {
31250
- }
31251
- }, 2e3);
31239
+ return prev - 1;
31240
+ });
31241
+ }, 1e3);
31252
31242
  } else {
31253
31243
  setQrStatus("error");
31254
31244
  message18.error("Failed to get QR code");
@@ -31259,10 +31249,36 @@ var PersonalAssistantChannelModal = ({
31259
31249
  } finally {
31260
31250
  setQrLoading(false);
31261
31251
  }
31262
- }, [get, clearQrPoll, form]);
31252
+ }, [get, clearQrCountdown]);
31253
+ const checkQrStatus = useCallback38(async () => {
31254
+ if (!qrCodeRef.current) return;
31255
+ try {
31256
+ const statusRes = await get(`/api/channels/wechat/setup/status?qrcode=${encodeURIComponent(qrCodeRef.current)}`);
31257
+ if (statusRes.success && statusRes.data) {
31258
+ const s = statusRes.data.status;
31259
+ if (s === "confirmed" && statusRes.data.botToken) {
31260
+ setQrStatus("confirmed");
31261
+ clearQrCountdown();
31262
+ form.setFieldsValue({
31263
+ botToken: statusRes.data.botToken,
31264
+ uin: statusRes.data.uin
31265
+ });
31266
+ message18.success("WeChat login confirmed!");
31267
+ } else if (s === "expired") {
31268
+ setQrStatus("expired");
31269
+ clearQrCountdown();
31270
+ setQrCountdown(0);
31271
+ } else if (s === "scaned") {
31272
+ setQrStatus("scaned");
31273
+ }
31274
+ }
31275
+ } catch {
31276
+ message18.error("Failed to check QR status");
31277
+ }
31278
+ }, [get, clearQrCountdown, form]);
31263
31279
  useEffect50(() => {
31264
31280
  return () => {
31265
- if (qrPollRef.current) clearInterval(qrPollRef.current);
31281
+ if (qrCountdownRef.current) clearInterval(qrCountdownRef.current);
31266
31282
  };
31267
31283
  }, []);
31268
31284
  const loadInstallations = useCallback38(async () => {
@@ -31640,7 +31656,7 @@ var PersonalAssistantChannelModal = ({
31640
31656
  /* @__PURE__ */ jsx118(Spin20, {}),
31641
31657
  /* @__PURE__ */ jsx118(Text48, { type: "secondary", style: { display: "block", marginTop: 8, fontSize: 12 }, children: "Generating QR code..." })
31642
31658
  ] }),
31643
- (qrStatus === "wait" || qrStatus === "scaned") && qrCodeUrl && /* @__PURE__ */ jsxs85("div", { children: [
31659
+ (qrStatus === "wait" || qrStatus === "scaned") && qrCodeUrl && /* @__PURE__ */ jsxs85("div", { style: { display: "flex", flexDirection: "column", alignItems: "center" }, children: [
31644
31660
  /* @__PURE__ */ jsx118(QRCode, { value: qrCodeUrl, size: 180 }),
31645
31661
  /* @__PURE__ */ jsx118(
31646
31662
  Text48,
@@ -31655,7 +31671,16 @@ var PersonalAssistantChannelModal = ({
31655
31671
  children: qrStatus === "scaned" ? "Scanned! Confirm on your phone..." : "Scan with WeChat"
31656
31672
  }
31657
31673
  ),
31658
- /* @__PURE__ */ jsx118(Text48, { type: "secondary", style: { fontSize: 11, marginTop: 4, display: "block" }, children: "QR expires in 5 minutes" })
31674
+ /* @__PURE__ */ jsx118(Text48, { type: "secondary", style: { fontSize: 11, marginTop: 4, display: "block" }, children: qrCountdown > 0 ? `Expires in ${Math.floor(qrCountdown / 60)}:${String(qrCountdown % 60).padStart(2, "0")}` : "QR code expired" }),
31675
+ /* @__PURE__ */ jsx118(
31676
+ Button54,
31677
+ {
31678
+ size: "small",
31679
+ style: { marginTop: 8 },
31680
+ onClick: checkQrStatus,
31681
+ children: "Refresh Status"
31682
+ }
31683
+ )
31659
31684
  ] }),
31660
31685
  qrStatus === "confirmed" && /* @__PURE__ */ jsxs85("div", { style: { padding: "12px 0" }, children: [
31661
31686
  /* @__PURE__ */ jsx118(Text48, { strong: true, style: { fontSize: 14, color: "var(--color-success, #22c55e)", display: "block" }, children: "Login confirmed!" }),