diff --git a/src/components/OffsetOrder.tsx b/src/components/OffsetOrder.tsx
index e1e0e9f..b53fe37 100644
--- a/src/components/OffsetOrder.tsx
+++ b/src/components/OffsetOrder.tsx
@@ -40,207 +40,6 @@ const ProjectTypeIcon = ({ project }: ProjectTypeIconProps) => {
}
};
-// Project card component to improve readability and ensure consistent behavior
-const ProjectCard = ({
- project,
- index,
- onSelect
-}: {
- project: OffsetProject;
- index: number;
- onSelect: (project: OffsetProject) => void;
-}) => {
- // Handler to ensure event propagation is stopped correctly
- const handleClick = (e: React.MouseEvent) => {
- e.preventDefault();
- e.stopPropagation();
- console.log('Project clicked:', project.name);
- onSelect(project);
- };
-
- return (
-
-
-
- {project.percentage && (
-
- {(project.percentage * 100).toFixed(1)}%
-
- )}
-
- {project.imageUrl && (
-
-

-
- )}
-
- {project.shortDescription || project.description}
-
-
-
- Price per ton:
-
- ${project.pricePerTon.toFixed(2)}
-
-
-
-
- Click for details
-
-
- );
-};
-
-// Lightbox modal component
-const ProjectLightbox = ({
- project,
- onClose
-}: {
- project: OffsetProject | null;
- onClose: () => void;
-}) => {
- // Close on Escape key
- useEffect(() => {
- const handleKeyDown = (e: KeyboardEvent) => {
- if (e.key === 'Escape') onClose();
- };
-
- window.addEventListener('keydown', handleKeyDown);
- return () => window.removeEventListener('keydown', handleKeyDown);
- }, [onClose]);
-
- // Prevent body scrolling when modal is open
- useEffect(() => {
- document.body.style.overflow = 'hidden';
- return () => {
- document.body.style.overflow = 'auto';
- };
- }, []);
-
- if (!project) return null;
-
- return (
-
- {/* Backdrop */}
-
-
- {/* Modal Content */}
-
e.stopPropagation()}
- >
- {/* Close Button */}
-
-
- {/* Project Image */}
- {project.imageUrl && (
-
-

-
-
-
{project.name}
-
-
-
{project.type || 'Environmental Project'}
-
-
-
- )}
-
- {/* Project Details */}
-
- {!project.imageUrl && (
- <>
-
{project.name}
-
-
-
{project.type || 'Environmental Project'}
-
- >
- )}
-
-
- {project.description || project.shortDescription}
-
-
-
-
-
Price per Ton
-
${project.pricePerTon.toFixed(2)}
-
- {project.percentage && (
-
-
Portfolio Allocation
-
{(project.percentage * 100).toFixed(1)}%
-
- )}
-
-
- {(project.location || project.verificationStandard) && (
-
- {project.location && (
-
- Location:
- {project.location}
-
- )}
- {project.verificationStandard && (
-
- Verification Standard:
- {project.verificationStandard}
-
- )}
-
- )}
-
- {project.impactMetrics && project.impactMetrics.co2Reduced > 0 && (
-
-
Impact Metrics
-
- {project.impactMetrics.co2Reduced.toLocaleString()} tons CO₂ reduced
-
-
- )}
-
-
-
- );
-};
-
export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Props) {
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
@@ -329,16 +128,26 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr
// Calculate offset cost using the portfolio price
const offsetCost = monetaryAmount || (portfolio ? tons * (portfolio.pricePerTon || 18) : 0);
- // Handler for project selection
- const handleProjectSelect = (project: OffsetProject) => {
- console.log(`Setting selected project: ${project.name}`);
+ // Simplified handler for project selection with maximum debugging
+ const handleProjectClick = (project: OffsetProject) => {
+ console.log('=== PROJECT CLICK HANDLER FIRED ===');
+ console.log('Project name:', project.name);
+ console.log('Project ID:', project.id);
+ console.log('Current selectedProject state:', selectedProject?.name || 'null');
+
+ // Force the state update
setSelectedProject(project);
+
+ console.log('State updated to:', project.name);
+ console.log('=== END PROJECT CLICK HANDLER ===');
};
// Handler for closing the lightbox
- const handleCloseLightbox = () => {
- console.log('Closing lightbox');
+ const handleCloseLightbox = (e: React.MouseEvent | React.TouchEvent) => {
+ if (e) e.preventDefault();
+ console.log('=== CLOSING LIGHTBOX ===');
setSelectedProject(null);
+ console.log('selectedProject set to null');
};
return (
@@ -543,12 +352,58 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr
transition={{ duration: 0.5, delay: 0.3 }}
>
{portfolio.projects.map((project, index) => (
-
+ className="bg-gray-50 rounded-lg p-4 hover:shadow-lg transition-all cursor-pointer border border-gray-200 hover:border-blue-300"
+ onClick={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ console.log('Project clicked:', project.name);
+ handleProjectClick(project);
+ }}
+ style={{
+ userSelect: 'none',
+ WebkitUserSelect: 'none',
+ msUserSelect: 'none',
+ MozUserSelect: 'none'
+ }}
+ >
+
+
+ {project.percentage && (
+
+ {(project.percentage * 100).toFixed(1)}%
+
+ )}
+
+ {project.imageUrl && (
+
+

+
+ )}
+
+ {project.shortDescription || project.description}
+
+
+
+ Price per ton:
+
+ ${project.pricePerTon.toFixed(2)}
+
+
+
+
+ 👆 Click for details
+
+
))}
)}
@@ -621,8 +476,119 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr
>
) : null}
- {/* Project Lightbox Modal - Rendered directly without AnimatePresence for better compatibility */}
- {selectedProject && }
+ {/* Debug info */}
+ {selectedProject && (
+
+ Selected: {selectedProject.name}
+
+ )}
+
+ {/* Project Lightbox Modal */}
+
+ {selectedProject && (
+ handleCloseLightbox(e)}
+ initial={{ opacity: 0 }}
+ animate={{ opacity: 1 }}
+ exit={{ opacity: 0 }}
+ >
+ {/* Modal Content */}
+ e.stopPropagation()}
+ >
+ {/* Close Button */}
+
+
+ {/* Project Image */}
+ {selectedProject.imageUrl && (
+
+

+
+
+
{selectedProject.name}
+
+
+
{selectedProject.type || 'Environmental Project'}
+
+
+
+ )}
+
+ {/* Project Details */}
+
+ {!selectedProject.imageUrl && (
+ <>
+
{selectedProject.name}
+
+
+
{selectedProject.type || 'Environmental Project'}
+
+ >
+ )}
+
+
+ {selectedProject.description || selectedProject.shortDescription}
+
+
+
+
+
Price per Ton
+
${selectedProject.pricePerTon.toFixed(2)}
+
+ {selectedProject.percentage && (
+
+
Portfolio Allocation
+
{(selectedProject.percentage * 100).toFixed(1)}%
+
+ )}
+
+
+ {(selectedProject.location || selectedProject.verificationStandard) && (
+
+ {selectedProject.location && (
+
+ Location:
+ {selectedProject.location}
+
+ )}
+ {selectedProject.verificationStandard && (
+
+ Verification Standard:
+ {selectedProject.verificationStandard}
+
+ )}
+
+ )}
+
+ {selectedProject.impactMetrics && selectedProject.impactMetrics.co2Reduced > 0 && (
+
+
Impact Metrics
+
+ {selectedProject.impactMetrics.co2Reduced.toLocaleString()} tons CO₂ reduced
+
+
+ )}
+
+
+
+ )}
+
);
}