|
| 1 | +// src/pages/user_dashboard.tsx (Update the import path) |
| 2 | +//import ""; |
| 3 | +import { useEffect,useState } from "react"; |
| 4 | + |
| 5 | +import InventoryItemModal from "../popups/user_inventory_select_popup"; |
| 6 | + |
| 7 | +export type InventoryItem = { |
| 8 | + id: number; |
| 9 | + name: string; |
| 10 | + date: string; |
| 11 | +}; |
| 12 | + |
| 13 | +const UserInventoryTable = () => { |
| 14 | + const [inventory, setInventory] = useState<InventoryItem[]>([]); |
| 15 | + const [selectedItem, setSelectedItem] = useState<InventoryItem | null>(null); |
| 16 | + const [isModalOpen, setIsModalOpen] = useState(false); |
| 17 | + |
| 18 | + // Mock data (replace with Django API call later) |
| 19 | + useEffect(() => { |
| 20 | + const mockInventory: InventoryItem[] = Array.from( |
| 21 | + { length: 30 }, |
| 22 | + (_, i) => ({ |
| 23 | + id: i + 1, |
| 24 | + name: `Item ${i + 1}`, |
| 25 | + date: |
| 26 | + ((Math.floor(Math.random() * 10) % 11) + 1).toString() + |
| 27 | + "/" + |
| 28 | + (Math.floor(Math.random() * 10) + 1).toString() + |
| 29 | + "/2026", |
| 30 | + }), |
| 31 | + ); |
| 32 | + { |
| 33 | + /* have |
| 34 | + is_due_soon = date is larger than 2 weeks |
| 35 | + in the array? -- as flag for due soon inventory */ |
| 36 | + } |
| 37 | + setInventory(mockInventory); |
| 38 | + }, []); |
| 39 | + |
| 40 | + return ( |
| 41 | + <> |
| 42 | + {/* Scrollable container */} |
| 43 | + <div className="flex-1 cursor-pointer overflow-y-auto rounded-md border"> |
| 44 | + {/* logic for clicking to open pop-up window to edit/resolve an item*/} |
| 45 | + |
| 46 | + {inventory.length === 0 ? ( |
| 47 | + <p className="py-6 text-center text-gray-500">No items found.</p> |
| 48 | + ) : ( |
| 49 | + inventory.map((item) => ( |
| 50 | + <div |
| 51 | + key={item.id} |
| 52 | + onClick={() => { |
| 53 | + setSelectedItem(item); |
| 54 | + setIsModalOpen(true); |
| 55 | + }} |
| 56 | + className="flex items-center justify-between border-b px-3 py-3 last:border-b-0 hover:bg-gray-50" |
| 57 | + > |
| 58 | + <span className="font-medium text-gray-800">{item.name}</span> |
| 59 | + <span className="font-medium text-gray-800"> |
| 60 | + date:{item.date} |
| 61 | + </span> |
| 62 | + </div> |
| 63 | + )) |
| 64 | + )} |
| 65 | + </div> |
| 66 | + <InventoryItemModal |
| 67 | + isOpen={isModalOpen} |
| 68 | + item={selectedItem} |
| 69 | + onClose={() => setIsModalOpen(false)} |
| 70 | + /> |
| 71 | + </> |
| 72 | + ); |
| 73 | +}; |
| 74 | +export default UserInventoryTable; |
0 commit comments