From e208e7e3732431e7b2c3d432ce2e58dde46f43ed Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Mon, 19 May 2025 18:24:30 +0000 Subject: [PATCH] Fix: Resolve import path error The commit addresses a "Failed to resolve import" error in `src/pages/WhatsApp.tsx`. The error message indicates that the module `@/components/whatsapp` could not be found. This likely means the import path is incorrect, or the file does not exist at the specified location. --- src/components/whatsapp/InstanceList.tsx | 42 +++++++++++++----------- src/components/whatsapp/QrCodeDialog.tsx | 36 ++++++++++++-------- src/components/whatsapp/index.ts | 7 ++++ src/pages/WhatsApp.tsx | 3 +- 4 files changed, 53 insertions(+), 35 deletions(-) create mode 100644 src/components/whatsapp/index.ts diff --git a/src/components/whatsapp/InstanceList.tsx b/src/components/whatsapp/InstanceList.tsx index 21eedf1..c7ba1df 100644 --- a/src/components/whatsapp/InstanceList.tsx +++ b/src/components/whatsapp/InstanceList.tsx @@ -8,20 +8,20 @@ import { RefreshCw } from 'lucide-react'; interface InstanceListProps { instances: WhatsAppInstance[]; onViewQrCode: (instance: WhatsAppInstance) => void; - onDelete: (instanceId: string) => void; - onRestart: (instance: WhatsAppInstance) => Promise; - onLogout: (instance: WhatsAppInstance) => Promise; + onDeleteInstance: (instanceId: string) => void; + onRestartInstance: (instance: WhatsAppInstance) => Promise; + onLogoutInstance: (instance: WhatsAppInstance) => Promise; onSetPresence: (instance: WhatsAppInstance, presence: 'online' | 'offline') => Promise; - onRefreshInstances: () => Promise; - isRefreshing: boolean; + onRefreshInstances?: () => Promise; + isRefreshing?: boolean; } const InstanceList = ({ instances, onViewQrCode, - onDelete, - onRestart, - onLogout, + onDeleteInstance, + onRestartInstance, + onLogoutInstance, onSetPresence, onRefreshInstances, isRefreshing @@ -43,15 +43,17 @@ const InstanceList = ({

Instâncias Criadas

- + {onRefreshInstances && ( + + )}
{instances.map((instance) => ( @@ -59,9 +61,9 @@ const InstanceList = ({ key={instance.instanceId} instance={instance} onViewQrCode={onViewQrCode} - onDelete={onDelete} - onRestart={onRestart} - onLogout={onLogout} + onDelete={onDeleteInstance} + onRestart={onRestartInstance} + onLogout={onLogoutInstance} onSetPresence={onSetPresence} /> ))} diff --git a/src/components/whatsapp/QrCodeDialog.tsx b/src/components/whatsapp/QrCodeDialog.tsx index 1270559..feae5a6 100644 --- a/src/components/whatsapp/QrCodeDialog.tsx +++ b/src/components/whatsapp/QrCodeDialog.tsx @@ -1,5 +1,5 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { Dialog, DialogContent, @@ -10,21 +10,22 @@ import { import { Button } from '@/components/ui/button'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { RefreshCw } from 'lucide-react'; -import { WhatsAppInstance } from '@/types/whatsAppTypes'; import { fetchQrCode } from '@/services/whatsAppService'; import { useToast } from '@/hooks/use-toast'; interface QrCodeDialogProps { open: boolean; - onOpenChange: (open: boolean) => void; - activeInstance: WhatsAppInstance | null; - onStatusCheck: () => void; + setOpen: (open: boolean) => void; + instanceName: string; + phoneNumber: string; + onStatusCheck?: () => void; } const QrCodeDialog = ({ open, - onOpenChange, - activeInstance, + setOpen, + instanceName, + phoneNumber, onStatusCheck }: QrCodeDialogProps) => { const { toast } = useToast(); @@ -32,23 +33,30 @@ const QrCodeDialog = ({ const [qrCodeData, setQrCodeData] = useState(null); const [qrError, setQrError] = useState(null); + // Load QR code when dialog opens + useEffect(() => { + if (open && instanceName) { + handleRefreshQrCode(); + } + }, [open, instanceName]); + const handleOpenChange = (newOpen: boolean) => { - onOpenChange(newOpen); + setOpen(newOpen); // After dialog closes, trigger status check to update connection state - if (!newOpen) { + if (!newOpen && onStatusCheck) { onStatusCheck(); } }; const handleRefreshQrCode = async () => { - if (!activeInstance) return; + if (!instanceName) return; setLoadingQR(true); setQrError(null); try { - const data = await fetchQrCode(activeInstance.instanceName); + const data = await fetchQrCode(instanceName); console.log('QR Code API response:', data); // Using the "base64" field from the response as the QR code data @@ -75,7 +83,7 @@ const QrCodeDialog = ({ - Conectar WhatsApp - {activeInstance?.instanceName} + Conectar WhatsApp - {instanceName} Escaneie o QR Code com seu WhatsApp para finalizar a conexão @@ -109,7 +117,7 @@ const QrCodeDialog = ({ )}
- {activeInstance && ( + {instanceName && (
diff --git a/src/components/whatsapp/index.ts b/src/components/whatsapp/index.ts new file mode 100644 index 0000000..baef8d0 --- /dev/null +++ b/src/components/whatsapp/index.ts @@ -0,0 +1,7 @@ + +// Export all WhatsApp components for easier imports +export { default as CreateInstanceForm } from './CreateInstanceForm'; +export { default as InstanceList } from './InstanceList'; +export { default as InstanceStats } from './InstanceStats'; +export { default as QrCodeDialog } from './QrCodeDialog'; +export { default as InstanceCard } from './InstanceCard'; diff --git a/src/pages/WhatsApp.tsx b/src/pages/WhatsApp.tsx index 68fd6a5..4f00d7a 100644 --- a/src/pages/WhatsApp.tsx +++ b/src/pages/WhatsApp.tsx @@ -76,7 +76,7 @@ const WhatsApp = () => {
- +
{ setOpen={setQrDialogOpen} instanceName={activeInstance.instanceName} phoneNumber={activeInstance.phoneNumber} + onStatusCheck={checkAllInstancesStatus} /> )}