Skip to content

Commit

Permalink
feat(con): profile page - display overlay when mentee views "a mentor…
Browse files Browse the repository at this point in the history
… who's not their mentor"
  • Loading branch information
ericbolikowski committed Oct 4, 2024
1 parent d258fd2 commit c6762e4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
9 changes: 7 additions & 2 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 @@ -200,10 +201,14 @@ const FindAMentor = () => {
const menteeHasAnActiveMatch =
profile?.userType === 'MENTEE' &&
profile?.mentorshipMatches.length > 0 &&
profile?.mentorshipMatches?.[0].status === 'ACCEPTED'
profile?.mentorshipMatches?.some(match =>
match.status === MentorshipMatchStatus.Accepted
)

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

Expand Down
47 changes: 43 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,12 @@ 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 +261,17 @@ 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 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>.
</>
)
}
return (
<LoggedIn>
Expand Down Expand Up @@ -303,12 +320,34 @@ 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'

// 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?
const activeMentorshipMatch =
currentUserProfile.mentorshipMatches.find(match =>
match.status === MentorshipMatchStatus.Accepted
)
if (
currentUserProfile.userType === UserType.Mentee &&
activeMentorshipMatch?.status === MentorshipMatchStatus.Accepted &&
activeMentorshipMatch?.mentorId != activeMentorshipMatch.mentorId
) {
return 'currentUserIsMenteeAndViewsNotTheirMentor'
}

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

0 comments on commit c6762e4

Please sign in to comment.