more fixes

This commit is contained in:
Matt 2025-05-13 20:21:05 +02:00
parent 279098e9fa
commit 7be9fc3722

View File

@ -64,9 +64,6 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr
fetchPortfolio(); fetchPortfolio();
}, []); }, []);
const [portfolios, setPortfolios] = useState<Portfolio[]>([]);
const [selectedPortfolioId, setSelectedPortfolioId] = useState<number | null>(null);
const fetchPortfolio = async () => { const fetchPortfolio = async () => {
try { try {
const allPortfolios = await getPortfolios(); const allPortfolios = await getPortfolios();
@ -76,21 +73,19 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr
throw new Error('No portfolios available'); throw new Error('No portfolios available');
} }
setPortfolios(allPortfolios); // Only get the puffin portfolio, no selection allowed
// Set default portfolio - prefer one with "puffin" in the name, otherwise first one
const puffinPortfolio = allPortfolios.find(p => const puffinPortfolio = allPortfolios.find(p =>
p.name.toLowerCase().includes('puffin') || p.name.toLowerCase().includes('puffin') ||
p.name.toLowerCase().includes('maritime') p.name.toLowerCase().includes('maritime')
); );
if (puffinPortfolio) { if (puffinPortfolio) {
console.log('[OffsetOrder] Found Puffin portfolio with ID:', puffinPortfolio.id);
setPortfolio(puffinPortfolio); setPortfolio(puffinPortfolio);
setSelectedPortfolioId(puffinPortfolio.id);
} else { } else {
// Default to first portfolio if no puffin portfolio found // Default to first portfolio if no puffin portfolio found
console.log('[OffsetOrder] No Puffin portfolio found, using first available portfolio with ID:', allPortfolios[0].id);
setPortfolio(allPortfolios[0]); setPortfolio(allPortfolios[0]);
setSelectedPortfolioId(allPortfolios[0].id);
} }
} catch (err) { } catch (err) {
setError('Failed to fetch portfolio information. Please try again.'); setError('Failed to fetch portfolio information. Please try again.');
@ -99,15 +94,6 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr
} }
}; };
// Handle portfolio selection change
const handlePortfolioChange = (portfolioId: number) => {
const selected = portfolios.find(p => p.id === portfolioId);
if (selected) {
setPortfolio(selected);
setSelectedPortfolioId(portfolioId);
}
};
const handleOffsetOrder = async () => { const handleOffsetOrder = async () => {
if (!portfolio) return; if (!portfolio) return;
@ -311,52 +297,6 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr
</div> </div>
) : portfolio ? ( ) : portfolio ? (
<> <>
{portfolios.length > 0 && (
<div className="mb-8">
<h3 className="text-lg font-semibold text-gray-900 mb-4">
Select A Carbon Offset Portfolio
</h3>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
{portfolios.map((p) => (
<div
key={p.id}
onClick={() => handlePortfolioChange(p.id)}
className={`cursor-pointer border rounded-lg p-4 transition-all ${
selectedPortfolioId === p.id
? 'border-blue-500 bg-blue-50 shadow-md'
: 'border-gray-200 hover:border-blue-300 hover:bg-blue-50'
}`}
>
<div className="flex justify-between items-start mb-2">
<h4 className="text-lg font-medium text-gray-900">{p.name}</h4>
{selectedPortfolioId === p.id && (
<div className="bg-blue-500 text-white rounded-full p-1">
<Check size={16} />
</div>
)}
</div>
<p className="text-sm text-gray-600 mb-3 line-clamp-2">
{p.description}
</p>
<div className="flex justify-between items-center">
<div className="text-xs text-gray-500">
{p.projects?.length || 0} project{p.projects?.length !== 1 ? 's' : ''}
</div>
<div className="text-blue-600 font-semibold">
{formatCurrency(p.pricePerTon, getCurrencyByCode(currency))}/ton
</div>
</div>
</div>
))}
</div>
<p className="mt-4 text-sm text-gray-500">
Click on a portfolio to select which climate projects you'd like to support.
</p>
</div>
)}
<div className="bg-white border rounded-lg p-6 mb-8"> <div className="bg-white border rounded-lg p-6 mb-8">
<h3 className="text-xl font-semibold text-gray-900 mb-4"> <h3 className="text-xl font-semibold text-gray-900 mb-4">
{portfolio.name} {portfolio.name}