-
Notifications
You must be signed in to change notification settings - Fork 13
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, | ||
} |
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' | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 }>() | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
} | ||
}, [opportunityId, copilotApplication]) | ||
return ( | ||
<div onClick={onClick} className={styles.actionWrapper}> | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@import '@libs/ui/styles/includes'; | ||
|
||
.status { | ||
text-transform: capitalize; | ||
} | ||
|
||
.actionWrapper { | ||
width: 24px; | ||
height: 24px; | ||
cursor: pointer; | ||
svg { | ||
color: $teal-100; | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,21 @@ export const applyCopilotOpportunity = async (opportunityId: number, request?: { | |
return xhrPostAsync(url, request, {}) | ||
} | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function name |
||
* apply copilot opportunity | ||
* @param opportunityId | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @param applicationId | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
* @returns | ||
*/ | ||
export const assignCopilotOpportunity = async ( | ||
opportunityId: string, | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
applicationId: number, | ||
): Promise<{applicationId: number}> => { | ||
const url = `${copilotBaseUrl}/copilots/opportunity/${opportunityId}/assign` | ||
|
||
return xhrPostAsync(url, { applicationId: applicationId.toString() }, {}) | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* Custom hook to fetch copilot applications by opportunity id. | ||
* | ||
|
There was a problem hiding this comment.
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.