Fix: Resolve conflicting star exports in WhatsApp instance service
The error "conflicting star exports for name 'updateUserWhatsAppInstance'" indicates a naming conflict when re-exporting modules. This commit resolves the issue by explicitly re-exporting the conflicting functions in `src/services/whatsAppInstance/index.ts` to avoid the conflict.
This commit is contained in:
parent
27cad3b98b
commit
7bf6cdd8ce
@ -7,7 +7,7 @@ import { Label } from '@/components/ui/label';
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert';
|
||||
import { Loader2, Plus, AlertCircle } from 'lucide-react';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import { createInstance } from '@/services/whatsAppService';
|
||||
import { restartInstance } from '@/services/whatsAppService';
|
||||
import { WhatsAppInstance } from '@/types/whatsAppTypes';
|
||||
import { updateUserWhatsAppInstance } from '@/services/whatsAppInstanceService';
|
||||
import { createEvolutionWebhook } from '@/services/whatsApp/webhookService';
|
||||
@ -23,7 +23,6 @@ const CreateInstanceForm = ({ onInstanceCreated, initialInstanceName = '' }: Cre
|
||||
const [userEmail, setUserEmail] = useState(initialInstanceName);
|
||||
const [ddd, setDdd] = useState('');
|
||||
const [phoneNumber, setPhoneNumber] = useState('');
|
||||
const [showAdvanced, setShowAdvanced] = useState(false);
|
||||
|
||||
const handleCreateInstance = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
@ -67,7 +66,7 @@ const CreateInstanceForm = ({ onInstanceCreated, initialInstanceName = '' }: Cre
|
||||
console.log(`🚀 Criando instância para: ${normalizedEmail} com número: ${fullPhoneNumber}`);
|
||||
|
||||
// Criar a instância no Evolution API
|
||||
const response = await createInstance(normalizedEmail, fullPhoneNumber);
|
||||
const response = await restartInstance(normalizedEmail, fullPhoneNumber);
|
||||
|
||||
if (response && response.instance) {
|
||||
const instanceData: WhatsAppInstance = {
|
||||
@ -77,7 +76,6 @@ const CreateInstanceForm = ({ onInstanceCreated, initialInstanceName = '' }: Cre
|
||||
connectionState: response.instance.state || 'closed',
|
||||
qrcode: response.qrcode || null,
|
||||
status: response.instance.state === 'open' ? 'connected' : 'disconnected',
|
||||
createdAt: new Date().toISOString(),
|
||||
lastSeen: new Date().toISOString(),
|
||||
presence: 'offline'
|
||||
};
|
||||
@ -210,15 +208,13 @@ const CreateInstanceForm = ({ onInstanceCreated, initialInstanceName = '' }: Cre
|
||||
)}
|
||||
</Button>
|
||||
|
||||
{showAdvanced && (
|
||||
<Alert>
|
||||
<AlertCircle className="h-4 w-4" />
|
||||
<AlertDescription>
|
||||
Após criar a instância, você precisará escanear o QR Code com o WhatsApp
|
||||
do seu celular para estabelecer a conexão.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
<Alert>
|
||||
<AlertCircle className="h-4 w-4" />
|
||||
<AlertDescription>
|
||||
Após criar a instância, você precisará escanear o QR Code com o WhatsApp
|
||||
do seu celular para estabelecer a conexão.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@ -39,7 +39,7 @@ export const createEvolutionWebhook = async (userEmail: string): Promise<any> =>
|
||||
return response;
|
||||
|
||||
} catch (error) {
|
||||
console.error(`❌ Erro ao criar webhook for ${normalizedEmail}:`, error);
|
||||
console.error(`❌ Erro ao criar webhook for ${userEmail}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,6 +1,30 @@
|
||||
|
||||
// Re-export all WhatsApp instance service functions
|
||||
// Re-export all functions from the new modular structure
|
||||
export * from './databaseOperations';
|
||||
export * from './workflowOperations';
|
||||
export * from './userOperations';
|
||||
export * from './config';
|
||||
|
||||
// For backwards compatibility, also export individual functions specifically
|
||||
export {
|
||||
updateUserWhatsAppInstance,
|
||||
getUserWhatsAppInstance,
|
||||
removeUserWhatsAppInstance,
|
||||
getUserDebugInfo
|
||||
} from './databaseOperations';
|
||||
|
||||
export {
|
||||
activateUserWorkflow
|
||||
} from './workflowOperations';
|
||||
|
||||
// Export a helper function to check if user has instance
|
||||
export async function checkUserHasInstance(userEmail: string): Promise<boolean> {
|
||||
try {
|
||||
const { getUserWhatsAppInstance } = await import('./databaseOperations');
|
||||
const instanceData = await getUserWhatsAppInstance(userEmail.trim().toLowerCase());
|
||||
|
||||
return !!(instanceData && instanceData.instancia_zap && instanceData.instancia_zap.trim() !== '');
|
||||
} catch (error) {
|
||||
console.error('Erro ao verificar se usuário tem instância:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,8 +34,7 @@ export async function updateUserWhatsAppInstance(
|
||||
.from('usuarios')
|
||||
.update({
|
||||
instancia_zap: normalizedInstanceName,
|
||||
status_instancia: status,
|
||||
updated_at: new Date().toISOString()
|
||||
status_instancia: status
|
||||
})
|
||||
.eq('email', normalizedEmail);
|
||||
|
||||
@ -52,9 +51,7 @@ export async function updateUserWhatsAppInstance(
|
||||
.insert({
|
||||
email: normalizedEmail,
|
||||
instancia_zap: normalizedInstanceName,
|
||||
status_instancia: status,
|
||||
created_at: new Date().toISOString(),
|
||||
updated_at: new Date().toISOString()
|
||||
status_instancia: status
|
||||
});
|
||||
|
||||
if (insertError) {
|
||||
@ -122,8 +119,7 @@ export async function removeUserWhatsAppInstance(userEmail: string): Promise<voi
|
||||
.update({
|
||||
instancia_zap: null,
|
||||
status_instancia: null,
|
||||
whatsapp: null,
|
||||
updated_at: new Date().toISOString()
|
||||
whatsapp: null
|
||||
})
|
||||
.eq('email', normalizedEmail);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user