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
22 changes: 19 additions & 3 deletions apps/redi-connect/src/pages/app/find-a-mentor/FindAMentor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ConnectProfileStatus,
Language,
MentoringTopic,
MentorshipMatchStatus,
RediLocation,
useFavoriteMentorMutation,
useFindAvailableMentorsQuery,
Expand Down Expand Up @@ -197,14 +198,29 @@ const FindAMentor = () => {
if (profile && profile?.profileStatus !== ConnectProfileStatus.Approved)
return <LoggedIn />

const activeMentorshipMatch = profile?.mentorshipMatches.find(
(match) => match.status === MentorshipMatchStatus.Accepted
)
const menteeHasAnActiveMatch =
profile?.userType === 'MENTEE' &&
profile?.mentorshipMatches.length > 0 &&
profile?.mentorshipMatches?.[0].status === 'ACCEPTED'
activeMentorshipMatch

if (menteeHasAnActiveMatch) {
const matchId = profile?.mentorshipMatches?.[0].id
history.replace(`/app/mentorships/${matchId}`)
return (
<LoggedIn>
<Content>
Hey there! It looks like you already have{' '}
<a href={`/app/mentorships/${activeMentorshipMatch?.mentor.id}`}>
an ongoing mentorship
</a>{' '}
with another mentor. Please remember that you can only have one mentor
at a time. You can check available mentors 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>.
</Content>
</LoggedIn>
)
}

const filteredMentorProfiles = mentorsQuery.data?.conProfilesAvailableMentors
Expand Down
52 changes: 48 additions & 4 deletions apps/redi-connect/src/pages/app/profile/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
LoadMyProfileQuery,
MentorshipMatchStatus,
useLoadMyProfileQuery,
UserType,
Expand Down Expand Up @@ -89,7 +90,11 @@ function Profile() {

const shouldHidePrivateContactInfo = currentUserIsMentee && !isAcceptedMatch

const viewMode = determineViewMode(profile)
const activeMentorshipMatch = myProfile.mentorshipMatches.find(
(match) => match.status === MentorshipMatchStatus.Accepted
)

const viewMode = determineViewMode(profile, myProfile)

const profileView = (
<>
Expand Down Expand Up @@ -255,6 +260,18 @@ function Profile() {
<a href="/faq">FAQ</a>.
</>
),
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 check available mentors 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>.
</>
),
}
return (
<LoggedIn>
Expand Down Expand Up @@ -303,12 +320,39 @@ function Profile() {
)
}

type ViewMode = 'display' | 'notActivelyMentoring' | 'mentoringButNoFreeSpots'
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'
}
Comment on lines +323 to +354
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!

Comment on lines 329 to +354
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'
}


if (profile.menteeCountCapacity === 0) return 'notActivelyMentoring'
if (profile.doesNotHaveAvailableMentorshipSlot)
return 'mentoringButNoFreeSpots'
Expand Down
Loading