Updated with Lightboxes
This commit is contained in:
parent
5d0cfdef47
commit
96496350ee
@ -1,5 +1,5 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Check, AlertCircle, ArrowLeft, Loader2, Globe2, TreePine, Waves, Factory, Wind } from 'lucide-react';
|
||||
import { Check, AlertCircle, ArrowLeft, Loader2, Globe2, TreePine, Waves, Factory, Wind, X } from 'lucide-react';
|
||||
import { createOffsetOrder, getPortfolios } from '../api/wrenClient';
|
||||
import type { CurrencyCode, OffsetOrder as OffsetOrderType, Portfolio, OffsetProject } from '../types';
|
||||
import { currencies, formatCurrency, getCurrencyByCode } from '../utils/currencies';
|
||||
@ -54,6 +54,9 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr
|
||||
company: '',
|
||||
message: `I would like to offset ${tons.toFixed(2)} tons of CO2 from my yacht's ${calculatorType} emissions.`
|
||||
});
|
||||
|
||||
// lightbox state
|
||||
const [selectedProject, setSelectedProject] = useState<OffsetProject | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!config.wrenApiKey) {
|
||||
@ -64,6 +67,19 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr
|
||||
fetchPortfolio();
|
||||
}, []);
|
||||
|
||||
// handle Escape key to close lightbox
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') setSelectedProject(null);
|
||||
};
|
||||
if (selectedProject) {
|
||||
document.addEventListener('keydown', onKey);
|
||||
}
|
||||
return () => {
|
||||
document.removeEventListener('keydown', onKey);
|
||||
};
|
||||
}, [selectedProject]);
|
||||
|
||||
const fetchPortfolio = async () => {
|
||||
try {
|
||||
const allPortfolios = await getPortfolios();
|
||||
@ -308,7 +324,11 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr
|
||||
{portfolio.projects && portfolio.projects.length > 0 && (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-6">
|
||||
{portfolio.projects.map((project) => (
|
||||
<div key={project.id} className="bg-gray-50 rounded-lg p-4 hover:shadow-md transition-shadow">
|
||||
<div
|
||||
key={project.id}
|
||||
onClick={() => setSelectedProject(project)}
|
||||
className="cursor-pointer bg-gray-50 rounded-lg p-4 hover:shadow-md transition-shadow"
|
||||
>
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<div className="flex items-center space-x-2">
|
||||
<ProjectTypeIcon project={project} />
|
||||
@ -345,6 +365,46 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* lightbox modal */}
|
||||
{selectedProject && (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50"
|
||||
onClick={() => setSelectedProject(null)}
|
||||
>
|
||||
<div
|
||||
className="relative bg-white rounded-lg p-6 max-w-lg w-full"
|
||||
onClick={e => e.stopPropagation()}
|
||||
>
|
||||
<button
|
||||
onClick={() => setSelectedProject(null)}
|
||||
className="absolute top-4 right-4 text-gray-500 hover:text-gray-700"
|
||||
>
|
||||
<X size={24} />
|
||||
</button>
|
||||
<h3 className="text-2xl font-bold mb-4">
|
||||
{selectedProject.name}
|
||||
</h3>
|
||||
{selectedProject.imageUrl && (
|
||||
<img
|
||||
src={selectedProject.imageUrl}
|
||||
alt={selectedProject.name}
|
||||
className="w-full h-48 object-cover rounded mb-4"
|
||||
/>
|
||||
)}
|
||||
<p className="text-gray-700 mb-4">
|
||||
{selectedProject.description}
|
||||
</p>
|
||||
<div className="flex justify-between">
|
||||
<span className="font-medium">Type:</span>
|
||||
<span>{selectedProject.type}</span>
|
||||
</div>
|
||||
<div className="flex justify-between mt-2">
|
||||
<span className="font-medium">Price per ton:</span>
|
||||
<span>${selectedProject.pricePerTon.toFixed(2)}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center justify-between bg-blue-50 p-4 rounded-lg">
|
||||
<span className="text-blue-900 font-medium">Portfolio Price per Ton:</span>
|
||||
<span className="text-blue-900 font-bold text-lg">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user