// @flow import * as React from 'react'; import styled from 'styled-components'; import { NewDocumentIcon } from 'outline-icons'; import { color } from 'shared/styles/constants'; import Document from 'models/Document'; import { documentEditUrl, documentNewUrl } from 'utils/routeHelpers'; import DocumentMenu from 'menus/DocumentMenu'; import Collaborators from 'components/Collaborators'; import Actions, { Action, Separator } from 'components/Actions'; type Props = { document: Document, isDraft: boolean, isEditing: boolean, isSaving: boolean, isPublishing: boolean, savingIsDisabled: boolean, onDiscard: () => *, onSave: ({ redirect?: boolean, publish?: boolean, }) => *, history: Object, }; class DocumentActions extends React.Component { handleNewDocument = () => { this.props.history.push(documentNewUrl(this.props.document)); }; handleEdit = () => { this.props.history.push(documentEditUrl(this.props.document)); }; handleSave = () => { this.props.onSave({ redirect: true }); }; handlePublish = () => { this.props.onSave({ redirect: true, publish: true }); }; render() { const { document, isEditing, isDraft, isPublishing, isSaving, savingIsDisabled, } = this.props; return ( {!isDraft && !isEditing && } {isDraft && ( {isPublishing ? 'Publishing…' : 'Publish'} )} {isEditing && ( {isSaving && !isPublishing ? 'Saving…' : 'Save'} {isDraft && } )} {!isEditing && ( Edit )} {isEditing && ( {document.hasPendingChanges ? 'Discard' : 'Done'} )} {!isEditing && ( )} {!isEditing && !isDraft && ( )} ); } } const Link = styled.a` display: flex; align-items: center; font-weight: ${props => (props.highlight ? 500 : 'inherit')}; color: ${props => props.highlight ? `${color.primary} !important` : 'inherit'}; opacity: ${props => (props.disabled ? 0.5 : 1)}; pointer-events: ${props => (props.disabled ? 'none' : 'auto')}; cursor: ${props => (props.disabled ? 'default' : 'pointer')}; `; export default DocumentActions;