-
Notifications
You must be signed in to change notification settings - Fork 15
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
Conversation
@@ -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' |
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.
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() |
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 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>() |
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.
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) |
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 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) => ({ |
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.
Avoid using any
type for prevValues
. Consider defining a specific type for form values to improve type safety.
} | ||
|
||
useEffect(() => { | ||
fetchProject() |
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.
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> => { |
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 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.
Related JIRA Ticket:
https://topcoder.atlassian.net/browse/PM-1365
What's in this PR?