Skip to content

feat(scanner): pass scan country through frontend scan/submit flow (#924)#936

Merged
ericsocrat merged 2 commits intomainfrom
feat/924-frontend-scan-country-flow
Mar 17, 2026
Merged

feat(scanner): pass scan country through frontend scan/submit flow (#924)#936
ericsocrat merged 2 commits intomainfrom
feat/924-frontend-scan-country-flow

Conversation

@ericsocrat
Copy link
Owner

Summary

Implements issue #924Frontend: wire scan-country flow through scan & submit pages.

The frontend scan and submit pages now read the user's preferred country from usePreferences() and pass it through to the api_record_scan and api_submit_product RPCs via the p_scan_country and p_suggested_country parameters added in PR #935 (issue #923).

Closes #924


Changes

Production Code (7 files)

File Change
frontend/src/lib/api.ts recordScan accepts optional scanCountry, forwards as p_scan_country. submitProduct params include scanCountry and suggestedCountry, forwarded as p_scan_country / p_suggested_country.
frontend/src/lib/api-gateway.ts Gateway body includes scan_country. Fallback RPC passes p_scan_country / p_suggested_country. ApiGateway interface and factory updated.
frontend/src/app/app/scan/page.tsx Reads usePreferences().country, passes to recordScan() and <ScanNotFoundView country={...}>.
frontend/src/app/app/scan/submit/page.tsx Reads country from URL param (?country=XX) or usePreferences(). Passes scanCountry + suggestedCountry to submitProduct().
frontend/src/components/scan/ScanMissSubmitCTA.tsx Accepts country prop, appends &country=XX to submit link when present.
frontend/src/components/scan/ScanResultView.tsx ScanNotFoundView accepts and forwards country prop to ScanMissSubmitCTA.
frontend/src/hooks/use-submissions.ts Mutation params include scanCountry and suggestedCountry.

Test Code (4 files, 7 new tests)

File New Tests
api.test.ts recordScan passes scan country when provided, submitProduct passes scan and suggested country when provided + updated 3 existing tests with new params
api-gateway.test.ts should pass scan_country to gateway when provided + updated 3 existing assertions
ScanMissSubmitCTA.test.tsx includes country in submit link when provided
ScanResultView.test.tsx passes country prop to ScanMissSubmitCTA

Data Flow

scan/page.tsx
  → usePreferences().country → userCountry
  → recordScan(supabase, ean, userCountry)    → api.ts → p_scan_country
  → <ScanNotFoundView country={userCountry}>
      → <ScanMissSubmitCTA country={...}>
          → /app/scan/submit?ean=XXX&country=YY

submit/page.tsx
  → URL ?country=XX || usePreferences().country → scanCountry
  → submitProduct(..., scanCountry, suggestedCountry: scanCountry)
      → api.ts → p_scan_country + p_suggested_country

Verification

npx tsc --noEmit                    → 0 errors
npx vitest run (4 test files)       → 211/211 tests pass (3.21s)

11 files changed, +120 / -9 lines


Scope Boundaries (per #924 acceptance criteria)

)

- api.ts: recordScan/submitProduct accept and forward scan country params
- api-gateway.ts: gateway body and fallback RPC forward scan_country/suggested_country
- scan/page.tsx: read user country via usePreferences, pass to recordScan + ScanNotFoundView
- submit/page.tsx: read country from URL param or user prefs, pass to submitProduct
- ScanMissSubmitCTA.tsx: accept country prop, include in submit link query string
- ScanResultView.tsx: ScanNotFoundView accepts and forwards country prop
- use-submissions.ts: mutation params include scanCountry/suggestedCountry

Tests: 7 new tests across 4 files (api, api-gateway, ScanMissSubmitCTA, ScanResultView)
Copilot AI review requested due to automatic review settings March 17, 2026 11:44
@vercel
Copy link

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tryvit Ready Ready Preview, Comment Mar 17, 2026 1:08pm

@github-actions
Copy link

github-actions bot commented Mar 17, 2026

Bundle Size Report

Metric Value
Main baseline 0 KB
This PR 0 KB
Delta +0 KB (+0%)
JS chunks 0
Hard limit 4000 KB

✅ Bundle size is within acceptable limits.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Wires the user’s country context through the scanner and submission flows so the frontend can pass scan/submission country to the updated scanner RPCs (api_record_scan, api_submit_product) and preserve that context during navigation.

Changes:

  • Extend RPC wrappers (recordScan, submitProduct) to accept/pass scanCountry (+ suggestedCountry for submissions).
  • Propagate country through UI flow (scan → not-found CTA → submit page) via props and ?country=XX.
  • Update API-gateway client typings/request bodies and add/adjust unit tests for the new parameters.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
frontend/src/lib/api.ts Adds scanCountry/suggestedCountry params and forwards them to RPCs.
frontend/src/lib/api.test.ts Updates tests to assert new RPC params (p_scan_country, p_suggested_country).
frontend/src/lib/api-gateway.ts Adds scan_country/suggested_country to gateway client types/body and RPC fallback.
frontend/src/lib/api-gateway.test.ts Updates/extends gateway client tests for scan_country forwarding and fallback RPC args.
frontend/src/app/app/scan/page.tsx Reads usePreferences().country and passes it into recordScan + not-found view.
frontend/src/app/app/scan/submit/page.tsx Reads ?country= (or prefs) and passes through to submitProduct.
frontend/src/components/scan/ScanMissSubmitCTA.tsx Adds country prop and appends it to the submit link querystring.
frontend/src/components/scan/ScanMissSubmitCTA.test.tsx Tests that country is included in the submit link when provided.
frontend/src/components/scan/ScanResultView.tsx Threads country prop into the not-found CTA component.
frontend/src/components/scan/ScanResultView.test.tsx Tests that country is passed through to ScanMissSubmitCTA.
frontend/src/hooks/use-submissions.ts Extends mutation param shape to include scanCountry/suggestedCountry.

Comment on lines +34 to +36
const submitHref = country
? `/app/scan/submit?ean=${ean}&country=${country}`
: `/app/scan/submit?ean=${ean}`;
Comment on lines 24 to +27
const prefillEan = searchParams.get("ean") ?? "";
const urlCountry = searchParams.get("country") ?? undefined;
const prefs = usePreferences();
const scanCountry = urlCountry ?? prefs?.country ?? undefined;
Comment on lines 723 to 731
export function recordScan(
supabase: SupabaseClient,
ean: string,
scanCountry?: string,
): Promise<RpcResult<RecordScanResponse>> {
return callRpc<RecordScanResponse>(supabase, "api_record_scan", {
p_ean: ean,
p_scan_country: scanCountry ?? null,
});
Comment on lines 747 to +768
export function submitProduct(
supabase: SupabaseClient,
params: {
ean: string;
productName: string;
brand?: string;
category?: string;
photoUrl?: string;
notes?: string;
scanCountry?: string;
suggestedCountry?: string;
},
): Promise<RpcResult<SubmitProductResponse>> {
return callRpc<SubmitProductResponse>(supabase, "api_submit_product", {
p_ean: params.ean,
p_product_name: params.productName,
p_brand: params.brand ?? null,
p_category: params.category ?? null,
p_photo_url: params.photoUrl ?? null,
p_notes: params.notes ?? null,
p_scan_country: params.scanCountry ?? null,
p_suggested_country: params.suggestedCountry ?? null,
Comment on lines +125 to +128
const result = await invokeGateway(supabase, "record-scan", {
ean,
scan_country: scanCountry ?? null,
});
Comment on lines 187 to +191
p_category: params.category ?? null,
p_photo_url: params.photo_url ?? null,
p_notes: params.notes ?? null,
p_scan_country: params.scan_country ?? null,
p_suggested_country: params.suggested_country ?? null,
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f98c36439

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +125 to +127
const result = await invokeGateway(supabase, "record-scan", {
ean,
scan_country: scanCountry ?? null,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Forward scan country in reachable gateway path

recordScanViaGateway now takes scanCountry, but when the gateway is reachable the request is handled by handleRecordScan, which still calls api_record_scan with only p_ean (supabase/functions/api-gateway/index.ts:383-386). That means scan_country is only written in the gateway_unreachable fallback branch, so normal gateway traffic silently loses country context and skews country-aware scan metrics.

Useful? React with 👍 / 👎.

Comment on lines +190 to +191
p_scan_country: params.scan_country ?? null,
p_suggested_country: params.suggested_country ?? null,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve submit countries outside gateway fallback

These new country fields are only guaranteed in the direct-RPC fallback branch here; in the normal gateway-success path, handleSubmitProduct forwards only p_ean, p_product_name, p_brand, p_category, p_photo_url, and p_notes (supabase/functions/api-gateway/index.ts:494-500). When the gateway is up, scan_country and suggested_country are dropped, which leaves country-targeted submission data incomplete.

Useful? React with 👍 / 👎.

@ericsocrat ericsocrat merged commit 2a705a6 into main Mar 17, 2026
15 of 17 checks passed
@ericsocrat ericsocrat deleted the feat/924-frontend-scan-country-flow branch March 17, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(frontend): pass scan country from frontend scan/submit flow to RPCs

2 participants