-
Notifications
You must be signed in to change notification settings - Fork 801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add invite link functionality to team #1168
base: main
Are you sure you want to change the base?
Changes from 1 commit
1a6ab26
492e89f
a8e99a4
e195e92
329a4c8
119ae18
165157f
ce4c858
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
import { getServerSession } from "next-auth/next"; | ||
import prisma from "@/lib/prisma"; | ||
import { authOptions } from "@/pages/api/auth/[...nextauth]"; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
const generateUniqueInviteLink = (): string => { | ||
return `https://papermark.com/teams/invite/${uuidv4()}`; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you use |
||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
const { teamId } = req.query as { teamId: string }; | ||
|
||
const session = await getServerSession(req, res, authOptions); | ||
if (!session) { | ||
return res.status(401).end("Unauthorized"); | ||
} | ||
|
||
switch (req.method) { | ||
case "POST": | ||
// Generate a new invite link | ||
const newInviteLink = generateUniqueInviteLink(); | ||
const updatedTeam = await prisma.team.update({ | ||
where: { id: teamId }, | ||
data: { inviteLink: newInviteLink }, | ||
select: { inviteLink: true }, | ||
}); | ||
return res.json({ inviteLink: updatedTeam.inviteLink }); | ||
|
||
case "GET": | ||
// Get the current invite link | ||
const team = await prisma.team.findUnique({ | ||
where: { id: teamId }, | ||
select: { inviteLink: true }, | ||
}); | ||
|
||
if (!team?.inviteLink) { | ||
// If no invite link exists, create one | ||
const newLink = generateUniqueInviteLink(); | ||
const updatedTeam = await prisma.team.update({ | ||
where: { id: teamId }, | ||
data: { inviteLink: newLink }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also let's only store the unique There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this appears in several other places |
||
select: { inviteLink: true }, | ||
}); | ||
return res.json({ inviteLink: updatedTeam.inviteLink }); | ||
} | ||
|
||
return res.json({ inviteLink: team.inviteLink }); | ||
|
||
default: | ||
res.setHeader("Allow", ["POST", "GET"]); | ||
return res.status(405).end(`Method ${req.method} Not Allowed`); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add the invite by link as a separate dialog / modal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mfts
I made all changes but I did not understand last changes you told me.
"please add the invite by link as a separate dialog / modal".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ShreyasLakhani instead of adding the button with the copy invite link on the add-team-member-modal.tsx, please create a new component only for copying the invite link. and that should be a separate button on the /people page.