diff --git a/src/components/MobileCalculator.tsx b/src/components/MobileCalculator.tsx index b264c70..51f5e5c 100644 --- a/src/components/MobileCalculator.tsx +++ b/src/components/MobileCalculator.tsx @@ -6,6 +6,7 @@ import { calculateTripCarbon, calculateCarbonFromFuel } from '../utils/carbonCal import { currencies, formatCurrency, getCurrencyByCode } from '../utils/currencies'; import { CurrencySelect } from './CurrencySelect'; import { PWAInstallPrompt } from './PWAInstallPrompt'; +import { MobileOffsetOrder } from './MobileOffsetOrder'; interface Props { vesselData: VesselData; @@ -25,6 +26,9 @@ export function MobileCalculator({ vesselData, onOffsetClick, onBack }: Props) { const [offsetPercentage, setOffsetPercentage] = useState(100); const [customPercentage, setCustomPercentage] = useState(''); const [customAmount, setCustomAmount] = useState(''); + const [showOffsetOrder, setShowOffsetOrder] = useState(false); + const [offsetTons, setOffsetTons] = useState(0); + const [monetaryAmount, setMonetaryAmount] = useState(); const handleCalculate = useCallback((e: React.FormEvent) => { e.preventDefault(); @@ -79,6 +83,17 @@ export function MobileCalculator({ vesselData, onOffsetClick, onBack }: Props) { { id: 'custom', icon: DollarSign, label: 'Custom Amount', color: 'purple' } ]; + if (showOffsetOrder) { + return ( + setShowOffsetOrder(false)} + /> + ); + } + return (
{/* Mobile Header */} @@ -210,7 +225,11 @@ export function MobileCalculator({ vesselData, onOffsetClick, onBack }: Props) { {customAmount && Number(customAmount) > 0 && ( onOffsetClick?.(0, Number(customAmount))} + onClick={() => { + setOffsetTons(0); + setMonetaryAmount(Number(customAmount)); + setShowOffsetOrder(true); + }} className="w-full mt-6 bg-gradient-to-r from-blue-500 to-blue-600 text-white py-4 px-6 rounded-xl font-semibold text-lg shadow-md hover:shadow-lg transition-all" whileHover={{ scale: 1.02 }} whileTap={{ scale: 0.98 }} @@ -435,7 +454,11 @@ export function MobileCalculator({ vesselData, onOffsetClick, onBack }: Props) {
+ + ); + + const renderPaymentStep = () => ( + +
+

+ + Payment Information +

+ +
+
+ + +
+ +
+
+ + +
+
+ + +
+
+ +
+ + +
+
+
+ +
+

Order Summary

+
+
+ CO₂ Offset: + {tons.toFixed(2)} tons +
+
+ Total: + + {formatCurrency(totalCost, targetCurrency)} + +
+
+
+ +
+ + +
+
+ ); + + const renderConfirmationStep = () => ( + +
+
+ +
+ +

+ Order Confirmed! +

+ +

+ Congratulations! You've successfully offset {tons.toFixed(2)} tons of CO₂ from your yacht emissions. +

+ +
+

Order Details

+
+
+ Order ID: + {generateOrderId()} +
+
+ CO₂ Offset: + {tons.toFixed(2)} tons +
+
+ Amount Paid: + + {formatCurrency(totalCost, targetCurrency)} + +
+
+ Email: + {orderData.email} +
+
+
+ +
+

+ 📧 A confirmation email has been sent to {orderData.email} with your certificate and receipt. +

+
+
+ + +
+ ); + + return ( +
+ {/* Mobile Header */} + +
+ { + if (currentStep === 'payment') { + setCurrentStep('summary'); + } else { + onBack(); + } + }} + className="p-2 rounded-xl bg-gray-100 hover:bg-gray-200 transition-colors" + whileHover={{ scale: 1.05 }} + whileTap={{ scale: 0.95 }} + > + + + +
+

+ {currentStep === 'summary' ? 'Order Summary' : + currentStep === 'payment' ? 'Payment' : + 'Order Confirmed'} +

+
+ +
{/* Spacer */} +
+ + {/* Progress Bar */} + {currentStep !== 'confirmation' && ( +
+
+
+
+
+
+ )} + + +
+ + {currentStep === 'summary' && renderSummaryStep()} + {currentStep === 'payment' && renderPaymentStep()} + {currentStep === 'confirmation' && renderConfirmationStep()} + +
+
+ ); +}