Skip to content

PM-1064 Request Copilot button on opportunity feed #1051

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
Apr 29, 2025
Merged
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
16 changes: 15 additions & 1 deletion src/apps/copilots/src/pages/copilot-opportunity-list/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { FC, useMemo } from 'react'
import { FC, useContext, useMemo } from 'react'
import { useNavigate } from 'react-router-dom'
import classNames from 'classnames'

import {
ButtonProps,
ContentLayout,
LoadingSpinner,
PageTitle,
Table,
TableColumn,
} from '~/libs/ui'
import { profileContext, ProfileContextData, UserRole } from '~/libs/core'

import { CopilotOpportunity } from '../../models/CopilotOpportunity'
import { copilotRoutesMap } from '../../copilots.routes'
Expand Down Expand Up @@ -88,6 +90,12 @@ const tableColumns: TableColumn<CopilotOpportunity>[] = [
const CopilotOpportunityList: FC<{}> = () => {
const navigate = useNavigate()

const { profile }: ProfileContextData = useContext(profileContext)
const isAdminOrPM: boolean = useMemo(
() => !!profile?.roles?.some(role => role === UserRole.tcaAdmin || role === UserRole.projectManager),

Choose a reason for hiding this comment

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

Consider using includes instead of some for checking roles if the list of roles is small and fixed, as it can be more readable and straightforward.

[profile],
)

const {
data: opportunities, isValidating, size, setSize,
}: CopilotOpportunitiesResponse = useCopilotOpportunities()
Expand All @@ -107,9 +115,15 @@ const CopilotOpportunityList: FC<{}> = () => {

const opportunitiesLoading = isValidating

const addNewRequestButton: ButtonProps = {
label: 'New Copilot Request',
onClick: () => navigate(copilotRoutesMap.CopilotRequestForm),

Choose a reason for hiding this comment

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

Consider adding error handling for the navigate function to handle cases where the navigation might fail.

}

return (
<ContentLayout
title='Copilot Opportunities'
buttonConfig={isAdminOrPM ? addNewRequestButton : undefined}
>
<PageTitle>Copilot Opportunities</PageTitle>
<Table
Expand Down