Working direct install flow

This commit is contained in:
Tom Moor
2017-11-21 23:51:31 -08:00
parent 13623cb1b3
commit dd2cd2f9d8
7 changed files with 63 additions and 64 deletions

View File

@ -1,47 +1,22 @@
// @flow
import React from 'react';
import { observer, inject } from 'mobx-react';
import { inject } from 'mobx-react';
import { slackAuth } from 'shared/utils/routeHelpers';
import AuthStore from 'stores/AuthStore';
type Props = {
children: React$Element<*>,
scopes?: string[],
auth: AuthStore,
redirectUri: string,
scopes?: string[],
redirectUri?: string,
};
@observer
class SlackAuthLink extends React.Component {
props: Props;
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 ? this.props.scopes.join(' ') : '',
redirect_uri: this.props.redirectUri || SLACK_REDIRECT_URI,
state: this.props.auth.getOauthState(),
};
const urlParams = Object.keys(params)
.map(key => `${key}=${encodeURIComponent(params[key])}`)
.join('&');
return `${baseUrl}?${urlParams}`;
};
render() {
return <a href={this.slackUrl()}>{this.props.children}</a>;
}
function SlackAuthLink({ auth, children, scopes, redirectUri }: Props) {
return (
<a href={slackAuth(this.props.auth.getOauthState(), scopes, redirectUri)}>
{children}
</a>
);
}
export default inject('auth')(SlackAuthLink);