feat(scanner): pass scan country through frontend scan/submit flow (#924)#936
feat(scanner): pass scan country through frontend scan/submit flow (#924)#936ericsocrat merged 2 commits intomainfrom
Conversation
) - 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)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Bundle Size Report
✅ Bundle size is within acceptable limits. |
There was a problem hiding this comment.
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/passscanCountry(+suggestedCountryfor 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. |
| const submitHref = country | ||
| ? `/app/scan/submit?ean=${ean}&country=${country}` | ||
| : `/app/scan/submit?ean=${ean}`; |
| const prefillEan = searchParams.get("ean") ?? ""; | ||
| const urlCountry = searchParams.get("country") ?? undefined; | ||
| const prefs = usePreferences(); | ||
| const scanCountry = urlCountry ?? prefs?.country ?? undefined; |
| 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, | ||
| }); |
| 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, |
| const result = await invokeGateway(supabase, "record-scan", { | ||
| ean, | ||
| scan_country: scanCountry ?? null, | ||
| }); |
| 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, |
There was a problem hiding this comment.
💡 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".
| const result = await invokeGateway(supabase, "record-scan", { | ||
| ean, | ||
| scan_country: scanCountry ?? null, |
There was a problem hiding this comment.
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 👍 / 👎.
| p_scan_country: params.scan_country ?? null, | ||
| p_suggested_country: params.suggested_country ?? null, |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
Implements issue #924 — Frontend: 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 theapi_record_scanandapi_submit_productRPCs via thep_scan_countryandp_suggested_countryparameters added in PR #935 (issue #923).Closes #924
Changes
Production Code (7 files)
frontend/src/lib/api.tsrecordScanaccepts optionalscanCountry, forwards asp_scan_country.submitProductparams includescanCountryandsuggestedCountry, forwarded asp_scan_country/p_suggested_country.frontend/src/lib/api-gateway.tsscan_country. Fallback RPC passesp_scan_country/p_suggested_country.ApiGatewayinterface and factory updated.frontend/src/app/app/scan/page.tsxusePreferences().country, passes torecordScan()and<ScanNotFoundView country={...}>.frontend/src/app/app/scan/submit/page.tsx?country=XX) orusePreferences(). PassesscanCountry+suggestedCountrytosubmitProduct().frontend/src/components/scan/ScanMissSubmitCTA.tsxcountryprop, appends&country=XXto submit link when present.frontend/src/components/scan/ScanResultView.tsxScanNotFoundViewaccepts and forwardscountryprop toScanMissSubmitCTA.frontend/src/hooks/use-submissions.tsscanCountryandsuggestedCountry.Test Code (4 files, 7 new tests)
api.test.tsrecordScan passes scan country when provided,submitProduct passes scan and suggested country when provided+ updated 3 existing tests with new paramsapi-gateway.test.tsshould pass scan_country to gateway when provided+ updated 3 existing assertionsScanMissSubmitCTA.test.tsxincludes country in submit link when providedScanResultView.test.tsxpasses country prop to ScanMissSubmitCTAData Flow
Verification
11 files changed, +120 / -9 lines
Scope Boundaries (per #924 acceptance criteria)