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'],
queryFn: async () => {
const { data, error } = await supabase
.from('ficha_tecnica_contratos')
.select('of_number, descricao_resumida, cliente, gestor')
.not('of_number', 'is', null)
.order('of_number');
.from('ordens_fabricacao')
.select(`
num_of,
descritivo,
gestor,
ficha_tecnica_contratos (
cliente
)
`)
.eq('status', 'ativa')
.order('num_of');
if (error) {
console.error('Erro ao buscar OFs ativas:', 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 () => {
console.log('🔍 Fetching available OFs...');
const { data, error } = await supabase
.from('ficha_tecnica_contratos')
.select('of_number, cliente')
.order('of_number');
.from('ordens_fabricacao')
.select(`
num_of,
ficha_tecnica_contratos (
cliente
)
`)
.eq('status', 'ativa')
.order('num_of');
if (error) {
console.error('❌ Error fetching OFs:', error);
throw error;
}
console.log('✅ Available OFs fetched:', data?.length || 0);
return data || [];
const mappedData = data?.map((of: any) => ({
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');
const { data, error } = await supabase
.from('ficha_tecnica_contratos')
.select('of_number, cliente')
.order('of_number');
.from('ordens_fabricacao')
.select(`
num_of,
ficha_tecnica_contratos (
cliente
)
`)
.eq('status', 'ativa')
.order('num_of');
if (error) {
console.error('❌ Error fetching OFs:', error);
throw error;
}
console.log('✅ Available OFs fetched:', data?.length || 0);
return data || [];
const mappedData = data?.map((of: any) => ({
of_number: of.num_of,
cliente: of.ficha_tecnica_contratos?.cliente
}));
console.log('✅ Available OFs fetched:', mappedData?.length || 0);
return mappedData || [];
},
enabled: !!user,
});