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/frontend/components/SlackAuthLink/SlackAuthLink.js
2017-05-03 22:49:50 -07:00

49 lines
1.0 KiB
JavaScript

// @flow
import React from 'react';
import { observer, inject } from 'mobx-react';
import type { User } from 'types';
@inject('user')
@observer
class SlackAuthLink extends React.Component {
props: {
children: any,
scopes: Array<string>,
user: User,
redirectUri: string,
};
static defaultProps = {
scopes: [
'identity.email',
'identity.basic',
'identity.avatar',
'identity.team',
],
};
slackUrl = () => {
const baseUrl = 'https://slack.com/oauth/authorize';
const params = {
client_id: SLACK_KEY,
scope: this.props.scopes.join(' '),
redirect_uri: this.props.redirectUri || SLACK_REDIRECT_URI,
state: this.props.user.getOauthState(),
};
const urlParams = Object.keys(params)
.map(key => {
return `${key}=${encodeURIComponent(params[key])}`;
})
.join('&');
return `${baseUrl}?${urlParams}`;
};
render() {
return <a href={this.slackUrl()}>{this.props.children}</a>;
}
}
export default SlackAuthLink;