|
|
@@ -10,25 +10,20 @@ import {
|
|
|
DropdownToggle, DropdownMenu, DropdownItem, Modal,
|
|
|
} from 'reactstrap';
|
|
|
|
|
|
-import { toastSuccess, toastError } from '~/client/util/toastr';
|
|
|
import type { IPageGrantData } from '~/interfaces/page';
|
|
|
import {
|
|
|
useIsEditable, useIsAclEnabled,
|
|
|
useIsSlackConfigured,
|
|
|
} from '~/stores/context';
|
|
|
import { useWaitingSaveProcessing, useSWRxSlackChannels, useIsSlackEnabled } from '~/stores/editor';
|
|
|
-import { useSWRMUTxCurrentPage, useSWRxCurrentPage, useCurrentPagePath } from '~/stores/page';
|
|
|
-import { mutatePageTree } from '~/stores/page-listing';
|
|
|
+import { useSWRxCurrentPage, useCurrentPagePath } from '~/stores/page';
|
|
|
import {
|
|
|
useSelectedGrant,
|
|
|
useEditorMode, useIsDeviceLargerThanMd,
|
|
|
- EditorMode,
|
|
|
+
|
|
|
} from '~/stores/ui';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
-
|
|
|
-import { unpublish } from '../client/services/page-operation';
|
|
|
-
|
|
|
import { GrantSelector } from './SavePageControls/GrantSelector';
|
|
|
import { SlackNotification } from './SlackNotification';
|
|
|
|
|
|
@@ -45,10 +40,7 @@ const logger = loggerFactory('growi:SavePageControls');
|
|
|
const SavePageButton = (props: {slackChannels: string, isDeviceLargerThanMd?: boolean}) => {
|
|
|
|
|
|
const { t } = useTranslation();
|
|
|
- const { data: currentPage } = useSWRxCurrentPage();
|
|
|
const { data: _isWaitingSaveProcessing } = useWaitingSaveProcessing();
|
|
|
- const { trigger: mutateCurrentPage } = useSWRMUTxCurrentPage();
|
|
|
- const { mutate: mutateEditorMode } = useEditorMode();
|
|
|
const [isSavePageModalShown, setIsSavePageModalShown] = useState<boolean>(false);
|
|
|
|
|
|
const { slackChannels, isDeviceLargerThanMd } = props;
|
|
|
@@ -57,33 +49,18 @@ const SavePageButton = (props: {slackChannels: string, isDeviceLargerThanMd?: bo
|
|
|
|
|
|
const save = useCallback(async(): Promise<void> => {
|
|
|
// save
|
|
|
- globalEmitter.emit('saveAndReturnToView', { slackChannels });
|
|
|
+ globalEmitter.emit('saveAndReturnToView', { wip: false, slackChannels });
|
|
|
}, [slackChannels]);
|
|
|
|
|
|
const saveAndOverwriteScopesOfDescendants = useCallback(() => {
|
|
|
// save
|
|
|
- globalEmitter.emit('saveAndReturnToView', { overwriteScopesOfDescendants: true, slackChannels });
|
|
|
+ globalEmitter.emit('saveAndReturnToView', { wip: false, overwriteScopesOfDescendants: true, slackChannels });
|
|
|
}, [slackChannels]);
|
|
|
|
|
|
- const clickUnpublishButtonHandler = useCallback(async() => {
|
|
|
- const pageId = currentPage?._id;
|
|
|
-
|
|
|
- if (pageId == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- await unpublish(pageId);
|
|
|
- await mutateCurrentPage();
|
|
|
- await mutatePageTree();
|
|
|
- await mutateEditorMode(EditorMode.View);
|
|
|
- toastSuccess(t('wip_page.success_save_as_wip'));
|
|
|
- }
|
|
|
- catch (err) {
|
|
|
- logger.error(err);
|
|
|
- toastError(t('wip_page.fail_save_as_wip'));
|
|
|
- }
|
|
|
- }, [currentPage?._id, mutateCurrentPage, mutateEditorMode, t]);
|
|
|
+ const saveAndMakeWip = useCallback(() => {
|
|
|
+ // save
|
|
|
+ globalEmitter.emit('saveAndReturnToView', { wip: true, slackChannels });
|
|
|
+ }, [slackChannels]);
|
|
|
|
|
|
const labelSubmitButton = t('Update');
|
|
|
const labelOverwriteScopes = t('page_edit.overwrite_scopes', { operation: labelSubmitButton });
|
|
|
@@ -113,7 +90,7 @@ const SavePageButton = (props: {slackChannels: string, isDeviceLargerThanMd?: bo
|
|
|
<DropdownItem onClick={saveAndOverwriteScopesOfDescendants}>
|
|
|
{labelOverwriteScopes}
|
|
|
</DropdownItem>
|
|
|
- <DropdownItem onClick={clickUnpublishButtonHandler}>
|
|
|
+ <DropdownItem onClick={saveAndMakeWip}>
|
|
|
{labelUnpublishPage}
|
|
|
</DropdownItem>
|
|
|
</DropdownMenu>
|
|
|
@@ -130,7 +107,7 @@ const SavePageButton = (props: {slackChannels: string, isDeviceLargerThanMd?: bo
|
|
|
<button type="button" className="btn btn-primary" onClick={() => { setIsSavePageModalShown(false); saveAndOverwriteScopesOfDescendants() }}>
|
|
|
{labelOverwriteScopes}
|
|
|
</button>
|
|
|
- <button type="button" className="btn btn-primary" onClick={() => { setIsSavePageModalShown(false); clickUnpublishButtonHandler() }}>
|
|
|
+ <button type="button" className="btn btn-primary" onClick={() => { setIsSavePageModalShown(false); saveAndMakeWip() }}>
|
|
|
{labelUnpublishPage}
|
|
|
</button>
|
|
|
<button type="button" className="btn btn-outline-neutral-secondary mx-auto mt-1" onClick={() => setIsSavePageModalShown(false)}>
|