import React, { useState, useRef, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { useNavigate } from 'react-router-dom'; import { useTheme } from '../context/ThemeContext'; import { useAuth } from '../context/AuthContext'; import { User, MapPin, Briefcase, Shield, Users, ChevronLeft, Zap, FileText, Save, } from 'lucide-react'; import LeadSectionWrapper from '../components/leads/LeadSectionWrapper'; import LeadJobSection from '../components/leads/LeadJobSection'; import LeadContactSection from '../components/leads/LeadContactSection'; import LeadPropertySection from '../components/leads/LeadPropertySection'; import LeadInsuranceSection from '../components/leads/LeadInsuranceSection'; import LeadAssignmentSection from '../components/leads/LeadAssignmentSection'; import gsap from 'gsap'; // --------------------------------------------------------------------------- // Section definitions // --------------------------------------------------------------------------- const SECTIONS = [ { id: 'contact', title: 'Contact', icon: User, accentColor: '#3B82F6', quickCapture: true, description: 'Name, phone numbers, and email addresses', }, { id: 'property', title: 'Property', icon: MapPin, accentColor: '#10B981', quickCapture: true, description: 'Property address, type, and site photos', }, { id: 'job', title: 'Job Details', icon: Briefcase, accentColor: '#F59E0B', quickCapture: true, description: 'Lead source, work type, urgency, and notes', }, { id: 'insurance', title: 'Insurance', icon: Shield, accentColor: '#8B5CF6', quickCapture: false, description: 'Carrier, claim number, adjuster, and policy details', }, { id: 'assignment', title: 'Assignment', icon: Users, accentColor: '#06B6D4', quickCapture: false, description: 'Assign a rep, set priority, and schedule follow-up', }, ]; // --------------------------------------------------------------------------- // Initial form state // --------------------------------------------------------------------------- const INITIAL_FORM = { // Job Details leadSource: '', leadType: '', workType: '', tradeType: '', urgency: 'standard', notes: '', // Contact firstName: '', lastName: '', phones: [{ id: '1', number: '', type: 'Mobile', isPrimary: true }], emails: [], // Property address: '', city: '', state: 'TX', zip: '', propertyType: '', propertyPhotos: [], // Insurance (Phase 5) insuranceCompany: '', claimNumber: '', claimStatus: '', adjusterName: '', adjusterPhone: '', policyNumber: '', // Assignment (Phase 6) assignedTo: '', priority: 'medium', followUpDate: '', }; // --------------------------------------------------------------------------- // Component // --------------------------------------------------------------------------- export default function CreateLeadPage() { const { theme } = useTheme(); const { user } = useAuth(); const isDark = theme === 'dark'; const navigate = useNavigate(); const [isQuickCapture, setIsQuickCapture] = useState(true); const [openSections, setOpenSections] = useState({ contact: true, property: false, job: false, insurance: false, assignment: false, }); const [formData, setFormData] = useState(INITIAL_FORM); const progressBarRef = useRef(null); // Section completion map const sectionCompletion = { contact: !!( formData.firstName && formData.lastName && formData.phones.some(p => p.number.replace(/\D/g, '').length >= 10) ), property: !!(formData.address && formData.city), job: isQuickCapture ? !!formData.leadSource : !!(formData.leadSource && formData.leadType && formData.workType), insurance: !!(formData.insuranceCompany && formData.claimStatus), assignment: !!(formData.assignedTo && formData.followUpDate), }; // Progress = % of visible sections that are complete const visibleSectionIds = (isQuickCapture ? SECTIONS.filter(s => s.quickCapture) : SECTIONS).map(s => s.id); const completedCount = visibleSectionIds.filter(id => sectionCompletion[id]).length; const progress = visibleSectionIds.length > 0 ? Math.round((completedCount / visibleSectionIds.length) * 100) : 0; // GSAP animates the progress bar whenever progress changes useEffect(() => { if (progressBarRef.current) { gsap.to(progressBarRef.current, { width: `${progress}%`, duration: 0.45, ease: 'power2.out', }); } }, [progress]); const updateField = (field, value) => { setFormData(prev => ({ ...prev, [field]: value })); }; const toggleSection = (id) => { setOpenSections(prev => ({ ...prev, [id]: !prev[id] })); }; const visibleSections = isQuickCapture ? SECTIONS.filter(s => s.quickCapture) : SECTIONS; const modeSwitchTo = (quick) => { if (quick === isQuickCapture) return; setIsQuickCapture(quick); if (quick) { setOpenSections(prev => ({ ...prev, insurance: false, assignment: false })); } }; // Render the content for a given section (placeholder until its phase is built) const renderSectionContent = (section) => { if (section.id === 'contact') { return ( ); } if (section.id === 'property') { return ( ); } if (section.id === 'job') { return ( ); } if (section.id === 'insurance') { return ( ); } if (section.id === 'assignment') { return ( ); } return null; }; return (
{/* --- Progress bar --- */}
{/* ---------------------------------------------------------------- Page content ---------------------------------------------------------------- */}
{/* --- Page Header --- */}
{/* Title */}

New Lead

{isQuickCapture ? 'Essential fields only — fastest capture at the door.' : 'Full lead profile with insurance and assignment details.'}

{/* Quick / Full Form toggle */}
{/* Section indicator pills */}
{SECTIONS.map(s => (
{s.title}
))}
{/* --- Sections --- */}
{visibleSections.map(section => ( toggleSection(section.id)} isComplete={sectionCompletion[section.id]} > {renderSectionContent(section)} ))}
{/* ---------------------------------------------------------------- Mobile sticky save footer ---------------------------------------------------------------- */}
{/* Compact mode toggle */}
{/* Save */}
); }