diff --git a/app/components/Sidebar/Settings.js b/app/components/Sidebar/Settings.js index dc93d5fb..0d0e7478 100644 --- a/app/components/Sidebar/Settings.js +++ b/app/components/Sidebar/Settings.js @@ -1,5 +1,5 @@ // @flow -import { observer, inject } from "mobx-react"; +import { observer } from "mobx-react"; import { DocumentIcon, EmailIcon, @@ -13,11 +13,9 @@ import { ExpandedIcon, } from "outline-icons"; import * as React from "react"; -import { withTranslation, type TFunction } from "react-i18next"; -import type { RouterHistory } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { useHistory } from "react-router-dom"; import styled from "styled-components"; -import AuthStore from "stores/AuthStore"; -import PoliciesStore from "stores/PoliciesStore"; import Flex from "components/Flex"; import Scrollable from "components/Scrollable"; @@ -30,131 +28,123 @@ import Version from "./components/Version"; import SlackIcon from "./icons/Slack"; import ZapierIcon from "./icons/Zapier"; import env from "env"; +import useCurrentTeam from "hooks/useCurrentTeam"; +import useStores from "hooks/useStores"; const isHosted = env.DEPLOYMENT === "hosted"; -type Props = { - history: RouterHistory, - policies: PoliciesStore, - auth: AuthStore, - t: TFunction, -}; +function SettingsSidebar() { + const { t } = useTranslation(); + const history = useHistory(); + const team = useCurrentTeam(); + const { policies } = useStores(); + const can = policies.abilities(team.id); -@observer -class SettingsSidebar extends React.Component { - returnToDashboard = () => { - this.props.history.push("/home"); - }; + const returnToDashboard = React.useCallback(() => { + history.push("/home"); + }, [history]); - render() { - const { policies, t, auth } = this.props; - const { team } = auth; - if (!team) return null; + return ( + + + {t("Return to App")} + + } + teamName={team.name} + logoUrl={team.avatarUrl} + onClick={returnToDashboard} + /> - const can = policies.abilities(team.id); - - return ( - - - {t("Return to App")} - - } - teamName={team.name} - logoUrl={team.avatarUrl} - onClick={this.returnToDashboard} - /> - - - -
-
Account
- } - label={t("Profile")} - /> - } - label={t("Notifications")} - /> - } - label={t("API Tokens")} - /> -
-
-
Team
- {can.update && ( - } - label={t("Details")} - /> - )} - {can.update && ( - } - label={t("Security")} - /> - )} - } - exact={false} - label={t("People")} - /> - } - exact={false} - label={t("Groups")} - /> - } - label={t("Share Links")} - /> - {can.export && ( - } - label={t("Export Data")} - /> - )} -
+ + +
+
{t("Account")}
+ } + label={t("Profile")} + /> + } + label={t("Notifications")} + /> + } + label={t("API Tokens")} + /> +
+
+
{t("Team")}
{can.update && ( -
-
{t("Integrations")}
+ } + label={t("Details")} + /> + )} + {can.update && ( + } + label={t("Security")} + /> + )} + } + exact={false} + label={t("People")} + /> + } + exact={false} + label={t("Groups")} + /> + } + label={t("Share Links")} + /> + {can.export && ( + } + label={t("Export Data")} + /> + )} +
+ {can.update && ( +
+
{t("Integrations")}
+ } + label="Slack" + /> + {isHosted && ( } - label="Slack" + to="/settings/integrations/zapier" + icon={} + label="Zapier" /> - {isHosted && ( - } - label="Zapier" - /> - )} -
- )} - {can.update && !isHosted && ( -
-
{t("Installation")}
- -
- )} - - - - ); - } + )} +
+ )} + {can.update && !isHosted && ( +
+
{t("Installation")}
+ +
+ )} +
+
+
+ ); } const BackIcon = styled(ExpandedIcon)` @@ -166,6 +156,4 @@ const ReturnToApp = styled(Flex)` height: 16px; `; -export default withTranslation()( - inject("auth", "policies")(SettingsSidebar) -); +export default observer(SettingsSidebar); diff --git a/app/hooks/useCurrentTeam.js b/app/hooks/useCurrentTeam.js new file mode 100644 index 00000000..e03b0ade --- /dev/null +++ b/app/hooks/useCurrentTeam.js @@ -0,0 +1,9 @@ +// @flow +import invariant from "invariant"; +import useStores from "./useStores"; + +export default function useCurrentTeam() { + const { auth } = useStores(); + invariant(auth.team, "team required"); + return auth.team; +}