diff --git a/pages/api/teams.ts b/pages/api/teams.ts index bca5901fa9..aa708fc9ae 100644 --- a/pages/api/teams.ts +++ b/pages/api/teams.ts @@ -23,7 +23,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) }); if (nameCollisions > 0) { - return res.status(409).json({ errorCode: "TeamNameCollision", message: "Team name already take." }); + return res + .status(409) + .json({ errorCode: "TeamNameCollision", message: "Team username already taken." }); } const createTeam = await prisma.team.create({ diff --git a/pages/settings/teams.tsx b/pages/settings/teams.tsx index 6396340a75..a5d45513fd 100644 --- a/pages/settings/teams.tsx +++ b/pages/settings/teams.tsx @@ -13,6 +13,7 @@ import Shell from "@components/Shell"; import EditTeam from "@components/team/EditTeam"; import TeamList from "@components/team/TeamList"; import TeamListItem from "@components/team/TeamListItem"; +import { Alert } from "@components/ui/Alert"; import Button from "@components/ui/Button"; export default function Teams() { @@ -24,6 +25,8 @@ export default function Teams() { const [showCreateTeamModal, setShowCreateTeamModal] = useState(false); const [editTeamEnabled, setEditTeamEnabled] = useState(false); const [teamToEdit, setTeamToEdit] = useState(); + const [hasErrors, setHasErrors] = useState(false); + const [errorMessage, setErrorMessage] = useState(""); const nameRef = useRef() as React.MutableRefObject; const handleErrors = async (resp: Response) => { @@ -48,6 +51,11 @@ export default function Teams() { loadData(); }, []); + useEffect(() => { + setHasErrors(false); + setErrorMessage(""); + }, [showCreateTeamModal]); + if (loading) { return ; } @@ -60,10 +68,16 @@ export default function Teams() { headers: { "Content-Type": "application/json", }, - }).then(() => { - loadData(); - setShowCreateTeamModal(false); - }); + }) + .then(handleErrors) + .then(() => { + loadData(); + setShowCreateTeamModal(false); + }) + .catch((err) => { + setHasErrors(true); + setErrorMessage(err.message); + }); }; const editTeam = (team: Team) => { @@ -162,6 +176,7 @@ export default function Teams() { + {hasErrors && }