| | | 1 | | import { Form, Link } from "react-router"; |
| | | 2 | | import type { RoomResponse } from "~/api/client"; |
| | | 3 | | |
| | | 4 | | type RoomsListProps = { |
| | | 5 | | locationId: number; |
| | | 6 | | locationName: string; |
| | | 7 | | rooms: RoomResponse[]; |
| | | 8 | | }; |
| | | 9 | | |
| | 0 | 10 | | export function RoomsList({ locationId, locationName, rooms }: RoomsListProps) { |
| | 0 | 11 | | const base = `/locations/${locationId}/rooms`; |
| | | 12 | | |
| | 0 | 13 | | if (rooms.length === 0) { |
| | 0 | 14 | | return ( |
| | | 15 | | <div className="card-empty"> |
| | | 16 | | <p className="text-muted">No rooms in {locationName} yet.</p> |
| | | 17 | | <Link to={`${base}/new`} className="link-text" style={{ display: "inline-block", marginTop: 12 }}> |
| | | 18 | | Add the first room → |
| | | 19 | | </Link> |
| | | 20 | | </div> |
| | | 21 | | ); |
| | | 22 | | } |
| | | 23 | | |
| | 0 | 24 | | return ( |
| | | 25 | | <table className="console-table"> |
| | | 26 | | <thead> |
| | | 27 | | <tr> |
| | | 28 | | <th>Name</th> |
| | | 29 | | <th>Description</th> |
| | | 30 | | <th style={{ width: 1, whiteSpace: "nowrap" }}></th> |
| | | 31 | | </tr> |
| | | 32 | | </thead> |
| | | 33 | | <tbody> |
| | 0 | 34 | | {rooms.map((room) => ( |
| | 0 | 35 | | <tr key={room.id}> |
| | | 36 | | <td> |
| | | 37 | | <span style={{ fontWeight: 500 }}>{room.name ?? "Unnamed"}</span> |
| | | 38 | | </td> |
| | | 39 | | <td style={{ color: "var(--c-fg-3)", fontSize: 12 }}> |
| | | 40 | | {room.description || "—"} |
| | | 41 | | </td> |
| | | 42 | | <td> |
| | | 43 | | <div style={{ display: "flex", alignItems: "center", gap: 6 }}> |
| | | 44 | | <Link to={`/locations/${locationId}/rooms/${room.id}/items`} className="link-chip">Items</Link> |
| | | 45 | | <Link to={`${base}/${room.id}/edit`} className="link-chip">Edit</Link> |
| | | 46 | | <Form |
| | | 47 | | method="post" |
| | 0 | 48 | | onSubmit={(e) => { |
| | 0 | 49 | | if (!confirm("Delete this room and all its items?")) e.preventDefault(); |
| | | 50 | | }} |
| | | 51 | | > |
| | | 52 | | <input type="hidden" name="_action" value="delete" /> |
| | | 53 | | <input type="hidden" name="id" value={room.id} /> |
| | | 54 | | <button type="submit" className="link-chip" style={{ color: "var(--c-danger)", borderColor: "transpare |
| | | 55 | | Delete |
| | | 56 | | </button> |
| | | 57 | | </Form> |
| | | 58 | | </div> |
| | | 59 | | </td> |
| | | 60 | | </tr> |
| | | 61 | | ))} |
| | | 62 | | </tbody> |
| | | 63 | | </table> |
| | | 64 | | ); |
| | | 65 | | } |