// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import React from 'react'; import PropTypes from 'prop-types'; import * as Utils from 'utils/utils.jsx'; import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; import FormError from 'components/form_error.jsx'; import DeleteIntegration from './delete_integration.jsx'; const FAKE_SECRET = '***************'; export default class InstalledOAuthApp extends React.PureComponent { static propTypes = { /** * The oauthApp data */ oauthApp: PropTypes.object.isRequired, /** * The request state for regenOAuthAppSecret action. Contains status and error */ regenOAuthAppSecretRequest: PropTypes.object.isRequired, /** * The function to call when Regenerate Secret link is clicked */ onRegenerateSecret: PropTypes.func.isRequired, /** * The function to call when Delete link is clicked */ onDelete: PropTypes.func.isRequired, /** * Set to filter OAuthApp */ filter: PropTypes.string } constructor(props) { super(props); this.state = { clientSecret: FAKE_SECRET }; } handleShowClientSecret = (e) => { if (e && e.preventDefault) { e.preventDefault(); } this.setState({clientSecret: this.props.oauthApp.client_secret}); } handleHideClientSecret = (e) => { e.preventDefault(); this.setState({clientSecret: FAKE_SECRET}); } handleRegenerate = (e) => { e.preventDefault(); this.props.onRegenerateSecret(this.props.oauthApp.id).then( () => { const {error} = this.props.regenOAuthAppSecretRequest; if (error) { this.setState({error: error.message}); } else { this.setState({error: null}); this.handleShowClientSecret(); } } ); } 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} {' - '}
); } }