import posthog from "posthog-js"; import React from "react"; import { useTranslation } from "react-i18next"; import { SuggestionItem } from "#/components/features/suggestions/suggestion-item"; import { I18nKey } from "#/i18n/declaration"; import { useUserProviders } from "#/hooks/use-user-providers"; import { useActiveConversation } from "#/hooks/query/use-active-conversation"; interface ActionSuggestionsProps { onSuggestionsClick: (value: string) => void; } export function ActionSuggestions({ onSuggestionsClick, }: ActionSuggestionsProps) { const { t } = useTranslation(); const { providers } = useUserProviders(); const { data: conversation } = useActiveConversation(); const [hasPullRequest, setHasPullRequest] = React.useState(false); const providersAreSet = providers.length > 0; const isGitLab = providers.includes("gitlab"); const pr = isGitLab ? "merge request" : "pull request"; const prShort = isGitLab ? "MR" : "PR"; const terms = { pr, prShort, pushToBranch: `Please push the changes to a remote branch on ${ isGitLab ? "GitLab" : "GitHub" }, but do NOT create a ${pr}. Please use the exact SAME branch name as the one you are currently on.`, createPR: `Please push the changes to ${ isGitLab ? "GitLab" : "GitHub" } and open a ${pr}. Please create a meaningful branch name that describes the changes. If a ${pr} template exists in the repository, please follow it when creating the ${prShort} description.`, pushToPR: `Please push the latest changes to the existing ${pr}.`, }; return (
{providersAreSet && conversation?.selected_repository && (
{!hasPullRequest ? ( <> { posthog.capture("push_to_branch_button_clicked"); onSuggestionsClick(value); }} /> { posthog.capture("create_pr_button_clicked"); onSuggestionsClick(value); setHasPullRequest(true); }} /> ) : ( { posthog.capture("push_to_pr_button_clicked"); onSuggestionsClick(value); }} /> )}
)}
); }