2018-02-11 07:24:12 +00:00
|
|
|
// @flow
|
2020-06-20 20:59:15 +00:00
|
|
|
import * as React from "react";
|
|
|
|
import { observer, inject } from "mobx-react";
|
|
|
|
import styled from "styled-components";
|
2019-04-06 23:20:27 +00:00
|
|
|
import {
|
|
|
|
ArchiveIcon,
|
|
|
|
HomeIcon,
|
|
|
|
EditIcon,
|
|
|
|
SearchIcon,
|
|
|
|
StarredIcon,
|
2020-08-08 22:18:37 +00:00
|
|
|
ShapesIcon,
|
2019-11-19 02:51:32 +00:00
|
|
|
TrashIcon,
|
2019-06-25 05:14:59 +00:00
|
|
|
PlusIcon,
|
2020-06-20 20:59:15 +00:00
|
|
|
} from "outline-icons";
|
2018-02-11 07:24:12 +00:00
|
|
|
|
2020-07-10 05:33:07 +00:00
|
|
|
import Flex from "components/Flex";
|
2020-06-20 20:59:15 +00:00
|
|
|
import Modal from "components/Modal";
|
|
|
|
import Invite from "scenes/Invite";
|
|
|
|
import AccountMenu from "menus/AccountMenu";
|
|
|
|
import Sidebar from "./Sidebar";
|
|
|
|
import Scrollable from "components/Scrollable";
|
|
|
|
import Section from "./components/Section";
|
|
|
|
import Collections from "./components/Collections";
|
|
|
|
import SidebarLink from "./components/SidebarLink";
|
|
|
|
import HeaderBlock from "./components/HeaderBlock";
|
|
|
|
import Bubble from "./components/Bubble";
|
2018-02-11 07:24:12 +00:00
|
|
|
|
2020-06-20 20:59:15 +00:00
|
|
|
import AuthStore from "stores/AuthStore";
|
|
|
|
import DocumentsStore from "stores/DocumentsStore";
|
|
|
|
import PoliciesStore from "stores/PoliciesStore";
|
|
|
|
import UiStore from "stores/UiStore";
|
|
|
|
import { observable } from "mobx";
|
2018-02-11 07:24:12 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
auth: AuthStore,
|
2018-02-28 06:41:12 +00:00
|
|
|
documents: DocumentsStore,
|
2019-08-22 04:41:37 +00:00
|
|
|
policies: PoliciesStore,
|
2018-02-11 07:24:12 +00:00
|
|
|
ui: UiStore,
|
|
|
|
};
|
|
|
|
|
|
|
|
@observer
|
2018-05-05 23:16:08 +00:00
|
|
|
class MainSidebar extends React.Component<Props> {
|
2019-06-25 05:14:59 +00:00
|
|
|
@observable inviteModalOpen: boolean = false;
|
|
|
|
|
2018-06-23 22:27:16 +00:00
|
|
|
componentDidMount() {
|
|
|
|
this.props.documents.fetchDrafts();
|
2020-08-08 22:18:37 +00:00
|
|
|
this.props.documents.fetchTemplates();
|
2018-06-23 22:27:16 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 20:27:11 +00:00
|
|
|
handleCreateCollection = (ev: SyntheticEvent<>) => {
|
|
|
|
ev.preventDefault();
|
2020-06-20 20:59:15 +00:00
|
|
|
this.props.ui.setActiveModal("collection-new");
|
2018-02-11 07:24:12 +00:00
|
|
|
};
|
|
|
|
|
2020-04-05 20:27:11 +00:00
|
|
|
handleInviteModalOpen = (ev: SyntheticEvent<>) => {
|
|
|
|
ev.preventDefault();
|
2019-06-25 05:14:59 +00:00
|
|
|
this.inviteModalOpen = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
handleInviteModalClose = () => {
|
|
|
|
this.inviteModalOpen = false;
|
|
|
|
};
|
|
|
|
|
2018-02-11 07:24:12 +00:00
|
|
|
render() {
|
2019-08-22 04:41:37 +00:00
|
|
|
const { auth, documents, policies } = this.props;
|
2018-02-11 07:24:12 +00:00
|
|
|
const { user, team } = auth;
|
2018-12-05 06:24:30 +00:00
|
|
|
if (!user || !team) return null;
|
2018-02-11 07:24:12 +00:00
|
|
|
|
2019-01-07 00:25:05 +00:00
|
|
|
const draftDocumentsCount = documents.drafts.length;
|
2019-10-06 01:42:03 +00:00
|
|
|
const can = policies.abilities(team.id);
|
2019-01-07 00:25:05 +00:00
|
|
|
|
2018-02-11 07:24:12 +00:00
|
|
|
return (
|
|
|
|
<Sidebar>
|
|
|
|
<AccountMenu
|
|
|
|
label={
|
|
|
|
<HeaderBlock
|
|
|
|
subheading={user.name}
|
|
|
|
teamName={team.name}
|
|
|
|
logoUrl={team.avatarUrl}
|
2018-05-12 18:09:59 +00:00
|
|
|
showDisclosure
|
2018-02-11 07:24:12 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Flex auto column>
|
2018-05-06 19:46:52 +00:00
|
|
|
<Scrollable shadow>
|
2018-02-11 07:24:12 +00:00
|
|
|
<Section>
|
2019-01-07 00:12:07 +00:00
|
|
|
<SidebarLink
|
2020-02-27 05:10:20 +00:00
|
|
|
to="/home"
|
2020-06-20 00:18:03 +00:00
|
|
|
icon={<HomeIcon color="currentColor" />}
|
2019-01-07 00:12:07 +00:00
|
|
|
exact={false}
|
|
|
|
label="Home"
|
|
|
|
/>
|
2019-01-10 05:57:17 +00:00
|
|
|
<SidebarLink
|
2019-03-10 00:10:53 +00:00
|
|
|
to={{
|
2020-06-20 20:59:15 +00:00
|
|
|
pathname: "/search",
|
2019-03-10 00:10:53 +00:00
|
|
|
state: { fromMenu: true },
|
|
|
|
}}
|
2020-06-20 00:18:03 +00:00
|
|
|
icon={<SearchIcon color="currentColor" />}
|
2019-01-10 05:57:17 +00:00
|
|
|
label="Search"
|
|
|
|
exact={false}
|
|
|
|
/>
|
2019-01-07 00:12:07 +00:00
|
|
|
<SidebarLink
|
|
|
|
to="/starred"
|
2020-06-20 00:18:03 +00:00
|
|
|
icon={<StarredIcon color="currentColor" />}
|
2019-01-07 00:12:07 +00:00
|
|
|
exact={false}
|
|
|
|
label="Starred"
|
|
|
|
/>
|
2020-08-08 22:18:37 +00:00
|
|
|
<SidebarLink
|
|
|
|
to="/templates"
|
|
|
|
icon={<ShapesIcon color="currentColor" />}
|
|
|
|
exact={false}
|
|
|
|
label="Templates"
|
|
|
|
active={
|
|
|
|
documents.active ? documents.active.template : undefined
|
|
|
|
}
|
|
|
|
/>
|
2018-02-28 06:41:12 +00:00
|
|
|
<SidebarLink
|
|
|
|
to="/drafts"
|
2020-06-20 00:18:03 +00:00
|
|
|
icon={<EditIcon color="currentColor" />}
|
2019-08-06 06:17:41 +00:00
|
|
|
label={
|
|
|
|
<Drafts align="center">
|
2020-08-09 01:53:11 +00:00
|
|
|
Drafts
|
|
|
|
{draftDocumentsCount > 0 && (
|
2019-08-06 06:17:41 +00:00
|
|
|
<Bubble count={draftDocumentsCount} />
|
|
|
|
)}
|
|
|
|
</Drafts>
|
2019-01-07 00:25:05 +00:00
|
|
|
}
|
2018-02-28 06:41:12 +00:00
|
|
|
active={
|
2019-11-19 02:51:32 +00:00
|
|
|
documents.active
|
|
|
|
? !documents.active.publishedAt &&
|
2020-08-08 22:18:37 +00:00
|
|
|
!documents.active.isDeleted &&
|
|
|
|
!documents.active.isTemplate
|
2019-11-19 02:51:32 +00:00
|
|
|
: undefined
|
2018-02-28 06:41:12 +00:00
|
|
|
}
|
2019-01-07 00:12:07 +00:00
|
|
|
/>
|
2018-02-11 07:24:12 +00:00
|
|
|
</Section>
|
|
|
|
<Section>
|
2019-01-19 08:23:39 +00:00
|
|
|
<Collections onCreateCollection={this.handleCreateCollection} />
|
2018-02-11 07:24:12 +00:00
|
|
|
</Section>
|
2019-04-06 23:20:27 +00:00
|
|
|
<Section>
|
|
|
|
<SidebarLink
|
|
|
|
to="/archive"
|
2020-06-20 00:18:03 +00:00
|
|
|
icon={<ArchiveIcon color="currentColor" />}
|
2019-04-06 23:20:27 +00:00
|
|
|
exact={false}
|
|
|
|
label="Archive"
|
|
|
|
active={
|
2019-11-19 02:51:32 +00:00
|
|
|
documents.active
|
|
|
|
? documents.active.isArchived && !documents.active.isDeleted
|
|
|
|
: undefined
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<SidebarLink
|
|
|
|
to="/trash"
|
2020-06-20 00:18:03 +00:00
|
|
|
icon={<TrashIcon color="currentColor" />}
|
2019-11-19 02:51:32 +00:00
|
|
|
exact={false}
|
|
|
|
label="Trash"
|
|
|
|
active={
|
|
|
|
documents.active ? documents.active.isDeleted : undefined
|
2019-04-06 23:20:27 +00:00
|
|
|
}
|
|
|
|
/>
|
2019-08-22 04:41:37 +00:00
|
|
|
{can.invite && (
|
2019-06-25 05:14:59 +00:00
|
|
|
<SidebarLink
|
2020-04-05 20:27:11 +00:00
|
|
|
to="/settings/people"
|
2019-06-25 05:14:59 +00:00
|
|
|
onClick={this.handleInviteModalOpen}
|
2020-06-20 00:18:03 +00:00
|
|
|
icon={<PlusIcon color="currentColor" />}
|
2019-06-25 05:14:59 +00:00
|
|
|
label="Invite people…"
|
|
|
|
/>
|
|
|
|
)}
|
2019-04-06 23:20:27 +00:00
|
|
|
</Section>
|
2018-02-11 07:24:12 +00:00
|
|
|
</Scrollable>
|
|
|
|
</Flex>
|
2019-06-25 05:14:59 +00:00
|
|
|
<Modal
|
|
|
|
title="Invite people"
|
|
|
|
onRequestClose={this.handleInviteModalClose}
|
|
|
|
isOpen={this.inviteModalOpen}
|
|
|
|
>
|
|
|
|
<Invite onSubmit={this.handleInviteModalClose} />
|
|
|
|
</Modal>
|
2018-02-11 07:24:12 +00:00
|
|
|
</Sidebar>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-06 06:17:41 +00:00
|
|
|
const Drafts = styled(Flex)`
|
|
|
|
height: 24px;
|
|
|
|
`;
|
|
|
|
|
2020-06-20 20:59:15 +00:00
|
|
|
export default inject("documents", "policies", "auth", "ui")(MainSidebar);
|