This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
outline/app/scenes/Settings/Slack.js
Tom Moor 8cbcb77486 Base model refactor (#810)
* Big upgrades

* WIP: Stash

* Stash, 30 flow errors left

* Downgrade mobx

* WIP

* When I understand the difference between class and instance methods

* 💚

* Fixes: File import
Model saving edge cases
pinning and starring docs
Collection editing
Upgrade mobx devtools

* Notification settings saving works

* Disabled settings

* Document mailer

* Working notifications

* Colletion created notification
Ensure not notified for own actions

* Tidy up

* Document updated event only for document creation
Add indexes
Notification setting on user creation

* Commentary

* Fixed: Notification setting on signup

* Fix document move / duplicate stale data
Add BaseModel.refresh method

* Fixes: Title in sidebar not updated after editing document

* 💚

* Improve / restore error handling
Better handle offline errors

* 👕
2018-12-04 22:24:30 -08:00

133 lines
3.7 KiB
JavaScript

// @flow
import * as React from 'react';
import { inject, observer } from 'mobx-react';
import { find } from 'lodash';
import styled from 'styled-components';
import Button from 'components/Button';
import CenteredContent from 'components/CenteredContent';
import PageTitle from 'components/PageTitle';
import HelpText from 'components/HelpText';
import SlackButton from './components/SlackButton';
import CollectionsStore from 'stores/CollectionsStore';
import IntegrationsStore from 'stores/IntegrationsStore';
import Notice from 'shared/components/Notice';
import getQueryVariable from 'shared/utils/getQueryVariable';
type Props = {
collections: CollectionsStore,
integrations: IntegrationsStore,
};
@observer
class Slack extends React.Component<Props> {
error: ?string;
componentDidMount() {
this.error = getQueryVariable('error');
this.props.integrations.fetchPage();
}
get commandIntegration() {
return find(this.props.integrations.slackIntegrations, {
type: 'command',
});
}
render() {
const { collections, integrations } = this.props;
return (
<CenteredContent>
<PageTitle title="Slack" />
<h1>Slack</h1>
{this.error === 'access_denied' && (
<Notice>
Whoops, you need to accept the permissions in Slack to connect
Outline to your team. Try again?
</Notice>
)}
<HelpText>
Preview Outline links your team mates share and use the{' '}
<Code>/outline</Code> slash command in Slack to search for documents
in your teams wiki.
</HelpText>
<p>
{this.commandIntegration ? (
<Button onClick={this.commandIntegration.delete}>Disconnect</Button>
) : (
<SlackButton
scopes={['commands', 'links:read', 'links:write']}
redirectUri={`${BASE_URL}/auth/slack.commands`}
state=""
/>
)}
</p>
<p>&nbsp;</p>
<h2>Collections</h2>
<HelpText>
Connect Outline collections to Slack channels and messages will be
posted in Slack when documents are published or updated.
</HelpText>
<List>
{collections.orderedData.map(collection => {
const integration = find(integrations.slackIntegrations, {
collectionId: collection.id,
});
if (integration) {
return (
<ListItem key={integration.id}>
<span>
<strong>{collection.name}</strong> posting activity to the{' '}
<strong>{integration.settings.channel}</strong> Slack
channel
</span>
<Button onClick={integration.delete}>Disconnect</Button>
</ListItem>
);
}
return (
<ListItem key={collection.id}>
<strong>{collection.name}</strong>
<SlackButton
scopes={['incoming-webhook']}
redirectUri={`${BASE_URL}/auth/slack.post`}
state={collection.id}
label="Connect"
/>
</ListItem>
);
})}
</List>
</CenteredContent>
);
}
}
const List = styled.ol`
list-style: none;
margin: 8px 0;
padding: 0;
`;
const ListItem = styled.li`
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px 0;
border-bottom: 1px solid #eaebea;
`;
const Code = styled.code`
padding: 4px 6px;
margin: 0 2px;
background: #eaebea;
border-radius: 4px;
`;
export default inject('collections', 'integrations')(Slack);