/** * * PluginCard * */ import React from 'react'; import PropTypes from 'prop-types'; import cn from 'classnames'; import { isEmpty, replace } from 'lodash'; import { FormattedMessage } from 'react-intl'; // Temporary picture import Button from 'components/Button'; import InstallPluginPopup from 'components/InstallPluginPopup'; import Official from 'components/Official'; // import StarsContainer from 'components/StarsContainer'; import styles from './styles.scss'; import Screenshot from './screenshot.png'; class PluginCard extends React.Component { state = { isOpen: false, boostrapCol: 'col-lg-4' }; componentDidMount() { this.shouldOpenModal(this.props); window.addEventListener('resize', this.setBoostrapCol); this.setBoostrapCol(); } componentWillReceiveProps(nextProps) { if (nextProps.history.location.hash !== this.props.history.location.hash) { this.shouldOpenModal(nextProps); } } componentWillUnmount() { window.removeEventListener('resize', this.setBoostrapCol); } setBoostrapCol = () => { let boostrapCol = 'col-lg-4'; if (window.innerWidth > 1680) { boostrapCol = 'col-lg-3'; } if (window.innerWidth > 2300) { boostrapCol = 'col-lg-2'; } this.setState({ boostrapCol }); } handleClick = () => { if (this.props.plugin.id !== 'support-us') { this.props.history.push({ pathname: this.props.history.location.pathname, hash: `${this.props.plugin.id}::description`, }); } else { this.aTag.click(); } } handleDownloadPlugin = () => { this.props.downloadPlugin(); } shouldOpenModal = (props) => { this.setState({ isOpen: !isEmpty(props.history.location.hash) }); } render() { const buttonClass = !this.props.isAlreadyInstalled || this.props.showSupportUsButton ? styles.primary : styles.secondary; let buttonLabel = this.props.isAlreadyInstalled ? 'app.components.PluginCard.Button.label.install' : 'app.components.PluginCard.Button.label.download'; if (this.props.showSupportUsButton) { buttonLabel = 'app.components.PluginCard.Button.label.support'; } const pluginIcon = this.props.plugin.id !== 'email' ? (
icon
) : (
); return (
{pluginIcon}
{this.props.plugin.name}
 
{this.props.plugin.price !== 0 ? `${this.props.plugin.price}€` : ''}
e.stopPropagation()}>
{/*
{this.props.plugin.ratings} /5
*/}
); } } PluginCard.defaultProps = { isAlreadyInstalled: false, plugin: { description: '', id: '', icon: '', name: '', price: 0, ratings: 5, }, showSupportUsButton: false, }; PluginCard.propTypes = { downloadPlugin: PropTypes.func.isRequired, handleDownloadPlugin: PropTypes.func.isRequired, history: PropTypes.object.isRequired, isAlreadyInstalled: PropTypes.bool, plugin: PropTypes.object, showSupportUsButton: PropTypes.bool, }; export default PluginCard;