import React, { useEffect } from "react"; // next import { useParams } from "next/navigation"; // swr import { useFormContext, Controller } from "react-hook-form"; import useSWR from "swr"; import { IJiraImporterForm, IJiraMetadata } from "@plane/types"; // react hook form // services import { ToggleSwitch, Spinner } from "@plane/ui"; import { JIRA_IMPORTER_DETAIL } from "@/constants/fetch-keys"; import { JiraImporterService } from "@/services/integrations"; // fetch keys // components import type { IJiraIntegrationData, TJiraIntegrationSteps } from "."; type Props = { setCurrentStep: React.Dispatch>; setDisableTopBarAfter: React.Dispatch>; }; // services const jiraImporterService = new JiraImporterService(); export const JiraProjectDetail: React.FC = (props) => { const { setCurrentStep, setDisableTopBarAfter } = props; const { watch, setValue, control, formState: { errors }, } = useFormContext(); const { workspaceSlug } = useParams(); 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

} />
); };