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

✨ Custom Profile Pictures #1339

Merged
merged 9 commits into from
Sep 9, 2024
Merged

✨ Custom Profile Pictures #1339

merged 9 commits into from
Sep 9, 2024

Conversation

lukevella
Copy link
Owner

@lukevella lukevella commented Sep 9, 2024

Summary by CodeRabbit

  • New Features

    • Introduced functionality for managing user profile pictures, including upload and removal options.
    • Added a user interface for managing profile settings, allowing updates to user name and email display.
    • Implemented a custom hook to check if avatars feature is enabled.
  • Bug Fixes

    • Improved error messaging for profile picture upload failures.
  • Refactor

    • Updated image handling logic and component organization for better clarity and functionality.
  • Chores

    • Removed Sentry integration for error tracking, shifting to console logging for error management.

This reverts commit a236936.

# Conflicts:
#	apps/web/src/app/[locale]/(admin)/settings/profile/profile-picture.tsx
#	apps/web/src/app/[locale]/(admin)/settings/profile/profile-settings.tsx
Copy link

vercel bot commented Sep 9, 2024

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

Name Status Preview Comments Updated (UTC)
app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 9, 2024 3:37pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
landing ⬜️ Ignored (Inspect) Visit Preview Sep 9, 2024 3:37pm

Copy link
Contributor

coderabbitai bot commented Sep 9, 2024

Walkthrough

The pull request introduces significant changes across multiple files, primarily focusing on user profile management, including the removal of certain image configurations and localization strings, the addition of new components for handling profile pictures, and enhancements to user session management. The changes streamline how user avatars are processed and displayed, improve error handling, and introduce new hooks for feature flag management.

Changes

Files Change Summary
apps/web/next.config.js Removed image configuration block; added experimental server components for AWS SDK integration.
apps/web/public/locales/en/app.json Removed localization strings for unavailable features; added strings for upload error messaging.
apps/web/src/app/[locale]/(admin)/settings/profile/profile-page.tsx Updated import path for ProfileSettings component.
apps/web/src/app/[locale]/(admin)/settings/profile/profile-picture.tsx Introduced functionality for managing profile pictures, including upload and removal buttons, with error handling and validation.
apps/web/src/app/[locale]/(admin)/settings/profile/profile-settings.tsx Added ProfileSettings component for managing user profile settings with form validation.
apps/web/src/app/api/storage/[...key]/route.ts Removed Sentry integration for error tracking; replaced with console error logging.
apps/web/src/components/optimized-avatar-image.tsx Simplified avatar image handling by integrating URL generation into the component logic; added loading state.
apps/web/src/features/avatars.ts Introduced useAvatarsEnabled hook to manage avatar feature flag status.
apps/web/src/trpc/routers/user.ts Added MIME type validation for avatar uploads; improved error handling for S3 client availability; updated avatar image key generation logic.
apps/web/src/utils/auth.ts Modified session management to prioritize session data over user data; enhanced dynamic retrieval of user information.

Possibly related PRs

🐰 Hopping through the code, what a delightful sight,
Profile pictures and settings, all coming to light!
With errors now clearer, and features in play,
Our users will smile, come what may!
So here's to the changes, let's give them a cheer,
A fluffy new future is finally here! 🎉

Tip

New features

Walkthrough comment now includes:

  • Possibly related PRs: A list of potentially related PRs to help you recall past context.
  • Suggested labels: CodeRabbit can now suggest labels by learning from your past PRs. You can also provide custom labeling instructions in the UI or configuration file.

Notes:

  • Please share any feedback in the discussion post on our Discord.
  • Possibly related PRs, automatic label suggestions based on past PRs, learnings, and possibly related issues require data opt-in (enabled by default).

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (2)
apps/web/src/components/optimized-avatar-image.tsx (1)

Line range hint 4-42: Refactored component with improved avatar handling.

The OptimizedAvatarImage component has been significantly refactored to integrate the avatar URL logic directly into the rendering logic, which simplifies the component structure. The use of the useAvatarsEnabled hook to conditionally render avatars based on a feature flag is a robust design choice. Additionally, the introduction of a loading state using React.useState enhances the user experience by handling image loading more gracefully.

Consider adding error handling for the Image component to manage cases where the image fails to load due to network issues or other errors.

apps/web/src/app/api/storage/[...key]/route.ts (1)

Line range hint 39-53: Simplified error handling with potential monitoring drawbacks.

The removal of Sentry integration simplifies the error handling by using console.error for logging errors. While this reduces complexity, it may also reduce the visibility of errors in production environments. Consider reintroducing an error tracking service like Sentry or another similar service to enhance error monitoring and response capabilities.

The function correctly handles the absence of an imageKey and errors during the S3 object retrieval, ensuring robust error handling and appropriate user feedback.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1276bc2 and c5b830a.

Files selected for processing (10)
  • apps/web/next.config.js (2 hunks)
  • apps/web/public/locales/en/app.json (1 hunks)
  • apps/web/src/app/[locale]/(admin)/settings/profile/profile-page.tsx (1 hunks)
  • apps/web/src/app/[locale]/(admin)/settings/profile/profile-picture.tsx (1 hunks)
  • apps/web/src/app/[locale]/(admin)/settings/profile/profile-settings.tsx (1 hunks)
  • apps/web/src/app/api/storage/[...key]/route.ts (3 hunks)
  • apps/web/src/components/optimized-avatar-image.tsx (2 hunks)
  • apps/web/src/features/avatars.ts (1 hunks)
  • apps/web/src/trpc/routers/user.ts (2 hunks)
  • apps/web/src/utils/auth.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • apps/web/src/app/[locale]/(admin)/settings/profile/profile-page.tsx
Additional comments not posted (11)
apps/web/src/features/avatars.ts (1)

1-5: Well-implemented feature flag usage.

The function useAvatarsEnabled correctly utilizes the feature flag from posthog-js/react to determine if the avatars feature is enabled. This is a clean and effective way to toggle features in the application.

apps/web/src/app/[locale]/(admin)/settings/profile/profile-settings.tsx (1)

16-84: Well-structured and logically sound ProfileSettings function.

The ProfileSettings function is well-organized and makes good use of hooks and components to manage user profile settings. The form handling with useForm, including the reset on submission, is correctly implemented. The use of Trans for i18n support and the integration of the ProfilePicture component are also notable positives.

apps/web/next.config.js (1)

54-57: Good addition of AWS SDK in the experimental configuration.

The inclusion of @aws-sdk under the experimental section is a strategic enhancement to leverage AWS services in server components. Ensure that this integration is tested thoroughly to confirm that AWS services are utilized effectively without issues.

Run the following script to verify the integration with AWS services:

Verification successful

AWS SDK Integration Verified

The AWS SDK is actively used across multiple server components, confirming that the integration is effectively supporting AWS services as intended. The inclusion of @aws-sdk in the experimental section of next.config.js aligns with these usages.

  • Files with AWS SDK usage:
    • apps/web/src/utils/s3.ts
    • apps/web/src/trpc/routers/user.ts
    • apps/web/src/app/api/storage/[...key]/route.ts
    • packages/emails/src/send-email.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify AWS SDK integration.

# Test: Search for AWS SDK usage in server components. Expect: Proper configuration and usage patterns.
rg --type js --type ts "aws-sdk"

Length of output: 745

apps/web/src/app/[locale]/(admin)/settings/profile/profile-picture.tsx (3)

17-108: Robust implementation of ChangeAvatarButton.

The ChangeAvatarButton function is well-implemented with comprehensive error handling and user feedback. The use of pre-signed URLs for secure uploads and detailed feedback through toasts and Sentry logging are particularly commendable.


131-150: Effective implementation of RemoveAvatarButton.

The RemoveAvatarButton function is effectively designed, utilizing asynchronous operations and state management to handle the avatar removal process. The optional onSuccess callback adds flexibility to the component's usage.


153-188: Well-designed Upload function with conditional rendering and analytics integration.

The Upload function effectively uses feature flags to conditionally render components and integrates analytics tracking to monitor user interactions. This approach enhances the functionality and usability of the profile picture management.

apps/web/src/trpc/routers/user.ts (3)

20-23: Approved: Addition of MIME type to extension mapping.

The mimeToExtension constant is a well-implemented solution for mapping MIME types to file extensions, enhancing maintainability and reducing the risk of errors in file handling.


155-160: Approved: Enhanced input validation for file uploads.

The modification to use z.enum for specifying allowable file types (image/jpeg, image/png) in the getAvatarUploadUrl mutation is a crucial security enhancement. It effectively limits the types of files that can be uploaded, mitigating potential risks associated with unrestricted file uploads.


165-168: Approved: Improved error handling for S3 configuration.

The updated error handling in the getAvatarUploadUrl mutation, which throws a TRPCError when the S3 storage is not configured, enhances the clarity and actionability of error messages. This change aligns with best practices by providing specific feedback that aids in troubleshooting and configuration verification.

apps/web/src/utils/auth.ts (1)

266-311: Approved: Enhanced session management in authentication flow.

The changes to the session callback in the getAuthOptions function, which dynamically fetch user details based on the token.sub, significantly enhance the robustness and accuracy of session management. This approach ensures that the session data is always up-to-date and reflects the most current user information, which is crucial for maintaining a secure and reliable user authentication flow.

apps/web/public/locales/en/app.json (1)

284-285: Approved: Addition of localization strings for upload errors.

The new localization strings "errorUploadPicture" and "errorUploadPictureDescription" provide clear and specific feedback to users about upload failures. This enhancement is crucial for improving user experience by informing users about issues encountered during the profile picture upload process, thereby increasing clarity and support for error handling.

@lukevella lukevella merged commit e723d9a into main Sep 9, 2024
7 checks passed
@lukevella lukevella deleted the fix-image branch September 9, 2024 15:51
@coderabbitai coderabbitai bot mentioned this pull request Nov 8, 2024
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.

1 participant