Fix: Resolve "Nova Despesa" button issue
The AI will address the issue where the "Nova Despesa" button causes problems, specifically for the user "leopootz10@gmail.com". The changes will focus on the `TransactionForm.tsx`, `useTransactionForm.ts`, and `TransactionDialogs.tsx` files.
This commit is contained in:
parent
c25272b68f
commit
bfdd935853
@ -1,14 +1,8 @@
|
||||
|
||||
import { FormControl, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue
|
||||
} from "@/components/ui/select";
|
||||
import { UseFormReturn } from "react-hook-form";
|
||||
import { TransactionFormValues } from "@/hooks/useTransactionForm";
|
||||
import { FormField, FormItem, FormLabel, FormControl, FormMessage } from '@/components/ui/form';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { UseFormReturn } from 'react-hook-form';
|
||||
import { TransactionFormValues } from '@/hooks/useTransactionForm';
|
||||
|
||||
interface GroupSelectFieldProps {
|
||||
form: UseFormReturn<TransactionFormValues>;
|
||||
@ -16,30 +10,48 @@ interface GroupSelectFieldProps {
|
||||
}
|
||||
|
||||
export function GroupSelectField({ form, grupos }: GroupSelectFieldProps) {
|
||||
if (grupos.length === 0) return null;
|
||||
console.log('🏷️ GroupSelectField - grupos recebidos:', grupos);
|
||||
|
||||
// Filtrar grupos válidos (com remote_jid não vazio)
|
||||
const gruposValidos = grupos.filter(grupo =>
|
||||
grupo.remote_jid &&
|
||||
grupo.remote_jid.trim() !== '' &&
|
||||
grupo.remote_jid !== null
|
||||
);
|
||||
|
||||
console.log('✅ Grupos válidos para o select:', gruposValidos);
|
||||
|
||||
return (
|
||||
<FormItem>
|
||||
<FormLabel>Grupo WhatsApp (opcional)</FormLabel>
|
||||
<Select
|
||||
onValueChange={(value) => form.setValue("grupo_id", value === "none" ? null : value)}
|
||||
value={form.getValues("grupo_id") || undefined}
|
||||
>
|
||||
<FormControl>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Selecione um grupo (opcional)" />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent>
|
||||
<SelectItem value="none">Nenhum grupo</SelectItem>
|
||||
{grupos.map((grupo) => (
|
||||
<SelectItem key={grupo.remote_jid} value={grupo.remote_jid}>
|
||||
{grupo.nome_grupo || grupo.remote_jid}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="grupo_id"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Grupo (Opcional)</FormLabel>
|
||||
<Select
|
||||
onValueChange={(value) => field.onChange(value || null)}
|
||||
value={field.value || ""}
|
||||
>
|
||||
<FormControl>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Selecione um grupo (opcional)" />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent>
|
||||
<SelectItem value="">Nenhum grupo</SelectItem>
|
||||
{gruposValidos.map((grupo) => (
|
||||
<SelectItem
|
||||
key={grupo.remote_jid}
|
||||
value={grupo.remote_jid}
|
||||
>
|
||||
{grupo.nome_grupo || 'Grupo sem nome'}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
@ -39,6 +38,7 @@ export const useTransactionForm = (
|
||||
|
||||
if (!userEmail) {
|
||||
console.error('❌ Email do usuário não encontrado no localStorage');
|
||||
setGrupos([]);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -59,18 +59,28 @@ export const useTransactionForm = (
|
||||
|
||||
if (error) {
|
||||
console.error('❌ Erro ao buscar grupos:', error);
|
||||
// Não bloquear o formulário se não conseguir buscar grupos
|
||||
setGrupos([]);
|
||||
} else if (data) {
|
||||
console.log(`✅ ${data.length} grupos encontrados`);
|
||||
setGrupos(data);
|
||||
// Filtrar grupos que têm remote_jid válido (não vazio e não null)
|
||||
const gruposValidos = data.filter(grupo =>
|
||||
grupo.remote_jid &&
|
||||
grupo.remote_jid.trim() !== '' &&
|
||||
grupo.remote_jid !== null
|
||||
);
|
||||
|
||||
console.log(`✅ ${data.length} grupos encontrados, ${gruposValidos.length} grupos válidos`);
|
||||
|
||||
if (gruposValidos.length !== data.length) {
|
||||
console.warn('⚠️ Alguns grupos foram filtrados por terem remote_jid inválido');
|
||||
}
|
||||
|
||||
setGrupos(gruposValidos);
|
||||
} else {
|
||||
console.log('📝 Nenhum grupo encontrado, definindo array vazio');
|
||||
setGrupos([]);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('💥 Erro inesperado ao buscar grupos:', error);
|
||||
// Garantir que sempre temos um array vazio em caso de erro
|
||||
setGrupos([]);
|
||||
}
|
||||
}, []);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user