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.
This commit is contained in:
parent
e75d0058d6
commit
d304d5c9c6
@ -6,6 +6,8 @@ import { Input } from "@/components/ui/input";
|
|||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { supabase } from "@/integrations/supabase/client";
|
import { supabase } from "@/integrations/supabase/client";
|
||||||
import { enviarDadosParaWebhook } from '@/utils/webhookService';
|
import { enviarDadosParaWebhook } from '@/utils/webhookService';
|
||||||
|
import { Label } from '@/components/ui/label';
|
||||||
|
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
|
||||||
|
|
||||||
interface RegisterFormProps {
|
interface RegisterFormProps {
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
@ -114,6 +116,7 @@ const RegisterForm = ({ isLoading, setIsLoading }: RegisterFormProps) => {
|
|||||||
return (
|
return (
|
||||||
<form onSubmit={handleCadastro} className="space-y-4">
|
<form onSubmit={handleCadastro} className="space-y-4">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="nome">Nome completo</Label>
|
||||||
<Input
|
<Input
|
||||||
id="nome"
|
id="nome"
|
||||||
placeholder="Nome completo"
|
placeholder="Nome completo"
|
||||||
@ -124,6 +127,7 @@ const RegisterForm = ({ isLoading, setIsLoading }: RegisterFormProps) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="empresa">Empresa (opcional)</Label>
|
||||||
<Input
|
<Input
|
||||||
id="empresa"
|
id="empresa"
|
||||||
placeholder="Empresa (opcional)"
|
placeholder="Empresa (opcional)"
|
||||||
@ -133,6 +137,7 @@ const RegisterForm = ({ isLoading, setIsLoading }: RegisterFormProps) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="email">Email</Label>
|
||||||
<Input
|
<Input
|
||||||
id="email"
|
id="email"
|
||||||
placeholder="Email"
|
placeholder="Email"
|
||||||
@ -144,6 +149,7 @@ const RegisterForm = ({ isLoading, setIsLoading }: RegisterFormProps) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="whatsapp">WhatsApp (com DDD)</Label>
|
||||||
<Input
|
<Input
|
||||||
id="whatsapp"
|
id="whatsapp"
|
||||||
placeholder="WhatsApp (com DDD)"
|
placeholder="WhatsApp (com DDD)"
|
||||||
@ -155,6 +161,7 @@ const RegisterForm = ({ isLoading, setIsLoading }: RegisterFormProps) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="senha">Senha</Label>
|
||||||
<Input
|
<Input
|
||||||
id="senha"
|
id="senha"
|
||||||
placeholder="Senha"
|
placeholder="Senha"
|
||||||
@ -166,6 +173,7 @@ const RegisterForm = ({ isLoading, setIsLoading }: RegisterFormProps) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="confirma-senha">Confirme a senha</Label>
|
||||||
<Input
|
<Input
|
||||||
id="confirma-senha"
|
id="confirma-senha"
|
||||||
placeholder="Confirme a senha"
|
placeholder="Confirme a senha"
|
||||||
|
|||||||
@ -24,3 +24,4 @@
|
|||||||
// RETURN novo_usuario_id;
|
// RETURN novo_usuario_id;
|
||||||
// END;
|
// END;
|
||||||
// $function$
|
// $function$
|
||||||
|
|
||||||
|
|||||||
@ -31,8 +31,33 @@ serve(async (req) => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update the registrar_usuario function to include the whatsapp parameter
|
// Execute the SQL to update the function
|
||||||
const { data, error } = await supabaseClient.rpc('update_register_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;
|
if (error) throw error;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user