// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import React from 'react'; import FormError from 'components/form_error.jsx'; import * as Utils from 'utils/utils.jsx'; import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; import {regenerateOAuthAppSecret} from 'actions/admin_actions.jsx'; import DeleteIntegration from './delete_integration.jsx'; const FAKE_SECRET = '***************'; export default class InstalledOAuthApp extends React.Component { static get propTypes() { return { oauthApp: React.PropTypes.object.isRequired, onDelete: React.PropTypes.func.isRequired, filter: React.PropTypes.string }; } constructor(props) { super(props); this.handleShowClientSecret = this.handleShowClientSecret.bind(this); this.handleHideClientScret = this.handleHideClientScret.bind(this); this.handleRegenerate = this.handleRegenerate.bind(this); this.handleDelete = this.handleDelete.bind(this); this.matchesFilter = this.matchesFilter.bind(this); this.state = { clientSecret: FAKE_SECRET }; } handleShowClientSecret(e) { e.preventDefault(); this.setState({clientSecret: this.props.oauthApp.client_secret}); } handleHideClientScret(e) { e.preventDefault(); this.setState({clientSecret: FAKE_SECRET}); } handleRegenerate(e) { e.preventDefault(); regenerateOAuthAppSecret( this.props.oauthApp.id, (data) => { this.props.oauthApp.client_secret = data.client_secret; this.handleShowClientSecret(e); }, (err) => { this.setState({error: err.message}); } ); } handleDelete() { this.props.onDelete(this.props.oauthApp); } matchesFilter(oauthApp, filter) { if (!filter) { return true; } return oauthApp.name.toLowerCase().indexOf(filter) !== -1; } render() { const oauthApp = this.props.oauthApp; let error; if (this.state.error) { error = ( ); } if (!this.matchesFilter(oauthApp, this.props.filter)) { return null; } let name; if (oauthApp.name) { name = oauthApp.name; } else { name = ( ); } let description; if (oauthApp.description) { description = (
{oauthApp.description}
); } const urls = (
); let isTrusted; if (oauthApp.is_trusted) { isTrusted = Utils.localizeMessage('installed_oauth_apps.trusted.yes', 'Yes'); } else { isTrusted = Utils.localizeMessage('installed_oauth_apps.trusted.no', 'No'); } let showHide; if (this.state.clientSecret === FAKE_SECRET) { showHide = ( ); } else { showHide = ( ); } const regen = ( ); let icon; if (oauthApp.icon_url) { icon = (
); } return (
{icon}
{name}
{error} {description}
{urls}
{showHide} {' - '} {regen} {' - '}
); } }