mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
17ce3bab8a
* 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>
99 lines
2.7 KiB
TypeScript
99 lines
2.7 KiB
TypeScript
import { Modal, Button, Group, Text } from "@mantine/core";
|
|
import { movePageToSpace } from "@/features/page/services/page-service.ts";
|
|
import { useState } from "react";
|
|
import { notifications } from "@mantine/notifications";
|
|
import { useTranslation } from "react-i18next";
|
|
import { ISpace } from "@/features/space/types/space.types.ts";
|
|
import { queryClient } from "@/main.tsx";
|
|
import { SpaceSelect } from "@/features/space/components/sidebar/space-select.tsx";
|
|
import { useNavigate } from "react-router-dom";
|
|
import { buildPageUrl } from "@/features/page/page.utils.ts";
|
|
|
|
interface MovePageModalProps {
|
|
pageId: string;
|
|
slugId: string;
|
|
currentSpaceSlug: string;
|
|
open: boolean;
|
|
onClose: () => void;
|
|
}
|
|
|
|
export default function MovePageModal({
|
|
pageId,
|
|
slugId,
|
|
currentSpaceSlug,
|
|
open,
|
|
onClose,
|
|
}: MovePageModalProps) {
|
|
const { t } = useTranslation();
|
|
const [targetSpace, setTargetSpace] = useState<ISpace>(null);
|
|
const navigate = useNavigate();
|
|
|
|
const handlePageMove = async () => {
|
|
if (!targetSpace) return;
|
|
|
|
try {
|
|
await movePageToSpace({ pageId, spaceId: targetSpace.id });
|
|
queryClient.removeQueries({
|
|
predicate: (item) =>
|
|
["pages", "sidebar-pages", "root-sidebar-pages"].includes(
|
|
item.queryKey[0] as string,
|
|
),
|
|
});
|
|
|
|
const pageUrl = buildPageUrl(targetSpace.slug, slugId, undefined);
|
|
navigate(pageUrl);
|
|
notifications.show({
|
|
message: t("Page moved successfully"),
|
|
});
|
|
onClose();
|
|
} catch (err) {
|
|
notifications.show({
|
|
message: err.response?.data.message || "An error occurred",
|
|
color: "red",
|
|
});
|
|
console.log(err);
|
|
}
|
|
setTargetSpace(null);
|
|
};
|
|
|
|
const handleChange = (space: ISpace) => {
|
|
setTargetSpace(space);
|
|
};
|
|
|
|
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("Move page")}</Modal.Title>
|
|
<Modal.CloseButton />
|
|
</Modal.Header>
|
|
<Modal.Body>
|
|
<Text mb="xs" c="dimmed" size="sm">{t("Move page to a different space.")}</Text>
|
|
|
|
<SpaceSelect
|
|
value={currentSpaceSlug}
|
|
clearable={false}
|
|
onChange={handleChange}
|
|
/>
|
|
<Group justify="end" mt="md">
|
|
<Button onClick={onClose} variant="default">
|
|
{t("Cancel")}
|
|
</Button>
|
|
<Button onClick={handlePageMove}>{t("Move")}</Button>
|
|
</Group>
|
|
</Modal.Body>
|
|
</Modal.Content>
|
|
</Modal.Root>
|
|
);
|
|
}
|