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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revalidate invite cache even if email delivery fails #1823

Merged

Conversation

ShubhamPalriwala
Copy link
Contributor

@ShubhamPalriwala ShubhamPalriwala commented Dec 22, 2023

What does this PR do?

Currently, if the email delivery fails, we do not revalidate the cache which leads to the invite list not getting update (due to cache). So the user is unable to see if they have invited a person or not.

This PR changes that by revalidating the cache irrespective of the email status since invites can also be accepted via links present in the invite list~

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change adds a new database migration
  • This change requires a documentation update

How should this be tested?

  • Test A
  • Test B

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read How we Code at Formbricks
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand bits
  • Ran pnpm build
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues
  • First PR at Formbricks? Please sign the CLA! Without it we wont be able to merge it 馃檹

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Formbricks Docs if changes were necessary

Copy link

vercel bot commented Dec 22, 2023

The latest updates on your projects. Learn more about Vercel for Git 鈫楋笌

2 Ignored Deployments
Name Status Preview Updated (UTC)
formbricks-cloud 猬滐笍 Ignored (Inspect) Dec 22, 2023 9:39am
formbricks-com 猬滐笍 Ignored (Inspect) Dec 22, 2023 9:39am

Copy link
Contributor

github-actions bot commented Dec 22, 2023

Thank you for following the naming conventions for pull request titles! 馃檹

Copy link
Contributor

packages/lib/invite/service.ts

It would be beneficial to extract the calculation of the expiration date into a separate function. This would make the code more readable and maintainable, as the logic for calculating the expiration date would be encapsulated in a single place. This would also make it easier to change the expiration period in the future, if needed.
Create Issue
See the diff
Checkout the fix

    function calculateExpirationDate(days: number): Date {
      const expiresIn = days * 24 * 60 * 60 * 1000; // days
      return new Date(Date.now() + expiresIn);
    }

    // Usage
    const expiresAt = calculateExpirationDate(7);
git fetch origin && git checkout -b ReviewBot/Impro-rw2iywm origin/ReviewBot/Impro-rw2iywm

Currently, the code is making separate queries to check if an invite already exists and if the user is already a member of the team. These queries could be combined into a single query using the OR operator, which would reduce the number of database hits and improve performance.
Create Issue
See the diff
Checkout the fix

    const existingInviteOrMember = await prisma.$queryRaw`
      SELECT * FROM invite
      WHERE email = ${email} AND teamId = ${teamId}
      UNION
      SELECT * FROM membership
      WHERE userId = ${user.id} AND teamId = ${teamId}
    `;

    if (existingInviteOrMember) {
      throw new ValidationError("Invite already exists or User is already a member of this team");
    }
git fetch origin && git checkout -b ReviewBot/Impro-4dytsy2 origin/ReviewBot/Impro-4dytsy2

Copy link
Member

@mattinannt mattinannt left a comment

Choose a reason for hiding this comment

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

@ShubhamPalriwala thanks for the fix 馃憤馃殌

@mattinannt mattinannt added this pull request to the merge queue Dec 22, 2023
Merged via the queue into main with commit 6ac48a2 Dec 22, 2023
15 checks passed
@mattinannt mattinannt deleted the shubham/revalidate-cache-irrespective-of-email-delivery branch December 22, 2023 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants