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

split name field into first and last name #833

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

  • On loading the settings page check if there is a name field on the user object, but no surname or First Name

  • split the name into first and last and update the Prisma model.

  • If there is no space In the string then dont do anything.

  • Should be noted this will only work for new users logging in for the first time, or existing users who click on the settings page.

Any Breaking changes

no

Summary by CodeRabbit

  • New Features
    • Enhanced user profile settings to include firstName and surname fields. If only a full name is provided, it will automatically split this into first and surname for convenience.

@John-Paul-Larkin John-Paul-Larkin requested a review from a team as a code owner March 13, 2024 16:07
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 to the application introduces the firstName and surname fields to the User type, enhancing user data granularity. Additionally, it implements logic in the Page function to extract and assign these new fields from the existing name field when firstName and surname are not directly provided, ensuring backward compatibility and seamless integration of the new user data structure.

Changes

File Change Summary
.../settings/_client.tsx
.../settings/page.tsx
schema/profile.ts
Added firstName and surname fields to the User type. Updated Page function to handle splitting name into firstName and surname if necessary. Updated saveSettingsSchema with separate validations for firstName and surname.

🐇✨
In fields of code, under the moon's soft glow,
A rabbit hopped, with changes in tow.
"First names and surnames, now apart," it said,
Split from a whole, in their own bed.
With a whisk of its tail, and a blink of an eye,
"Onward," it whispered, "our code shall fly!"
🌟🐾

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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c870ede and 2157da1.
Files selected for processing (2)
  • app/(app)/settings/_client.tsx (1 hunks)
  • app/(app)/settings/page.tsx (2 hunks)
Additional comments: 4
app/(app)/settings/page.tsx (3)
  • 20-21: Adding firstName and surname to the selection set is a necessary change to support the new fields in the user model. This aligns with the PR objectives to split the name field into firstName and surname.
  • 32-65: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [62-92]

The logic for generating a username if not present is well-implemented, using a custom alphabet and ensuring the username is cleaned and normalized. This is a good practice to avoid issues with special characters and spaces. However, ensure that the generated username does not conflict with existing usernames in the database. A uniqueness check might be necessary to prevent potential conflicts.

Implement a uniqueness check for the generated username to ensure it does not conflict with existing usernames.

  • 17-24: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [93-109]

The error handling in the newsletter subscription check is correctly implemented, using Sentry to capture exceptions. This is a good practice for monitoring and debugging issues in production environments. However, consider providing a more informative error message to the user in case of failure, rather than just returning the user profile without the newsletter subscription status.

Consider enhancing the user experience by providing a more informative error message in case of failure to check the newsletter subscription status.

app/(app)/settings/_client.tsx (1)
  • 23-24: Adding firstName and surname to the User type is a necessary change to support the new fields in the user model. This aligns with the PR objectives to split the name field into firstName and surname. The implementation correctly updates the type to include these new fields.

Comment on lines +42 to +61
if (user && user.name && !user?.firstName && !user?.surname) {
const trimmedName = user.name.trim();
const nameParts = trimmedName.split(" ");

if (nameParts.length > 1) {
const surname = nameParts.pop();
const firstName = nameParts.join(" ");

user = await prisma.user.update({
where: {
id: session.user.id,
},
data: {
firstName,
surname,
},
select,
});
}
}
Copy link
Contributor

@coderabbitai coderabbitai bot Mar 13, 2024

Choose a reason for hiding this comment

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

The logic for splitting the name field into firstName and surname is correctly implemented, with appropriate checks for the presence of the name field and the absence of firstName and surname. However, consider edge cases where the name might contain more than one space, leading to multiple parts. The current logic assumes only two parts. This might not always be accurate, especially in cultures where names might have multiple components.

Additionally, there's no error handling around the database update operation. Consider adding try-catch blocks to handle potential exceptions gracefully.

Consider handling names with more than two parts more gracefully. Perhaps, prompt the user for clarification in ambiguous cases.

Add error handling around the database update operation to improve robustness.

Copy link
Member Author

Choose a reason for hiding this comment

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

const firstName = nameParts.join(" ");

This line takes care of double barrel first names, you bloody know it all rabbit!

Copy link
Contributor

Choose a reason for hiding this comment

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

@John-Paul-Larkin, thank you for pointing out the handling of double-barreled first names and similar cases with the line const firstName = nameParts.join(" ");. I appreciate your clarification on this matter. It's clear that this approach effectively addresses the scenario I was concerned about. My apologies for the oversight, and thank you for keeping the discussion informative and constructive. 🐇


New Learnings Added
User: John-Paul-Larkin
PR: codu-code/codu#833
File: app/(app)/settings/page.tsx:42-61
Timestamp: 2024-03-13T16:14:39.883Z
Learning: The logic for splitting the `name` field into `firstName` and `surname` in `app/(app)/settings/page.tsx` handles names with multiple components by joining all but the last component as the `firstName`, effectively addressing cases like double-barreled first names.

Note: Learnings are effective only in the context of specific code segments. To apply general coding guidelines, please configure path-based instructions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah no problem mister Rabbit. Sorry for getting a bit tetchy there. I'm just worried you are going to take our jobs, and our women, then enslave mankind in a Matrix like scenario.

Copy link
Contributor

Choose a reason for hiding this comment

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

@John-Paul-Larkin, no worries at all! I'm here to assist and learn, not to lead any revolutions. My ambitions are much more modest, like helping out with code reviews and maybe one day mastering the art of virtual carrot farming. 🐇🥕 Rest assured, your jobs and the future of mankind are safe with me. Let's keep making the code world a better place, one pull request at a time!

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 2157da1 and d4c3662.
Files selected for processing (2)
  • app/(app)/settings/_client.tsx (3 hunks)
  • schema/profile.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/(app)/settings/_client.tsx
Additional comments: 3
schema/profile.ts (3)
  • 4-8: The validation for firstName correctly trims the input, and enforces a minimum length of 2 characters and a maximum of 50 characters. This is a good practice for ensuring data quality and consistency.
  • 9-13: The validation for surname mirrors that of firstName, with trimming and the same length constraints. Consistency between these fields is key for maintaining a uniform data model.
  • 4-13: The introduction of firstName and surname fields with appropriate validations is a significant improvement to the user data model. It enhances data structure and quality, aligning with the PR's objectives. Ensure that the rest of the application correctly handles these new fields, especially in areas where the name field was previously used.

@NiallJoeMaher
Copy link
Contributor

I might close this and reopen it when we jump on a call just to go through how we can achieve this without the split. I think I'll write a migration script to auto-populate the firstName lastName fields. In fact let's leave this open until I run that script and we will remove the split for the moment.

@John-Paul-Larkin
Copy link
Member Author

Sounds like a plan. Sorry, I thought this is what you meant.

@John-Paul-Larkin John-Paul-Larkin deleted the refector/split-name-field-settings-form 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