Fix CreateInstanceForm and userOperations errors
Fixed type errors in CreateInstanceForm.tsx and userOperations.ts related to argument counts, property definitions, and Supabase update calls. Corrected the WhatsAppInstance type definition and ensured correct data passing to Supabase.
This commit is contained in:
parent
7bf6cdd8ce
commit
3e3b931ca7
@ -9,7 +9,7 @@ import { Loader2, Plus, AlertCircle } from 'lucide-react';
|
|||||||
import { useToast } from '@/hooks/use-toast';
|
import { useToast } from '@/hooks/use-toast';
|
||||||
import { restartInstance } from '@/services/whatsAppService';
|
import { restartInstance } from '@/services/whatsAppService';
|
||||||
import { WhatsAppInstance } from '@/types/whatsAppTypes';
|
import { WhatsAppInstance } from '@/types/whatsAppTypes';
|
||||||
import { updateUserWhatsAppInstance } from '@/services/whatsAppInstanceService';
|
import { updateUserWhatsAppInstance } from '@/services/whatsAppInstance/userOperations';
|
||||||
import { createEvolutionWebhook } from '@/services/whatsApp/webhookService';
|
import { createEvolutionWebhook } from '@/services/whatsApp/webhookService';
|
||||||
|
|
||||||
interface CreateInstanceFormProps {
|
interface CreateInstanceFormProps {
|
||||||
@ -77,13 +77,14 @@ const CreateInstanceForm = ({ onInstanceCreated, initialInstanceName = '' }: Cre
|
|||||||
qrcode: response.qrcode || null,
|
qrcode: response.qrcode || null,
|
||||||
status: response.instance.state === 'open' ? 'connected' : 'disconnected',
|
status: response.instance.state === 'open' ? 'connected' : 'disconnected',
|
||||||
lastSeen: new Date().toISOString(),
|
lastSeen: new Date().toISOString(),
|
||||||
presence: 'offline'
|
presence: 'offline',
|
||||||
|
userId: normalizedEmail
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('✅ Instância criada:', instanceData);
|
console.log('✅ Instância criada:', instanceData);
|
||||||
|
|
||||||
// Atualizar no banco de dados local
|
// Atualizar no banco de dados local com o número de telefone
|
||||||
await updateUserWhatsAppInstance(normalizedEmail, normalizedEmail, 'conectado');
|
await updateUserWhatsAppInstance(normalizedEmail, normalizedEmail, 'conectado', fullPhoneNumber);
|
||||||
|
|
||||||
// Criar webhook na Evolution API
|
// Criar webhook na Evolution API
|
||||||
await createEvolutionWebhook(normalizedEmail);
|
await createEvolutionWebhook(normalizedEmail);
|
||||||
|
|||||||
@ -7,7 +7,8 @@ import { supabase } from "@/integrations/supabase/client";
|
|||||||
export async function updateUserWhatsAppInstance(
|
export async function updateUserWhatsAppInstance(
|
||||||
userEmail: string,
|
userEmail: string,
|
||||||
instanceName: string,
|
instanceName: string,
|
||||||
status: string
|
status: string,
|
||||||
|
phoneNumber?: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
// ⚠️ PADRONIZAÇÃO CRÍTICA: Converter email para lowercase
|
// ⚠️ PADRONIZAÇÃO CRÍTICA: Converter email para lowercase
|
||||||
@ -30,12 +31,19 @@ export async function updateUserWhatsAppInstance(
|
|||||||
|
|
||||||
if (existingUser) {
|
if (existingUser) {
|
||||||
// Atualizar registro existente
|
// Atualizar registro existente
|
||||||
const { error: updateError } = await supabase
|
const updateData: any = {
|
||||||
.from('usuarios')
|
|
||||||
.update({
|
|
||||||
instancia_zap: normalizedInstanceName,
|
instancia_zap: normalizedInstanceName,
|
||||||
status_instancia: status
|
status_instancia: status
|
||||||
})
|
};
|
||||||
|
|
||||||
|
// Adicionar telefone se fornecido
|
||||||
|
if (phoneNumber) {
|
||||||
|
updateData.whatsapp = phoneNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { error: updateError } = await supabase
|
||||||
|
.from('usuarios')
|
||||||
|
.update(updateData)
|
||||||
.eq('email', normalizedEmail);
|
.eq('email', normalizedEmail);
|
||||||
|
|
||||||
if (updateError) {
|
if (updateError) {
|
||||||
@ -45,14 +53,17 @@ export async function updateUserWhatsAppInstance(
|
|||||||
|
|
||||||
console.log(`✅ Instância WhatsApp atualizada para ${normalizedEmail}: ${normalizedInstanceName} (${status})`);
|
console.log(`✅ Instância WhatsApp atualizada para ${normalizedEmail}: ${normalizedInstanceName} (${status})`);
|
||||||
} else {
|
} else {
|
||||||
// Criar novo registro
|
// Criar novo registro - whatsapp é obrigatório na inserção
|
||||||
const { error: insertError } = await supabase
|
const insertData = {
|
||||||
.from('usuarios')
|
|
||||||
.insert({
|
|
||||||
email: normalizedEmail,
|
email: normalizedEmail,
|
||||||
instancia_zap: normalizedInstanceName,
|
instancia_zap: normalizedInstanceName,
|
||||||
status_instancia: status
|
status_instancia: status,
|
||||||
});
|
whatsapp: phoneNumber || '00000000000' // Valor padrão se não fornecido
|
||||||
|
};
|
||||||
|
|
||||||
|
const { error: insertError } = await supabase
|
||||||
|
.from('usuarios')
|
||||||
|
.insert(insertData);
|
||||||
|
|
||||||
if (insertError) {
|
if (insertError) {
|
||||||
console.error('Erro ao criar registro de instância WhatsApp:', insertError);
|
console.error('Erro ao criar registro de instância WhatsApp:', insertError);
|
||||||
|
|||||||
@ -8,4 +8,5 @@ export interface WhatsAppInstance {
|
|||||||
qrcode?: string | null;
|
qrcode?: string | null;
|
||||||
connectionState?: 'open' | 'closed' | 'connecting' | string;
|
connectionState?: 'open' | 'closed' | 'connecting' | string;
|
||||||
presence?: 'online' | 'offline';
|
presence?: 'online' | 'offline';
|
||||||
|
lastSeen?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user