From 755ebfd06b1e2b21d32f7fb9b905c4bdc98b9a9b Mon Sep 17 00:00:00 2001 From: Theis Gaedigk Date: Thu, 11 Sep 2025 16:40:31 +0200 Subject: [PATCH] added inpu elemts and backend API routes for changing the item table --- admin/src/components/ItemTable.tsx | 55 ++++++++++++++++++++++++++++-- admin/src/utils/userActions.ts | 13 +++++++ backend/routes/api.js | 23 +++++++++++++ backend/services/database.js | 9 +++++ 4 files changed, 97 insertions(+), 3 deletions(-) diff --git a/admin/src/components/ItemTable.tsx b/admin/src/components/ItemTable.tsx index acc83fe..d18123e 100644 --- a/admin/src/components/ItemTable.tsx +++ b/admin/src/components/ItemTable.tsx @@ -10,6 +10,7 @@ import { Heading, Icon, Tag, + Input, } from "@chakra-ui/react"; import { Tooltip } from "@/components/ui/tooltip"; import MyAlert from "./myChakra/MyAlert"; @@ -19,10 +20,11 @@ import { CirclePlus, CheckCircle2, XCircle, + Save, } from "lucide-react"; import Cookies from "js-cookie"; import { useState, useEffect } from "react"; -import { deleteItem } from "@/utils/userActions"; +import { deleteItem, handleEditItems } from "@/utils/userActions"; import AddItemForm from "./AddItemForm"; import { formatDateTime } from "@/utils/userFuncs"; @@ -44,6 +46,18 @@ const ItemTable: React.FC = () => { const [reload, setReload] = useState(false); const [addForm, setAddForm] = useState(false); + const handleItemNameChange = (id: number, value: string) => { + setItems((prev) => + prev.map((it) => (it.id === id ? { ...it, item_name: value } : it)) + ); + }; + + const handleCanBorrowRoleChange = (id: number, value: string) => { + setItems((prev) => + prev.map((it) => (it.id === id ? { ...it, can_borrow_role: value } : it)) + ); + }; + const setError = ( status: "error" | "success", message: string, @@ -180,8 +194,22 @@ const ItemTable: React.FC = () => { {items.map((item) => ( {item.id} - {item.item_name} - {item.can_borrow_role} + + + handleItemNameChange(item.id, e.target.value) + } + value={item.item_name} + /> + + + + handleCanBorrowRoleChange(item.id, e.target.value) + } + value={item.can_borrow_role} + /> + {item.inSafe ? ( { {formatDateTime(item.entry_created_at)} +