Skip to content

Commit

Permalink
fix(con): mentors accept requests only within selected capacity (#1004)
Browse files Browse the repository at this point in the history
* wip

* Restrict accepting new mentee applications when mentors reached their selected mentee limit

* Refactor
  • Loading branch information
katamatata authored Jan 14, 2025
1 parent a78006f commit 1d58eeb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
37 changes: 34 additions & 3 deletions apps/redi-connect/src/components/organisms/ConfirmMentorship.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@talent-connect/shared-atomic-design-components'
import { useFormik } from 'formik'
import { useState } from 'react'
import { Content } from 'react-bulma-components'
import { Content, Notification } from 'react-bulma-components'
import { useQueryClient } from 'react-query'
import { useHistory } from 'react-router-dom'
import * as Yup from 'yup'
Expand All @@ -17,6 +17,8 @@ import {
interface ConfirmMentorshipProps {
match: ConfirmMentorshipMatchPropFragment
menteeName?: string
hasReachedDesiredMenteeLimit?: boolean
menteeCountCapacity?: number
}

interface ConfirmMentorshipFormValues {
Expand All @@ -29,6 +31,7 @@ const initialValues = {

const MIN_CHARS_COUNT = 250
const MAX_CHARS_COUNT = 600
const MAX_MENTEE_LIMIT = 2

const validationSchema = Yup.object({
mentorReplyMessageOnAccept: Yup.string()
Expand All @@ -37,7 +40,11 @@ const validationSchema = Yup.object({
.max(MAX_CHARS_COUNT),
})

const ConfirmMentorship = ({ match }: ConfirmMentorshipProps) => {
const ConfirmMentorship = ({
match,
hasReachedDesiredMenteeLimit,
menteeCountCapacity,
}: ConfirmMentorshipProps) => {
const queryClient = useQueryClient()
const acceptMentorshipMutation = useAcceptMentorshipMutation()
const [isModalActive, setModalActive] = useState(false)
Expand Down Expand Up @@ -73,7 +80,31 @@ const ConfirmMentorship = ({ match }: ConfirmMentorshipProps) => {

return (
<>
<Button onClick={() => setModalActive(true)}>Accept</Button>
{hasReachedDesiredMenteeLimit ? (
<>
{menteeCountCapacity === MAX_MENTEE_LIMIT ? (
<Notification color="info" className="is-light">
You've reached our recommended maximum number of mentees. If you
wish to mentor more than 2 mentees at the same time, please reach
out to us at{' '}
<a href="mailto:[email protected]">[email protected]</a>
. Otherwise, please decline the application.
</Notification>
) : (
<Notification color="info" className="is-light">
You've reached your desired number of mentees. If you wish to
accept another mentee, please go to the{' '}
<a onClick={() => history.push('/app/me')}>My Profile</a> page and
increase the mentee count value. Otherwise, please decline the
application.
</Notification>
)}
<Button disabled={hasReachedDesiredMenteeLimit}>Accept</Button>
</>
) : (
<Button onClick={() => setModalActive(true)}>Accept</Button>
)}

<Modal
show={isModalActive}
stateFn={setModalActive}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ const ApplicationCard = ({ application }: Props) => {
const loopbackUserId = getAccessTokenFromLocalStorage().userId
const myProfileQuery = useLoadMyProfileQuery({ loopbackUserId })

const hasReachedMenteeLimit =
const hasReachedDesiredMenteeLimit =
myProfileQuery.data.conProfile.doesNotHaveAvailableMentorshipSlot

const menteeCountCapacity = myProfileQuery.data.conProfile.menteeCountCapacity

const currentUser = myProfileQuery.data.conProfile

const {
Expand Down Expand Up @@ -147,7 +150,11 @@ const ApplicationCard = ({ application }: Props) => {
{currentUserIsMentor &&
application.status === MentorshipMatchStatus.Applied ? (
<>
<ConfirmMentorship match={application} />
<ConfirmMentorship
match={application}
hasReachedDesiredMenteeLimit={hasReachedDesiredMenteeLimit}
menteeCountCapacity={menteeCountCapacity}
/>
<DeclineMentorshipButton match={application} />
</>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ function MobileApplicationCard({ application }: Props) {
const loopbackUserId = getAccessTokenFromLocalStorage().userId
const myProfileQuery = useLoadMyProfileQuery({ loopbackUserId })

const hasReachedDesiredMenteeLimit =
myProfileQuery.data.conProfile.doesNotHaveAvailableMentorshipSlot

const menteeCountCapacity = myProfileQuery.data.conProfile.menteeCountCapacity

const currentUser = myProfileQuery.data.conProfile

const {
Expand Down Expand Up @@ -139,7 +144,11 @@ function MobileApplicationCard({ application }: Props) {
application.status === MentorshipMatchStatus.Applied ? (
<div className="action-buttons">
<div>
<ConfirmMentorship match={application} />
<ConfirmMentorship
match={application}
hasReachedDesiredMenteeLimit={hasReachedDesiredMenteeLimit}
menteeCountCapacity={menteeCountCapacity}
/>
<DeclineMentorshipButton match={application} />
</div>
</div>
Expand Down

0 comments on commit 1d58eeb

Please sign in to comment.