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(con/profile page): mentees with active mentor can't view profile of other mentor #984

Merged
merged 9 commits into from
Oct 16, 2024

Conversation

ericbolikowski
Copy link
Contributor

@ericbolikowski ericbolikowski commented Oct 5, 2024

What Github issue does this PR relate to? Insert link.

Closes #982

What should the reviewer know?

This PR implements a quick solution to add further restrictions to mentees visiting the profile page of a mentor. Besides the two existing restrictions (mentor isn't actively mentoring, or mentor has no free mentoring spots), we add a third one: mentees with an active mentor/mentorship can't view the profile of another mentor.

NOTE: PR implemented while travelling on a laptop without working dev environment - please test the implementation and error-free build:

  1. Log in as a mentee in an active mentorship
  2. Access the profile page /app/find-a-mentor/profile/:profileId of a mentor
  3. Confirm that an overlay is shown
  4. Confirm that the an ongoing mentorship link leads to the dashboard of the current mentorship

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced mentorship match status checks for improved accuracy.
    • Introduced new user feedback messages based on mentorship status.
    • Added nuanced view mode for users viewing mentor profiles.
  • Bug Fixes

    • Improved logic for determining the most recent accepted mentorship match.
  • Documentation

    • Updated rendering logic for clearer user guidance regarding mentorship relationships.

Copy link

coderabbitai bot commented Oct 5, 2024

Walkthrough

The pull request introduces modifications to the FindAMentor and Profile components. In FindAMentor.tsx, the logic for checking mentorship match statuses is updated to enhance robustness by using the find method. In Profile.tsx, a new query for loading the user's profile is added, along with enhancements to the mentorship match handling and view mode logic. The changes improve user feedback and ensure accurate representation of the user's mentorship status without altering the public interface.

Changes

File Change Summary
apps/redi-connect/src/pages/app/find-a-mentor/FindAMentor.tsx Introduced MentorshipMatchStatus, updated logic for mentorship match status checks using find method. Constructed user message for ongoing mentorship.
apps/redi-connect/src/pages/app/profile/Profile.tsx Added LoadMyProfileQuery, introduced activeMentorshipMatch, updated viewMode to include myProfile, expanded ViewMode type, modified determineViewMode function, and updated rendering logic for user feedback.

Assessment against linked issues

Objective Addressed Explanation
Mentees with ongoing mentorship should not open another mentor's profile (982)
Mentees with ongoing mentorship should not open the "find a mentor" page (982)

Possibly related PRs

Suggested reviewers

  • katamatata
  • astkhikatredi
  • ericbolikowski

Poem

🐇 In the meadow where mentors play,
A match was found, brightening the day.
With logic refined, and profiles in view,
Guidance flows freely, as friendships grow true.
Hopping with joy, we embrace the new light,
In mentorship's dance, everything feels right! 🌼


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>, 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 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

@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: 2

🧹 Outside diff range and nitpick comments (2)
apps/redi-connect/src/pages/app/find-a-mentor/FindAMentor.tsx (1)

204-211: LGTM: Improved mentorship status check.

The new implementation robustly checks for any accepted mentorship match, aligning with the PR objective. It's more reliable than the previous version which assumed the first match was the active one.

Consider a minor optimization:

-    profile?.mentorshipMatches?.some(match =>
-      match.status === MentorshipMatchStatus.Accepted
-    )
+    profile?.mentorshipMatches?.some(match => match.status === MentorshipMatchStatus.Accepted)

-    const matchId = profile?.mentorshipMatches?.find(match =>
-      match.status === MentorshipMatchStatus.Accepted
-    ).id
+    const matchId = profile?.mentorshipMatches?.find(match => match.status === MentorshipMatchStatus.Accepted)?.id

This change reduces line count and improves readability without affecting functionality.

apps/redi-connect/src/pages/app/profile/Profile.tsx (1)

329-350: Ensure consistent usage of activeMentorshipMatch

In the determineViewMode function, you have defined activeMentorshipMatch to find the active mentorship of the current user. Make sure that this variable is consistently used and that its scope and purpose are clear throughout the function. Additionally, consider checking if redundant conditions can be simplified.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d258fd2 and c6762e4.

📒 Files selected for processing (2)
  • apps/redi-connect/src/pages/app/find-a-mentor/FindAMentor.tsx (2 hunks)
  • apps/redi-connect/src/pages/app/profile/Profile.tsx (4 hunks)
🔇 Additional comments (4)
apps/redi-connect/src/pages/app/find-a-mentor/FindAMentor.tsx (2)

5-5: LGTM: Import statement addition is appropriate.

The addition of MentorshipMatchStatus to the import statement is consistent with the changes in the component logic and necessary for the new implementation of checking mentorship match status.


Line range hint 1-391: Summary: Core logic implemented, but additional verification needed.

The changes in this file successfully implement the core logic for restricting mentees with active mentorships from viewing other mentor profiles. The implementation is robust and efficient.

However, to fully meet the PR objectives, please ensure that:

  1. The overlay for restricted mentor profile access is implemented (possibly in another file).
  2. The link to the ongoing mentorship dashboard is correctly implemented.
  3. The changes build without errors and function as expected in the development environment.

Given that the PR was developed under less than ideal conditions, I recommend thorough testing of the entire feature, including edge cases and different user scenarios.

To assist with verification, you can use this script to check for any TODO comments or unfinished implementations:

#!/bin/bash
# Description: Check for TODO comments or unfinished implementations related to this feature

echo "Searching for TODO comments or unfinished implementations:"
rg -i 'TODO|FIXME|XXX|HACK|unfinished|incomplete' --glob '*.{ts,tsx,js,jsx}'

echo "\nSearching for files related to mentor profile restrictions:"
rg -l 'mentor.*profile.*restrict|active.*mentorship' --glob '*.{ts,tsx,js,jsx}'

This script will help identify any remaining tasks or relevant files that might need attention to complete the feature implementation.

apps/redi-connect/src/pages/app/profile/Profile.tsx (2)

2-2: Import statement approved

The addition of LoadMyProfileQuery to the import statements is appropriate and necessary for the new functionality.


267-267: Verify the mentorship link URL

Please ensure that the URL /app/mentorships/${activeMentorshipMatch?.mentorId} correctly navigates to the user's ongoing mentorship. Depending on the routing setup, you might need to use the mentorship match ID or adjust the path to reflect the correct route.

Run the following script to check if the route exists and uses the expected parameter:

Comment on lines 207 to 212

if (menteeHasAnActiveMatch) {
const matchId = profile?.mentorshipMatches?.[0].id
const matchId = profile?.mentorshipMatches?.find(match =>
match.status === MentorshipMatchStatus.Accepted
).id
history.replace(`/app/mentorships/${matchId}`)
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Overlay implementation for restricted mentor profile access is missing.

While the codebase includes modal components, there is no evidence of an overlay being triggered when a mentee with an active mentorship attempts to view another mentor's profile. Please implement the overlay as described in the PR objectives to restrict access and provide the necessary user feedback.

🔗 Analysis chain

Verify the overlay implementation for restricted mentor profile access.

The changes successfully implement the restriction for mentees with active mentorships. However, the PR objectives mention displaying an overlay when a mentee with an active mentorship attempts to view another mentor's profile. This overlay implementation is not visible in the current changes.

Please ensure that:

  1. The overlay is implemented as described in the PR objectives.
  2. The link labeled "an ongoing mentorship" in the overlay directs users to their current mentorship dashboard.

To verify the implementation, you can use the following script:

This script will help identify any overlay-related components or logic, as well as the routing to the mentorship dashboard, which should be present to fulfill the PR objectives.


Please run the corrected verification script below to ensure the overlay implementation is present as per the PR objectives:


Please run the corrected verification script below to ensure the overlay implementation is present as per the PR objectives:


Please run the corrected verification script below to ensure the overlay implementation is present as per the PR objectives:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for the presence of an overlay component or logic in the codebase

# Search for potential overlay components or logic
echo "Searching for overlay components or logic:"
rg -i -t tsx -t ts 'overlay|modal|popup|restriction' --glob '!*test*'

# Search for mentorship dashboard routing logic
echo "\nSearching for mentorship dashboard routing:"
rg -i -t tsx -t ts 'mentorship.*dashboard|ongoing.*mentorship' --glob '!*test*'

Length of output: 14328


Script:

#!/bin/bash
# Description: Check for the presence of an overlay component or logic in the codebase

# Search for potential overlay components or logic
echo "Searching for overlay components or logic:"
rg -i -t tsx -t ts 'overlay|modal|popup|restriction' --glob '!*test*'

# Search for mentorship dashboard routing logic
echo "\nSearching for mentorship dashboard routing:"
rg -i -t tsx -t ts 'mentorship.*dashboard|ongoing.*mentorship' --glob '!*test*'

Length of output: 405


Script:

#!/bin/bash
# Description: Check for the presence of an overlay component or logic in the codebase

# Search for potential overlay components or logic
echo "Searching for overlay components or logic:"
rg -i -t typescriptreact -t typescript 'overlay|modal|popup|restriction' --glob '!*test*'

# Search for mentorship dashboard routing logic
echo "\nSearching for mentorship dashboard routing:"
rg -i -t typescriptreact -t typescript 'mentorship.*dashboard|ongoing.*mentorship' --glob '!*test*'

Length of output: 469


Script:

#!/bin/bash
# Description: Check for the presence of an overlay component or logic in the codebase

# Search for potential overlay components or logic
echo "Searching for overlay components or logic:"
rg -i 'overlay|modal|popup|restriction' --glob '*.{ts,tsx}' --glob '!*test*'

# Search for mentorship dashboard routing logic
echo "\nSearching for mentorship dashboard routing:"
rg -i 'mentorship.*dashboard|ongoing.*mentorship' --glob '*.{ts,tsx}' --glob '!*test*'

Length of output: 30009

Comment on lines 344 to 346
currentUserProfile.userType === UserType.Mentee &&
activeMentorshipMatch?.status === MentorshipMatchStatus.Accepted &&
activeMentorshipMatch?.mentorId != activeMentorshipMatch.mentorId
Copy link

@coderabbitai coderabbitai bot Oct 5, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the logical error in mentor ID comparison

The condition activeMentorshipMatch?.mentorId != activeMentorshipMatch.mentorId is comparing the same property to itself, which will always evaluate to false. This means the intended check is not functioning correctly. To verify if the active mentorship is with a different mentor than the one currently being viewed, you should compare activeMentorshipMatch?.mentorId with profile.id.

Apply this diff to correct the condition:

if (
  currentUserProfile.userType === UserType.Mentee &&
  activeMentorshipMatch?.status === MentorshipMatchStatus.Accepted &&
- activeMentorshipMatch?.mentorId != activeMentorshipMatch.mentorId
+ activeMentorshipMatch?.mentorId != profile.id
) {
  return 'currentUserIsMenteeAndViewsNotTheirMentor'
}
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
currentUserProfile.userType === UserType.Mentee &&
activeMentorshipMatch?.status === MentorshipMatchStatus.Accepted &&
activeMentorshipMatch?.mentorId != activeMentorshipMatch.mentorId
currentUserProfile.userType === UserType.Mentee &&
activeMentorshipMatch?.status === MentorshipMatchStatus.Accepted &&
activeMentorshipMatch?.mentorId != profile.id

Copy link
Contributor

Choose a reason for hiding this comment

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

@ericbolikowski It seems like coderabbit is right. You are comparing two same things not being equal to each other here. Am I missing something?

Also let's use !== instead, if there's again not a good reason.

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice find, this is wrong. Pushed a fixed.

@astkhikatredi
Copy link
Contributor

Dear @ericbolikowski, as I told you in Slack - PR is not covering Case 2, please implement the same solution for Case 2.
Thanks

@katamatata
Copy link
Contributor

katamatata commented Oct 8, 2024

Hey @ericbolikowski,
I tested the implementation in this PR. Here are my findings:

  1. Log in as a mentee in an active mentorship

Mentees with an active mentorship can't access the profile page of their current mentor. Instead, they see the "another mentee got to this mentor first" overlay.

Case 1: open another mentor's profile

When accessing the profile page (/app/find-a-mentor/profile/:profiled) of other mentors, a mentee with an active mentorship sees other overlays instead of the "looks like you already have an ongoing mentorship with another mentor" overlay.

Case 2: open https://connect.redi-school.org/app/find-a-mentor

When accessing the find-a-mentor page, a mentee with an active mentorship sees this:
image
@astkhikatredi, is it like you imagined it?

  1. Confirm that the ongoing mentorship link leads to the dashboard of the current mentorship

The ongoing mentorship link seems to lead to the wrong mentorship ID, and instead of the dashboard of the current mentorship, an empty page is being displayed:
image

@astkhikatredi
Copy link
Contributor

Hello guys!

Mentees with an active mentorship can't access the profile page of their current mentor. Instead, they see the "another mentee got to this mentor first" overlay.

So, mentee should be able to open his mentor's page. but pages of other mentors should be blurred with a message.

@astkhikatredi, is it like you imagined it?

no, unfortunately not.
Find a mentor page should be blurred and message should be displayed in the middle.
Same as in this PR.

Thanks!

@ericbolikowski
Copy link
Contributor Author

@katamatata this error should now be fixed:

The ongoing mentorship link seems to lead to the wrong mentorship ID, and instead of the dashboard of the current mentorship, an empty page is being displayed:

Can you please pull latest changes and test?

Copy link

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

🧹 Outside diff range and nitpick comments (2)
apps/redi-connect/src/pages/app/profile/Profile.tsx (2)

93-96: LGTM: New activeMentorshipMatch variable is well-implemented.

The new variable correctly finds the active mentorship match. However, consider using Array.find() instead of Array.filter() for a slight performance improvement, as we only need the first match.

Consider applying this optimization:

const activeMentorshipMatch = 
-  myProfile.mentorshipMatches.filter(match =>
+  myProfile.mentorshipMatches.find(match =>
    match.status === MentorshipMatchStatus.Accepted
-  )[0]
  )

323-349: LGTM: ViewMode and determineViewMode updates are well-implemented.

The changes to ViewMode and determineViewMode correctly implement the new requirement for restricting mentees with active mentorships. The early return for mentee profiles is a good optimization.

Consider simplifying the condition for checking if the current user is a mentee with an active mentorship viewing another mentor's profile:

if (
  currentUserProfile.userType === UserType.Mentee &&
- activeMentorshipMatch?.status === MentorshipMatchStatus.Accepted &&
  activeMentorshipMatch?.mentor.id !== profile.userId
) {
  return 'currentUserIsMenteeAndViewsNotTheirMentor'
}

This simplification is possible because activeMentorshipMatch is already filtered to only include accepted matches.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1ef1cd3 and a2d781f.

📒 Files selected for processing (2)
  • apps/redi-connect/src/pages/app/find-a-mentor/FindAMentor.tsx (2 hunks)
  • apps/redi-connect/src/pages/app/profile/Profile.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/redi-connect/src/pages/app/find-a-mentor/FindAMentor.tsx
🧰 Additional context used
🔇 Additional comments (3)
apps/redi-connect/src/pages/app/profile/Profile.tsx (3)

2-5: LGTM: Import changes are consistent with new functionality.

The addition of LoadMyProfileQuery to the imports is appropriate for the new functionality implemented in this file.


98-98: LGTM: viewMode determination updated correctly.

The viewMode variable now uses the updated determineViewMode function, passing both the profile and the current user's profile. This change allows for more context-aware view mode determination, which is consistent with the new requirements.


Line range hint 1-355: Overall implementation looks good, with a few suggestions for improvement.

The changes effectively implement the new restrictions for mentees with active mentorships, aligning well with the PR objectives. The code is generally well-structured and readable. Here's a summary of the review:

  1. The new imports and variable declarations are appropriate.
  2. The ViewMode type and determineViewMode function have been correctly updated to handle the new use case.
  3. The new message for mentees viewing other mentors' profiles is well-written and informative.

However, there are a few areas that could benefit from minor improvements or verification:

  1. Consider using Array.find() instead of Array.filter() for activeMentorshipMatch for better performance.
  2. Verify the correctness of the mentorship link in the new message.
  3. Simplify the condition in determineViewMode for checking if a mentee with an active mentorship is viewing another mentor's profile.

Please address these suggestions and verify the mentorship link to ensure the implementation is fully correct and optimized.

Comment on lines 264 to 274
currentUserIsMenteeAndViewsNotTheirMentor: (
<>
Hey there! It looks like you already have{' '}
<a href={`/app/mentorships/${activeMentorshipMatch?.mentorId}`}>an ongoing mentorship</a> with
another mentor. Please remember that you can only have one mentor at a
time. You can save this link to check if this mentor remains available
once you complete your current mentorship match. If you have any
questions in the meantime, feel free to check out the{' '}
<a href="/faq">FAQ</a>.
</>
)
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Verify the mentorship link identifier in Profile.tsx.

The mentorship link in Profile.tsx uses activeMentorshipMatch?.mentorId, whereas in FindAMentor.tsx, it uses activeMentorshipMatch?.mentor.id. Please ensure that the correct identifier (mentor.id) is used consistently across the codebase to prevent potential issues with mentorship link navigation.

  • File: apps/redi-connect/src/pages/app/profile/Profile.tsx
    • Line: 264-274
🔗 Analysis chain

Message content LGTM, but verify the mentorship link.

The new message for mentees viewing other mentors' profiles is well-written and aligns with the requirements. However, there's a potential issue with the link to the ongoing mentorship.

The link to the ongoing mentorship uses activeMentorshipMatch?.mentorId, which might not be the correct ID for the mentorship dashboard. Please verify if this is the correct ID to use or if it should be a different identifier for the mentorship itself.

To help verify this, you can run the following script:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for mentorship-related route definitions and usages

# Search for route definitions related to mentorships
echo "Searching for mentorship route definitions:"
rg --type typescript 'mentorship.*route'

# Search for usages of mentorship-related links
echo "\nSearching for mentorship link usages:"
rg --type typescript 'href.*mentorship'

Length of output: 340


Script:

#!/bin/bash
# Description: Check for mentorship-related route definitions and usages

# Search for route definitions related to mentorships
echo "Searching for mentorship route definitions:"
rg --type ts 'mentorship.*route'

# Search for usages of mentorship-related links
echo "\nSearching for mentorship link usages:"
rg --type ts 'href.*mentorship'

Length of output: 577

@ericbolikowski
Copy link
Contributor Author

@astkhikatredi, is it like you imagined it?

no, unfortunately not. Find a mentor page should be blurred and message should be displayed in the middle. Same as in this PR.

Thanks!

@astkhikatredi unfortunately since the FindAMentor has a lot of vertical content the overlay centered vertically in the same manner as on the profile might lead to the message not being easily visible. I tried to "move the overlay" so that it's higher up, but couldn't find an easy fix for this. If we can't wait much longer, I suggest we deploy this change as-is and get back to figuring out a proper overlay for FindAMentor later.

@ericbolikowski
Copy link
Contributor Author

ericbolikowski commented Oct 9, 2024

Mentees with an active mentorship can't access the profile page of their current mentor. Instead, they see the "another mentee got to this mentor first" overlay.

So, mentee should be able to open his mentor's page. but pages of other mentors should be blurred with a message.

Edge case I hadn't thought of - just pushed code that should take care of it. @katamatata can you please pull & test?

PS! Nice find - @katamatata you live up to your reputation finding the bugs!

@astkhikatredi
Copy link
Contributor

Hey @ericbolikowski , one more comment: could you please replace this sentence "You can save this link to check if this mentor remains available once you complete your current mentorship match." with this: "You can check available mentors once you complete your current mentorship match"

THANKS

@astkhikatredi
Copy link
Contributor

@astkhikatredi unfortunately since the FindAMentor has a lot of vertical content the overlay centered vertically in the same manner as on the profile might lead to the message not being easily visible. I tried to "move the overlay" so that it's higher up, but couldn't find an easy fix for this. If we can't wait much longer, I suggest we deploy this change as-is and get back to figuring out a proper overlay for FindAMentor later.

Alright, please make a ticket about this so that we don't forget.

THANK YOU!

@katamatata
Copy link
Contributor

So, mentee should be able to open his mentor's page. but pages of other mentors should be blurred with a message.

Edge case I hadn't thought of - just pushed code that should take care of it. @katamatata can you please pull & test?

Tested it again.

  1. The mentees with an active mentorship still can't access the profile page of their current mentor. Now, they see the "looks like you already have an ongoing mentorship with another mentor" overlay.

  2. The ongoing mentorship link /app/mentorships/:id leads to the wrong ID (to the mentorId instead of the currentmentorshipMatches ID), and the blank page is being displayed:

image
  1. It's not possible to access the find-a-mentor page:
    image

Copy link

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2462426 and 0cd5cac.

📒 Files selected for processing (2)
  • apps/redi-connect/src/pages/app/find-a-mentor/FindAMentor.tsx (2 hunks)
  • apps/redi-connect/src/pages/app/profile/Profile.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/redi-connect/src/pages/app/find-a-mentor/FindAMentor.tsx
🧰 Additional context used
🔇 Additional comments (3)
apps/redi-connect/src/pages/app/profile/Profile.tsx (3)

2-2: LGTM: New imports and variable declarations

The new import LoadMyProfileQuery and the activeMentorshipMatch variable are well-implemented and necessary for the new functionality. The updated viewMode variable now correctly uses the myProfile parameter.

Also applies to: 93-97


Line range hint 1-364: Overall implementation looks good, but needs thorough testing

The changes implement the new restriction for mentees viewing other mentors' profiles, which aligns with the PR objectives. The new ViewMode type, determineViewMode function, and the message for mentees with active mentorships are well-implemented.

However, please address the issues mentioned in the previous comments, particularly:

  1. Fixing the logic in the determineViewMode function.
  2. Verifying the correct identifier for the mentorship link.

Additionally, as mentioned in the PR description, thorough testing is crucial, especially given the development conditions. Please ensure to:

  1. Test the implementation by logging in as a mentee with an active mentorship.
  2. Verify that the overlay is displayed when viewing other mentors' profiles.
  3. Confirm that the "ongoing mentorship" link correctly directs to the current mentorship dashboard.

To assist with testing, you can use the following script to simulate different user scenarios:

#!/bin/bash
# Description: Simulate different user scenarios for testing

# Function to simulate user login and profile viewing
simulate_user() {
  local user_type=$1
  local has_active_mentorship=$2
  local viewing_profile=$3

  echo "Simulating $user_type with${has_active_mentorship:+ active} mentorship viewing $viewing_profile's profile"
  # Add your test logic here, e.g., API calls or state changes
}

# Test scenarios
simulate_user "mentee" "active" "other_mentor"
simulate_user "mentee" "" "other_mentor"
simulate_user "mentee" "active" "current_mentor"
simulate_user "mentor" "" "mentee"

echo "Manual verification required for UI elements and navigation"

263-274: Verify the mentorship link identifier

The new message for mentees viewing other mentors' profiles is well-written and aligns with the requirements. However, there's a potential issue with the link to the ongoing mentorship.

The link uses activeMentorshipMatch?.mentorId, which might not be the correct ID for the mentorship dashboard. Please verify if this is the correct ID to use or if it should be a different identifier for the mentorship itself.

Run the following script to check for mentorship-related route definitions and usages:

Comment on lines +323 to +354
type ViewMode =
| 'display'
| 'notActivelyMentoring'
| 'mentoringButNoFreeSpots'
| 'currentUserIsMenteeAndViewsNotTheirMentor'

function determineViewMode(
profile: ProfilePageQueryQuery['conProfile']
profile: ProfilePageQueryQuery['conProfile'],
currentUserProfile: LoadMyProfileQuery['conProfile']
): ViewMode {
if (profile.userType !== UserType.Mentor) return 'display'
// If we're looking at a mentee, show the profile. Otherwise, the profile
// is a mentor's profile, so continue to determine if the view mode is a
// "special" one.
if (profile.userType === UserType.Mentee) return 'display'

const activeMentorshipMatch = currentUserProfile.mentorshipMatches.find(
(match) => match.status === MentorshipMatchStatus.Accepted
)

// Is current user a mentee, does that mentee have an active match, and is
// that match with another mentor than the one we're currently looking at?
if (activeMentorshipMatch.mentorId === currentUserProfile.id) return 'display'

console.log(activeMentorshipMatch, profile)

if (
currentUserProfile.userType === UserType.Mentee &&
activeMentorshipMatch?.status === MentorshipMatchStatus.Accepted &&
activeMentorshipMatch?.mentorId !== profile.userId
) {
return 'currentUserIsMenteeAndViewsNotTheirMentor'
}
Copy link

@coderabbitai coderabbitai bot Oct 10, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix issues in ViewMode type and determineViewMode function

The changes to the ViewMode type and determineViewMode function are good, but there are a few issues that need to be addressed:

  1. Remove the incorrect condition on line 344. This check is not necessary and may cause unexpected behavior.
  2. Remove the console.log statement on line 346. This should not be present in production code.
  3. Update the condition on line 351 to use profile.id instead of profile.userId for consistency.

Apply this diff to fix the issues:

-  if (activeMentorshipMatch.mentorId === currentUserProfile.id) return 'display'
-
-  console.log(activeMentorshipMatch, profile)
-
   if (
     currentUserProfile.userType === UserType.Mentee &&
     activeMentorshipMatch?.status === MentorshipMatchStatus.Accepted &&
-    activeMentorshipMatch?.mentorId !== profile.userId
+    activeMentorshipMatch?.mentorId !== profile.id
   ) {
     return 'currentUserIsMenteeAndViewsNotTheirMentor'
   }
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type ViewMode =
| 'display'
| 'notActivelyMentoring'
| 'mentoringButNoFreeSpots'
| 'currentUserIsMenteeAndViewsNotTheirMentor'
function determineViewMode(
profile: ProfilePageQueryQuery['conProfile']
profile: ProfilePageQueryQuery['conProfile'],
currentUserProfile: LoadMyProfileQuery['conProfile']
): ViewMode {
if (profile.userType !== UserType.Mentor) return 'display'
// If we're looking at a mentee, show the profile. Otherwise, the profile
// is a mentor's profile, so continue to determine if the view mode is a
// "special" one.
if (profile.userType === UserType.Mentee) return 'display'
const activeMentorshipMatch = currentUserProfile.mentorshipMatches.find(
(match) => match.status === MentorshipMatchStatus.Accepted
)
// Is current user a mentee, does that mentee have an active match, and is
// that match with another mentor than the one we're currently looking at?
if (activeMentorshipMatch.mentorId === currentUserProfile.id) return 'display'
console.log(activeMentorshipMatch, profile)
if (
currentUserProfile.userType === UserType.Mentee &&
activeMentorshipMatch?.status === MentorshipMatchStatus.Accepted &&
activeMentorshipMatch?.mentorId !== profile.userId
) {
return 'currentUserIsMenteeAndViewsNotTheirMentor'
}
type ViewMode =
| 'display'
| 'notActivelyMentoring'
| 'mentoringButNoFreeSpots'
| 'currentUserIsMenteeAndViewsNotTheirMentor'
function determineViewMode(
profile: ProfilePageQueryQuery['conProfile'],
currentUserProfile: LoadMyProfileQuery['conProfile']
): ViewMode {
// If we're looking at a mentee, show the profile. Otherwise, the profile
// is a mentor's profile, so continue to determine if the view mode is a
// "special" one.
if (profile.userType === UserType.Mentee) return 'display'
const activeMentorshipMatch = currentUserProfile.mentorshipMatches.find(
(match) => match.status === MentorshipMatchStatus.Accepted
)
if (
currentUserProfile.userType === UserType.Mentee &&
activeMentorshipMatch?.status === MentorshipMatchStatus.Accepted &&
activeMentorshipMatch?.mentorId !== profile.id
) {
return 'currentUserIsMenteeAndViewsNotTheirMentor'
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@helloanil, I guess this hasn't been handled, and it now causes an error on production:
image

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0cd5cac and 3fb42d6.

📒 Files selected for processing (2)
  • apps/redi-connect/src/pages/app/find-a-mentor/FindAMentor.tsx (2 hunks)
  • apps/redi-connect/src/pages/app/profile/Profile.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/redi-connect/src/pages/app/find-a-mentor/FindAMentor.tsx
🧰 Additional context used
🔇 Additional comments (4)
apps/redi-connect/src/pages/app/profile/Profile.tsx (4)

2-2: LGTM: New imports and variables added correctly

The new import LoadMyProfileQuery and the addition of the activeMentorshipMatch variable enhance the component's functionality. The update to the viewMode variable is consistent with the changes in the determineViewMode function. These changes appear to be well-implemented and necessary for the new features.

Also applies to: 93-97


323-327: LGTM: ViewMode type updated correctly

The ViewMode type has been appropriately updated to include the new currentUserIsMenteeAndViewsNotTheirMentor option. This addition accurately represents the new scenario being handled in the component.


Line range hint 1-354: Overall implementation aligns with PR objectives

The changes in this file effectively implement the new restrictions for mentees with active mentorships, as outlined in the PR objectives and linked issue #982. The new ViewMode option, updated determineViewMode function, and additional message for mentees viewing other mentors' profiles all contribute to achieving the desired functionality.

A few minor issues were identified in the determineViewMode function, which have been addressed in a previous comment. Once these are resolved, the implementation will be complete and aligned with the requirements.

To fully meet the objectives, ensure that:

  1. The "find a mentor" page restrictions are also implemented (as mentioned in the linked issue).
  2. The mentorship link in the new message is verified to use the correct identifier.

To ensure all requirements are met, please confirm that the "find a mentor" page restrictions have been implemented in the appropriate file(s).


263-274: Verify the mentorship link identifier

The new message for mentees viewing other mentors' profiles is well-written and aligns with the requirements. However, please verify if activeMentorshipMatch?.id is the correct identifier for linking to the mentorship dashboard. Ensure this is consistent with how mentorship links are generated elsewhere in the application.

Run the following script to check for consistency in mentorship link generation:

✅ Verification successful

Run an updated script to search mentorship link patterns in TypeScript files:


Mentorship link identifier is consistent and correct

The mentorship link in Profile.tsx uses activeMentorshipMatch?.id, which is consistently implemented across the codebase in files like FindAMentor.tsx. This ensures reliable linking to the mentorship dashboard.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for mentorship link generation patterns
echo "Searching for mentorship link patterns:"
rg --type typescript 'href.*mentorship.*id'

Length of output: 169


Script:

#!/bin/bash
# Description: Check for mentorship link generation patterns in TypeScript files without using --type
echo "Searching for mentorship link patterns in .ts and .tsx files:"
rg 'href.*mentorship.*id' --glob "*.ts" --glob "*.tsx"

Length of output: 439

Comment on lines 329 to +354
function determineViewMode(
profile: ProfilePageQueryQuery['conProfile']
profile: ProfilePageQueryQuery['conProfile'],
currentUserProfile: LoadMyProfileQuery['conProfile']
): ViewMode {
if (profile.userType !== UserType.Mentor) return 'display'
// If we're looking at a mentee, show the profile. Otherwise, the profile
// is a mentor's profile, so continue to determine if the view mode is a
// "special" one.
if (profile.userType === UserType.Mentee) return 'display'

const activeMentorshipMatch = currentUserProfile.mentorshipMatches.find(
(match) => match.status === MentorshipMatchStatus.Accepted
)

// Is current user a mentee, does that mentee have an active match, and is
// that match with another mentor than the one we're currently looking at?
if (activeMentorshipMatch.mentorId === currentUserProfile.id) return 'display'

console.log(activeMentorshipMatch, profile)

if (
currentUserProfile.userType === UserType.Mentee &&
activeMentorshipMatch?.status === MentorshipMatchStatus.Accepted &&
activeMentorshipMatch?.mentorId !== profile.userId
) {
return 'currentUserIsMenteeAndViewsNotTheirMentor'
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix issues in determineViewMode function

The updated function signature and new logic for handling mentees viewing other mentors' profiles are good additions. However, there are a few issues that need to be addressed:

  1. Remove the incorrect condition on line 344. This check is not necessary and may cause unexpected behavior.
  2. Remove the console.log statement on line 346. This should not be present in production code.
  3. Update the condition on line 351 to use profile.id instead of profile.userId for consistency.

Apply this diff to fix the issues:

-  if (activeMentorshipMatch.mentorId === currentUserProfile.id) return 'display'
-
-  console.log(activeMentorshipMatch, profile)
-
   if (
     currentUserProfile.userType === UserType.Mentee &&
     activeMentorshipMatch?.status === MentorshipMatchStatus.Accepted &&
-    activeMentorshipMatch?.mentorId !== profile.userId
+    activeMentorshipMatch?.mentorId !== profile.id
   ) {
     return 'currentUserIsMenteeAndViewsNotTheirMentor'
   }
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function determineViewMode(
profile: ProfilePageQueryQuery['conProfile']
profile: ProfilePageQueryQuery['conProfile'],
currentUserProfile: LoadMyProfileQuery['conProfile']
): ViewMode {
if (profile.userType !== UserType.Mentor) return 'display'
// If we're looking at a mentee, show the profile. Otherwise, the profile
// is a mentor's profile, so continue to determine if the view mode is a
// "special" one.
if (profile.userType === UserType.Mentee) return 'display'
const activeMentorshipMatch = currentUserProfile.mentorshipMatches.find(
(match) => match.status === MentorshipMatchStatus.Accepted
)
// Is current user a mentee, does that mentee have an active match, and is
// that match with another mentor than the one we're currently looking at?
if (activeMentorshipMatch.mentorId === currentUserProfile.id) return 'display'
console.log(activeMentorshipMatch, profile)
if (
currentUserProfile.userType === UserType.Mentee &&
activeMentorshipMatch?.status === MentorshipMatchStatus.Accepted &&
activeMentorshipMatch?.mentorId !== profile.userId
) {
return 'currentUserIsMenteeAndViewsNotTheirMentor'
}
function determineViewMode(
profile: ProfilePageQueryQuery['conProfile'],
currentUserProfile: LoadMyProfileQuery['conProfile']
): ViewMode {
// If we're looking at a mentee, show the profile. Otherwise, the profile
// is a mentor's profile, so continue to determine if the view mode is a
// "special" one.
if (profile.userType === UserType.Mentee) return 'display'
const activeMentorshipMatch = currentUserProfile.mentorshipMatches.find(
(match) => match.status === MentorshipMatchStatus.Accepted
)
if (
currentUserProfile.userType === UserType.Mentee &&
activeMentorshipMatch?.status === MentorshipMatchStatus.Accepted &&
activeMentorshipMatch?.mentorId !== profile.id
) {
return 'currentUserIsMenteeAndViewsNotTheirMentor'
}

@helloanil helloanil merged commit 20aaafb into master Oct 16, 2024
2 checks passed
@helloanil helloanil deleted the feat/con/profile-page-overlay-third-case branch October 16, 2024 21:08
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.

[CON]: Restrictions for mentees with an ongoing mentorship
4 participants