diff --git a/admin/src/Layout/Dashboard.tsx b/admin/src/Layout/Dashboard.tsx index 0d60ae5..040254c 100644 --- a/admin/src/Layout/Dashboard.tsx +++ b/admin/src/Layout/Dashboard.tsx @@ -36,7 +36,7 @@ const Dashboard: React.FC = ({ onLogout }) => { borderColor="gray.200" bg="gray.900" > - Dashboard + Dashboard Willkommen {userName}, im Admin-Dashboard! diff --git a/admin/src/Layout/Sidebar.tsx b/admin/src/Layout/Sidebar.tsx index 92e5699..37e2d27 100644 --- a/admin/src/Layout/Sidebar.tsx +++ b/admin/src/Layout/Sidebar.tsx @@ -39,7 +39,7 @@ const Sidebar: React.FC = ({ _hover={{ bg: "gray.700", textDecoration: "none" }} onClick={viewUser} > - User + Benutzer { - return <>Loan Table; + const [items, setItems] = useState([]); + const [errorStatus, setErrorStatus] = useState<"error" | "success">("error"); + const [errorMessage, setErrorMessage] = useState(""); + const [errorDsc, setErrorDsc] = useState(""); + const [isError, setIsError] = useState(false); + const [isLoading, setIsLoading] = useState(false); + + const setError = ( + status: "error" | "success", + message: string, + description: string + ) => { + setIsError(false); + setErrorStatus(status); + setErrorMessage(message); + setErrorDsc(description); + setIsError(true); + }; + + type Loan = { + id: number; + username: string; + loan_code: string; + start_date: string; + end_date: string; + take_date: string; + returned_date: string; + created_at: string; + loaned_items_name: string[]; + }; + + useEffect(() => { + const fetchData = async () => { + setIsLoading(true); + try { + const response = await fetch("http://localhost:8002/api/allLoans", { + method: "GET", + headers: { + Authorization: `Bearer ${Cookies.get("token")}`, + }, + }); + const data = await response.json(); + return data; + } catch (error) { + setError("error", "Failed to fetch loans", "There is an error"); + } finally { + setIsLoading(false); + } + }; + fetchData().then((data) => { + if (Array.isArray(data)) { + setItems(data); + } + }); + }, []); + + return ( + <> + + Ausleihen + + {isError && ( + + )} + {isLoading && ( + + + Loading... + + )} + {!isLoading && ( + + + + + # + + + Besitzer + + + Ausleih code + + + Startdatum + + + Enddatum + + + Ausleihdatum + + + Rückgabedatum + + + Erstellt am + + + Ausgeliehene Artikel + + + Aktionen + + + + + {items.map((item) => ( + + {item.id} + {item.username} + + {item.loan_code} + + {formatDateTime(item.start_date)} + {formatDateTime(item.end_date)} + {formatDateTime(item.take_date)} + {formatDateTime(item.returned_date)} + {formatDateTime(item.created_at)} + {item.loaned_items_name.join(", ")} + + + + + ))} + + + )} + + ); }; export default LoanTable; diff --git a/admin/src/components/UserTable.tsx b/admin/src/components/UserTable.tsx index b9efaa6..6d91078 100644 --- a/admin/src/components/UserTable.tsx +++ b/admin/src/components/UserTable.tsx @@ -9,6 +9,7 @@ import { Input, HStack, IconButton, + Heading, } from "@chakra-ui/react"; import { Tooltip } from "@/components/ui/tooltip"; import { fetchUserData } from "@/utils/fetcher"; @@ -16,6 +17,7 @@ import { Save, Trash2, RefreshCcwDot, CirclePlus } from "lucide-react"; import { handleDelete, handleEdit } from "@/utils/userActions"; import MyAlert from "./myChakra/MyAlert"; import AddForm from "./AddForm"; +import { formatDateTime } from "@/utils/userFuncs"; type User = { id: number; @@ -134,6 +136,9 @@ const UserTable: React.FC = () => { {/* End action toolbar */} + + Benutzer + {isError && ( { - id - Username - Password - Role - Entry Created At - Actions + + # + + + Benutzername + + + Passwort + + + Rolle + + + Eintrag erstellt am + + + Aktionen + @@ -197,7 +214,7 @@ const UserTable: React.FC = () => { value={user.role} /> - {user.entry_created_at} + {formatDateTime(user.entry_created_at)}