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:
@@ -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
@@ -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 || [];
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user