Integrate state, routing, accessibility and localization
Integrate the dashboard without duplicating state
Use the URL for the filter, component state for draft input, and one owner for the loaded inventory. The offline API is the authoritative data model; the UI holds a snapshot. A production server-state cache could replace the explicit request logic, but a second global store is not necessary here. The selected ID and input text are local form state. Never derive permissions from editable URL values.
export function formatQuantity(value, locale='en-US') { return new Intl.NumberFormat(locale==='en-GB'?'en-GB':'en-US').format(value);}export function replaceItem(items, replacement) { return items.map(item=>item.id===replacement.id?replacement:item);}Keep stored quantities numeric. Formatting is applied only at display time. Both English locales currently use similar grouping for integers; localization should not introduce invented differences. The locale is restricted to two supported English regions. Translation infrastructure is a design extension, not a requirement to add Persian content.
import React from 'react';export function Button({children,...props}) { return <button type="button" {...props}>{children}</button>;}export function Status({children}) { return <p role="status">{children}</p>; }export function TextField({id,label,...props}) { return <div><label htmlFor={id}>{label}</label><input id={id} {...props}/></div>;}Native buttons, labels and status messages provide a starting point for accessible behavior. A reusable primitive must preserve its native keyboard semantics; passing props does not by itself ensure accessibility. Use a unique input ID for each mounted field.
Connect routing, forms and async states
import React, {useState,useEffect} from 'react';import {Link, Route, Routes, useSearchParams} from 'react-router';import {canAdjust,filterItems,parseQuantity} from './contracts.mjs';import {formatQuantity,replaceItem} from './formatting.mjs';import {Button,Status,TextField} from './primitives.jsx';function Inventory({api,actor,locale}) { const [params,setParams]=useSearchParams(); const query=params.get('q')??''; const [items,setItems]=useState([]); const [phase,setPhase]=useState('loading'); const [attempt,setAttempt]=useState(0); const [busy,setBusy]=useState(false); const [message,setMessage]=useState(''); const [draft,setDraft]=useState(''); const [selected,setSelected]=useState('drill'); useEffect(()=>{ let active=true; api.list().then(rows=>{if(active){setItems(rows);setPhase('ready');}},()=>{if(active)setPhase('error');}); return ()=>{active=false;}; },[api,attempt]); function reload(){setPhase('loading');setAttempt(n=>n+1);} async function submit(event){ event.preventDefault(); const item=items.find(x=>x.id===selected); const quantity=parseQuantity(draft); if(!item||quantity===null){setMessage('Enter a whole quantity from 0 to 999.');return;} setBusy(true);setMessage('Saving'); const before=items; setItems(rows=>replaceItem(rows,{...item,quantity})); try { const result=await api.adjust(item.id,draft,item.version); if(!result.ok){setItems(before);setMessage(result.status===409?'Conflict. Reload and retry.':'Save rejected.');if(result.status===409)reload();} else {setItems(rows=>replaceItem(rows,result.item));setMessage('Saved');} } catch {setItems(before);setMessage('Save failed. Retry.');} finally {setBusy(false);} } if(phase==='loading')return <Status>Loading inventory</Status>; if(phase==='error')return <section><p role="alert">Inventory unavailable</p><Button onClick={reload}>Retry</Button></section>; const visible=filterItems(items,query); return <section><h2>Inventory</h2><TextField id="filter" label="Filter equipment" value={query} onChange={e=>setParams(e.target.value?{q:e.target.value}:{})}/> <table><caption>Equipment quantities</caption><thead><tr><th scope="col">Equipment</th><th scope="col">Quantity</th></tr></thead><tbody>{visible.map(item=><tr key={item.id}><th scope="row">{item.name}</th><td>{formatQuantity(item.quantity,locale)}</td></tr>)}</tbody></table> {!visible.length&&<p>No matching equipment</p>} {canAdjust(actor)&&<form onSubmit={submit}><fieldset disabled={busy}><legend>Adjust quantity</legend><label htmlFor="equipment">Equipment</label><select id="equipment" value={selected} onChange={e=>setSelected(e.target.value)}>{items.map(x=><option key={x.id} value={x.id}>{x.name}</option>)}</select><TextField id="quantity" label="New quantity" inputMode="numeric" value={draft} onChange={e=>setDraft(e.target.value)}/><Button type="submit">Save quantity</Button></fieldset></form>} <Status>{message}</Status><Button disabled={busy} onClick={reload}>Reload inventory</Button></section>;}export default function App({api,actor}) { const [locale,setLocale]=useState('en-US'); return <main><h1>Tool library</h1><nav aria-label="Main"><Link to="/">Inventory</Link> <Link to="/about">About</Link></nav><label htmlFor="locale">English region</label><select id="locale" value={locale} onChange={e=>setLocale(e.target.value)}><option value="en-US">US</option><option value="en-GB">UK</option></select><Routes><Route path="/" element={<Inventory api={api} actor={actor} locale={locale}/>}/><Route path="/about" element={<p>Offline training fixture.</p>}/><Route path="*" element={<p>Page not found.</p>}/></Routes></main>;}This reference source expects React 18+ and React Router 7 declarative mode in a reviewed toolchain. The entry file supplies a stable API and actor. Navigate between Inventory and About; type saw to see only Saw; a manager can set Drill to 7. A viewer sees no adjustment form. Loading, error and empty states are separate. A failed save restores the previous snapshot, and a 409 triggers reload. This is a deliberately bounded single-writer fixture: no simultaneous mutation or role changes during a save, no authentication or cross-tab synchronization. In a production app use request identity and account-scoped caches to handle concurrency. Browser behavior is an acceptance target, not a verified observation.
Try a read failure using failNextRead before mounting. Retry should restore the list. Use keyboard Tab and Enter to navigate the controls. Verify the table caption, row headers and status announcements with assistive technology; passing syntax checks is not sufficient.