Add inventory audit mode with camera QR scanning
Lets an employee walk the premises, scan each object's QR to confirm it's present and record where it was found (defaulting to the last picked location), and track found/not-found progress for the walk. Scanning a box's QR shows its contents read-only without affecting the found/not-found counts. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
37
frontend/src/hooks/useAuditSession.ts
Normal file
37
frontend/src/hooks/useAuditSession.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { useCallback, useState } from 'react'
|
||||
|
||||
const SESSION_START_KEY = 'inventory_audit_session_start'
|
||||
const LAST_BOX_KEY = 'inventory_audit_last_box_id'
|
||||
|
||||
function readSessionStart(): number {
|
||||
const raw = sessionStorage.getItem(SESSION_START_KEY)
|
||||
if (raw) return Number(raw)
|
||||
const now = Date.now()
|
||||
sessionStorage.setItem(SESSION_START_KEY, String(now))
|
||||
return now
|
||||
}
|
||||
|
||||
/** Tracks the current audit walk: when it started (for the found/not-found split) and the
|
||||
* last room/box picked, so the next scanned object can default to the same location. */
|
||||
export function useAuditSession() {
|
||||
const [sessionStart, setSessionStart] = useState<number>(readSessionStart)
|
||||
const [lastBoxId, setLastBoxIdState] = useState<string | null>(() =>
|
||||
sessionStorage.getItem(LAST_BOX_KEY),
|
||||
)
|
||||
|
||||
const restart = useCallback(() => {
|
||||
const now = Date.now()
|
||||
sessionStorage.setItem(SESSION_START_KEY, String(now))
|
||||
sessionStorage.removeItem(LAST_BOX_KEY)
|
||||
setSessionStart(now)
|
||||
setLastBoxIdState(null)
|
||||
}, [])
|
||||
|
||||
const setLastBoxId = useCallback((boxId: string | null) => {
|
||||
if (boxId) sessionStorage.setItem(LAST_BOX_KEY, boxId)
|
||||
else sessionStorage.removeItem(LAST_BOX_KEY)
|
||||
setLastBoxIdState(boxId)
|
||||
}, [])
|
||||
|
||||
return { sessionStart, restart, lastBoxId, setLastBoxId }
|
||||
}
|
||||
Reference in New Issue
Block a user