Files
inventory/frontend/src/hooks/useAuditSession.ts
jze9 d6a7ac0a68 Replace box picker with free-text location in audit scan
"Where found" during inventory audit is now a plain text field
(e.g. "каб. 305") stored on the object instead of assigning it to a
box, since audit walks often use room/office labels that don't map
to the box/shelf hierarchy used elsewhere. Box assignment via the
regular object form is unaffected.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-22 15:41:30 +05:00

38 lines
1.3 KiB
TypeScript

import { useCallback, useState } from 'react'
const SESSION_START_KEY = 'inventory_audit_session_start'
const LAST_LOCATION_KEY = 'inventory_audit_last_location'
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 location typed in, so the next scanned object can default to the same location. */
export function useAuditSession() {
const [sessionStart, setSessionStart] = useState<number>(readSessionStart)
const [lastLocation, setLastLocationState] = useState<string | null>(() =>
sessionStorage.getItem(LAST_LOCATION_KEY),
)
const restart = useCallback(() => {
const now = Date.now()
sessionStorage.setItem(SESSION_START_KEY, String(now))
sessionStorage.removeItem(LAST_LOCATION_KEY)
setSessionStart(now)
setLastLocationState(null)
}, [])
const setLastLocation = useCallback((location: string | null) => {
if (location) sessionStorage.setItem(LAST_LOCATION_KEY, location)
else sessionStorage.removeItem(LAST_LOCATION_KEY)
setLastLocationState(location)
}, [])
return { sessionStart, restart, lastLocation, setLastLocation }
}