diff --git a/app.db-shm b/app.db-shm deleted file mode 100644 index fe9ac284..00000000 Binary files a/app.db-shm and /dev/null differ diff --git a/app.db-wal b/app.db-wal deleted file mode 100644 index e69de29b..00000000 diff --git a/bin/Debug/net8.0/Web-Development.dll b/bin/Debug/net8.0/Web-Development.dll index 510bced2..52ce399e 100644 Binary files a/bin/Debug/net8.0/Web-Development.dll and b/bin/Debug/net8.0/Web-Development.dll differ diff --git a/bin/Debug/net8.0/Web-Development.pdb b/bin/Debug/net8.0/Web-Development.pdb index c8f9da11..3904d945 100644 Binary files a/bin/Debug/net8.0/Web-Development.pdb and b/bin/Debug/net8.0/Web-Development.pdb differ diff --git a/frontend/clientapp/src/App.tsx b/frontend/clientapp/src/App.tsx index 72ee5197..91a0aaa6 100644 --- a/frontend/clientapp/src/App.tsx +++ b/frontend/clientapp/src/App.tsx @@ -11,6 +11,7 @@ import AdminDashboard from './components/shop/Admindashboard'; import UserDetails from './components/auth/Userdetails'; import Achievements from './components/achievements/Achievements'; import Layout from './components/layout/Layout'; +import UserDashboard from './components/shop/UserDashboard'; interface ProtectedRouteProps { children: ReactNode; @@ -72,6 +73,12 @@ function App() { } /> + + + + + } /> diff --git a/frontend/clientapp/src/components/calendar/events.tsx b/frontend/clientapp/src/components/calendar/events.tsx index 561c9bf2..fdd63e63 100644 --- a/frontend/clientapp/src/components/calendar/events.tsx +++ b/frontend/clientapp/src/components/calendar/events.tsx @@ -1,29 +1,30 @@ import React, { useEffect, useState } from "react"; -import { Loader2, CheckCircle, XCircle, ArrowUpDown, ChevronDown, MoreHorizontal, Pencil, Trash2 } from "lucide-react"; -import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "../../components/ui/dialog" -import { ColumnDef, ColumnFiltersState, SortingState, - VisibilityState, flexRender, getCoreRowModel, - getFilteredRowModel, getPaginationRowModel, getSortedRowModel, - useReactTable -} from "@tanstack/react-table" - -import { Label } from "../../components/ui/label" - -import { Button } from "../../components/ui/button" -import { Input } from "../../components/ui/input" - -import { DropdownMenu, DropdownMenuCheckboxItem, - DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, - DropdownMenuSeparator, DropdownMenuTrigger -} from "../../components/ui/dropdown-menu" - -import { Table, TableBody, TableCell, - TableHead, TableHeader, TableRow -} from "../../components/ui/table" - -import { Textarea } from "../../components/ui/textarea" - -import { Checkbox } from "../../components/ui/checkbox" +import { + Loader2, + CheckCircle, + XCircle, + ArrowUpDown, + ChevronDown, + MoreHorizontal, + Trash2, + Clipboard, + Plus, + Users, +} from "lucide-react"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "../../components/ui/dialog"; +import { Button } from "../../components/ui/button"; +import { Input } from "../../components/ui/input"; +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../../components/ui/table"; +import { Checkbox } from "../../components/ui/checkbox"; +import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from "../../components/ui/dropdown-menu"; interface Event { id: string; @@ -35,105 +36,88 @@ interface Event { approval: boolean; } -const EventsDashboard: React.FC = () => { +interface User { + id: string; + role: string; // To check if user is admin +} +const EventsDashboard: React.FC = () => { const [events, setEvents] = useState([]); + const [user, setUser] = useState(null); const [loading, setLoading] = useState(true); + const [isAdmin, setIsAdmin] = useState(false); // Check if the user is an admin const [error, setError] = useState(null); - const [sorting, setSorting] = React.useState([]) - const [columnFilters, setColumnFilters] = React.useState([]) - const [columnVisibility, setColumnVisibility] = React.useState({}) - const [rowSelection, setRowSelection] = React.useState({}) - const [id, setId] = useState(""); - const [title, setTitle] = useState(""); - const [description, setDescription] = useState(""); - const [startTime, setStartTime] = useState(""); - const [endTime, setEndTime] = useState(""); - const [location, setLocation] = useState(""); - const [approval, setApproval] = useState(false); - - const handleUpdateEvent = async (e: React.FormEvent) => { - e.preventDefault(); + useEffect(() => { + const fetchUserData = async () => { + const token = localStorage.getItem("token"); + if (!token) { + alert("User is not logged in"); + return; + } - const updatedEvent = { - Id: id, - Title: title, - Description: description, - StartTime: startTime, - EndTime: endTime, - Location: location, - Approval: approval, + try { + // Fetch user data + const userResponse = await fetch("http://localhost:5001/api/user/fromToken", { + headers: { + Authorization: `Bearer ${token}`, + "Content-Type": "application/json", + }, + }); + + if (!userResponse.ok) throw new Error("Failed to fetch user data"); + + const userData: User = await userResponse.json(); + setUser(userData); + setIsAdmin(userData.role === "Admin"); // Check if user is admin + } catch (err) { + setError("Failed to load user data"); + } }; - try { - const response = await fetch("http://localhost:5001/api/events/update", { - method: "PUT", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(updatedEvent), - }); - - if (response.ok) { - const updatedEventData = await response.json(); - alert("Event updated successfully!"); - setEvents((prevEvents) => - prevEvents.map((evt) => (evt.id === id ? updatedEventData : evt)) - ); - } else { - throw new Error("Failed to update event."); + const fetchEvents = async () => { + try { + const response = await fetch("http://localhost:5001/api/events/all"); + if (!response.ok) throw new Error("Failed to fetch events."); + const data: Event[] = await response.json(); + setEvents(data); + } catch (err) { + setError("Something went wrong."); + } finally { + setLoading(false); } - } catch (error) { - alert(error); - } - }; - - const handleCreateEvent = async (e: React.FormEvent) => { - e.preventDefault(); - - const newEvent = { - Title: title, - Description: description, - StartTime: startTime, - EndTime: endTime, - Location: location, - Approval: approval, }; - try { - const response = await fetch("http://localhost:5001/api/events/create", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(newEvent), - }); + fetchUserData(); + fetchEvents(); + }, []); - if (!response.ok) { - throw new Error(`Failed to update event: ${response.statusText}`); - } - - const contentType = response.headers.get("content-type"); - if (contentType && contentType.includes("application/json")) { - const data = await response.json(); - alert("Event updated successfully!"); - console.log(data); // Debugging: Check the returned data - } else { - alert("Event updated successfully!"); - } - } catch (error) { - alert(error); - } + const handleJoinEvent = (eventId: string) => { + alert(`You joined event with ID: ${eventId}`); + // Implement join logic here + }; + + const handleCopyEventId = (eventId: string) => { + navigator.clipboard.writeText(eventId); + alert(`Copied Event ID: ${eventId}`); }; const handleDeleteEvent = async (eventId: string) => { + if (!isAdmin) { + alert("Only admins can delete events."); + return; + } + try { const response = await fetch(`http://localhost:5001/api/events/delete/${eventId}`, { method: "DELETE", headers: { "Content-Type": "application/json" }, }); - + if (!response.ok) { - throw new Error(`Failed to delete event: ${response.statusText}`); + throw new Error("Failed to delete event."); } - + alert("Event deleted successfully!"); setEvents((prevEvents) => prevEvents.filter((event) => event.id !== eventId)); } catch (error) { @@ -141,109 +125,6 @@ const EventsDashboard: React.FC = () => { } }; - React.useEffect(() => { - const fetchEvents = async () => { - try { - const response = await fetch("http://localhost:5001/api/events/all"); - if (!response.ok) throw new Error("Failed to fetch events."); - const data: Event[] = await response.json(); - setEvents(data); - } catch (err) { - setError("Something went wrong."); - } finally { - setLoading(false); - } - }; - fetchEvents(); - }, []); - - const columns: ColumnDef[] = [ - { - accessorKey: "id", - header: "ID", - cell: ({ row }) => (
{row.getValue("id")}
) - }, - { - accessorKey: "title", - header: ({ column }) => { - return ( - - ) - }, - cell: ({ row }) =>
{row.getValue("title")}
- }, - { - accessorKey: "description", - header: "Description", - cell: ({ row }) =>
{row.getValue("description")}
- }, - { - accessorKey: "startTime", - header: "Start Time", - cell: ({ row }) =>
{row.getValue("startTime")}
- }, - { - accessorKey: "endTime", - header: "End Time", - cell: ({ row }) =>
{row.getValue("endTime")}
- }, - { - accessorKey: "location", - header: "Location", - cell: ({ row }) =>
{row.getValue("location")}
- }, - { - accessorKey: "approval", - header: "Approval", - cell: ({ row }) =>
{row.getValue("approval") ? : }
- }, - { - id: "actions", - enableHiding: false, - cell: ({ row }) => { - const payment = row.original - - return ( - - - - - - Actions - navigator.clipboard.writeText(payment.id)}>Copy ID - - {handleDeleteEvent(payment.id)}}> Delete Event - - - - ) - }, - }, - ] - - const table = useReactTable({ - data: events, - columns, - onSortingChange: setSorting, - onColumnFiltersChange: setColumnFilters, - getCoreRowModel: getCoreRowModel(), - getPaginationRowModel: getPaginationRowModel(), - getSortedRowModel: getSortedRowModel(), - getFilteredRowModel: getFilteredRowModel(), - onColumnVisibilityChange: setColumnVisibility, - onRowSelectionChange: setRowSelection, - state: { - sorting, - columnFilters, - columnVisibility, - rowSelection, - }, - }) - if (loading) { return (
@@ -263,190 +144,103 @@ const EventsDashboard: React.FC = () => { return (
- table.getColumn("title")?.setFilterValue(event.target.value)} className="max-w-sm"/> - - - - - - - - Create event - Make changes to your event here. Click save when you're done. - -
-
- -
- - setTitle(e.target.value)} required/> -
- -
- -