From a9ee70ccb6abf64136e2c1861ed2f8f8ea5aea6e Mon Sep 17 00:00:00 2001
From: "gpt-engineer-app[bot]"
<159125892+gpt-engineer-app[bot]@users.noreply.github.com>
Date: Tue, 20 May 2025 19:26:10 +0000
Subject: [PATCH] feat: Implement "Atualizar Lista" button
The "Connect WhatsApp" menu now loads instances only on clicking the "Atualizar Lista" button. The button fetches instances from the API, filters by the user's instance name, and displays the results. It also shows an appropriate message if no instances are found and addresses potential rendering errors.
---
src/components/whatsapp/InstanceList.tsx | 26 +++++----
src/hooks/whatsApp/useInstanceRefresh.ts | 64 +++++++++++----------
src/hooks/whatsApp/useWhatsAppInstance.ts | 7 +--
src/pages/WhatsApp.tsx | 28 ++++++---
src/services/whatsApp/instanceManagement.ts | 3 +-
5 files changed, 73 insertions(+), 55 deletions(-)
diff --git a/src/components/whatsapp/InstanceList.tsx b/src/components/whatsapp/InstanceList.tsx
index 21eedf1..b18ccd8 100644
--- a/src/components/whatsapp/InstanceList.tsx
+++ b/src/components/whatsapp/InstanceList.tsx
@@ -26,13 +26,26 @@ const InstanceList = ({
onRefreshInstances,
isRefreshing
}: InstanceListProps) => {
- if (instances.length === 0) {
+ // Safely check if instances is an array and has elements
+ const hasInstances = Array.isArray(instances) && instances.length > 0;
+
+ if (!hasInstances) {
return (
Nenhuma instância criada ainda. Crie uma instância usando o formulário acima. Clique em 'Atualizar Lista' para buscar novamente.