fix(offer-editor): fix category bug, add ripristina, always-saveable

- Bug: remove server-side category pre-filter from getOfferEditorData;
  services now loaded unfiltered, client-side filter handles display →
  changing category no longer wipes the service list
- Fix tierTotals to use full service map (not filtered subset) so totals
  stay correct when category is edited mid-session
- Add Ripristina button for archived offers (calls toggleOfferArchived false)
- Remove canSave gate: always allow saving; button is "Salva Bozza"
  (secondary style, stays on page) when no services assigned, "Salva
  Offerta" (primary, redirects to list) when at least one tier has services
- Show "Bozza salvata." inline feedback after draft save

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-18 18:25:50 +02:00
parent 56f9fd1d07
commit 4f7e0033c4
2 changed files with 65 additions and 24 deletions
+5 -11
View File
@@ -206,23 +206,17 @@ export async function getOfferEditorData(macroId: string): Promise<OfferEditorDa
servicesTotal: totalsMap.get(tier.id) ?? "0",
}));
// Category-filtered service catalog for the composition matrix (D-4
// pre-filter, best-effort). If macro.category is unset, return all active
// services unfiltered.
const availableServicesQuery = db
// Full service catalog (unfiltered by category) — category filtering happens
// client-side so changing the category field doesn't wipe the service list.
const availableServices = await db
.select({
id: services.id,
name: services.name,
unit_price: services.unit_price,
category: services.category,
})
.from(services);
const availableServices = macro.category
? await availableServicesQuery.where(
and(eq(services.active, true), eq(services.category, macro.category))
)
: await availableServicesQuery.where(eq(services.active, true));
.from(services)
.where(eq(services.active, true));
// Tipo/Obiettivo tags for this macro.
const tagRows = await db