import React, { useState } from "react"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import { Dialog, Transition } from "@headlessui/react"; // hooks import { useProject } from "hooks/store"; // services import { ProjectExportService } from "services/project"; // ui import { Button, CustomSearchSelect, TOAST_TYPE, setToast } from "@plane/ui"; // types import { IUser, IImporterService } from "@plane/types"; type Props = { isOpen: boolean; handleClose: () => void; data: IImporterService | null; user: IUser | null; provider: string | string[]; mutateServices: () => void; }; const projectExportService = new ProjectExportService(); export const Exporter: React.FC = observer((props) => { const { isOpen, handleClose, user, provider, mutateServices } = props; // states const [exportLoading, setExportLoading] = useState(false); const [isSelectOpen, setIsSelectOpen] = useState(false); // router const router = useRouter(); const { workspaceSlug } = router.query; // store hooks const { workspaceProjectIds, getProjectById } = useProject(); const options = workspaceProjectIds?.map((projectId) => { const projectDetails = getProjectById(projectId); return { value: projectDetails?.id, query: `${projectDetails?.name} ${projectDetails?.identifier}`, content: (
{projectDetails?.identifier} {projectDetails?.name}
), }; }); const [value, setValue] = React.useState([]); const [multiple, setMultiple] = React.useState(false); const onChange = (val: any) => { setValue(val); }; const ExportCSVToMail = async () => { setExportLoading(true); if (workspaceSlug && user && typeof provider === "string") { const payload = { provider: provider, project: value, multiple: multiple, }; await projectExportService .csvExport(workspaceSlug as string, payload) .then(() => { mutateServices(); router.push(`/${workspaceSlug}/settings/exports`); setExportLoading(false); setToast({ type: TOAST_TYPE.SUCCESS, title: "Export Successful", message: `You will be able to download the exported ${ provider === "csv" ? "CSV" : provider === "xlsx" ? "Excel" : provider === "json" ? "JSON" : "" } from the previous export.`, }); }) .catch(() => { setExportLoading(false); setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Export was unsuccessful. Please try again.", }); }); } }; return ( { if (!isSelectOpen) handleClose(); }} >

Export to{" "} {provider === "csv" ? "CSV" : provider === "xlsx" ? "Excel" : provider === "json" ? "JSON" : ""}

onChange(val)} options={options} input label={ value && value.length > 0 ? value .map((projectId) => { const projectDetails = getProjectById(projectId); return projectDetails?.identifier; }) .join(", ") : "All projects" } onOpen={() => setIsSelectOpen(true)} onClose={() => setIsSelectOpen(false)} optionsClassName="min-w-full" multiple />
setMultiple(!multiple)} className="flex max-w-min cursor-pointer items-center gap-2" > setMultiple(!multiple)} />
Export the data into separate files
); });