From 4f84ab9a9f2b63dfb905fd30663746af1625063e 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 02:24:58 +0000 Subject: [PATCH] Add workflow integration for WhatsApp groups Integrate n8n workflow cloning upon WhatsApp group registration. Adds a `workflow_id` column to the `grupos_whatsapp` table and updates the `cadastrarGrupoWhatsApp` function to call the n8n webhook, capturing the returned workflow ID and saving it to the database. The button "Cadastrar Grupo" is only visible when the user is logged in. --- src/integrations/supabase/types.ts | 3 ++ src/pages/GruposWhatsApp.tsx | 25 +++++++++- src/services/gruposWhatsAppService.ts | 66 +++++++++++++++++++++++++++ src/types/financialTypes.ts | 1 + 4 files changed, 93 insertions(+), 2 deletions(-) diff --git a/src/integrations/supabase/types.ts b/src/integrations/supabase/types.ts index cc77d46..36517b6 100644 --- a/src/integrations/supabase/types.ts +++ b/src/integrations/supabase/types.ts @@ -129,6 +129,7 @@ export type Database = { remote_jid: string status: string | null user_id: string + workflow_id: string | null } Insert: { created_at?: string | null @@ -138,6 +139,7 @@ export type Database = { remote_jid: string status?: string | null user_id: string + workflow_id?: string | null } Update: { created_at?: string | null @@ -147,6 +149,7 @@ export type Database = { remote_jid?: string status?: string | null user_id?: string + workflow_id?: string | null } Relationships: [] } diff --git a/src/pages/GruposWhatsApp.tsx b/src/pages/GruposWhatsApp.tsx index f15a354..5443395 100644 --- a/src/pages/GruposWhatsApp.tsx +++ b/src/pages/GruposWhatsApp.tsx @@ -47,6 +47,15 @@ const GruposWhatsApp = () => { // Cadastrar novo grupo const handleCadastrarGrupo = async () => { + if (!userEmail) { + toast({ + title: 'Erro', + description: 'Você precisa estar logado para cadastrar um grupo', + variant: 'destructive', + }); + return; + } + setCadastrando(true); try { const novoGrupo = await cadastrarGrupoWhatsApp(); @@ -96,7 +105,7 @@ const GruposWhatsApp = () => {