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
18 changes: 16 additions & 2 deletions src/hooks/quotes/useQuoteBuilderState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,15 @@ export function useQuoteBuilderState() {
fetchQuote(quoteId).then((quote) => {
if (quote) {
setClientId(quote.client_id || '');
setContactId(quote.client_id || '');
/**
* BUG-02 FIX: usar contact_id (ID do contato) em vez de client_id (ID da empresa).
*
* PROBLEMA ORIGINAL: setContactId recebia quote.client_id, ou seja, o ID da
* empresa. Isso fazia a validação do step 'client' passar (ambos clientId e
* contactId != ''), mas semanticamente errada — contactId deveria ser o ID
* da pessoa de contato, não da empresa.
*/
setContactId((quote as Record<string, unknown>).contact_id as string || '');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Load contactId from a field that actually exists

fetchQuote returns a Quote, but this code now reads quote.contact_id via a cast even though the current quote model/schema does not expose that field (see Quote in src/hooks/quotes/quoteTypes.ts and quotes.Row in src/integrations/supabase/types.ts), so contactId resolves to '' for edited quotes. Because the client step is only considered complete when both clientId and contactId are set (useQuoteBuilderState.ts line 221), edit flows lose their preselected contact and can be blocked from completing/saving unless the user manually reselects a contact (or cannot proceed at all when no contacts are available).

Useful? React with 👍 / 👎.

Comment on lines +455 to +462
setValidUntil(quote.valid_until || format(addDays(new Date(), 30), 'yyyy-MM-dd'));
setNotes(quote.notes || '');
setInternalNotes(quote.internal_notes || '');
Expand Down Expand Up @@ -699,9 +707,15 @@ export function useQuoteBuilderState() {
placeholderData: (previousData) => previousData,
});

/**
* BUG-05 FIX: removida dependência fantasma `productSearch`.
*
* PROBLEMA ORIGINAL: productSearch estava na lista de deps mas nunca era usado
* no corpo do useMemo — causava re-computações desnecessárias a cada keystroke.
*/
const filteredProducts = useMemo(() => {
return products || [];
}, [products, productSearch]);
}, [products]);

// ── Calculations ──
const formatCurrency = useCallback((value: number) => {
Expand Down
Loading