diff --git a/app/scenes/Document/components/Header.js b/app/scenes/Document/components/Header.js index 60ed71bb86..cedae6f96b 100644 --- a/app/scenes/Document/components/Header.js +++ b/app/scenes/Document/components/Header.js @@ -14,12 +14,7 @@ import { useTranslation } from "react-i18next"; import { Link } from "react-router-dom"; import AutoSizer from "react-virtualized-auto-sizer"; import { FixedSizeList as List } from "react-window"; -import { - Dialog, - DialogBackdrop, - DialogDisclosure, - useDialogState, -} from "reakit"; +import { Dialog, DialogBackdrop, useDialogState } from "reakit"; import styled, { useTheme } from "styled-components"; import breakpoint from "styled-components-breakpoint"; import { type DocumentPath } from "stores/CollectionsStore"; @@ -84,14 +79,6 @@ function DocumentHeader({ const isMobile = useMobile(); const dialog = useDialogState({ modal: false }); const theme = useTheme(); - const handleSave = React.useCallback(() => { - onSave({ done: true }); - }, [onSave]); - - const handlePublish = React.useCallback(() => { - onSave({ done: true, publish: true }); - }, [onSave]); - const isNew = document.isNewDocument; const isTemplate = document.isTemplate; const can = policies.abilities(document.id); @@ -101,6 +88,18 @@ function DocumentHeader({ const hasCollection = collections.get(document.computedCollectionId); const [searchTerm, setSearchTerm] = React.useState(); + const handleSave = React.useCallback(() => { + onSave({ done: true }); + }, [onSave]); + + const handlePublish = React.useCallback(() => { + if (!hasCollection) { + dialog.setVisible(true); + return; + } + onSave({ done: true, publish: true }); + }, [dialog, hasCollection, onSave]); + const handleFilter = (ev) => { setSearchTerm(ev.target.value); }; @@ -157,12 +156,14 @@ function DocumentHeader({ const handleSuccess = async (result: DocumentPath) => { if (!document) return; + dialog.setVisible(false); if (result.type === "collection") { - onSave({ done: true, collectionId: result.collectionId }); + onSave({ done: true, publish: true, collectionId: result.collectionId }); } else { onSave({ done: true, + publish: true, collectionId: result.collectionId, parentDocumentId: result.id, }); @@ -279,11 +280,6 @@ function DocumentHeader({ )} {can.update && isDraft && !isRevision && !hasCollection && ( - - - Choose collection - - )} - {can.update && isDraft && !isRevision && hasCollection && ( + {can.update && isDraft && !isRevision && (