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

fix(portal/profile): unable to create or update when the website field is not filled #353

Merged
merged 1 commit into from
Mar 11, 2025

Conversation

HasithDeAlwis
Copy link
Collaborator

@HasithDeAlwis HasithDeAlwis commented Mar 11, 2025

  • I've thoroughly read the latest contribution guidelines.
  • I've rebased my branch onto main before creating this PR.
  • I've added tests to cover my changes (if applicable).
  • I've verified that all new and existing tests have passed locally for mobile, tablet, and desktop screen sizes.
  • My commit messages follow guidelines
  • My change requires documentation updates.
  • I've updated the documentation accordingly.
  • My code follows existing patterns of this project and/or improves upon them.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced the accuracy of profile details by filtering out empty or null fields.
    • Improved validations for links and contact information to ensure a more reliable profile experience.

Copy link

coderabbitai bot commented Mar 11, 2025

Walkthrough

The pull request updates the handling of user data in the profile feature. In the refinedUserData function, a new object refinedUser is created to consolidate user details, including dietary restrictions, allergies, and graduation date. A forEach loop iterates over its keys to remove any that have null values. Additionally, the useProfileSchema function now explicitly calls optional() for the Google Drive link validation and applies nullable() for the emergency contact URL validation, thereby enhancing data integrity.

Changes

File Change Summary
libs/portal/features/.../use-profile-schema.ts Updated refinedUserData to create a consolidated user details object and filter out null values. Modified useProfileSchema to explicitly apply optional() on the Google Drive link and nullable() on the emergency contact URL validations.

Sequence Diagram(s)

sequenceDiagram
    participant U as User Object
    participant R as refinedUserData
    participant F as ForEach Loop
    U->>R: Pass user data
    R->>R: Consolidate details into "refinedUser"
    R->>F: Iterate over keys
    F-->>R: Filter out keys with null values
    R->>U: Return refined user object
Loading
sequenceDiagram
    participant U as User Object
    participant S as useProfileSchema
    participant V as Validation Chain
    U->>S: Provide user data & isStudent flag
    S->>S: Call refinedUserData internally
    S->>V: Apply field validations (optional() & nullable())
    V-->>S: Return validated fields
    S->>U: Return final schema
Loading

Poem

In the realm of code so keen,
Nulls fade into the unseen.
User details now gleam, refined and clear,
Validations sing, drawing near.
A symphony of data, smooth and sincere. 😊

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

Progress: resolved 0, reused 0, downloaded 1, added 0
Progress: resolved 39, reused 0, downloaded 39, added 0
Progress: resolved 50, reused 0, downloaded 50, added 0
Progress: resolved 50, reused 0, downloaded 51, added 0
 ERR_PNPM_LINKED_PKG_DIR_NOT_FOUND  Could not install from "/tmp/eslint/infra/sdks/netlify" as it does not exist.

This error happened while installing a direct dependency of /tmp/eslint


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3d44266 and 7014975.

📒 Files selected for processing (1)
  • libs/portal/features/profile/hooks/use-profile-schema.ts (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (3)
libs/portal/features/profile/hooks/use-profile-schema.ts (3)

33-47: Improved data handling to properly filter null values

This change enhances the refinedUserData function by creating a consolidated object and systematically removing any null values before returning. This directly addresses the issue where profiles couldn't be created/updated when the website field was empty.

+  const refinedUser = {
+    ...user,
+    dietaryRestrictions: refinedRestrictions,
+    allergies: refinedAllergies,
+    expectedGraduationDate: graduationDate,
+  }
+
+  Object.keys(refinedUser).forEach((key) => {
+    if (refinedUser[key] === null) {
+      delete refinedUser[key]
+    }
+  })
+
+  return refinedUser

This approach is more maintainable and will prevent similar issues with other fields.


89-89: Explicit optional() method call improves readability

Making the optional nature of the resumeLink explicit is a good practice for code clarity.


174-174: Added nullable() to website field validation

This is the critical fix that resolves the issue. By making the website field nullable (in addition to optional), the schema now properly handles cases where the website field is not filled.

Before this change, a null website value would fail validation despite being optional, preventing profile creation/updates.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this 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.

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.

@HasithDeAlwis HasithDeAlwis merged commit b06cb49 into main Mar 11, 2025
4 of 6 checks passed
@MFarabi619
Copy link
Member

🎉 This PR is included in version 3.10.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants