import React, { useEffect } from "react"; // next import { useRouter } from "next/router"; // swr import useSWR from "swr"; // react hook form import { useFormContext, Controller } from "react-hook-form"; // services import jiraImporterService from "services/integration/jira.service"; // fetch keys import { JIRA_IMPORTER_DETAIL } from "constants/fetch-keys"; import { IJiraImporterForm, IJiraMetadata } from "types"; // components import { Spinner, ToggleSwitch } from "components/ui"; import type { IJiraIntegrationData, TJiraIntegrationSteps } from "./"; type Props = { setCurrentStep: React.Dispatch>; setDisableTopBarAfter: React.Dispatch>; }; export const JiraProjectDetail: React.FC = (props) => { const { setCurrentStep, setDisableTopBarAfter } = props; const { watch, setValue, control, formState: { errors }, } = useFormContext(); const router = useRouter(); const { workspaceSlug } = router.query; const params: IJiraMetadata = { api_token: watch("metadata.api_token"), project_key: watch("metadata.project_key"), email: watch("metadata.email"), cloud_hostname: watch("metadata.cloud_hostname"), }; const { data: projectInfo, error } = useSWR( workspaceSlug && !errors.metadata?.api_token && !errors.metadata?.project_key && !errors.metadata?.email && !errors.metadata?.cloud_hostname ? JIRA_IMPORTER_DETAIL(workspaceSlug.toString(), params) : null, workspaceSlug && !errors.metadata?.api_token && !errors.metadata?.project_key && !errors.metadata?.email && !errors.metadata?.cloud_hostname ? () => jiraImporterService.getJiraProjectInfo(workspaceSlug.toString(), params) : null ); useEffect(() => { if (!projectInfo) return; setValue("data.total_issues", projectInfo.issues); setValue("data.total_labels", projectInfo.labels); setValue( "data.users", projectInfo.users?.map((user) => ({ email: user.emailAddress, import: false, username: user.displayName, })) ); setValue("data.total_states", projectInfo.states); setValue("data.total_modules", projectInfo.modules); }, [projectInfo, setValue]); useEffect(() => { if (error) setDisableTopBarAfter("display-import-data"); else setDisableTopBarAfter(null); }, [error, setDisableTopBarAfter]); useEffect(() => { if (!projectInfo && !error) setDisableTopBarAfter("display-import-data"); else if (!error) setDisableTopBarAfter(null); }, [projectInfo, error, setDisableTopBarAfter]); if (!projectInfo && !error) { return (
); } if (error) { return (

Something went wrong. Please{" "} {" "} and check your Jira project details.

); } return (

Import Data

Import Completed. We have found:

{projectInfo?.issues}

Issues

{projectInfo?.states}

States

{projectInfo?.modules}

Modules

{projectInfo?.labels}

Labels

{projectInfo?.users?.length}

Users

Import Epics

Import epics as modules

( )} />
); };