import {Fragment, useEffect, useMemo} from 'react';
import styled from '@emotion/styled';
import type {ModalRenderProps} from 'sentry/actionCreators/modal';
import {Button} from 'sentry/components/button';
import {AutofixCodebaseIndexingStatus} from 'sentry/components/events/autofix/types';
import {useAutofixCodebaseIndexing} from 'sentry/components/events/autofix/useAutofixCodebaseIndexing';
import {
type AutofixSetupRepoDefinition,
type AutofixSetupResponse,
useAutofixSetup,
} from 'sentry/components/events/autofix/useAutofixSetup';
import {GuidedSteps} from 'sentry/components/guidedSteps/guidedSteps';
import HookOrDefault from 'sentry/components/hookOrDefault';
import ExternalLink from 'sentry/components/links/externalLink';
import LoadingError from 'sentry/components/loadingError';
import LoadingIndicator from 'sentry/components/loadingIndicator';
import {IconCheckmark, IconGithub} from 'sentry/icons';
import {t, tct} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import {trackAnalytics} from 'sentry/utils/analytics';
import useOrganization from 'sentry/utils/useOrganization';
interface AutofixSetupModalProps extends ModalRenderProps {
groupId: string;
projectId: string;
}
const ConsentStep = HookOrDefault({
hookName: 'component:autofix-setup-step-consent',
defaultComponent: null,
});
function AutofixIntegrationStep({autofixSetup}: {autofixSetup: AutofixSetupResponse}) {
if (autofixSetup.integration.ok) {
return (
{tct(
'The GitHub integration has been installed but is not active. Navigate to the [integration settings page] and enable it to continue.',
{
link:
{tct(
'Once enabled, come back to this page. For more information related to installing the GitHub integration, read the [link:documentation].',
{
link: (
{tct(
'You have an active GitHub installation, but no code mappings for this project. Add code mappings by visiting the [link:integration settings page] and editing your configuration.',
{
link:
{tct(
'Once added, come back to this page. For more information related to installing the GitHub integration, read the [link:documentation].',
{
link: (
{tct(
'Install the GitHub integration by navigating to the [link:integration settings page] and clicking the "Install" button. Follow the steps provided.',
{
link:
{tct(
'Once installed, come back to this page. For more information related to installing the GitHub integration, read the [link:documentation].',
{
link: (
{tct(
'The [link:Sentry Autofix GitHub App] has been installed on all required repositories:',
{
link: (
{tct(
'Install and grant write access to the [link:Sentry Autofix Github App] for the following repositories:',
{
link: (
{t( 'Without this, Autofix can still provide root analysis and suggested code changes.' )}
{tct(
'Install and grant write access to the [link:Sentry Autofix Github App] for the relevant repositories.',
{
link: (
{t( 'Without this, Autofix can still provide root analysis and suggested code changes.' )}
{t( 'Sentry will index your repositories to enable Autofix. This process may take a few minutes.' )}
{status === AutofixCodebaseIndexingStatus.ERRORED && reason ? ({t("You've successfully configured Autofix!")}