Skip to content
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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ShreyasLakhani
Copy link
Contributor

Summary: This PR introduces the ability for teams to invite members using a unique share link, secured by UUIDs. Previously, team invitations were sent individually via email. This update enhances the invitation process. #1049

  1. Added a new inviteLink field to the Team table in the database

    • Type: UUID
    • Generated automatically when a new team is created
    • Can be reset by team administrators
  2. Implemented functionality to generate and reset the invite link

  3. Created API endpoints for:

    • Retrieving the current invite link
    • Resetting the invite link
    • Joining a team using the invite link
  4. Updated the UI to display and manage the team invite link

  • The invite link is unique to each team

  • Team administrators can reset the link if needed

  • The existing functionality to invite users individually by email is preserved

  • Thoroughly tested the invite link functionality using Postman:

    • Verified the generation of a valid invite link
    • Tested the reset functionality for the invite link
    • Confirmed successful team joining process using the invite link
2024-10-20.13-37-44.mp4

@ShreyasLakhani ShreyasLakhani requested a review from mfts as a code owner October 20, 2024 08:27
Copy link

vercel bot commented Oct 20, 2024

@ShreyasLakhani is attempting to deploy a commit to the mftsio Team on Vercel.

A member of the Team first needs to authorize it.

@ShreyasLakhani
Copy link
Contributor Author

ShreyasLakhani commented Oct 20, 2024

@mfts I migration folder I change code because of veriable conflict. Initially I used "shareLink " in prisma but in code I used "inviteLink" . So i changed all name and use single name "inviteLink".

Let me know, if any error occur.

Copy link
Owner

@mfts mfts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start! There are a couple of comments for improvement and changes.

One thing I didn't see is how the user actually signs up using the invite link. I think that part is missing or I missed it in the review somehow.

Comment on lines 5 to 9
import { v4 as uuidv4 } from 'uuid';

const generateUniqueInviteLink = (): string => {
return `https://papermark.com/teams/invite/${uuidv4()}`;
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you use nanoid() instead of uuid.

const newLink = generateUniqueInviteLink();
const updatedTeam = await prisma.team.update({
where: { id: teamId },
data: { inviteLink: newLink },
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also let's only store the unique code for each team, not the full URL

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this appears in several other places

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to change this file. this is not related to the team invite link

Comment on lines 1 to 8
-- AlterTable
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'Team' AND column_name = 'inviteLink') THEN
ALTER TABLE "Team" DROP COLUMN "inviteLink";
END IF;
END $$;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that you changed the schema locally for yourself, but please remove this from the migration

@@ -84,6 +84,8 @@ model Team {

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

inviteLink String? @unique // Add this line for the unique share link
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a more appropriate field name is inviteCode

Comment on lines 140 to 163
<div className="mb-4">
<Label className="opacity-80">Or share invite link</Label>
<Input
value={inviteLink || ""}
readOnly
className="mt-1 w-full"
/>
<div className="mt-2 flex justify-between">
<Button
onClick={handleCopyInviteLink}
disabled={!inviteLink || inviteLinkLoading}
className="flex-1 mr-2"
>
Copy Link
</Button>
</DialogFooter>
</form>
<Button
onClick={handleResetInviteLink}
disabled={inviteLinkLoading}
className="flex-1"
>
Reset Link
</Button>
</div>
</div>
Copy link
Owner

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

Copy link
Contributor Author

@ShreyasLakhani ShreyasLakhani Oct 22, 2024

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".

Copy link
Owner

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.

@mfts mfts added 🕹️ oss.gg 🕹️ 750 points revisit Currently not required but important in the future iteration-1 labels Oct 20, 2024
@AndrewHamal
Copy link
Contributor

/assign

Copy link

oss-gg bot commented Oct 20, 2024

The /assign command can only be used on issues, not on pull requests.

@pikachusensei
Copy link

/assign

Copy link

oss-gg bot commented Oct 20, 2024

The /assign command can only be used on issues, not on pull requests.

@ShreyasLakhani ShreyasLakhani requested a review from mfts October 22, 2024 06:33
Copy link
Contributor Author

@ShreyasLakhani ShreyasLakhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mfts check my PR and give me feedback.

@ShreyasLakhani
Copy link
Contributor Author

@mfts if anything missing or not done please tell me.
I didn't understand "please add the invite by link as a separate dialog / modal" and also I try to solve "One thing I didn't see is how the user actually signs up using the invite link. I think that part is missing or I missed it in the review somehow" this.

Copy link
Owner

@mfts mfts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes requested. Let me know if you have a question :)

Comment on lines 140 to 163
<div className="mb-4">
<Label className="opacity-80">Or share invite link</Label>
<Input
value={inviteLink || ""}
readOnly
className="mt-1 w-full"
/>
<div className="mt-2 flex justify-between">
<Button
onClick={handleCopyInviteLink}
disabled={!inviteLink || inviteLinkLoading}
className="flex-1 mr-2"
>
Copy Link
</Button>
</DialogFooter>
</form>
<Button
onClick={handleResetInviteLink}
disabled={inviteLinkLoading}
className="flex-1"
>
Reset Link
</Button>
</div>
</div>
Copy link
Owner

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.

prisma/schema.prisma Show resolved Hide resolved
where: { id: teamId },
data: { inviteCode: newCode }, // Store the unique code in inviteCode
});
return res.json({ inviteLink: `https://papermark.com/teams/invite/${newCode}` }); // Return the full invite link
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be app.papermark.io but better to use process.env.NEXTAUTH_URL.

also there should be a page for the accepting the invite code as the url indicates. so pages/teams/invite/[code]/index.tsx that's currently missing.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think this is relevant here if you let the user accept the invite on a dedicated page.

Copy link
Contributor Author

@ShreyasLakhani ShreyasLakhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mfts all changes you mentioned I have completed.

Let me know, If anything I miss.

@ShreyasLakhani ShreyasLakhani requested a review from mfts October 22, 2024 15:25
@ShreyasLakhani
Copy link
Contributor Author

@mfts can you please review my changes before end of hacktoberfest.

@mfts
Copy link
Owner

mfts commented Oct 26, 2024

@ShreyasLakhani will review your PR tomorrow.

and don't worry will award before end of hacktoberfest :)

@ShreyasLakhani
Copy link
Contributor Author

@mfts Brother, I respect your time but You said that you will review.
still no update on it and hacktoberfest and oss.gg is about to end.

I request to review or proceed award.

@mfts mfts removed the revisit Currently not required but important in the future label Oct 31, 2024
@mfts mfts removed the iteration-2 label Oct 31, 2024
Copy link
Owner

@mfts mfts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned a couple of things inline.

package.json Outdated Show resolved Hide resolved
pages/teams/invite/[code]/index.tsx Outdated Show resolved Hide resolved
pages/teams/invite/[code]/index.tsx Outdated Show resolved Hide resolved
components/teams/add-team-member-modal.tsx Outdated Show resolved Hide resolved
components/teams/add-team-member-modal.tsx Outdated Show resolved Hide resolved
@mfts
Copy link
Owner

mfts commented Oct 31, 2024

@ShreyasLakhani great progress, I mentioned the change requests inline.

I'm happy to award you 50% of the points now for the work already done. would love to push this over the line with your help.

/award 375

Copy link

oss-gg bot commented Oct 31, 2024

Awarding ShreyasLakhani: 375 points 🕹️ Well done! Check out your new contribution on oss.gg/ShreyasLakhani

@mfts mfts added revisit Currently not required but important in the future iteration-3 labels Oct 31, 2024
@ShreyasLakhani ShreyasLakhani requested a review from mfts October 31, 2024 10:13
@ShreyasLakhani
Copy link
Contributor Author

@mfts Look at the changes I made.

  1. create new file for invite-link modal (components/teams/invite-link-modal.tsx)
  2. add accept and reject button along with error handling and build regular functions (pages/teams/invite/[code]/index.tsx)
  3. use swr instead of useEffect (components/teams/add-team-member-modal.tsx)
  4. removed uuid package

@mfts
Copy link
Owner

mfts commented Oct 31, 2024

/award 375

Thanks @ShreyasLakhani awarding the second half. will review tomorrow and then hopefully can merge it in

Copy link

oss-gg bot commented Oct 31, 2024

Awarding ShreyasLakhani: 375 points 🕹️ Well done! Check out your new contribution on oss.gg/ShreyasLakhani

Copy link
Contributor Author

@ShreyasLakhani ShreyasLakhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check @mfts

Copy link

vercel bot commented Dec 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
papermark ❌ Failed (Inspect) Dec 5, 2024 9:31am

@ShreyasLakhani
Copy link
Contributor Author

@mfts can you give me any updates regarding this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awarded iteration-3 🕹️ oss.gg ready-for-review revisit Currently not required but important in the future
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants