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

Copy settings page to alpha directory for refactoring #832

Merged

Conversation

John-Paul-Larkin
Copy link
Member

@John-Paul-Larkin John-Paul-Larkin commented Mar 13, 2024

✨ Codu Pull Request 💻

Codu Logo

Pull Request details

  • Started refactor of the settings page.
  • Copied over settings folder to alpha (page.tsx and _client.tsx)
  • No changes made to either file.

Any Breaking changes

None

Summary by CodeRabbit

  • New Features
    • Introduced a new Settings component for users to manage their profile settings, including personal information, email notifications, and weekly newsletter subscriptions.
    • Added functionality for uploading and updating profile photos with form validation and API integration.
    • Launched a dedicated settings page for user profile updates with enhanced error handling.

@John-Paul-Larkin John-Paul-Larkin requested a review from a team as a code owner March 13, 2024 11:46
Copy link

vercel bot commented Mar 13, 2024

@John-Paul-Larkin is attempting to deploy a commit to the Codú Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Mar 13, 2024

Walkthrough

The recent update brings a holistic enhancement to user interaction with the introduction of a robust Settings component in a React application. This component empowers users to manage their profiles effectively, enabling actions like updating personal information, handling email notifications, opting for newsletters, and managing profile photos. Additionally, a new page component enriches the user experience by providing seamless settings management with integrated error tracking.

Changes

File Path Change Summary
app/(app)/alpha/settings Introduces a Settings component for profile management, including updates, photo handling, and subscription management.
app/(app)/alpha/settings/page Adds a new page component for user settings, incorporating Sentry for error handling.
app/(app)/alpha/settings/profile.ts Introduces schemas for saving settings, fetching profiles, and managing profile photo URLs using Zod validation.

🐰✨
In the realm of code, where changes abound,
A rabbit hopped in, leaving footprints on the ground.
"Look yonder," it cheered, with a twirl and a hop,
"New settings to explore, and the updates won't stop!"
🌟📝 With every click and type, your world's a bit brighter,
So celebrate the changes, for they make hearts lighter.
🎉🐾

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-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7229656 and a4b0587.
Files selected for processing (2)
  • app/(app)/alpha/settings/_client.tsx (1 hunks)
  • app/(app)/alpha/settings/page.tsx (1 hunks)
Check Runs (1)
welcome-new-contributor completed (2)
Additional comments: 8
app/(app)/alpha/settings/page.tsx (3)
  • 1-7: Consider organizing imports by their source or functionality for better readability. Grouping external library imports separately from internal module imports can make the code easier to navigate.
  • 63-65: Using notFound to handle cases where the user's email is missing is appropriate. However, ensure that this behavior aligns with the application's overall error handling strategy and user experience design.
  • 67-77: The try-catch block for handling newsletter subscription status is well-implemented. Capturing exceptions with Sentry is a good practice for monitoring and debugging. Ensure that the error handling strategy is consistent across the application.
app/(app)/alpha/settings/_client.tsx (5)
  • 1-14: Organizing imports by their source or functionality can improve code readability. Consider grouping external library imports separately from internal module imports.
  • 16-18: The classNames utility function is a clean and efficient way to conditionally apply CSS classes. Good use of utility functions can significantly enhance code readability and maintainability.
  • 38-47: Initializing form values with user profile data is a good practice. However, consider validating or sanitizing the default values to prevent potential security issues, such as Cross-Site Scripting (XSS), especially if the data comes from user input or an external source.
  • 74-125: The file upload logic is well-structured and handles both success and error states effectively. However, ensure that the file size and type are validated on the server-side as well to prevent malicious uploads.
  • 355-356: Disabling eslint rules should be done with caution. Ensure that the no-redundant-roles rule is disabled for a valid reason and consider documenting the rationale either in the code or in the project's documentation.

title: "Settings - Update your profile",
};

// @TODO - Loading state for this page
Copy link
Contributor

Choose a reason for hiding this comment

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

The TODO comment about adding a loading state is a good reminder. Implementing a loading state would enhance the user experience by providing feedback during data fetching or processing operations.

Would you like me to help implement a loading state for this page?

Comment on lines +29 to +31
if (!session || !session.user) {
redirect("/get-started");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Redirecting users who are not logged in is a good practice. However, ensure that the redirect function is awaited or returned to prevent further execution of the function after the redirect.

-    redirect("/get-started");
+    return redirect("/get-started");

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (!session || !session.user) {
redirect("/get-started");
}
if (!session || !session.user) {
return redirect("/get-started");
}

Comment on lines +40 to +49
if (!user?.username) {
const nanoid = customAlphabet("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ", 3);

const userName = session.user.name || "";
const cleanedUserName = userName
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "");
const initialUsername =
`${cleanedUserName.replace(/\s/g, "-")}-${nanoid()}`.toLowerCase();

Copy link
Contributor

Choose a reason for hiding this comment

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

Generating a username for users without one is a creative approach. However, consider extracting this logic into a separate function or module to improve readability and maintainability. This would also facilitate unit testing of the username generation logic.

Comment on lines +207 to +209
// TODO: review this
// eslint-disable-next-line jsx-a11y/img-redundant-alt
<img
Copy link
Contributor

Choose a reason for hiding this comment

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

The TODO comment and eslint-disable line suggest that there's an intention to review the image element. It's important to address TODOs and review disabled eslint rules to ensure code quality and maintainability.

Would you like me to address this TODO or help review the eslint rule?

Comment on lines +431 to +442
type="button"
className="inline-flex justify-center border border-neutral-300 bg-white px-4 py-2 text-sm font-medium text-neutral-700 shadow-sm hover:bg-neutral-50 focus:outline-none focus:ring-2 focus:ring-pink-300 focus:ring-offset-2"
>
Cancel
</button>
<button
disabled={isLoading}
type="submit"
className="ml-5 inline-flex w-20 justify-center bg-gradient-to-r from-orange-400 to-pink-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:from-orange-300 hover:to-pink-500 focus:outline-none focus:ring-2 focus:ring-pink-300 focus:ring-offset-2 disabled:opacity-20"
>
Save
</button>
Copy link
Contributor

Choose a reason for hiding this comment

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

The "Cancel" button does not have an onClick handler. If the button is intended to navigate the user away from the settings page or reset the form, implementing the corresponding functionality would enhance the user experience.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a4b0587 and e280676.
Files selected for processing (2)
  • app/(app)/alpha/settings/_client.tsx (1 hunks)
  • app/(app)/alpha/settings/profile.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/(app)/alpha/settings/_client.tsx
Additional comments: 5
app/(app)/alpha/settings/profile.ts (5)
  • 3-21: The saveSettingsSchema is well-defined, covering essential user settings fields with appropriate validations. However, consider adding custom error messages for all fields to improve user feedback, similar to the custom message provided for the username field's maximum length constraint.
  • 23-25: The getProfileSchema is concise and serves its purpose for fetching profile information based on the username. It's straightforward and doesn't require further refinement at this stage.
  • 27-30: The uploadPhotoUrlSchema is designed to validate the type and size of a photo being uploaded. It's a good practice to specify acceptable type values (e.g., MIME types for images) and enforce a maximum size limit to prevent excessively large uploads.

Consider enhancing the type field validation by enumerating allowed MIME types and setting a reasonable maximum size limit if not already done.

  • 32-34: The updateProfilePhotoUrlSchema ensures that the provided URL is valid. This is crucial for maintaining data integrity and preventing invalid URLs from being stored. It's well-defined for its purpose.
  • 36-36: The type alias saveSettingsInput is correctly derived from the saveSettingsSchema. This promotes type safety and consistency across the codebase when handling user settings input.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e280676 and d4ec7fc.
Files selected for processing (1)
  • app/(app)/alpha/settings/profile.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/(app)/alpha/settings/profile.ts

@NiallJoeMaher NiallJoeMaher merged commit c870ede into codu-code:develop Mar 13, 2024
2 of 3 checks passed
@John-Paul-Larkin John-Paul-Larkin deleted the refactor/settings-page-alpha branch March 27, 2024 13:06
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.

2 participants