From b93d05455892fad453ace9f4c72bd2fdd44d32dd Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 3 Nov 2025 19:47:31 +0100 Subject: [PATCH] Improve QR test page: better error handling and de-emphasize vessel info - Enhanced error handling to show HTTP status codes (e.g., "HTTP 404: Not Found") - Moved vessel information to collapsible section at bottom - Clear vessel default values (was pre-filled with test data) - Added note explaining vessel info is metadata only, not used in calculations - Made vessel fields visually de-emphasized with gray text and optional labels --- app/qr-test/page.tsx | 87 +++++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 33 deletions(-) diff --git a/app/qr-test/page.tsx b/app/qr-test/page.tsx index fcac1e0..8ec82ec 100644 --- a/app/qr-test/page.tsx +++ b/app/qr-test/page.tsx @@ -13,8 +13,8 @@ export default function QRTestPage() { const [fuelAmount, setFuelAmount] = useState('500'); const [fuelUnit, setFuelUnit] = useState<'liters' | 'gallons'>('liters'); const [customAmount, setCustomAmount] = useState('5'); - const [vesselName, setVesselName] = useState('Test Yacht'); - const [imo, setImo] = useState('1234567'); + const [vesselName, setVesselName] = useState(''); + const [imo, setImo] = useState(''); // Response state const [isLoading, setIsLoading] = useState(false); @@ -99,6 +99,20 @@ export default function QRTestPage() { body: JSON.stringify(requestData), }); + // Check HTTP status first + if (!res.ok) { + let errorMessage = `HTTP ${res.status}: ${res.statusText}`; + try { + const errorData = await res.json(); + if (errorData.error) { + errorMessage = errorData.error; + } + } catch { + // Not JSON, use status text + } + throw new Error(errorMessage); + } + const result = await res.json(); if (!result.success) { @@ -199,37 +213,6 @@ export default function QRTestPage() { - {/* Vessel Information */} -
-

Vessel Information (Optional)

-
-
- - setVesselName(e.target.value)} - placeholder="e.g., Test Yacht" - className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent text-sm" - /> -
-
- - setImo(e.target.value)} - placeholder="e.g., 1234567" - className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent text-sm" - /> -
-
-
- {/* Conditional Fields */} {calculationType === 'distance' && (
@@ -312,6 +295,44 @@ export default function QRTestPage() {
)} + {/* Vessel Information - Optional Metadata */} +
+ + Optional: Vessel Information (metadata only - not used in calculations) + +
+

+ Note: Vessel name and IMO are stored as metadata only. They are not used in carbon calculations. +

+
+
+ + setVesselName(e.target.value)} + placeholder="e.g., My Yacht (optional)" + className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent text-sm" + /> +
+
+ + setImo(e.target.value)} + placeholder="e.g., 1234567 (optional)" + className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent text-sm" + /> +
+
+
+
+ {/* Generate Button */}