Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add revoke invitation function
Marc Seitzd65b32f6d422
diff --git a/pages/api/teams/[teamId]/invitations/index.ts b/pages/api/teams/[teamId]/invitations/index.tsindex 25d7fd82..f63a7354 100644--- a/pages/api/teams/[teamId]/invitations/index.ts+++ b/pages/api/teams/[teamId]/invitations/index.ts@@ -51,5 +51,42 @@ export default async function handle(} catch (error) {errorhandler(error, res);}+ } else if (req.method === "DELETE") {+ // DELETE /api/teams/:teamId/invitations+ const session = await getServerSession(req, res, authOptions);+ if (!session) {+ return res.status(401).end("Unauhorized");+ }++ const { teamId } = req.query as { teamId: string };++ const { email } = req.body as { email: string };++ try {+ // check if currentUser is part of the team with the teamId+ const userTeam = await prisma.userTeam.findFirst({+ where: {+ teamId,+ userId: (session.user as CustomUser).id,+ },+ });++ if (!userTeam) {+ return res.status(403).json("You are not part of this team");+ }++ // delete invitation+ await prisma.invitation.delete({+ where: {+ teamId: teamId,+ email: email,+ },+ });++ res.status(204).end();+ return;+ } catch (error) {+ errorhandler(error, res);+ }}}diff --git a/pages/settings/people.tsx b/pages/settings/people.tsxindex 6bb5fe97..3178f4c0 100644--- a/pages/settings/people.tsx+++ b/pages/settings/people.tsx@@ -119,6 +119,32 @@ export default function Billing() {toast.success("Invitation resent successfully!");};+ // revoke invitation function+ const revokeInvitation = async (invitation: { email: string } & any) => {+ const response = await fetch(+ `/api/teams/${teamInfo?.currentTeam?.id}/invitations`,+ {+ method: "DELETE",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ email: invitation.email as string,+ }),+ },+ );++ if (!response.ok) {+ const error = await response.json();+ toast.error(error);+ return;+ }++ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/invitations`);++ toast.success("Invitation revoked successfully!");+ };+return (<AppLayout><Navbar current="People" />@@ -288,6 +314,12 @@ export default function Billing() {>Resend</DropdownMenuItem>+ <DropdownMenuItem+ onClick={() => revokeInvitation(invitation)}+ className="text-red-500 focus:bg-destructive focus:text-destructive-foreground hover:cursor-pointer"+ >+ Revoke invitation+ </DropdownMenuItem></DropdownMenuContent></DropdownMenu></div>