import { find } from "lodash"; import { observer } from "mobx-react"; import * as React from "react"; import { useTranslation, Trans } from "react-i18next"; import styled from "styled-components"; import { IntegrationType } from "@shared/types"; import Collection from "~/models/Collection"; import Integration from "~/models/Integration"; import Button from "~/components/Button"; import Heading from "~/components/Heading"; import CollectionIcon from "~/components/Icons/CollectionIcon"; import List from "~/components/List"; import ListItem from "~/components/List/Item"; import Notice from "~/components/Notice"; import Scene from "~/components/Scene"; import Text from "~/components/Text"; import env from "~/env"; import useCurrentTeam from "~/hooks/useCurrentTeam"; import useQuery from "~/hooks/useQuery"; import useStores from "~/hooks/useStores"; import SlackIcon from "./Icon"; import SlackButton from "./components/SlackButton"; import SlackListItem from "./components/SlackListItem"; function Slack() { const team = useCurrentTeam(); const { collections, integrations } = useStores(); const { t } = useTranslation(); const query = useQuery(); const error = query.get("error"); React.useEffect(() => { collections.fetchPage({ limit: 100, }); integrations.fetchPage({ limit: 100, }); }, [collections, integrations]); const commandIntegration = find( integrations.slackIntegrations, (i) => i.type === IntegrationType.Command ); const groupedCollections = collections.orderedData .map<[Collection, Integration | undefined]>((collection) => { const integration = find(integrations.slackIntegrations, { collectionId: collection.id, }); return [collection, integration]; }) .sort((a) => (a[1] ? -1 : 1)); const appName = env.APP_NAME; return ( }> Slack {error === "access_denied" && ( Whoops, you need to accept the permissions in Slack to connect {{ appName }} to your team. Try again? )} {error === "unauthenticated" && ( Something went wrong while authenticating your request. Please try logging in again? )} , }} /> {env.SLACK_CLIENT_ID ? ( <>

{commandIntegration ? ( ) : ( } /> )}

 

{t("Collections")}

Connect {{ appName }} collections to Slack channels. Messages will be automatically posted to Slack when documents are published or updated. {groupedCollections.map(([collection, integration]) => { if (integration) { return ( } /> ); } return ( } actions={ } /> ); })} ) : ( The Slack integration is currently disabled. Please set the associated environment variables and restart the server to enable the integration. )}
); } const Code = styled.code` padding: 4px 6px; margin: 0 2px; background: ${(props) => props.theme.codeBackground}; border-radius: 4px; `; export default observer(Slack);