2017-12-02 16:10:18 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* PluginCard
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import cn from 'classnames';
|
2017-12-12 17:49:06 +01:00
|
|
|
import { isEmpty, replace } from 'lodash';
|
2017-12-02 18:46:22 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
|
|
|
|
// Temporary picture
|
|
|
|
import Button from 'components/Button';
|
2017-12-12 14:30:24 +01:00
|
|
|
import InstallPluginPopup from 'components/InstallPluginPopup';
|
2017-12-16 16:51:23 +01:00
|
|
|
import Official from 'components/Official';
|
|
|
|
// import StarsContainer from 'components/StarsContainer';
|
|
|
|
|
2017-12-02 16:10:18 +01:00
|
|
|
import styles from './styles.scss';
|
2017-12-14 17:37:33 +01:00
|
|
|
import Screenshot from './screenshot.png';
|
2017-12-02 16:10:18 +01:00
|
|
|
|
2017-12-02 18:46:22 +01:00
|
|
|
class PluginCard extends React.Component {
|
2017-12-11 19:04:27 +01:00
|
|
|
state = { isOpen: false, boostrapCol: 'col-lg-4' };
|
2017-12-02 18:46:22 +01:00
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.shouldOpenModal(this.props);
|
2017-12-11 19:04:27 +01:00
|
|
|
window.addEventListener('resize', this.setBoostrapCol);
|
|
|
|
this.setBoostrapCol();
|
2017-12-02 18:46:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (nextProps.history.location.hash !== this.props.history.location.hash) {
|
|
|
|
this.shouldOpenModal(nextProps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-11 19:04:27 +01:00
|
|
|
componentWillUnmount() {
|
2017-12-12 14:30:24 +01:00
|
|
|
window.removeEventListener('resize', this.setBoostrapCol);
|
2017-12-11 19:04:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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 });
|
|
|
|
}
|
|
|
|
|
2017-12-12 14:30:24 +01:00
|
|
|
handleClick = () => {
|
2017-12-12 18:30:09 +01:00
|
|
|
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();
|
|
|
|
}
|
2017-12-12 14:30:24 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 19:04:22 +01:00
|
|
|
handleDownloadPlugin = () => {
|
|
|
|
this.props.downloadPlugin();
|
|
|
|
}
|
|
|
|
|
2017-12-02 18:46:22 +01:00
|
|
|
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';
|
|
|
|
}
|
2018-01-04 19:04:22 +01:00
|
|
|
|
2017-12-16 16:51:23 +01:00
|
|
|
const pluginIcon = this.props.plugin.id !== 'email' ? (
|
|
|
|
<div className={styles.frame}>
|
|
|
|
<span className={styles.helper} />
|
2018-01-04 19:04:22 +01:00
|
|
|
<img src={`${this.props.plugin.logo}?sanitize=true`} alt="icon" />
|
2017-12-16 16:51:23 +01:00
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className={styles.iconContainer}><i className={`fa fa-${this.props.plugin.icon}`} /></div>
|
|
|
|
);
|
2017-12-02 18:46:22 +01:00
|
|
|
|
|
|
|
return (
|
2017-12-12 14:30:24 +01:00
|
|
|
<div className={cn(this.state.boostrapCol, styles.pluginCard)} onClick={this.handleClick}>
|
2017-12-02 18:46:22 +01:00
|
|
|
<div className={styles.wrapper}>
|
|
|
|
<div className={styles.cardTitle}>
|
2017-12-16 16:51:23 +01:00
|
|
|
{pluginIcon}
|
2017-12-02 18:46:22 +01:00
|
|
|
<div>{this.props.plugin.name}</div>
|
|
|
|
</div>
|
|
|
|
<div className={styles.cardDescription}>
|
2018-01-04 19:04:22 +01:00
|
|
|
<FormattedMessage id={this.props.plugin.description.short} />
|
2017-12-11 20:19:22 +01:00
|
|
|
<FormattedMessage id="app.components.PluginCard.more-details" />
|
2017-12-02 18:46:22 +01:00
|
|
|
</div>
|
2017-12-14 17:37:33 +01:00
|
|
|
<div className={styles.cardScreenshot} style={{ backgroundImage: `url(${Screenshot})` }}>
|
2017-12-11 19:04:27 +01:00
|
|
|
|
2017-12-02 18:46:22 +01:00
|
|
|
</div>
|
|
|
|
<div className={styles.cardPrice}>
|
|
|
|
<div>
|
|
|
|
<i className={`fa fa-${this.props.plugin.isCompatible ? 'check' : 'times'}`} />
|
|
|
|
<FormattedMessage id={`app.components.PluginCard.compatible${this.props.plugin.id === 'support-us' ? 'Community' : ''}`} />
|
|
|
|
</div>
|
2017-12-11 19:04:27 +01:00
|
|
|
<div>{this.props.plugin.price !== 0 ? `${this.props.plugin.price}€` : ''}</div>
|
2017-12-02 18:46:22 +01:00
|
|
|
</div>
|
2018-01-04 19:04:22 +01:00
|
|
|
<div className={styles.cardFooter} onClick={e => e.stopPropagation()}>
|
2017-12-02 18:46:22 +01:00
|
|
|
<div className={styles.ratings}>
|
2017-12-16 16:51:23 +01:00
|
|
|
{/*<StarsContainer ratings={this.props.plugin.ratings} />
|
2017-12-02 18:46:22 +01:00
|
|
|
<div>
|
|
|
|
<span style={{ fontWeight: '600', color: '#333740' }}>{this.props.plugin.ratings}</span>
|
|
|
|
<span style={{ fontWeight: '500', color: '#666666' }}>/5</span>
|
|
|
|
</div>
|
2017-12-16 16:51:23 +01:00
|
|
|
*/}
|
|
|
|
<Official />
|
2017-12-02 18:46:22 +01:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<Button
|
|
|
|
className={cn(buttonClass, styles.button)}
|
|
|
|
label={buttonLabel}
|
2018-01-04 19:04:22 +01:00
|
|
|
onClick={this.props.handleDownloadPlugin}
|
2017-12-02 18:46:22 +01:00
|
|
|
/>
|
2017-12-12 18:30:09 +01:00
|
|
|
<a
|
|
|
|
href="mailto:hi@strapi.io?subject=I'd like to support Strapi"
|
|
|
|
style={{ display: 'none' }}
|
|
|
|
ref={(a) => { this.aTag = a; }}
|
|
|
|
>
|
|
|
|
|
|
|
|
</a>
|
2017-12-02 18:46:22 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-12-02 16:10:18 +01:00
|
|
|
</div>
|
2017-12-12 14:30:24 +01:00
|
|
|
<InstallPluginPopup
|
|
|
|
history={this.props.history}
|
2017-12-12 19:53:04 +01:00
|
|
|
isAlreadyInstalled={this.props.isAlreadyInstalled}
|
2017-12-12 14:30:24 +01:00
|
|
|
isOpen={!isEmpty(this.props.history.location.hash) && replace(this.props.history.location.hash.split('::')[0], '#', '') === this.props.plugin.id}
|
|
|
|
plugin={this.props.plugin}
|
|
|
|
/>
|
2017-12-02 16:10:18 +01:00
|
|
|
</div>
|
2017-12-02 18:46:22 +01:00
|
|
|
);
|
|
|
|
}
|
2017-12-02 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PluginCard.defaultProps = {
|
|
|
|
isAlreadyInstalled: false,
|
|
|
|
plugin: {
|
|
|
|
description: '',
|
|
|
|
id: '',
|
|
|
|
icon: '',
|
|
|
|
name: '',
|
|
|
|
price: 0,
|
|
|
|
ratings: 5,
|
|
|
|
},
|
|
|
|
showSupportUsButton: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
PluginCard.propTypes = {
|
2018-01-04 19:04:22 +01:00
|
|
|
downloadPlugin: PropTypes.func.isRequired,
|
|
|
|
handleDownloadPlugin: PropTypes.func.isRequired,
|
2017-12-02 18:46:22 +01:00
|
|
|
history: PropTypes.object.isRequired,
|
2017-12-02 16:10:18 +01:00
|
|
|
isAlreadyInstalled: PropTypes.bool,
|
|
|
|
plugin: PropTypes.object,
|
|
|
|
showSupportUsButton: PropTypes.bool,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PluginCard;
|