From d2018bb71aa8ab6698b5bf397cc2867c4bbd3b2e Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Fri, 14 Jan 2022 18:18:40 -0800 Subject: [PATCH] simple admin page but not done --- components/Loading/index.tsx | 20 ++-- pages/teams/[teamid]/admin.tsx | 183 +++++++++++++++++++++++++++++++-- 2 files changed, 183 insertions(+), 20 deletions(-) diff --git a/components/Loading/index.tsx b/components/Loading/index.tsx index 3677ad6..0c3ba9b 100644 --- a/components/Loading/index.tsx +++ b/components/Loading/index.tsx @@ -2,20 +2,16 @@ import { Divider } from "antd"; export default function Loading() { return ( -
+
{/* header */} -
-
+
+
+
+
+
- -
Loading
- -
-
- ) -} \ No newline at end of file + ); +} diff --git a/pages/teams/[teamid]/admin.tsx b/pages/teams/[teamid]/admin.tsx index 4497556..1cc91fc 100644 --- a/pages/teams/[teamid]/admin.tsx +++ b/pages/teams/[teamid]/admin.tsx @@ -1,12 +1,179 @@ -import { useRouter } from 'next/router' +import { Divider } from "antd"; +import { useRouter } from "next/router"; +import { useEffect, useState } from "react"; +import Loading from "../../../components/Loading"; +import { + TeamDashboardContextProvider, + useTeamDashboardContext, +} from "../../../contexts/teamDashboardContext"; +import { TeamMemberRole } from "../../../models/teamMember"; +import { toast } from "react-hot-toast"; +import { Team, TeamStatus } from "../../../models/team"; -export default function TeamAdmin() { - const router = useRouter() - const { teamid } = router.query +export default function TeamAdminWrapper() { + return ( + + + + ); +} - // check if the team is a valid team route and show the dashboard for the team +const initialSite: string = "https://"; + +function TeamAdmin() { + const router = useRouter(); + const { teamid } = router.query; + const { team, userTeamMember, teamMembers, user } = useTeamDashboardContext(); + + const [error, setError] = useState(""); + const [teamName, setTeamName] = useState(team.name); + const [companySite, setcompanySite] = useState(team.companySite); + const [loading, setLoading] = useState(true); + + useEffect(() => { + (async function () { + // have checks for team and part of team or not in context + try { + // if not admin, I shouldn't be here + if (userTeamMember.role != TeamMemberRole.admin) { + toast.error("You are not allowed here!"); + router.push("/teams"); + } + } catch (error) { + console.log("something went wrong in admin team page"); + router.push("/teams"); + } + + setLoading(false); + })(); + }, []); + + async function handleSubmit(e) { + e.preventDefault(); + + setLoading(true); + + if (!teamName) { + setError("You must input a team name!"); + return; + } + + try { + const team = new Team(); + team.name = teamName; + team.createdByUserId = user.id; + team.status = TeamStatus.created; + + if (companySite != initialSite) { + // make sure to put null in database for the team + team.companySite = companySite; + } + + // check again that the team has allowed count of people + + // create invites for new people + + // update team name and company site if it changed + + // take user back to team dashboard + router.push("/teams/" + team.id); + } catch (error) { + setError(error.message); + } + + setLoading(false); + } + + if (loading) { + return ; + } return ( - this is the admin page for team: {teamid} - ) -} \ No newline at end of file +
+ {/* header */} +
🙌Manage Team
+ + {error && {error}} + + + + + Team Name + + Everyone in your team will see this. + + setTeamName(e.target.value)} + /> + + + + Company Site + optional + setcompanySite(e.target.value)} + /> + + + + + Team + + {/* current user */} +
+ asdf + + + {user.firstName + " " + user.lastName} + + + admin + + + {user.emailAddress} + +
+ + {teamMembers.map((tmember, i) => { + return ( +
+
+ + + + {tmember.inviteEmailAddress} + + {user.emailAddress} + +
+ ); + })} + + + + + + + + + ); +}