@fayz-ai/plugin-conversations 0.45.3 → 0.45.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.js CHANGED
@@ -13,7 +13,7 @@ import * as React from 'react';
13
13
  import React__default, { useState, useRef, useEffect, useCallback, useMemo } from 'react';
14
14
  import { Check, ShieldCheck, ShieldAlert, Loader2, RefreshCw, QrCode, Zap, ExternalLink } from 'lucide-react';
15
15
  import { defineSettingsTab, SettingsGroup, useNavContribution, playChime, notifySystem, requestNotificationPermission } from '@fayz-ai/admin';
16
- import { Skeleton, Input, Button, toast, defineKpiWidget, defineTableWidget, KpiCard, TableWidget } from '@fayz-ai/ui';
16
+ import { toast, Skeleton, Input, Button, defineKpiWidget, defineTableWidget, KpiCard, TableWidget } from '@fayz-ai/ui';
17
17
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
18
18
  import { createConnectionStore, connectionRuns, connectionStatus, tl, lazyComponent, useActiveTenantId, registerTranslations, describeError, getSupabaseClientOptional, getActiveTenantId, countByTenant, CONNECTOR_RUNTIME_TOKEN_HEADER, connectorRuntimeToken, useTranslation, navigateApp } from '@fayz-ai/core';
19
19
  import { MIGRATIONS } from '#migrations/main';
@@ -42,6 +42,11 @@ var COPY = {
42
42
  }
43
43
  };
44
44
  var ALL = ["tyxter", "evolution"];
45
+ var QR_REFRESH_MS = 15e3;
46
+ var QR_REFRESH_LIMIT_MS = 3 * 6e4;
47
+ function isTypableCode(code) {
48
+ return Boolean(code && code.replace(/[^A-Za-z0-9]/g, "").length <= 12);
49
+ }
45
50
  function StatusChip({ row }) {
46
51
  if (!row || row.status === "unconfigured") {
47
52
  return /* @__PURE__ */ jsx("span", { className: "rounded-full bg-muted px-2 py-0.5 text-[10px] text-muted-foreground", children: "n\xE3o configurado" });
@@ -154,9 +159,45 @@ function WhatsAppProviders({ only, onChanged } = {}) {
154
159
  });
155
160
  const pair = (p) => run(`qr:${p}`, async () => {
156
161
  const d = await providersApi.pair(p);
157
- setQr({ provider: p, image: d.qr, code: d.code });
162
+ setQr({ provider: p, image: d.qr, code: d.code, startedAt: Date.now() });
158
163
  if (!d.qr && !d.code) toast.error("A inst\xE2ncia n\xE3o devolveu QR \u2014 j\xE1 est\xE1 pareada?");
159
164
  });
165
+ const qrProvider = qr?.provider;
166
+ const qrStartedAt = qr?.startedAt;
167
+ React__default.useEffect(() => {
168
+ if (!qrProvider || !qrStartedAt) return;
169
+ let cancelled = false;
170
+ const timer = window.setInterval(async () => {
171
+ if (Date.now() - qrStartedAt > QR_REFRESH_LIMIT_MS) {
172
+ window.clearInterval(timer);
173
+ if (!cancelled) {
174
+ setQr(null);
175
+ toast.error("O QR expirou. Clique em Parear para gerar outro.");
176
+ }
177
+ return;
178
+ }
179
+ try {
180
+ const h = await providersApi.health(qrProvider);
181
+ if (cancelled) return;
182
+ if (h.ok) {
183
+ window.clearInterval(timer);
184
+ setQr(null);
185
+ await load();
186
+ toast.success("WhatsApp pareado");
187
+ return;
188
+ }
189
+ const d = await providersApi.pair(qrProvider);
190
+ if (!cancelled && (d.qr || d.code)) {
191
+ setQr((cur) => cur && cur.provider === qrProvider ? { ...cur, image: d.qr, code: d.code } : cur);
192
+ }
193
+ } catch {
194
+ }
195
+ }, QR_REFRESH_MS);
196
+ return () => {
197
+ cancelled = true;
198
+ window.clearInterval(timer);
199
+ };
200
+ }, [qrProvider, qrStartedAt, load]);
160
201
  const body = /* @__PURE__ */ jsxs(Fragment, { children: [
161
202
  rows === null && /* @__PURE__ */ jsx("div", { className: "space-y-2 py-2", "aria-busy": "true", children: (only ? [only] : ALL).map((p) => /* @__PURE__ */ jsxs("div", { className: "space-y-2 rounded-card border bg-card p-4", children: [
162
203
  /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-40" }),
@@ -235,7 +276,8 @@ function WhatsAppProviders({ only, onChanged } = {}) {
235
276
  qr?.provider === p && /* @__PURE__ */ jsxs("div", { className: "mt-3 border-t pt-3", children: [
236
277
  /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mb-2", children: "Abra o WhatsApp no celular \u2192 Aparelhos conectados \u2192 Conectar aparelho." }),
237
278
  qr.image && /* @__PURE__ */ jsx("img", { src: qr.image, alt: "QR", className: "h-48 w-48 rounded border bg-white p-2" }),
238
- qr.code && /* @__PURE__ */ jsx("p", { className: "mt-2 font-mono text-lg tracking-widest", children: qr.code })
279
+ isTypableCode(qr.code) && /* @__PURE__ */ jsx("p", { className: "mt-2 font-mono text-lg tracking-widest", children: qr.code }),
280
+ /* @__PURE__ */ jsx("p", { className: "mt-2 text-[11px] text-muted-foreground", children: "O QR se renova sozinho a cada 15 segundos. Quando o celular conectar, esta \xE1rea fecha." })
239
281
  ] })
240
282
  ]
241
283
  },