mirror of
https://github.com/docmost/docmost.git
synced 2025-11-25 01:41:12 +10:00
* feat: Move the page to another space - The ability to move a page to another space has been added * feat: Move the page to another space * feat: Move the page to another space - Correction of the visibility attribute of elements that extend beyond the boundaries of the space selection modal window * feat: Move the page to another space - Added removal of query keys when moving pages * feat: Move the page to another space - Fix locales * feat: Move the page to another space * feat: Move the page to another space - Fix docker compose * feat: Move the page to another space * feat: Move the page to another space - Some refactor * feat: Move the page to another space - Attachments update * feat: Move the page to another space - The function of searching for attachments by page ID and updating attachments has been combined * feat: Move the page to another space - Fix variable name * feat: Move the page to another space - Move current space to parameter of component SpaceSelectionModal * refactor ui --------- Co-authored-by: plekhanov <astecom@mail.ru>
155 lines
4.1 KiB
TypeScript
155 lines
4.1 KiB
TypeScript
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";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
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>(ExportFormat.Markdown);
|
|
const [includeChildren, setIncludeChildren] = useState<boolean>(false);
|
|
const [includeAttachments, setIncludeAttachments] = useState<boolean>(true);
|
|
const { t } = useTranslation();
|
|
|
|
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 (
|
|
<Modal.Root
|
|
opened={open}
|
|
onClose={onClose}
|
|
size={500}
|
|
padding="xl"
|
|
yOffset="10vh"
|
|
xOffset={0}
|
|
mah={400}
|
|
onClick={(e) => e.stopPropagation()}
|
|
>
|
|
<Modal.Overlay />
|
|
<Modal.Content style={{ overflow: "hidden" }}>
|
|
<Modal.Header py={0}>
|
|
<Modal.Title fw={500}>{t(`Export ${type}`)}</Modal.Title>
|
|
<Modal.CloseButton />
|
|
</Modal.Header>
|
|
<Modal.Body>
|
|
<Group justify="space-between" wrap="nowrap">
|
|
<div>
|
|
<Text size="md">{t("Format")}</Text>
|
|
</div>
|
|
<ExportFormatSelection format={format} onChange={handleChange} />
|
|
</Group>
|
|
|
|
{type === "page" && (
|
|
<>
|
|
<Divider my="sm" />
|
|
|
|
<Group justify="space-between" wrap="nowrap">
|
|
<div>
|
|
<Text size="md">{t("Include subpages")}</Text>
|
|
</div>
|
|
<Switch
|
|
onChange={(event) =>
|
|
setIncludeChildren(event.currentTarget.checked)
|
|
}
|
|
checked={includeChildren}
|
|
/>
|
|
</Group>
|
|
</>
|
|
)}
|
|
|
|
{type === "space" && (
|
|
<>
|
|
<Divider my="sm" />
|
|
|
|
<Group justify="space-between" wrap="nowrap">
|
|
<div>
|
|
<Text size="md">{t("Include attachments")}</Text>
|
|
</div>
|
|
<Switch
|
|
onChange={(event) =>
|
|
setIncludeAttachments(event.currentTarget.checked)
|
|
}
|
|
checked={includeAttachments}
|
|
/>
|
|
</Group>
|
|
</>
|
|
)}
|
|
|
|
<Group justify="center" mt="md">
|
|
<Button onClick={onClose} variant="default">
|
|
{t("Cancel")}
|
|
</Button>
|
|
<Button onClick={handleExport}>{t("Export")}</Button>
|
|
</Group>
|
|
</Modal.Body>
|
|
</Modal.Content>
|
|
</Modal.Root>
|
|
);
|
|
}
|
|
|
|
interface ExportFormatSelection {
|
|
format: ExportFormat;
|
|
onChange: (value: string) => void;
|
|
}
|
|
function ExportFormatSelection({ format, onChange }: ExportFormatSelection) {
|
|
const { t } = useTranslation();
|
|
|
|
return (
|
|
<Select
|
|
data={[
|
|
{ value: "markdown", label: "Markdown" },
|
|
{ value: "html", label: "HTML" },
|
|
]}
|
|
defaultValue={format}
|
|
onChange={onChange}
|
|
styles={{ wrapper: { maxWidth: 120 } }}
|
|
comboboxProps={{ width: "120" }}
|
|
allowDeselect={false}
|
|
withCheckIcon={false}
|
|
aria-label={t("Select export format")}
|
|
/>
|
|
);
|
|
}
|