Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import { useState, useCallback, useMemo, useRef } from 'react';
import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
import { supabase } from '@/integrations/supabase/client';
import { invokeExternalDb } from '@/lib/external-db';
import { toast } from 'sonner';
import { sanitizeError } from '@/lib/security/sanitize-error';
import {
Expand Down Expand Up @@ -53,17 +54,13 @@ export function useEngravingWizard(productId: string | undefined, isEdit: boolea
const { data: techniques = [], isLoading: loadingTechs } = useQuery({
queryKey: ['external-techniques-catalog'],
queryFn: async (): Promise<ExternalTechnique[]> => {
const { data, error } = await supabase.functions.invoke('external-db-bridge', {
body: {
table: 'tecnicas_gravacao',
operation: 'select',
orderBy: { column: 'nome', ascending: true },
limit: 200,
},
const result = await invokeExternalDb<ExternalTechnique>({
table: 'tecnicas_gravacao',
operation: 'select',
orderBy: { column: 'nome', ascending: true },
limit: 200,
});
if (error) throw new Error(error.message);
if (!data?.success) throw new Error(data?.error || 'Erro ao buscar técnicas');
return data.data?.records || [];
return result.records || [];
},
staleTime: 10 * 60 * 1000,
});
Expand All @@ -78,18 +75,14 @@ export function useEngravingWizard(productId: string | undefined, isEdit: boolea
const { data: savedAreas = [], isLoading: loadingAreas } = useQuery({
queryKey: ['print-area-techniques', productId],
queryFn: async (): Promise<EnrichedArea[]> => {
const { data, error } = await supabase.functions.invoke('external-db-bridge', {
body: {
table: 'print_area_techniques',
operation: 'select',
filters: { product_id: productId },
orderBy: { column: 'technique_order', ascending: true },
limit: 100,
},
const result = await invokeExternalDb<PrintAreaTechnique>({
table: 'print_area_techniques',
operation: 'select',
filters: { product_id: productId },
orderBy: { column: 'technique_order', ascending: true },
limit: 100,
});
if (error) throw new Error(error.message);
if (!data?.success) throw new Error(data?.error || 'Erro ao buscar áreas');
const records: PrintAreaTechnique[] = data.data?.records || [];
const records: PrintAreaTechnique[] = result.records || [];
Comment on lines +78 to +85
return records.map((area) => enrichArea(area, techById));
},
enabled: !!productId && isEdit && techniques.length > 0,
Expand Down
Loading