diff --git a/frontend/src/app/app/scan/page.test.tsx b/frontend/src/app/app/scan/page.test.tsx index 3cdd13d3..2a322452 100644 --- a/frontend/src/app/app/scan/page.test.tsx +++ b/frontend/src/app/app/scan/page.test.tsx @@ -805,6 +805,7 @@ describe("ScanPage", () => { expect(mockRecordScan).toHaveBeenCalledWith( expect.anything(), "5901234123457", + undefined, ); }); }); diff --git a/frontend/src/app/app/scan/page.tsx b/frontend/src/app/app/scan/page.tsx index 88ec5d21..8b608044 100644 --- a/frontend/src/app/app/scan/page.tsx +++ b/frontend/src/app/app/scan/page.tsx @@ -18,6 +18,7 @@ import { import { useAnalytics } from "@/hooks/use-analytics"; import { useBarcodeScanner } from "@/hooks/use-barcode-scanner"; import { recordScan } from "@/lib/api"; +import { usePreferences } from "@/components/common/RouteGuard"; import { NUTRI_COLORS } from "@/lib/constants"; import { eventBus } from "@/lib/events"; import { useTranslation } from "@/lib/i18n"; @@ -51,6 +52,8 @@ export default function ScanPage() { const queryClient = useQueryClient(); const { track } = useAnalytics(); const { t } = useTranslation(); + const prefs = usePreferences(); + const userCountry = prefs?.country ?? undefined; const [ean, setEan] = useState(""); const [manualEan, setManualEan] = useState(""); const [mode, setMode] = useState<"camera" | "manual">("camera"); @@ -70,7 +73,7 @@ export default function ScanPage() { const scanMutation = useMutation({ mutationFn: async (scanEan: string) => { - const result = await recordScan(supabase, scanEan); + const result = await recordScan(supabase, scanEan, userCountry); if (!result.ok) throw new Error(result.error.message); return result.data; }, @@ -200,6 +203,7 @@ export default function ScanPage() { ean={ean} scanResult={scanResult as RecordScanNotFoundResponse} onReset={() => handleReset()} + country={userCountry} /> ); } diff --git a/frontend/src/app/app/scan/submit/page.tsx b/frontend/src/app/app/scan/submit/page.tsx index 1bc6e8d6..2153881b 100644 --- a/frontend/src/app/app/scan/submit/page.tsx +++ b/frontend/src/app/app/scan/submit/page.tsx @@ -14,6 +14,7 @@ import { FileText } from "lucide-react"; import { createClient } from "@/lib/supabase/client"; import { submitProduct } from "@/lib/api"; import { useTranslation } from "@/lib/i18n"; +import { usePreferences } from "@/components/common/RouteGuard"; import type { FormSubmitEvent } from "@/lib/types"; export default function SubmitProductPage() { @@ -21,6 +22,9 @@ export default function SubmitProductPage() { const router = useRouter(); const searchParams = useSearchParams(); const prefillEan = searchParams.get("ean") ?? ""; + const urlCountry = searchParams.get("country") ?? undefined; + const prefs = usePreferences(); + const scanCountry = urlCountry ?? prefs?.country ?? undefined; const [ean, setEan] = useState(prefillEan); const [productName, setProductName] = useState(""); @@ -37,6 +41,8 @@ export default function SubmitProductPage() { brand: brand || undefined, category: category || undefined, notes: notes || undefined, + scanCountry, + suggestedCountry: scanCountry, }); if (!result.ok) throw new Error(result.error.message); if (result.data.error) throw new Error(result.data.error); diff --git a/frontend/src/components/scan/ScanMissSubmitCTA.test.tsx b/frontend/src/components/scan/ScanMissSubmitCTA.test.tsx index a734c3f1..7a01dbfe 100644 --- a/frontend/src/components/scan/ScanMissSubmitCTA.test.tsx +++ b/frontend/src/components/scan/ScanMissSubmitCTA.test.tsx @@ -40,6 +40,14 @@ describe("ScanMissSubmitCTA", () => { ); }); + it("includes country in submit link when provided", () => { + render(); + const link = screen.getByRole("link"); + expect(link.getAttribute("href")).toBe( + "/app/scan/submit?ean=5901234123457&country=DE" + ); + }); + it("renders hint text below the button", () => { render(); expect(screen.getByText("scan.helpAddHint")).toBeTruthy(); diff --git a/frontend/src/components/scan/ScanMissSubmitCTA.tsx b/frontend/src/components/scan/ScanMissSubmitCTA.tsx index 456f91f9..8668d630 100644 --- a/frontend/src/components/scan/ScanMissSubmitCTA.tsx +++ b/frontend/src/components/scan/ScanMissSubmitCTA.tsx @@ -7,12 +7,14 @@ import { Clock, FileText } from "lucide-react"; interface ScanMissSubmitCTAProps { ean: string; hasPendingSubmission?: boolean; + country?: string; } /** CTA shown when a scanned barcode is not found in the database. */ export function ScanMissSubmitCTA({ ean, hasPendingSubmission = false, + country, }: ScanMissSubmitCTAProps) { const { t } = useTranslation(); @@ -29,10 +31,14 @@ export function ScanMissSubmitCTA({ ); } + const submitHref = country + ? `/app/scan/submit?ean=${ean}&country=${country}` + : `/app/scan/submit?ean=${ean}`; + return (