import React, { useState } from "react"; // next import Link from "next/link"; import Image from "next/image"; import { useRouter } from "next/router"; // swr import { mutate } from "swr"; // react hook form import { FormProvider, useForm } from "react-hook-form"; // icons import { ArrowLeftIcon, ListBulletIcon } from "@heroicons/react/24/outline"; import { CogIcon, CloudUploadIcon, UsersIcon, CheckIcon } from "components/icons"; // services import jiraImporterService from "services/integration/jira.service"; // fetch keys import { IMPORTER_SERVICES_LIST } from "constants/fetch-keys"; // components import { PrimaryButton, SecondaryButton } from "components/ui"; import { JiraGetImportDetail, JiraProjectDetail, JiraImportUsers, JiraConfirmImport, jiraFormDefaultValues, TJiraIntegrationSteps, IJiraIntegrationData, } from "./"; import JiraLogo from "public/services/jira.png"; import { IJiraImporterForm } from "types"; const integrationWorkflowData: Array<{ title: string; key: TJiraIntegrationSteps; icon: React.FC>; }> = [ { title: "Configure", key: "import-configure", icon: CogIcon, }, { title: "Import Data", key: "display-import-data", icon: ListBulletIcon, }, { title: "Users", key: "import-users", icon: UsersIcon, }, { title: "Confirm", key: "import-confirmation", icon: CheckIcon, }, ]; export const JiraImporterRoot = () => { const [currentStep, setCurrentStep] = useState({ state: "import-configure", }); const [disableTopBarAfter, setDisableTopBarAfter] = useState(null); const router = useRouter(); const { workspaceSlug } = router.query; 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/import-export`); }) .catch((err) => { console.log(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" && ( { const currentElementIndex = integrationWorkflowData.findIndex( (i) => i?.key === currentStep?.state ); setCurrentStep({ state: integrationWorkflowData[currentElementIndex - 1]?.key, }); }} > Back )} { const currentElementIndex = integrationWorkflowData.findIndex( (i) => i?.key === currentStep?.state ); if (currentElementIndex === integrationWorkflowData.length - 1) { methods.handleSubmit(onSubmit)(); } else { setCurrentStep({ state: integrationWorkflowData[currentElementIndex + 1]?.key, }); } }} > {currentStep?.state === "import-confirmation" ? "Confirm & Import" : "Next"}
); };