Activity logging and quote sending modals implemented:
- LogActivityModal: Fast form (<10 sec) for registering calls, emails, meetings, notes
- SendQuoteModal: Two tabs for assigning existing quotes or creating new ones
- FollowUpWidget: Dashboard card showing leads needing follow-up (>7 days no contact)
- Server actions validate and update lead status to 'proposal_sent' on quote assignment
All requirements met (CRM-04, CRM-05, CRM-06, CRM-07). Build passes with 0 errors.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Created SendQuoteModal.tsx with two tabs: existing quote (paste token) and create new
- Existing quote tab: paste quote token and submit to link quote to lead
- New quote tab: button redirects to quote builder pre-filled with lead_id
- Added assignQuoteToLead server action to link quote and update lead status to proposal_sent
- Validates quote token existence before linking
- Revalidates lead detail page on successful assignment
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Created LogActivityModal.tsx with form for registering activities (call/email/meeting/note)
- Added type dropdown, date picker, optional duration, notes textarea
- Integrated createActivitySchema validation from lead-validators
- Added logActivity server action to create activity and auto-update lead.last_contact_date
- Updated LeadDetail.tsx to import and render LogActivityModal button
- Revalidates lead detail page on successful activity creation
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Create /admin/leads list page with LeadTable component showing all leads
- Implement /admin/leads/[id] detail page with activity log and reminders
- Add LeadForm component (CreateLeadModal and EditLeadModal) for CRUD operations
- Create server actions (createLead, updateLead, deleteLead) with Zod validation
- Add missing UI components (dialog.tsx, form.tsx) from shadcn
- Install date-fns for date formatting with Italian locale support
- All routes compile successfully with npm run build
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Add TypeScript type exports for Activity, NewActivity, Reminder, NewReminder
- Create lead-validators.ts: Zod schemas for CRUD operations with Italian localization
- Create lead-service.ts: Query layer with 14 functions (leads, activities, reminders)
- Implement immutable activity audit trail with auto-update of lead.last_contact_date
- Add pipeline stage enums (6 stages) and activity type enums (4 types)
- Cascade delete configured for data integrity
- Full TypeScript type safety throughout
- npm run build: PASSED (0 errors)
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- 3 tasks completed (rate limiting, components, page/actions)
- 9 files created, 1 file modified
- Public /quote/[token] route with multistep wizard (3 steps)
- Rate limiting: 3 views/min per IP via proxy middleware
- Immutable quote acceptance with optional email/notes capture
- quote_items never exposed; only accepted_total and phase summary visible
- All threat model mitigations in place
- npm run build: PASS (0 TypeScript errors)
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- layout.tsx: Simple centered public layout (no auth header) with quote branding
- page.tsx: Server component validating token, handling quote states (draft/accepted/rejected)
- actions.ts: Server actions for acceptQuote() and rejectQuote() with immutable accepted_at enforcement
- Validates token format (21-char nanoid), returns 404 for invalid tokens
- Shows 'already accepted' message if quote was previously accepted
- Integrates with QuoteMultistep component for active quotes
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- QuoteMultistep.tsx (110 lines): Parent component managing step state and navigation with visual indicator
- QuoteStep1Overview.tsx: Read-only overview with offer name, total price, and phase list
- QuoteStep2Selection.tsx: Phase/service listing (read-only MVP) with calculated total
- QuoteStep3Summary.tsx: Summary card with optional email and notes capture, Accept/Reject buttons
All components use shadcn/ui with Tailwind styling and follow accessibility patterns.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Enhanced proxy.ts with rate limit check for /quote/[token] routes
- Enforces 3 views per minute per IP address (MVP in-memory store)
- Returns 429 Too Many Requests when limit exceeded
- Rate limit utility supports distributed use (ready for Upstash Redis in Phase 10)
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- src/lib/quote-actions.ts: createQuote server action with nanoid tokens and atomic DB transaction
- src/components/admin/quotes/QuoteBuilderForm.tsx: Two-column form (left: client/offer/price inputs, right: live preview)
- src/components/admin/quotes/OfferSelector.tsx: Grouped dropdown for macro/micro offer selection
- src/components/admin/quotes/PriceOverrideInput.tsx: Price input with server validation feedback
- src/components/admin/quotes/QuotePreview.tsx: Live preview card showing offer details and calculated total
- src/app/admin/quotes/new/page.tsx: Quote builder page rendering form with data from DB
- src/app/admin/quotes/new/actions.ts: Re-export of createQuote for page-level action imports
- src/lib/admin-queries.ts: Added getAllOfferMacrosWithMicros() query for form population
Features:
- Admin selects client and offer (required fields)
- Form validates on blur and displays success/error states
- Server action validates data and rejects if total mismatch
- On success, displays public /quote/[token] link with copy button
- Quote saved as draft state with immutable accepted_total
Completes Phase 9 Plan 2 Wave 1: Admin UI Layer
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Add getOfferPhases(microId) — get all phases for an offer micro
- Add getOfferPhaseServices(phaseId) — get all services assigned to a phase
- Add getQuoteById(quoteId) — get full quote header by ID
- Add getQuoteByToken(token) — get quote by public token
- Add getQuotesByClient(clientId) — get all quotes for a client
- Update imports to include new tables and types
- All queries properly typed with Drizzle ORM
- Build verified with npm run build
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Create SQL migration 0003_offer_phases_quote_templates.sql
- Creates offers_phases, offer_phase_services, quotes, leads tables
- Adds new columns to quote_items, projects, phases (additive-only)
- Includes proper FK constraints, indexes, and CHECK constraints
- ZERO DATA LOSS: No drops, no truncates — fully reversible
- Create validation script scripts/validate-phase8-migration.ts
- Checks all 4 new tables exist
- Verifies 7 new columns added to existing tables
- Validates FK references intact
- Exit code 0 on success, 1 on failure
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Check 6: Count of services with migrated_from IS NULL (net-new rows created via /admin/catalog after migration)
- Printed as informational line at the end of validation output
- Does not fail validation if count is zero (expected for fresh test runs)
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Task 1: Update getAllServices() and activeServices queries to read from services table instead of service_catalog
- Both ClientFullDetail and ProjectFullDetail now return Service[] (not ServiceCatalog[])
- Quote items label join remains unchanged — still references service_catalog for historical quote_items.service_id FK integrity
- Task 2: Rewire /admin/catalog actions and components to operate on services table
- src/app/admin/catalog/actions.ts: createService/updateService/toggleServiceActive now write to services with optional category field
- ServiceTable.tsx: Updated to Service[] type, added category column rendering
- ServiceForm.tsx: Added optional category input field
- QuoteTab.tsx: Updated activeServices type annotation to Service[]
- New services created via /admin/catalog have migrated_from=null, migrated_id=null (not migrated)
- TypeScript compiles successfully
- npm run build: PASS
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Two-plan, two-wave migration: schema + backfill (07-01) then admin
catalog CRUD rewire (07-02), per CAT-U-01/CAT-U-02 and the
expand-contract pattern from PITFALLS_V2 Pitfall 1.
- 4 KPI cards: clienti attivi, revenue totale, progetti in corso, pagamenti in sospeso
- Activity feed: last 10 events with icon, label, detail, timestamp
- Page is RSC (async server component, no use client)
- revalidate = 0 for fresh data on each request
- KPI queries: clienti attivi, revenue totale, pagamenti in sospeso, progetti in corso
- Activity feed: last 10 events across clients, projects, deliverables, time entries
- Uses isNotNull for nullable timestamp filters, Promise.all for parallel fetch
- New /admin/clients/page.tsx contains full client list with getAllClientsWithPayments
- Toggle archived link updated from /admin?archived=1 to /admin/clients?archived=1
- /admin/page.tsx replaced with redirect() to /admin/clients
- AdminLayout now uses flex-row: AdminSidebar (left) + main (right)
- Removed NavBar import and max-w-5xl centered constraint
- Main content area takes remaining width with px-8 py-8 padding