diff --git a/pages/api/teams.ts b/pages/api/teams.ts index 1ab69adbc1..ef900fbeef 100644 --- a/pages/api/teams.ts +++ b/pages/api/teams.ts @@ -30,8 +30,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) } }); - return res.status(201).setHeader('Location', process.env.BASE_URL + '/api/teams/1').send(null); + return res.status(201).json({ message: 'Team created' }); } - res.status(404).send(null); + res.status(404).json({ message: 'Team not found' }); } diff --git a/pages/settings/teams.tsx b/pages/settings/teams.tsx index e4d1dc5f0b..127192505e 100644 --- a/pages/settings/teams.tsx +++ b/pages/settings/teams.tsx @@ -1,3 +1,4 @@ +import { GetServerSideProps } from "next"; import Head from 'next/head'; import prisma from '../../lib/prisma'; import Modal from '../../components/Modal'; @@ -18,14 +19,16 @@ export default function Teams(props) { const [invites, setInvites] = useState([]); const [showCreateTeamModal, setShowCreateTeamModal] = useState(false); - const loadTeams = () => fetch('/api/user/membership').then((res: any) => res.json()).then( + const loadData = () => fetch('/api/user/membership').then((res: any) => res.json()).then( (data) => { - setTeams(data.membership.filter((m) => m.role !== "INVITEE")); - setInvites(data.membership.filter((m) => m.role === "INVITEE")); + setTeams(data.membership && data.membership.filter((m) => m.role !== "INVITEE")); + setInvites(data.membership && data.membership.filter((m) => m.role === "INVITEE")); } ); - useEffect(() => { loadTeams(); }, []); + useEffect(() => { + loadData(); + }, []); if (loading) { return
Loading...
; @@ -40,7 +43,7 @@ export default function Teams(props) { 'Content-Type': 'application/json' } }).then(() => { - loadTeams(); + loadData(); setShowCreateTeamModal(false); }); } @@ -86,14 +89,14 @@ export default function Teams(props) {