"use client"; import React, { useState } from "react"; import Image from "next/image"; import Link from "next/link"; import { useParams, useRouter } from "next/navigation"; import { FormProvider, useForm } from "react-hook-form"; import { mutate } from "swr"; // icons import { ArrowLeft, Check, List, Settings, Users } from "lucide-react"; import { IJiraImporterForm } from "@plane/types"; // services // fetch keys // components import { Button } from "@plane/ui"; import { IMPORTER_SERVICES_LIST } from "@/constants/fetch-keys"; // assets import { JiraImporterService } from "@/services/integrations"; import JiraLogo from "public/services/jira.svg"; // types import { JiraGetImportDetail, JiraProjectDetail, JiraImportUsers, JiraConfirmImport, jiraFormDefaultValues, TJiraIntegrationSteps, IJiraIntegrationData, } from "."; const integrationWorkflowData: Array<{ title: string; key: TJiraIntegrationSteps; icon: any; }> = [ { title: "Configure", key: "import-configure", icon: Settings, }, { title: "Import Data", key: "display-import-data", icon: List, }, { title: "Users", key: "import-users", icon: Users, }, { title: "Confirm", key: "import-confirmation", icon: Check, }, ]; // services const jiraImporterService = new JiraImporterService(); export const JiraImporterRoot: React.FC = () => { const [currentStep, setCurrentStep] = useState({ state: "import-configure", }); const [disableTopBarAfter, setDisableTopBarAfter] = useState(null); const router = useRouter(); const { workspaceSlug } = useParams(); const methods = useForm({ defaultValues: jiraFormDefaultValues, mode: "all", reValidateMode: "onChange", }); const isValid = methods.formState.isValid; const onSubmit = async (data: IJiraImporterForm) => { if (!workspaceSlug) return; await jiraImporterService .createJiraImporter(workspaceSlug.toString(), data) .then(() => { mutate(IMPORTER_SERVICES_LIST(workspaceSlug.toString())); router.push(`/${workspaceSlug}/settings/imports`); }) .catch((err) => { console.error(err); }); }; const activeIntegrationState = () => { const currentElementIndex = integrationWorkflowData.findIndex((i) => i?.key === currentStep?.state); return currentElementIndex; }; return (
Cancel import & go back
jira logo
{integrationWorkflowData.map((integration, index) => ( {index < integrationWorkflowData.length - 1 && (
{" "}
)}
))}
{currentStep.state === "import-configure" && } {currentStep.state === "display-import-data" && ( )} {currentStep?.state === "import-users" && } {currentStep?.state === "import-confirmation" && }
{currentStep?.state !== "import-configure" && ( )}
); };