import { Modal, Button, Group, Text, Select, Switch, Divider, Tooltip, Badge, } from "@mantine/core"; import { exportPage, exportPageToDocx, } from "@/features/page/services/page-service.ts"; import { useState } from "react"; import { ExportFormat } from "@/features/page/types/page.types.ts"; import { notifications } from "@mantine/notifications"; import { exportSpace } from "@/features/space/services/space-service"; import { useTranslation } from "react-i18next"; import { Feature } from "@/ee/features"; import { useHasFeature } from "@/ee/hooks/use-feature"; import { useUpgradeLabel } from "@/ee/hooks/use-upgrade-label"; interface ExportModalProps { id: string; type: "space" | "page"; open: boolean; onClose: () => void; } export default function ExportModal({ id, type, open, onClose, }: ExportModalProps) { const [format, setFormat] = useState(ExportFormat.Markdown); const [includeChildren, setIncludeChildren] = useState(false); const [includeAttachments, setIncludeAttachments] = useState(false); const [isExporting, setIsExporting] = useState(false); const { t } = useTranslation(); const upgradeLabel = useUpgradeLabel(); const isDocx = format === ExportFormat.Docx; const docxEntitled = useHasFeature(Feature.DOCX_EXPORT); const blockedByLicense = isDocx && !docxEntitled; const handleExport = async () => { setIsExporting(true); try { if (type === "page") { if (format === ExportFormat.Docx) { await exportPageToDocx({ pageId: id }); } else { await exportPage({ pageId: id, format, includeChildren, includeAttachments, }); } } if (type === "space") { await exportSpace({ spaceId: id, format, includeAttachments }); } notifications.show({ message: t("Export successful"), }); onClose(); } catch (err) { notifications.show({ message: "Export failed:" + err.response?.data.message, color: "red", }); console.error("export error", err); } finally { setIsExporting(false); } }; const handleChange = (format: ExportFormat) => { setFormat(format); }; return ( e.stopPropagation()} > {t(`Export ${type}`)}
{t("Format")}
{type === "page" && !isDocx && ( <>
{t("Include subpages")}
setIncludeChildren(event.currentTarget.checked) } checked={includeChildren} />
{t("Include attachments")}
setIncludeAttachments(event.currentTarget.checked) } checked={includeAttachments} />
)} {type === "space" && ( <>
{t("Include attachments")}
setIncludeAttachments(event.currentTarget.checked) } checked={includeAttachments} />
)}
); } interface ExportFormatSelection { format: ExportFormat; onChange: (value: string) => void; includeDocx?: boolean; docxEntitled?: boolean; } function ExportFormatSelection({ format, onChange, includeDocx, docxEntitled, }: ExportFormatSelection) { const { t } = useTranslation(); const data = [ { value: "markdown", label: "Markdown" }, { value: "html", label: "HTML" }, ...(includeDocx ? [{ value: "docx", label: "Word (.docx)", disabled: !docxEntitled }] : []), ]; return (