1.7 KiB
Fix Task 7 — Build-breaking issues in RoomsPage
Changes made to apps/admin/src/pages/Rooms/index.tsx
-
Restored
const RoomsPage: React.FC = () => {wrapper — was accidentally removed, leaving state hooks dangling at module scope. Added at line 66. -
Restored
const [data, setData] = useState<any[]>([]);— was removed but referenced bybuildingsuseMemo andfetchData. Added right after the component opener. -
Added
useCallbackto React import (line 1) — needed for wrapping fetchBeds/fetchLockers. -
Fixed
handleSavefunction — its closing};was accidentally overwritten by the fetchBeds edit. Restored at line 160. -
Wrapped
fetchBedsandfetchLockersinuseCallback— they're in thecolumnsuseMemo deps array, but as plainconstfunctions they'd be recreated every render, causing unnecessary re-renders. Now wrapped with[]deps since they only reference stableapiand state setters. -
Deleted orphaned leftover code — old
} catch (e) { console.error(e); }\n };from the pre-useCallback fetchBeds definition was still present after the replacement. -
Fixed broken action column JSX — the ternary for archived/non-archived rows had mixed branches: the archived=true branch contained ALL buttons (恢复, 查看, 编辑, 归档) instead of only 恢复, with a dangling
</>closing a non-existent fragment. Restructured to: archived branch → just<Popconfirm>恢复</Popconfirm>; else branch → fragment-wrapped<查看/编辑/归档>. Also fixed missing]: [deps]useMemo closing after the action column array member. -
Removed Tooltip — not imported/unused. (Already clean; no action needed.)
Verification
npx tsc --noEmitpasses with zero errors.