fix: hooks de listagem de OFs modificados para buscar dados diretos de ordens_fabricacao ativas em vez de ficha_tecnica, inibindo exibir OFs removidas ou excluidas no dropdown, conforme solicitado na revisão

This commit is contained in:
2026-08-13 13:29:56 +00:00
parent 7f810f2b77
commit 216225be72
3 changed files with 49 additions and 15 deletions
+17 -5
View File
@@ -14,17 +14,29 @@ export const useOFsAtivas = () => {
queryKey: ['ofs-ativas'], queryKey: ['ofs-ativas'],
queryFn: async () => { queryFn: async () => {
const { data, error } = await supabase const { data, error } = await supabase
.from('ficha_tecnica_contratos') .from('ordens_fabricacao')
.select('of_number, descricao_resumida, cliente, gestor') .select(`
.not('of_number', 'is', null) num_of,
.order('of_number'); descritivo,
gestor,
ficha_tecnica_contratos (
cliente
)
`)
.eq('status', 'ativa')
.order('num_of');
if (error) { if (error) {
console.error('Erro ao buscar OFs ativas:', error); console.error('Erro ao buscar OFs ativas:', error);
throw error; throw error;
} }
return data as OFAtiva[]; return data.map((of: any) => ({
of_number: of.num_of,
descricao_resumida: of.descritivo,
gestor: of.gestor,
cliente: of.ficha_tecnica_contratos?.cliente
})) as OFAtiva[];
}, },
}); });
+16 -5
View File
@@ -182,17 +182,28 @@ export const useTasks = () => {
queryFn: async () => { queryFn: async () => {
console.log('🔍 Fetching available OFs...'); console.log('🔍 Fetching available OFs...');
const { data, error } = await supabase const { data, error } = await supabase
.from('ficha_tecnica_contratos') .from('ordens_fabricacao')
.select('of_number, cliente') .select(`
.order('of_number'); num_of,
ficha_tecnica_contratos (
cliente
)
`)
.eq('status', 'ativa')
.order('num_of');
if (error) { if (error) {
console.error('❌ Error fetching OFs:', error); console.error('❌ Error fetching OFs:', error);
throw error; throw error;
} }
console.log('✅ Available OFs fetched:', data?.length || 0); const mappedData = data?.map((of: any) => ({
return data || []; of_number: of.num_of,
cliente: of.ficha_tecnica_contratos?.cliente
}));
console.log('✅ Available OFs fetched:', mappedData?.length || 0);
return mappedData || [];
}, },
}); });
+16 -5
View File
@@ -316,17 +316,28 @@ export const useTasksEnhanced = () => {
if (!user) throw new Error('Usuário não autenticado'); if (!user) throw new Error('Usuário não autenticado');
const { data, error } = await supabase const { data, error } = await supabase
.from('ficha_tecnica_contratos') .from('ordens_fabricacao')
.select('of_number, cliente') .select(`
.order('of_number'); num_of,
ficha_tecnica_contratos (
cliente
)
`)
.eq('status', 'ativa')
.order('num_of');
if (error) { if (error) {
console.error('❌ Error fetching OFs:', error); console.error('❌ Error fetching OFs:', error);
throw error; throw error;
} }
console.log('✅ Available OFs fetched:', data?.length || 0); const mappedData = data?.map((of: any) => ({
return data || []; of_number: of.num_of,
cliente: of.ficha_tecnica_contratos?.cliente
}));
console.log('✅ Available OFs fetched:', mappedData?.length || 0);
return mappedData || [];
}, },
enabled: !!user, enabled: !!user,
}); });