Skip to content

feat(PM-1365): Populate project field in copilot request form when query param presents #1173

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 2 commits into from
Aug 1, 2025

Conversation

hentrymartin
Copy link
Collaborator

Related JIRA Ticket:

https://topcoder.atlassian.net/browse/PM-1365

What's in this PR?

  • Populate project field in copilot request form when query param presents

@@ -1,17 +1,18 @@
import { FC, useContext, useEffect, useMemo, useState } from 'react'
import { bind, debounce, isEmpty } from 'lodash'
import { toast } from 'react-toastify'
import { Params, useNavigate, useParams } from 'react-router-dom'
import { Params, useNavigate, useParams, useSearchParams } from 'react-router-dom'
Copy link

Choose a reason for hiding this comment

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

The useSearchParams hook is imported but not used in the code. Please ensure that it is utilized if needed, or remove the import to keep the code clean.

@@ -37,11 +38,13 @@ const CopilotRequestForm: FC<{}> = () => {
const { profile }: ProfileContextData = useContext(profileContext)
const navigate = useNavigate()
const routeParams: Params<string> = useParams()
const [params] = useSearchParams()
Copy link

Choose a reason for hiding this comment

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

Consider using a more descriptive name for the params variable to clarify its purpose, such as searchParams.


const [formValues, setFormValues] = useState<any>({})
const [isFormChanged, setIsFormChanged] = useState(false)
const [formErrors, setFormErrors] = useState<any>({})
const [paymentType, setPaymentType] = useState<string>('')
const [projectFromQuery, setProjectFromQuery] = useState<Project>()
Copy link

Choose a reason for hiding this comment

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

The projectFromQuery state is initialized but not used in the provided diff. Ensure that it is utilized appropriately in the component logic or remove it if unnecessary.

return
}

const project = await getProject(projectId as string)
Copy link

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 getProject function to manage cases where the project might not be found or the request fails.


const project = await getProject(projectId as string)

setFormValues((prevValues: any) => ({
Copy link

Choose a reason for hiding this comment

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

Avoid using any type for prevValues. Consider defining a specific type for form values to improve type safety.

}

useEffect(() => {
fetchProject()
Copy link

Choose a reason for hiding this comment

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

Ensure that fetchProject is only called when necessary. Currently, it will be called on every change to params, which might not be efficient if params changes frequently.

@@ -58,6 +58,11 @@ export const useProjects = (search?: string, config?: {isPaused?: () => boolean,
})
}

export const getProject = (projectId: string): Promise<Project> => {
Copy link

Choose a reason for hiding this comment

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

Consider adding error handling to the getProject function to manage cases where the request might fail or return an unexpected response. This will improve the robustness of the function.

@hentrymartin hentrymartin merged commit ef6d0cd into dev Aug 1, 2025
4 checks passed
@hentrymartin hentrymartin deleted the pm-1365_1 branch August 1, 2025 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant