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 TeamAdminWrapper() {
return (
);
}
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 (
);
}