feat(report): site and zone picker when no QR zone is detected
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
export type ZoneOption = { id: string; name: string; qr_code_token: string }
|
||||
export type SiteOption = { id: string; name: string; zones: ZoneOption[] }
|
||||
export type ZoneRow = { siteId: string; siteName: string; zoneId: string; zoneName: string; token: string }
|
||||
|
||||
export function groupSites(rows: ZoneRow[]): SiteOption[] {
|
||||
const bySite = new Map<string, SiteOption>()
|
||||
for (const r of rows) {
|
||||
let site = bySite.get(r.siteId)
|
||||
if (!site) {
|
||||
site = { id: r.siteId, name: r.siteName, zones: [] }
|
||||
bySite.set(r.siteId, site)
|
||||
}
|
||||
site.zones.push({ id: r.zoneId, name: r.zoneName, qr_code_token: r.token })
|
||||
}
|
||||
return [...bySite.values()]
|
||||
}
|
||||
|
||||
export function zonesForSite(sites: SiteOption[], siteId: string): ZoneOption[] {
|
||||
return sites.find(s => s.id === siteId)?.zones ?? []
|
||||
}
|
||||
|
||||
export function resolveZoneToken(args: {
|
||||
zoneToken: string | null
|
||||
sites: SiteOption[]
|
||||
zoneId: string
|
||||
}): string | null {
|
||||
if (args.zoneToken) return args.zoneToken
|
||||
for (const site of args.sites) {
|
||||
const zone = site.zones.find(z => z.id === args.zoneId)
|
||||
if (zone) return zone.qr_code_token
|
||||
}
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user