From 03bb67872ab79e9f0b6168cdb2d12cabed8c2fa8 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:37:49 +0000 Subject: [PATCH] Revert instance creation changes Reverts changes to the instance creation form and related hooks, restoring the functionality to create and connect instances as it was before the recent changes. --- src/components/whatsapp/InstanceList.tsx | 9 +++++++ src/pages/WhatsApp.tsx | 33 ++++++++++++++++++------ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/components/whatsapp/InstanceList.tsx b/src/components/whatsapp/InstanceList.tsx index b18ccd8..59bff70 100644 --- a/src/components/whatsapp/InstanceList.tsx +++ b/src/components/whatsapp/InstanceList.tsx @@ -56,6 +56,15 @@ const InstanceList = ({

Instâncias Criadas

+
{instances.map((instance) => ( diff --git a/src/pages/WhatsApp.tsx b/src/pages/WhatsApp.tsx index 09dd6b5..b3cdb18 100644 --- a/src/pages/WhatsApp.tsx +++ b/src/pages/WhatsApp.tsx @@ -12,6 +12,7 @@ import { useWhatsAppInstance, WHATSAPP_INSTANCE_KEY } from '@/hooks/whatsApp/use import { usePeriodicStatusCheck } from '@/hooks/whatsApp/usePeriodicStatusCheck'; import { Button } from '@/components/ui/button'; import { RefreshCw } from 'lucide-react'; +import { useState } from 'react'; const WhatsApp = () => { const { @@ -47,6 +48,9 @@ const WhatsApp = () => { clearInstanceName } = useWhatsAppInstance(currentUserId, addInstance); + // Toggle for showing the creation form + const [showCreateForm, setShowCreateForm] = useState(!instanceFound && instances.length === 0); + // Set up periodic status checking only after instances are loaded usePeriodicStatusCheck(instances.length, checkAllInstancesStatus); @@ -55,6 +59,7 @@ const WhatsApp = () => { console.log('New instance to be added:', newInstance); addInstance(newInstance); setInstanceFound(true); + setShowCreateForm(false); // Salvar o nome da instância no localStorage para uso futuro saveInstanceName(newInstance.instanceName); @@ -84,6 +89,7 @@ const WhatsApp = () => { // Se a instância excluída for a atual, limpar o nome salvo if (instanceToDelete.instanceName === instanceName) { clearInstanceName(); + setShowCreateForm(true); } } else { console.error(`Instance with ID ${instanceId} not found for deletion`); @@ -113,16 +119,27 @@ const WhatsApp = () => { {isLoading ? ( - ) : !instanceFound && !hasInstances ? ( - // Show create form if no instance found and no instances loaded - ) : ( - // Only show stats and instance list if instances are available <> - {/* Stats component */} + {/* Always show create form if showCreateForm is true */} + {showCreateForm && ( + + )} + + {/* Toggle Create Form Button - only show if form is hidden */} + {!showCreateForm && ( + + )} + + {/* Only show stats if instances are available */} {hasInstances && } {/* List of created instances */}