187 lines
5.6 KiB
JavaScript
Raw Normal View History

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';
// Icons
import IconAuth from 'assets/icons/icon_auth-permissions.svg';
import IconCM from 'assets/icons/icon_content-manager.svg';
import IconCTB from 'assets/icons/icon_content-type-builder.svg';
import IconSM from 'assets/icons/icon_settings-manager.svg';
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
}
2017-12-16 16:51:23 +01:00
getPluginICon = () => {
switch (this.props.plugin.id) {
case 'content-manager':
return IconCM;
case 'content-type-builder':
return IconCTB;
case 'settings-manager':
return IconSM;
case 'users-permissions':
return IconAuth;
default:
}
}
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
}
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';
}
2017-12-16 16:51:23 +01:00
const pluginIcon = this.props.plugin.id !== 'email' ? (
<div className={styles.frame}>
<span className={styles.helper} />
<img src={this.getPluginICon()} alt="icon" />
</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}>
<FormattedMessage id={this.props.plugin.description} />
2017-12-11 20:19:22 +01:00
&nbsp;<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>
<div className={styles.cardFooter}>
<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}
2017-12-12 18:30:09 +01:00
onClick={this.handleClick}
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; }}
>
&nbsp;
</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}
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 = {
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;