From eef5b0cca3a5b90d398c856a9d71eb172dd1c62e Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Mon, 22 Jul 2024 22:20:20 +0200 Subject: [PATCH] Update Home.jsx page --- .../src/states/Dashboard/pages/Home/Home.jsx | 72 +++++++++++++++++-- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/dashboard/src/states/Dashboard/pages/Home/Home.jsx b/dashboard/src/states/Dashboard/pages/Home/Home.jsx index 88bd49d..c68542b 100644 --- a/dashboard/src/states/Dashboard/pages/Home/Home.jsx +++ b/dashboard/src/states/Dashboard/pages/Home/Home.jsx @@ -1,24 +1,86 @@ -import {Stack, Typography} from "@mui/material"; -import {useContext} from "react"; +import {Box, Divider, IconButton, Stack, Typography} from "@mui/material"; +import {useContext, useEffect, useState} from "react"; import {UserContext} from "@contexts/User"; import {ProjectContext} from "@/states/Dashboard/contexts/Project"; import ProjectBox from "./components/ProjectBox"; +import {Add, Check, Close} from "@mui/icons-material"; +import ProjectCreationDialog from "./components/ProjectCreationDialog"; +import {getRequest, postRequest} from "@/common/utils/RequestUtil.js"; export const Home = () => { - const {user} = useContext(UserContext); - const {projects} = useContext(ProjectContext); + const {projects, updateProjects} = useContext(ProjectContext); + + const [creationDialogOpen, setCreationDialogOpen] = useState(false); + const [invitations, setInvitations] = useState([]); + + const boxStyle = {cursor: "pointer", "&:hover": {backgroundColor: "divider"}, + "&:active": {backgroundColor: "divider", scale: "0.95"}, "&:focus": {outline: "none"}, + transition: "all 0.1s ease-in-out", userSelect: "none"}; + + const manageInvitation = async (invitation, accept) => { + try { + await postRequest(`/user/me/invitations/${invitation.id}/${accept ? "accept" : "decline"}`); + setInvitations(invitations.filter((i) => i.id !== invitation.id)); + await updateProjects(); + } catch (e) { + console.error(e.message); + } + } + + useEffect(() => { + const fetchInvitations = async () => { + try { + const data = await getRequest("/user/me/invitations"); + if (data instanceof Array) setInvitations(data); + } catch (e) { + console.error(e.message); + } + } + + fetchInvitations(); + }, []); return ( + setCreationDialogOpen(false)} /> Dashboard Welcome back, {user.username}. Your projects: - {projects.map((project, index) => )} + {projects.map((project, index) => )} + setCreationDialogOpen(true)}> + + + + + + Create + + + {invitations.length > 0 && + Invitations: + + {invitations.map((invitation, index) => + + {invitation.name} + + + manageInvitation(invitation, true)}> + + + manageInvitation(invitation, false)}> + + + + )} + + } ) } \ No newline at end of file