diff --git a/apps/client/src/components/common/export-modal.tsx b/apps/client/src/components/common/export-modal.tsx new file mode 100644 index 00000000..1891849b --- /dev/null +++ b/apps/client/src/components/common/export-modal.tsx @@ -0,0 +1,149 @@ +import { + Modal, + Button, + Group, + Text, + Select, + Switch, + Divider, +} from "@mantine/core"; +import { exportPage } 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"; + +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(true); + + const handleExport = async () => { + try { + if (type === "page") { + await exportPage({ pageId: id, format, includeChildren }); + } + if (type === "space") { + await exportSpace({ spaceId: id, format, includeAttachments }); + } + setIncludeChildren(false); + setIncludeAttachments(true); + onClose(); + } catch (err) { + notifications.show({ + message: "Export failed:" + err.response?.data.message, + color: "red", + }); + console.error("export error", err); + } + }; + + const handleChange = (format: ExportFormat) => { + setFormat(format); + }; + + return ( + + + + + Export {type} + + + + +
+ Format +
+ +
+ + {type === "page" && ( + <> + + + +
+ Include subpages +
+ + setIncludeChildren(event.currentTarget.checked) + } + checked={includeChildren} + /> +
+ + )} + + {type === "space" && ( + <> + + + +
+ Include attachments +
+ + setIncludeAttachments(event.currentTarget.checked) + } + checked={includeAttachments} + /> +
+ + )} + + + + + +
+
+
+ ); +} + +interface ExportFormatSelection { + format: ExportFormat; + onChange: (value: string) => void; +} +function ExportFormatSelection({ format, onChange }: ExportFormatSelection) { + return ( +