fix: extract zone fields explicitly to avoid Supabase join type narrowing to never
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWxyMibCuGGtSQSqfajDQ7
This commit is contained in:
+9
-5
@@ -15,7 +15,8 @@ export default async function ReportPage({ searchParams }: Props) {
|
|||||||
|
|
||||||
if (authError || !data?.user) redirect(`/login?redirect=/report${zone ? `?zone=${zone}` : ''}`)
|
if (authError || !data?.user) redirect(`/login?redirect=/report${zone ? `?zone=${zone}` : ''}`)
|
||||||
|
|
||||||
let zoneData: { id: string; name: string; site_id: string; sites: { name: string } } | null = null
|
let zoneName: string | null = null
|
||||||
|
let siteName: string | null = null
|
||||||
|
|
||||||
if (zone) {
|
if (zone) {
|
||||||
const { data: zd } = await supabase
|
const { data: zd } = await supabase
|
||||||
@@ -23,22 +24,25 @@ export default async function ReportPage({ searchParams }: Props) {
|
|||||||
.select('id, name, site_id, sites (name)')
|
.select('id, name, site_id, sites (name)')
|
||||||
.eq('qr_code_token', zone)
|
.eq('qr_code_token', zone)
|
||||||
.single()
|
.single()
|
||||||
zoneData = zd as typeof zoneData
|
if (zd) {
|
||||||
|
zoneName = (zd as { name: string }).name ?? null
|
||||||
|
siteName = (zd.sites as unknown as { name: string } | null)?.name ?? null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="min-h-screen bg-gray-50 py-6 px-4 max-w-lg mx-auto">
|
<main className="min-h-screen bg-gray-50 py-6 px-4 max-w-lg mx-auto">
|
||||||
<div className="mb-6">
|
<div className="mb-6">
|
||||||
<h1 className="text-2xl font-bold text-gray-900">Report an Incident</h1>
|
<h1 className="text-2xl font-bold text-gray-900">Report an Incident</h1>
|
||||||
{zoneData ? (
|
{zoneName ? (
|
||||||
<p className="text-sm text-gray-600 mt-1">
|
<p className="text-sm text-gray-600 mt-1">
|
||||||
{zoneData.sites.name} — {zoneData.name}
|
{siteName ?? 'Unknown Site'} — {zoneName}
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<p className="text-sm text-amber-600 mt-1">No zone detected — zone will not be recorded</p>
|
<p className="text-sm text-amber-600 mt-1">No zone detected — zone will not be recorded</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<ReportForm zoneToken={zone ?? null} zoneName={zoneData?.name ?? null} siteName={zoneData?.sites.name ?? null} />
|
<ReportForm zoneToken={zone ?? null} zoneName={zoneName} siteName={siteName} />
|
||||||
</main>
|
</main>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user