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: avatar upload #1546

Merged
merged 10 commits into from
Nov 6, 2023
Merged

feat: avatar upload #1546

merged 10 commits into from
Nov 6, 2023

Conversation

pandeymangg
Copy link
Contributor

What does this PR do?

Screen.Recording.2023-11-01.at.3.10.17.PM.mov

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 Nov 1, 2023

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

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
formbricks-cloud ⬜️ Ignored (Inspect) Visit Preview Nov 6, 2023 11:01am
formbricks-com ⬜️ Ignored (Inspect) Visit Preview Nov 6, 2023 11:01am

Copy link
Contributor

github-actions bot commented Nov 1, 2023

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

  1. In Navigation.tsx, the handleEnvironmentChange, handleEnvironmentChangeByProduct, and handleEnvironmentChangeByTeam functions are pushing new routes to the router but not checking if the new route is different from the current one. This could lead to unnecessary re-renders. Consider adding a check to prevent this:
const handleEnvironmentChange = (environmentType: "production" | "development") => {
  const newEnvironmentId = environments.find((e) => e.type === environmentType)?.id;
  if (newEnvironmentId && newEnvironmentId !== environment.id) {
    router.push(`/environments/${newEnvironmentId}/`);
  }
};

const handleEnvironmentChangeByProduct = (productId: string) => {
  if (productId !== product.id) {
    router.push(`/products/${productId}/`);
  }
};

const handleEnvironmentChangeByTeam = (teamId: string) => {
  if (teamId !== team.id) {
    router.push(`/teams/${teamId}/`);
  }
};
  1. In EditAvatar.tsx, the handleFileUpload function is checking the file size after making a request to get the signed URL. Consider moving the file size check before the request to save unnecessary network calls:
const handleFileUpload = async (file: File) => {
  if (!file) return;
  if (!file.type.startsWith("image/")) {
    toast.error("Please upload an image file.");
    return;
  }
  if (file.size > 10 * 1024 * 1024) {
    toast.error("File size must be less than 10MB.");
    return;
  }
  // rest of the code...
};
  1. In authOptions.ts, the jwt and session functions are adding user attributes to the token and session objects respectively. However, these functions are not checking if the user object exists before accessing its properties. Consider adding a check to prevent potential errors:
async jwt({ token }) {
  const existingUser = await getProfileByEmail(token?.email!);
  if (existingUser) {
    const additionalAttributs = {
      id: existingUser.id,
      createdAt: existingUser.createdAt,
      onboardingCompleted: existingUser.onboardingCompleted,
      name: existingUser.name,
      image: existingUser.image,
    };
    return {
      ...token,
      ...additionalAttributs,
    };
  }
  return token;
},

async session({ session, token }) {
  if (token) {
    // @ts-ignore
    session.user.id = token?.id;
    // @ts-ignore
    session.user.createdAt = token?.createdAt ? new Date(token?.createdAt).toISOString() : undefined;
    // @ts-ignore
    session.user.onboardingCompleted = token?.onboardingCompleted;
    // @ts-ignore

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.

@pandeymangg Thank you very much for this :-) Looks great!
I only have a few small things I would like to change :-)

packages/lib/profile/service.ts Outdated Show resolved Hide resolved
packages/database/schema.prisma Outdated Show resolved Hide resolved
packages/types/profile.ts Outdated Show resolved Hide resolved
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.

💪🙏

@mattinannt mattinannt self-assigned this Nov 6, 2023
@mattinannt mattinannt added this pull request to the merge queue Nov 6, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 6, 2023
@mattinannt mattinannt added this pull request to the merge queue Nov 6, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 6, 2023
@mattinannt mattinannt added this pull request to the merge queue Nov 6, 2023
Merged via the queue into main with commit fbd3d95 Nov 6, 2023
12 checks passed
@mattinannt mattinannt deleted the feat/avatar branch November 6, 2023 11:12
kevinkong91 added a commit to kevinkong91/formbricks that referenced this pull request Nov 7, 2023
* main: (42 commits)
  chore: add revert to oss-friends (formbricks#745)
  fix: pass authOptions to getServerSession in authLayout (formbricks#1584)
  fix: fixed URL example for "Create Survey" API endpoint is wrong formbricks#1555 (formbricks#1586)
  fix(docs): default account info docs changes (formbricks#1583)
  chore: Add docker packages to Github Packages on release (formbricks#1585)
  feat: avatar upload (formbricks#1546)
  fix: editor crashing (formbricks#1582)
  fix: Add scroll to the setting navbar  (formbricks#1398)
  are you sure modal missing fix:formbricks#1419 (formbricks#1485)
  fix: github linting issues (formbricks#1510)
  refactor: added authorization to airtable integration and create a common actions file (formbricks#1538)
  docs: add docs for airtable (formbricks#1541)
  fix: missing static generation store in revalidation due to pages dir (formbricks#1581)
  feat: Pagination for other values in multi choice (formbricks#1560)
  feat:  $199 pricing model for unlimited plans (formbricks#1564)
  fix: make pricing pages consistent (formbricks#1567)
  fix: openText issue (formbricks#1579)
  fix: avoid blocking the request if it does not have an associated ip (formbricks#1540)
  feat: Add Unkey to OSS Friends (formbricks#1574)
  feat: FOR-683 Role Switch (formbricks#1450)
  ...
kevinkong91 added a commit to kevinkong91/formbricks that referenced this pull request Nov 7, 2023
* main: (70 commits)
  chore: add revert to oss-friends (formbricks#745)
  fix: pass authOptions to getServerSession in authLayout (formbricks#1584)
  fix: fixed URL example for "Create Survey" API endpoint is wrong formbricks#1555 (formbricks#1586)
  fix(docs): default account info docs changes (formbricks#1583)
  chore: Add docker packages to Github Packages on release (formbricks#1585)
  feat: avatar upload (formbricks#1546)
  fix: editor crashing (formbricks#1582)
  fix: Add scroll to the setting navbar  (formbricks#1398)
  are you sure modal missing fix:formbricks#1419 (formbricks#1485)
  fix: github linting issues (formbricks#1510)
  refactor: added authorization to airtable integration and create a common actions file (formbricks#1538)
  docs: add docs for airtable (formbricks#1541)
  fix: missing static generation store in revalidation due to pages dir (formbricks#1581)
  feat: Pagination for other values in multi choice (formbricks#1560)
  feat:  $199 pricing model for unlimited plans (formbricks#1564)
  fix: make pricing pages consistent (formbricks#1567)
  fix: openText issue (formbricks#1579)
  fix: avoid blocking the request if it does not have an associated ip (formbricks#1540)
  feat: Add Unkey to OSS Friends (formbricks#1574)
  feat: FOR-683 Role Switch (formbricks#1450)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants