From 9e676b06f905266183e8159dab15a7624995b07d Mon Sep 17 00:00:00 2001 From: esdrasrenan Date: Sun, 7 Dec 2025 01:32:34 -0300 Subject: [PATCH] Corrige widget de chat para nao quebrar sem API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Verifica se api.liveChat.listAgentSessions existe antes de renderizar - Retorna null no provider se Convex nao estiver sincronizado 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/components/chat/chat-widget-provider.tsx | 15 +++++++++++++++ src/components/chat/chat-widget.tsx | 1 + 2 files changed, 16 insertions(+) diff --git a/src/components/chat/chat-widget-provider.tsx b/src/components/chat/chat-widget-provider.tsx index 4847834..3ebbe09 100644 --- a/src/components/chat/chat-widget-provider.tsx +++ b/src/components/chat/chat-widget-provider.tsx @@ -1,6 +1,16 @@ "use client" import dynamic from "next/dynamic" +import { api } from "@/convex/_generated/api" + +// Verifica se a API do liveChat existe +function checkLiveChatApiExists() { + try { + return typeof api.liveChat?.listAgentSessions !== "undefined" + } catch { + return false + } +} // Importacao dinamica para evitar problemas de SSR const ChatWidget = dynamic( @@ -9,5 +19,10 @@ const ChatWidget = dynamic( ) export function ChatWidgetProvider() { + // Nao renderiza se a API nao existir (Convex nao sincronizado) + if (!checkLiveChatApiExists()) { + return null + } + return } diff --git a/src/components/chat/chat-widget.tsx b/src/components/chat/chat-widget.tsx index f646aa8..30818e6 100644 --- a/src/components/chat/chat-widget.tsx +++ b/src/components/chat/chat-widget.tsx @@ -13,6 +13,7 @@ import { MessageCircle, Send, X, Minimize2, User, Headphones, ChevronDown } from const MAX_MESSAGE_LENGTH = 4000 + function formatTime(timestamp: number) { return new Date(timestamp).toLocaleTimeString("pt-BR", { hour: "2-digit",