|
@@ -9,15 +9,18 @@ import {
|
|
|
DropdownToggle, DropdownMenu, DropdownItem,
|
|
DropdownToggle, DropdownMenu, DropdownItem,
|
|
|
} from 'reactstrap';
|
|
} from 'reactstrap';
|
|
|
|
|
|
|
|
|
|
+import { toastSuccess, toastError } from '~/client/util/toastr';
|
|
|
import type { IPageGrantData } from '~/interfaces/page';
|
|
import type { IPageGrantData } from '~/interfaces/page';
|
|
|
import {
|
|
import {
|
|
|
useIsEditable, useIsAclEnabled,
|
|
useIsEditable, useIsAclEnabled,
|
|
|
} from '~/stores/context';
|
|
} from '~/stores/context';
|
|
|
import { useWaitingSaveProcessing } from '~/stores/editor';
|
|
import { useWaitingSaveProcessing } from '~/stores/editor';
|
|
|
-import { useSWRxCurrentPage } from '~/stores/page';
|
|
|
|
|
|
|
+import { useSWRMUTxCurrentPage, useSWRxCurrentPage } from '~/stores/page';
|
|
|
import { useSelectedGrant } from '~/stores/ui';
|
|
import { useSelectedGrant } from '~/stores/ui';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
|
|
|
|
+import { unpublish } from '../client/services/page-operation';
|
|
|
|
|
+
|
|
|
import { GrantSelector } from './SavePageControls/GrantSelector';
|
|
import { GrantSelector } from './SavePageControls/GrantSelector';
|
|
|
|
|
|
|
|
|
|
|
|
@@ -41,6 +44,7 @@ export const SavePageControls = (props: SavePageControlsProps): JSX.Element | nu
|
|
|
const { data: isAclEnabled } = useIsAclEnabled();
|
|
const { data: isAclEnabled } = useIsAclEnabled();
|
|
|
const { data: grantData, mutate: mutateGrant } = useSelectedGrant();
|
|
const { data: grantData, mutate: mutateGrant } = useSelectedGrant();
|
|
|
const { data: _isWaitingSaveProcessing } = useWaitingSaveProcessing();
|
|
const { data: _isWaitingSaveProcessing } = useWaitingSaveProcessing();
|
|
|
|
|
+ const { trigger: mutateCurrentPage } = useSWRMUTxCurrentPage();
|
|
|
|
|
|
|
|
const isWaitingSaveProcessing = _isWaitingSaveProcessing === true; // ignore undefined
|
|
const isWaitingSaveProcessing = _isWaitingSaveProcessing === true; // ignore undefined
|
|
|
|
|
|
|
@@ -58,6 +62,24 @@ export const SavePageControls = (props: SavePageControlsProps): JSX.Element | nu
|
|
|
globalEmitter.emit('saveAndReturnToView', { overwriteScopesOfDescendants: true, slackChannels });
|
|
globalEmitter.emit('saveAndReturnToView', { overwriteScopesOfDescendants: true, slackChannels });
|
|
|
}, [slackChannels]);
|
|
}, [slackChannels]);
|
|
|
|
|
|
|
|
|
|
+ const clickUnpublishButtonHandler = useCallback(async() => {
|
|
|
|
|
+ const pageId = currentPage?._id;
|
|
|
|
|
+
|
|
|
|
|
+ if (pageId == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ await unpublish(pageId);
|
|
|
|
|
+ await mutateCurrentPage();
|
|
|
|
|
+ toastSuccess(t('wip_page.success_save_as_wip'));
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ logger.error(err);
|
|
|
|
|
+ toastError(t('wip_page.fail_save_as_wip'));
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [currentPage?._id, mutateCurrentPage, t]);
|
|
|
|
|
+
|
|
|
|
|
|
|
|
if (isEditable == null || isAclEnabled == null || grantData == null) {
|
|
if (isEditable == null || isAclEnabled == null || grantData == null) {
|
|
|
return null;
|
|
return null;
|
|
@@ -72,6 +94,7 @@ export const SavePageControls = (props: SavePageControlsProps): JSX.Element | nu
|
|
|
const isGrantSelectorDisabledPage = isTopPage(currentPage?.path ?? '') || isUsersProtectedPages(currentPage?.path ?? '');
|
|
const isGrantSelectorDisabledPage = isTopPage(currentPage?.path ?? '') || isUsersProtectedPages(currentPage?.path ?? '');
|
|
|
const labelSubmitButton = t('Update');
|
|
const labelSubmitButton = t('Update');
|
|
|
const labelOverwriteScopes = t('page_edit.overwrite_scopes', { operation: labelSubmitButton });
|
|
const labelOverwriteScopes = t('page_edit.overwrite_scopes', { operation: labelSubmitButton });
|
|
|
|
|
+ const labelUnpublishPage = t('wip_page.save_as_wip');
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div className="d-flex align-items-center flex-nowrap">
|
|
<div className="d-flex align-items-center flex-nowrap">
|
|
@@ -108,6 +131,9 @@ export const SavePageControls = (props: SavePageControlsProps): JSX.Element | nu
|
|
|
<DropdownItem onClick={saveAndOverwriteScopesOfDescendants}>
|
|
<DropdownItem onClick={saveAndOverwriteScopesOfDescendants}>
|
|
|
{labelOverwriteScopes}
|
|
{labelOverwriteScopes}
|
|
|
</DropdownItem>
|
|
</DropdownItem>
|
|
|
|
|
+ <DropdownItem onClick={clickUnpublishButtonHandler}>
|
|
|
|
|
+ {labelUnpublishPage}
|
|
|
|
|
+ </DropdownItem>
|
|
|
</DropdownMenu>
|
|
</DropdownMenu>
|
|
|
</UncontrolledButtonDropdown>
|
|
</UncontrolledButtonDropdown>
|
|
|
|
|
|