// @flow import { observable } from "mobx"; import { inject, observer } from "mobx-react"; import { PlusIcon } from "outline-icons"; import * as React from "react"; import { withTranslation, type TFunction } from "react-i18next"; import { Redirect } from "react-router-dom"; import CollectionsStore from "stores/CollectionsStore"; import PoliciesStore from "stores/PoliciesStore"; import Button from "components/Button"; import CollectionIcon from "components/CollectionIcon"; import { DropdownMenu, Header } from "components/DropdownMenu"; import DropdownMenuItems from "components/DropdownMenu/DropdownMenuItems"; import { newDocumentUrl } from "utils/routeHelpers"; type Props = { label?: React.Node, collections: CollectionsStore, policies: PoliciesStore, t: TFunction, }; @observer class NewTemplateMenu extends React.Component { @observable redirectTo: ?string; componentDidUpdate() { this.redirectTo = undefined; } handleNewDocument = (collectionId: string) => { this.redirectTo = newDocumentUrl(collectionId, { template: true, }); }; render() { if (this.redirectTo) return ; const { collections, policies, label, t, ...rest } = this.props; return ( } small> {t("New template")}… ) } {...rest} >
{t("Choose a collection")}
({ onClick: () => this.handleNewDocument(collection.id), disabled: !policies.abilities(collection.id).update, title: ( <>  {collection.name} ), }))} />
); } } export default withTranslation()( inject("collections", "policies")(NewTemplateMenu) );