Commit Graph

232 Commits

Author SHA1 Message Date
simone 43238341c1 feat: service offer tags, catalog cleanup, offer editor filter
- Import 58 offer membership tags for all 55 services (entity_type="services")
  via scripts/import-service-offer-tags.ts (already run on prod)
- ServiceTable: remove Categoria column, rename Tag → Offerta; QuickAddRow
  no longer has a category field (offer tags set post-creation)
- offer-queries: getOfferEditorData fetches offerTags per service (join on
  tags WHERE entity_type="services") and exposes them in OfferEditorData
- OfferEditorClient: filter chips above "Servizi Inclusi" — Tutti / Entry
  Offer / Signature Offer / Retainer Offer, derived from actual tag data

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 21:58:34 +02:00
simone 696a95950c chore: add Notion service import scripts
scripts/reset-and-import-services.ts — deletes 3 legacy test services,
imports 55 services from Notion "DB Offerta: Attività SC" CSV export
(Signature Offer / Entry Offer / Retainer Offer, with fase metadata).

scripts/import-services-notion.ts — standalone idempotent version.

Run via SSH tunnel with DATABASE_URL pointed at 127.0.0.1:54321.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 21:46:17 +02:00
simone 27e8706e39 fix(offer-editor): show all services regardless of offer category
offer_macros.category ("Entry Offer") and services.category are different
taxonomies — filtering one by the other always returns empty. Remove the
client-side category filter; all active services are always shown.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 18:35:37 +02:00
simone 4f7e0033c4 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>
2026-06-18 18:25:50 +02:00
simone 56f9fd1d07 docs(phase-12): complete phase execution
Phase 12 (Offer Editor: Tier A/B/C, Tag & Prezzo Pubblico) fully executed
and verified. All 5 plans complete, build gate passed, 5/5 requirements
confirmed in codebase (OFFER-11, OFFER-15, OFFER-16, OFFER-17, OFFER-18).

- 12-REVIEW.md: 0 critical, 6 warnings, 4 info (advisory, non-blocking)
- 12-VERIFICATION.md: all requirements PASS
- REQUIREMENTS.md: OFFER-11/15/16/17/18 → Complete
- STATE.md: advanced to Phase 13 as next

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 17:24:19 +02:00
simone 9a74e5ccfa docs(phase-12): update tracking after wave 4
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-15 10:31:07 +02:00
simone 791a6e64b1 chore: merge executor worktree (worktree-agent-a44f854f45ac76582) 2026-06-15 10:28:07 +02:00
simone 605dc323b6 chore: merge executor worktree (worktree-agent-a26188c3b00c610ed) 2026-06-15 10:27:55 +02:00
simone a486d27a2b docs(12-04): append self-check results to plan summary 2026-06-15 10:26:58 +02:00
simone ca3712612f docs(12-04): add plan summary for offer list page redesign 2026-06-15 10:26:38 +02:00
simone b7203c3da2 docs(12-05): complete offer editor detail page plan
- Add 12-05-SUMMARY.md documenting OfferEditorClient + edit route
2026-06-15 10:26:24 +02:00
simone 7df4b9c74a feat(12-04): build OfferListClient with category filter, archive toggle, card grid
- Category filter chips ("Tutti" + dynamic categoryOptions), active/inactive
  styling per UI-SPEC (#1A463C / #e5e7eb)
- "Mostra offerte archiviate" toggle (default off), filters via useMemo
- Responsive card grid (1/2/3 cols) linking to /admin/offers/[id]/edit,
  with category badge and "Archiviata" indicator
- "+ Nuova Offerta" inline form calling createOfferMacro via useTransition
  + router.refresh()
- Empty state with "Nessuna offerta" / "Inizia creando la tua prima offerta"
2026-06-15 10:25:15 +02:00
simone 68dc1b605b feat(12-04): rewrite /admin/offers page.tsx as new list page entry point
- Replace legacy macro/micro/offer_services CRUD page with thin server
  component fetching getOfferListCards() + getOfferFieldOptions()
- Delegate rendering to new OfferListClient (Task 2)
2026-06-15 10:25:03 +02:00
simone 8c5c918304 feat(12-05): build offer editor client component
- Add OfferEditorClient: full editor for /admin/offers/[id]/edit
- Categoria/Ticket single-select (OptionSelect) + Tipo/Obiettivo
  multi-select with on-the-fly creation (OptionMultiSelect)
- Services matrix (A/B/C checkboxes) pre-filtered by macro.category,
  with live "Totale Servizi" recalculation via useMemo (OFFER-11)
- Independent manual "Prezzo Pubblico" per tier (OFFER-16)
- 5-field "Promessa di Trasformazione" block via EditableCell (OFFER-17)
- Salva Offerta / Annulla / Archivia actions wired to saveOfferEditor,
  toggleOfferArchived and renameOfferOption (OFFER-15)
2026-06-15 10:25:02 +02:00
simone 8e0e4b9c59 feat(12-05): create offer editor route server component
- Add src/app/admin/offers/[id]/edit/page.tsx as async server component
- Fetches getOfferEditorData(id) + getOfferFieldOptions() via Promise.all
- Calls notFound() when offer id does not exist
- Delegates rendering to OfferEditorClient
2026-06-15 10:24:49 +02:00
simone e46607d217 docs(phase-12): update tracking after wave 3
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-15 10:19:52 +02:00
simone f01fa347c4 chore: merge executor worktree (worktree-agent-acd37263857560e21) 2026-06-15 10:19:13 +02:00
simone 8bdc854a6a docs(12-03): complete offer editor query layer & server actions plan
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 10:18:46 +02:00
simone a372c613e2 feat(12-03): add offer editor server actions
- saveOfferEditor(macroId, payload): persists macro scalars, per-tier
  upsert (tier_letter Zod-validated A/B/C), offer_tier_services
  delete-then-reinsert, and Tipo/Obiettivo tags delete-then-reinsert,
  all in one call
- toggleOfferArchived(macroId, archived) for OFFER-18
- addOfferTag/removeOfferTag/renameOfferOption for Tipo/Obiettivo/
  Categoria/Ticket dimensions, mirroring catalog option-pool pattern
- createOfferMacro(formData) — Plan 04 "+ Nuova Offerta" target
- scripts/verify-12-03-actions.ts documents the 9 spec'd test cases
  (typecheck-only, requireAdmin needs a request context)
2026-06-15 10:17:07 +02:00
simone 0d742f2328 feat(12-03): add offer editor query layer
- getOfferListCards() for Plan 04 list page (category + archive status)
- getOfferEditorData(macroId) returns macro fields, A/B/C tiers with
  assignedServiceIds + computed servicesTotal, category-filtered
  availableServices, and tipoTags/obiettivoTags
- getOfferFieldOptions() for categoria/ticket/tipo/obiettivo select pools
- scripts/verify-12-03-queries.ts documents the 5 spec'd test cases
  (typecheck-only, no test runner configured, prod DB not mutated)
2026-06-15 10:15:19 +02:00
simone e2d6e97168 docs(phase-12): update tracking after wave 2 checkpoint
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-15 09:50:23 +02:00
simone d4c89b4170 docs(12-02): apply migration 0008 to production (blocking checkpoint complete)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-15 09:50:23 +02:00
simone b8f14fad4d docs(phase-12): update tracking after wave 1
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-14 21:22:37 +02:00
simone 827604084e chore: merge executor worktree (worktree-agent-ab7d5b1ee10efadff) 2026-06-14 21:22:10 +02:00
simone b80f0563b8 docs(12-01): fix markdown lint formatting in summary
- Add blank lines around headings and lists per MD022/MD032
2026-06-14 21:21:37 +02:00
simone bfc99329c5 docs(12-01): complete offer tier schema foundation plan
- Add 12-01-SUMMARY.md documenting additive schema extension, migration 0008, and push script
2026-06-14 21:20:28 +02:00
simone 89d15eeb54 feat(12-01): add migration 0008 for offer tier schema + idempotent push script
- Hand-write 0008_offer_tier_schema.sql: additive ALTER TABLE ADD COLUMN IF NOT EXISTS for offer_macros/offer_micros, guarded DO-block CHECK constraint on tier_letter, CREATE TABLE IF NOT EXISTS offer_tier_services + index
- Append journal entry for 0008_offer_tier_schema following the 0006 entry shape
- Add scripts/push-12-offer-tier-schema.ts: idempotent push script with PRODUCTION DEPLOY NOTE — BLOCKING step for Plan 02 (SSH+docker exec) before Wave 3 query layer
2026-06-14 21:19:10 +02:00
simone 11d6c1179f feat(12-01): extend offer schema with tier, pricing, and category fields
- Add additive offer_macros columns: description, category, ticket, is_archived, and structured transformation-promise fields (cliente_ideale/risultato/tempo/pain/metodo)
- Add additive offer_micros columns: tier_letter (A/B/C, CHECK constraint added in migration 0008) and public_price
- Add new offer_tier_services junction table (offer_micros <-> services), relations, and types
- Extend offerMicrosRelations with tierServices; legacy offer_micro_services/offer_services untouched
2026-06-14 21:17:52 +02:00
simone 1414c3e95c docs(12): finalize wave resequencing in plans and tracking
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-14 21:15:09 +02:00
simone 640f986967 docs(12): create phase plan
Re-scoped Offer Editor (Tier A/B/C, Tag & Prezzo Pubblico) per 2026-06-14
user decision: 5-plan wave structure (schema migration -> prod apply
checkpoint -> query/action layer -> list + detail editor UI), OFFER-12
CSV/Notion import deferred.
2026-06-14 21:00:32 +02:00
simone 9bff7623da docs: move CRM Attio-style requirements to Validated (Phase 14)
PROJECT.md: CRM-08..12 moved from Active to Validated in v2.1,
referencing Phase 14 completion.
2026-06-14 15:27:07 +02:00
simone fa5672025f docs(14): mark phase complete, advance roadmap to Phase 15
phase complete 14: ROADMAP plans/progress, STATE position (Phase 15
next, blocked on user mockup), REQUIREMENTS CRM-08..12 -> Complete.
2026-06-14 15:22:40 +02:00
simone 2c227f4ef1 docs(14): add code review report and phase verification (passed)
14-REVIEW.md: 0 critical, 6 warnings, 3 info (standard depth, 11 files).
14-VERIFICATION.md: 5/5 success criteria verified after closing the
SC5/CRM-12 generate_new dead-branch gap.
2026-06-14 15:20:08 +02:00
simone c8d53134ba fix(14): remove dead generate_new branch from assignQuoteToLead (CRM-12)
assignQuoteToLead's generate_new check was unreachable since
SendQuoteModal always passed false. Removes the field from both
the server schema and the modal's local schema/defaultValues/call site.
2026-06-14 15:17:48 +02:00
simone 0378ba78a9 Merge branch 'worktree-agent-a260f91fada48defd' 2026-06-14 13:25:23 +02:00
simone 2a02ca8fbf docs(14-02): add plan summary for LeadTable Attio rewrite 2026-06-14 13:24:47 +02:00
simone ab7fa62059 feat(14-02): add LeadsSearch, rewire leads pages, surface tags in LeadDetail (CRM-08/09)
- New LeadsSearch.tsx: client-side instant filter across name/email/
  company/status/tags (mirrors CatalogSearch.tsx)
- page.tsx: fetch via getLeadsWithTags()/getLeadFieldOptions(), render
  LeadsSearch + CreateLeadModal, revalidate=0
- [id]/page.tsx: fetch getLeadsWithTags()/getLeadFieldOptions(), find
  lead by id, pass tags/tagOptions to LeadDetail
- LeadDetail.tsx: add OptionMultiSelect for lead tags in the "Profilo"
  card, wired to addLeadTag/removeLeadTag/renameLeadTag with error display
2026-06-14 13:21:55 +02:00
simone 4887a319f7 feat(14-02): rewrite LeadTable as raw-table database view (CRM-08/09)
Replace shadcn Table-based read-only LeadTable with an Attio-style raw
table database view (1:1 structural port of ServiceTable.tsx):
- EditableCell for name/email/phone/company/next_action, persisted via
  updateLeadField
- Local StatusCell: closed click-to-open dropdown over the 6 fixed
  LEAD_STAGES values, preserving semantic STAGE_COLOR badges (won=green,
  lost=red, etc.) without modifying shared option-select.tsx
- OptionMultiSelect for lead tags, wired to addLeadTag/removeLeadTag/
  renameLeadTag
- Per-row error display and "Nessun lead trovato" empty state
2026-06-14 13:21:23 +02:00
simone 39bd1ce2eb chore: merge executor worktree (worktree-agent-aaf61d7161f7818a0)
# Conflicts:
#	.planning/phases/14-crm-attio-style-fix/deferred-items.md
2026-06-14 12:51:37 +02:00
simone d664d8d3a7 chore: merge executor worktree (worktree-agent-a6c4f07a973e2df91) 2026-06-14 12:50:54 +02:00
simone 3c53672754 docs(14-03): append self-check results to plan summary 2026-06-14 12:49:41 +02:00
simone 6b51403404 docs(14-03): complete CRM residual bug fixes plan
Summary for 14-03: FollowUpWidget Italian translation (CRM-10), LeadForm typed useForm (CRM-11) + shared FormField generic fix, SendQuoteModal dead branch removal (CRM-12)
2026-06-14 12:48:53 +02:00
simone a495d84511 fix(14-03): remove dead onSubmit branch in SendQuoteModal (CRM-12)
- Remove unreachable if (tab === "new") branch in onSubmit - the new-tab button has its own onClick navigation and never triggers form submit
- Escape unescaped double quotes in JSX text (react/no-unescaped-entities)
- generate_new field left as-is per plan (optional cleanup, out of scope)
- Log pre-existing useForm<any>/onSubmit(data: any) no-explicit-any lint errors to deferred-items.md (out of scope: fixing requires resolving a zodResolver/Resolver generic incompatibility with assignQuoteSchema's optional/default fields)
2026-06-14 12:46:55 +02:00
simone f21f13909d docs(14-01): append self-check results to SUMMARY
- Verified created/modified files exist and task commits are present
  in git history
2026-06-14 12:44:19 +02:00
simone d1acfe9127 docs(14-01): complete lead data-layer foundation plan
- SUMMARY documents getLeadsWithTags/getLeadFieldOptions and
  updateLeadField/addLeadTag/removeLeadTag/renameLeadTag additions
- Logs 2 pre-existing lint issues (deferred-items.md) unrelated to
  this plan's changes
2026-06-14 12:43:21 +02:00
simone ee509cd5fb fix(14-03): type LeadForm useForm with CreateLeadInput (CRM-11)
- CreateLeadModal and EditLeadModal use useForm<CreateLeadInput>() instead of useForm<any>()
- Import CreateLeadInput from lead-validators, remove local z.infer redeclaration
- Narrow EditLeadModal status default value to CreateLeadInput["status"], remove 'as any'
- Fix FormField generic signature in shared ui/form.tsx (was ControllerProps<any, any>, broke Control<T> assignability once useForm<T> became concrete) - Rule 3 blocking issue
2026-06-14 12:43:00 +02:00
simone 7d98b27e75 feat(14-01): add updateLeadField and lead tag CRUD server actions
- requireAdmin() guard (mirrors catalog/actions.ts pattern), throws
  "Non autorizzato" before any DB access
- updateLeadField: EDITABLE_FIELDS allowlist, name/status validated
  server-side (LEAD_STAGES.includes), nullable fields cleared on empty
- addLeadTag/removeLeadTag/renameLeadTag: polymorphic tags table scoped
  to entity_type="leads" (LEADS_TAG_ENTITY), never touches
  entity_type="services" rows
- All four actions call revalidatePath for /admin/leads (+ detail page
  where a single leadId applies)
- Log pre-existing lint issues (unrelated to this task) to
  deferred-items.md per scope-boundary rule
2026-06-14 12:41:36 +02:00
simone 272e363f4d fix(14-03): translate FollowUpWidget to Italian (CRM-10)
- Replace 6 hardcoded English strings with Italian equivalents
- Remove pluralization ternary (Italian "lead" is invariant)
2026-06-14 12:38:12 +02:00
simone 5b583bcc5e feat(14-01): add getLeadsWithTags and getLeadFieldOptions to admin-queries
- LeadWithTags type + getLeadsWithTags() left-joins leads with tags
  scoped to entity_type="leads", Map-reduce pattern mirroring
  getAllServices (Phase 11)
- LeadFieldOptions type + getLeadFieldOptions() returns fixed
  LEAD_STAGES for status and distinct sorted lead tag names
- desc import added to drizzle-orm import; LEAD_STAGES imported from
  lib/lead-validators
2026-06-14 12:38:09 +02:00
simone f5309345b9 docs(14): annotate plan waves and update milestone progress
Wave-dependency annotations for Phase 14 (14-01/14-03 wave 1, 14-02 wave 2)
and corrected v2.1 progress tracking (4/7 plans, current focus → Phase 14).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-14 12:30:38 +02:00