mirror of
https://github.com/docmost/docmost.git
synced 2026-05-16 22:41:30 +08:00
d42091ccb1
* feat: favorites and templates(ee) * rename migrations * fix sidebar * cleanup tabs * fix * turn off templates * cleanup * uuid validation
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import { useTranslation } from "react-i18next";
|
|
import { useNavigate } from "react-router-dom";
|
|
import { ITemplate } from "@/ee/template/types/template.types";
|
|
import { useUseTemplateMutation } from "@/ee/template/queries/template-query";
|
|
import { buildPageUrl } from "@/features/page/page.utils";
|
|
import { DestinationPickerModal } from "@/components/ui/destination-picker/destination-picker-modal";
|
|
import { DestinationSelection } from "@/components/ui/destination-picker/destination-picker.types";
|
|
|
|
type UseTemplateModalProps = {
|
|
template: ITemplate;
|
|
opened: boolean;
|
|
onClose: () => void;
|
|
};
|
|
|
|
export default function UseTemplateModal({
|
|
template,
|
|
opened,
|
|
onClose,
|
|
}: UseTemplateModalProps) {
|
|
const { t } = useTranslation();
|
|
const navigate = useNavigate();
|
|
const useTemplateMutation = useUseTemplateMutation();
|
|
|
|
const handleSelect = async (selection: DestinationSelection) => {
|
|
const spaceId = selection.spaceId;
|
|
const parentPageId =
|
|
selection.type === "page" ? selection.pageId : undefined;
|
|
|
|
try {
|
|
const page = await useTemplateMutation.mutateAsync({
|
|
templateId: template.id,
|
|
spaceId,
|
|
parentPageId,
|
|
});
|
|
|
|
onClose();
|
|
|
|
if (page?.slugId) {
|
|
const space = selection.space;
|
|
if (space?.slug) {
|
|
navigate(buildPageUrl(space.slug, page.slugId, page.title));
|
|
}
|
|
}
|
|
} catch {
|
|
// error notification handled by mutation's onError
|
|
}
|
|
};
|
|
|
|
return (
|
|
<DestinationPickerModal
|
|
opened={opened}
|
|
onClose={onClose}
|
|
title={t("Choose destination")}
|
|
actionLabel={t("Create page")}
|
|
onSelect={handleSelect}
|
|
loading={useTemplateMutation.isPending}
|
|
/>
|
|
);
|
|
}
|