Corrige widget de chat para nao quebrar sem API
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
8c465008bf
commit
9e676b06f9
2 changed files with 16 additions and 0 deletions
|
|
@ -1,6 +1,16 @@
|
||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import dynamic from "next/dynamic"
|
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
|
// Importacao dinamica para evitar problemas de SSR
|
||||||
const ChatWidget = dynamic(
|
const ChatWidget = dynamic(
|
||||||
|
|
@ -9,5 +19,10 @@ const ChatWidget = dynamic(
|
||||||
)
|
)
|
||||||
|
|
||||||
export function ChatWidgetProvider() {
|
export function ChatWidgetProvider() {
|
||||||
|
// Nao renderiza se a API nao existir (Convex nao sincronizado)
|
||||||
|
if (!checkLiveChatApiExists()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return <ChatWidget />
|
return <ChatWidget />
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import { MessageCircle, Send, X, Minimize2, User, Headphones, ChevronDown } from
|
||||||
|
|
||||||
const MAX_MESSAGE_LENGTH = 4000
|
const MAX_MESSAGE_LENGTH = 4000
|
||||||
|
|
||||||
|
|
||||||
function formatTime(timestamp: number) {
|
function formatTime(timestamp: number) {
|
||||||
return new Date(timestamp).toLocaleTimeString("pt-BR", {
|
return new Date(timestamp).toLocaleTimeString("pt-BR", {
|
||||||
hour: "2-digit",
|
hour: "2-digit",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue