Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/apps/copilots/src/models/CopilotApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export interface CopilotApplication {
handle?: string,
userId: number,
status: CopilotApplicationStatus,
opportunityStatus: string,
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ const CopilotOpportunityDetails: FC<{}> = () => {
)
}
{activeTab === CopilotDetailsTabViews.details && <OpportunityDetails opportunity={opportunity} />}
{activeTab === CopilotDetailsTabViews.applications && isAdminOrPM && (
{activeTab === CopilotDetailsTabViews.applications && isAdminOrPM && opportunity && (

Choose a reason for hiding this comment

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

Consider checking if opportunity is not null or undefined before using it in the condition. This ensures that the CopilotApplications component is only rendered when opportunity is valid.

<CopilotApplications
copilotApplications={copilotApplications}
opportunity={opportunity}
members={members}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ const CopilotApplicationAction = (
[allCopilotApplications],
)
const onClick = useCallback(async () => {
if (copilotApplication.status !== CopilotApplicationStatus.PENDING || isInvited) {
if (
copilotApplication.status !== CopilotApplicationStatus.PENDING
|| isInvited
|| copilotApplication.opportunityStatus !== 'active'
) {
return
}

Expand All @@ -46,7 +50,9 @@ const CopilotApplicationAction = (
}

{
!isInvited && copilotApplication.status === CopilotApplicationStatus.PENDING && (
!isInvited
&& copilotApplication.status === CopilotApplicationStatus.PENDING
&& copilotApplication.opportunityStatus === 'active' && (

Choose a reason for hiding this comment

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

Consider using a constant or enum for the string 'active' to avoid potential typos and to make the code more maintainable.

<IconSolid.UserAddIcon />
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FC, useMemo } from 'react'

import { Table, TableColumn } from '~/libs/ui'
import { USER_PROFILE_URL } from '~/config/environments/default.env'
import { CopilotOpportunity } from '~/apps/copilots/src/models/CopilotOpportunity'

import { CopilotApplication } from '../../../../models/CopilotApplication'
import { FormattedMembers } from '../../../../services/members'
Expand Down Expand Up @@ -70,6 +71,7 @@ const tableColumns: TableColumn<CopilotApplication>[] = [
const CopilotApplications: FC<{
copilotApplications?: CopilotApplication[]
members?: FormattedMembers[]
opportunity: CopilotOpportunity
}> = props => {
const getData = (): CopilotApplication[] => (props.copilotApplications ? props.copilotApplications.map(item => {
const member = props.members && props.members.find(each => each.userId === item.userId)
Expand All @@ -78,6 +80,7 @@ const CopilotApplications: FC<{
activeProjects: member?.activeProjects || 0,
fulfilment: member?.copilotFulfillment || 0,
handle: member?.handle,
opportunityStatus: props.opportunity.status,
}
})
.sort((a, b) => (b.fulfilment || 0) - (a.fulfilment || 0)) : [])
Expand Down