Skip to content

feat(PM-580): added assign action to applications list #1086

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

Merged
merged 3 commits into from
May 27, 2025
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
7 changes: 7 additions & 0 deletions src/apps/copilots/src/models/CopilotApplication.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
export enum CopilotApplicationStatus {
INVITED = 'invited',
ACCEPTED = 'accepted',
PENDING = 'pending',
}

export interface CopilotApplication {
id: number,
notes?: string,
createdAt: Date,
opportunityId: string,
handle?: string,
userId: number,
status: CopilotApplicationStatus,

Choose a reason for hiding this comment

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

Consider ensuring that CopilotApplicationStatus is properly defined and imported in this file to avoid any potential issues with type resolution.

}
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ const CopilotOpportunityDetails: FC<{}> = () => {
}
infoComponent={(isCopilot && !(copilotApplications
&& copilotApplications.length === 0
&& opportunity?.status === 'active'
) && !!application) && (
) && opportunity?.status === 'active' && !!application) && (
<div className={styles.applied}>
<IconSolid.CheckCircleIcon className={styles.appliedIcon} />
<span
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { useParams } from 'react-router-dom'
import { toast } from 'react-toastify'
import { mutate } from 'swr'
import { useCallback } from 'react'

import { assignCopilotOpportunity, copilotBaseUrl } from '~/apps/copilots/src/services/copilot-opportunities'
import { CopilotApplication, CopilotApplicationStatus } from '~/apps/copilots/src/models/CopilotApplication'
import { IconSolid, Tooltip } from '~/libs/ui'

import styles from './styles.module.scss'

const CopilotApplicationAction = (copilotApplication: CopilotApplication): JSX.Element => {
const { opportunityId }: {opportunityId?: string} = useParams<{ opportunityId?: string }>()
const onClick = useCallback(async () => {
if (copilotApplication.status !== CopilotApplicationStatus.PENDING) {
return
}

if (opportunityId) {
try {
await assignCopilotOpportunity(opportunityId, copilotApplication.id)
toast.success('Invited a copilot')
mutate(`${copilotBaseUrl}/copilots/opportunity/${opportunityId}/applications`)
} catch (e) {
const error = e as Error
toast.error(error.message)
}

}
}, [opportunityId, copilotApplication])
return (
<div onClick={onClick} className={styles.actionWrapper}>
{
copilotApplication.status === CopilotApplicationStatus.INVITED && (
<Tooltip content='User already invited'>
<IconSolid.MailOpenIcon />
</Tooltip>
)
}

{
copilotApplication.status === CopilotApplicationStatus.PENDING && (
<IconSolid.UserAddIcon />
)
}

{
copilotApplication.status === CopilotApplicationStatus.ACCEPTED && (
<IconSolid.BadgeCheckIcon />
)
}
</div>
)
}

export default CopilotApplicationAction
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { USER_PROFILE_URL } from '~/config/environments/default.env'
import { CopilotApplication } from '../../../../models/CopilotApplication'
import { FormattedMembers } from '../../../../services/members'

import CopilotApplicationAction from './CopilotApplicationAction'
import styles from './styles.module.scss'

const tableColumns: TableColumn<CopilotApplication>[] = [
Expand Down Expand Up @@ -33,6 +34,16 @@ const tableColumns: TableColumn<CopilotApplication>[] = [
propertyName: 'activeProjects',
type: 'text',
},
{
label: 'Status',
propertyName: 'status',
renderer: (copilotApplication: CopilotApplication) => (
<div className={styles.status}>
{copilotApplication.status}
</div>
),
type: 'element',
},
{
label: 'Applied Date',
propertyName: 'createdAt',
Expand All @@ -48,6 +59,12 @@ const tableColumns: TableColumn<CopilotApplication>[] = [
),
type: 'element',
},
{
label: 'Actions',
propertyName: '',
renderer: CopilotApplicationAction,
type: 'element',
},
]

const CopilotApplications: FC<{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@import '@libs/ui/styles/includes';

.status {
text-transform: capitalize;
}

.actionWrapper {
width: 24px;
height: 24px;
cursor: pointer;
svg {
color: $teal-100;
}
}
15 changes: 15 additions & 0 deletions src/apps/copilots/src/services/copilot-opportunities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ export const applyCopilotOpportunity = async (opportunityId: number, request?: {
return xhrPostAsync(url, request, {})
}

/**

Choose a reason for hiding this comment

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

The function name assignCopilotOpportunity is similar to applyCopilotOpportunity. Consider renaming for clarity, especially if both functions are used in similar contexts.

* apply copilot opportunity
* @param opportunityId
* @param applicationId

Choose a reason for hiding this comment

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

The parameter name in the function signature should be updated to match the JSDoc comment. If the parameter is indeed applicationId, ensure the function signature reflects this change.

* @returns
*/
export const assignCopilotOpportunity = async (
opportunityId: string,
applicationId: number,
): Promise<{applicationId: number}> => {
const url = `${copilotBaseUrl}/copilots/opportunity/${opportunityId}/assign`

return xhrPostAsync(url, { applicationId: applicationId.toString() }, {})
}

/**
* Custom hook to fetch copilot applications by opportunity id.
*
Expand Down