From d304d5c9c6176388bb2b7072cf8d102d39348394 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 16:15:10 +0000 Subject: [PATCH] Fix: Add WhatsApp to registration form type The `RegisterForm.tsx` component was updated to include a WhatsApp field. The TypeScript error was resolved by adding the `whatsapp` property to the type definition used for the registration form data. This ensures that the object literal used to pass data to the `supabase.rpc('registrar_usuario')` function includes the `whatsapp` field, resolving the type error. --- src/components/auth/RegisterForm.tsx | 8 +++++ .../update-register-function-sql/index.ts | 1 + .../update-register-function/index.ts | 29 +++++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/components/auth/RegisterForm.tsx b/src/components/auth/RegisterForm.tsx index dd1a7da..a3191bf 100644 --- a/src/components/auth/RegisterForm.tsx +++ b/src/components/auth/RegisterForm.tsx @@ -6,6 +6,8 @@ import { Input } from "@/components/ui/input"; import { useToast } from "@/components/ui/use-toast"; import { supabase } from "@/integrations/supabase/client"; import { enviarDadosParaWebhook } from '@/utils/webhookService'; +import { Label } from '@/components/ui/label'; +import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; interface RegisterFormProps { isLoading: boolean; @@ -114,6 +116,7 @@ const RegisterForm = ({ isLoading, setIsLoading }: RegisterFormProps) => { return (
+ { />
+ { />
+ { />
+ { />
+ { />
+ { } ); - // Update the registrar_usuario function to include the whatsapp parameter - const { data, error } = await supabaseClient.rpc('update_register_function'); + // Execute the SQL to update the function + const { data, error } = await supabaseClient.rpc('update_register_function', { + sql: ` + CREATE OR REPLACE FUNCTION public.registrar_usuario( + nome text, + empresa text, + email text, + senha text, + whatsapp text + ) RETURNS uuid + LANGUAGE plpgsql + SECURITY DEFINER + AS $function$ + DECLARE + novo_usuario_id UUID; + BEGIN + -- Inserir novo usuário com senha hash + INSERT INTO public.usuarios (nome, empresa, email, senha, whatsapp) + VALUES (nome, empresa, email, crypt(senha, gen_salt('bf')), whatsapp) + RETURNING id INTO novo_usuario_id; + + -- Retorna o ID do usuário criado sem criar tabela individual + RETURN novo_usuario_id; + END; + $function$ + ` + }); if (error) throw error;