import { Divider } from "antd"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import { useAuth } from "../../contexts/authContext"; import { Team, TeamStatus } from "../../models/team"; import { User, UserStatus } from "../../models/user"; import TeamService from "../../services/teamService"; const initialSite: string = "https://"; const teamService = new TeamService(); export default function CreateTeam() { const { currUser } = useAuth(); const [error, setError] = useState(""); const [loading, setLoading] = useState(true); const router = useRouter(); useEffect(() => { (async function () { try { // if not authenticated, take user to the login if (!currUser) { console.log( "not authenticated...routing from dashboard to teams home" ); router.push("/teams/login"); } // todo if user is in a team already, notify them to make sure // buttt most likely will already be routed to the correct place from the router...don't do the router's job } catch (error) { console.log(error); router.push("/teams/login"); } 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 = currUser.uid; team.status = TeamStatus.created; if (companySite != initialSite) { // make sure to put null in database for the team team.companySite = companySite; } // provision a team with state of initiated const createdTeamId = await teamService.createTeam(team); router.push("/teams/" + createdTeamId); } catch (error) { setError(error.message); } setLoading(false); } const [teamName, setTeamName] = useState(""); const [companySite, setcompanySite] = useState(initialSite); return (
{/* header */}
🙌Create a Team
{error && {error}} Team Name Everyone in your team will see this. You can always change this later. setTeamName(e.target.value)} /> Company Site optional setcompanySite(e.target.value)} /> {loading ? (
Loading...
) : ( )}
); }