Fix: Resolve TypeScript error in RegisterForm
The commit addresses a TypeScript error in `RegisterForm.tsx` related to the `whatsapp` field. The error message "Object literal may only specify known properties, and 'whatsapp' does not exist in type" indicates that the `whatsapp` field is not correctly recognized within the object being used.
This commit is contained in:
parent
13db2b6b01
commit
bd322c9f45
@ -22,7 +22,7 @@ const RegisterForm = ({ isLoading, setIsLoading }: RegisterFormProps) => {
|
||||
const [nome, setNome] = useState('');
|
||||
const [empresa, setEmpresa] = useState('');
|
||||
const [email, setEmail] = useState('');
|
||||
const [whatsapp, setWhatsapp] = useState('55');
|
||||
const [whatsapp, setWhatsapp] = useState('55()');
|
||||
const [senha, setSenha] = useState('');
|
||||
const [confirmaSenha, setConfirmaSenha] = useState('');
|
||||
|
||||
@ -37,13 +37,19 @@ const RegisterForm = ({ isLoading, setIsLoading }: RegisterFormProps) => {
|
||||
}
|
||||
|
||||
// Formata com parênteses para o DDD
|
||||
if (nums.length > 7) {
|
||||
return `${nums.slice(0, 2)}(${nums.slice(2, 4)})${nums.slice(4)}`;
|
||||
} else if (nums.length > 4) {
|
||||
return `${nums.slice(0, 2)}(${nums.slice(2)}`;
|
||||
if (nums.length > 4) {
|
||||
const codigo = nums.slice(0, 2); // 55
|
||||
const ddd = nums.slice(2, 4); // DDD
|
||||
const numero = nums.slice(4); // Resto do número
|
||||
|
||||
if (nums.length > 6) {
|
||||
return `${codigo}(${ddd})${numero}`;
|
||||
} else {
|
||||
return `${codigo}(${ddd}${numero.length > 0 ? ')' + numero : ''}`;
|
||||
}
|
||||
}
|
||||
|
||||
return nums;
|
||||
return nums.length >= 2 ? `${nums.slice(0, 2)}(${nums.slice(2)}` : nums;
|
||||
};
|
||||
|
||||
// Função para cadastrar usuário
|
||||
@ -79,7 +85,7 @@ const RegisterForm = ({ isLoading, setIsLoading }: RegisterFormProps) => {
|
||||
// Garantir que todos os parâmetros sejam incluídos na chamada para a função registrar_usuario
|
||||
const { data, error } = await supabase.rpc('registrar_usuario', {
|
||||
nome,
|
||||
empresa,
|
||||
empresa: empresa || null,
|
||||
email,
|
||||
senha,
|
||||
whatsapp: whatsappLimpo
|
||||
|
||||
@ -25,3 +25,77 @@
|
||||
// END;
|
||||
// $function$
|
||||
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
|
||||
|
||||
const corsHeaders = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
||||
}
|
||||
|
||||
Deno.serve(async (req) => {
|
||||
// Handle CORS preflight requests
|
||||
if (req.method === 'OPTIONS') {
|
||||
return new Response(null, { headers: corsHeaders })
|
||||
}
|
||||
|
||||
try {
|
||||
const supabaseUrl = Deno.env.get('SUPABASE_URL')!
|
||||
const supabaseServiceKey = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!
|
||||
|
||||
const supabase = createClient(supabaseUrl, supabaseServiceKey)
|
||||
|
||||
console.log('Updating registrar_usuario function...')
|
||||
|
||||
// Update the registrar_usuario function to include whatsapp parameter
|
||||
const { data, error } = await supabase.rpc('exec', {
|
||||
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
|
||||
RETURN novo_usuario_id;
|
||||
END;
|
||||
$function$
|
||||
`
|
||||
})
|
||||
|
||||
if (error) {
|
||||
console.error('Error updating function:', error)
|
||||
return new Response(JSON.stringify({ error: error.message }), {
|
||||
status: 500,
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
|
||||
})
|
||||
}
|
||||
|
||||
console.log('Function updated successfully')
|
||||
|
||||
return new Response(JSON.stringify({
|
||||
message: 'registrar_usuario function updated successfully',
|
||||
data
|
||||
}), {
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
|
||||
})
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error:', error)
|
||||
return new Response(JSON.stringify({ error: error.message }), {
|
||||
status: 500,
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user