162 lines
5.7 KiB
JavaScript
Raw Normal View History

2017-12-12 14:30:24 +01:00
/*
*
* InstallPluginPopup
*
*/
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { Modal, ModalHeader, ModalBody } from 'reactstrap';
import { map } from 'lodash';
2017-12-12 17:05:43 +01:00
import cn from 'classnames';
2017-12-12 14:30:24 +01:00
2017-12-16 16:51:23 +01:00
import Official from 'components/Official';
// import StarsContainer from 'components/StarsContainer';
2017-12-12 14:30:24 +01:00
import styles from './styles.scss';
class InstallPluginPopup extends React.Component {
handleClick = () => {
this.props.history.push({ pathname: this.props.history.location.pathname });
if (!this.props.isAlreadyInstalled) {
this.context.downloadPlugin(this.props.plugin.id);
}
}
2017-12-12 14:30:24 +01:00
toggle = () => {
this.props.history.push({
pathname: this.props.history.location.pathname,
});
}
navLinks = [
{
content: 'app.components.InstallPluginPopup.navLink.description',
name: 'description',
},
2017-12-12 17:05:43 +01:00
{
content: 'app.components.InstallPluginPopup.navLink.screenshots',
name: 'screenshots',
},
{
content: 'app.components.InstallPluginPopup.navLink.avis',
name: 'avis',
},
{
content: 'app.components.InstallPluginPopup.navLink.faq',
name: 'faq',
},
{
content: 'app.components.InstallPluginPopup.navLink.changelog',
name: 'changelog',
},
2017-12-12 14:30:24 +01:00
];
render() {
const descriptions = {
short: this.props.plugin.id === 'support-us' ? <FormattedMessage id={this.props.plugin.description.short} /> : this.props.plugin.description.short,
long: this.props.plugin.id === 'support-us' ? <FormattedMessage id={this.props.plugin.description.long || this.props.plugin.description.short} /> : this.props.plugin.description.long || this.props.plugin.description.short,
};
const buttonName = this.props.isAlreadyInstalled ? 'app.components.PluginCard.Button.label.install' : 'app.components.InstallPluginPopup.downloads';
2017-12-12 14:30:24 +01:00
return (
<Modal isOpen={this.props.isOpen} toggle={this.toggle} className={styles.modalPosition}>
<ModalHeader toggle={this.toggle} className={styles.modalHeader} />
<ModalBody className={styles.modalBody}>
2017-12-12 15:44:04 +01:00
<div className={styles.wrapper}>
<div className={styles.headerWrapper}>
<div className={styles.logo}><img src={`${this.props.plugin.logo}`} alt="icon" /></div>
2017-12-12 15:44:04 +01:00
<div className={styles.headerInfo}>
<div className={styles.name}>{this.props.plugin.name}</div>
<div className={styles.ratings}>
2017-12-16 16:51:23 +01:00
{/*}
2017-12-12 17:49:06 +01:00
<StarsContainer ratings={this.props.plugin.ratings} />
2017-12-12 14:30:24 +01:00
<div>
2017-12-12 15:44:04 +01:00
<span style={{ fontWeight: '600', color: '#333740', fontSize: '12px'}}>{this.props.plugin.ratings}</span>
<span style={{ fontWeight: '500', color: '#666666', fontSize: '11px' }}>/5</span>
2017-12-12 14:30:24 +01:00
</div>
2017-12-16 16:51:23 +01:00
*/}
<Official style={{ marginTop: '0' }} />
2017-12-12 14:30:24 +01:00
</div>
2017-12-12 15:44:04 +01:00
<div className={styles.headerDescription}>
{descriptions.short}
2017-12-12 14:30:24 +01:00
</div>
2017-12-12 15:44:04 +01:00
<div className={styles.headerButtonContainer}>
<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>
<div>
2017-12-12 17:49:06 +01:00
<div>
2017-12-12 18:30:09 +01:00
{/*}
2017-12-12 17:49:06 +01:00
<span style={{ fontWeight: '600' }}>+{this.props.plugin.downloads_nb}k&nbsp;</span><FormattedMessage id="app.components.InstallPluginPopup.downloads" />
2017-12-12 18:30:09 +01:00
*/}
2017-12-12 17:49:06 +01:00
</div>
<div className={styles.buttonWrapper} onClick={this.handleClick}>
2017-12-12 15:44:04 +01:00
<div>
<FormattedMessage id={buttonName} />
2017-12-12 15:44:04 +01:00
</div>
2017-12-12 17:49:06 +01:00
{/* Uncomment whebn prices are running}
2017-12-12 15:44:04 +01:00
<div>{this.props.plugin.price}&nbsp;</div>
2017-12-12 17:49:06 +01:00
*/}
2017-12-12 14:30:24 +01:00
</div>
</div>
</div>
</div>
</div>
</div>
<div className={styles.navContainer}>
{map(this.navLinks, link => {
2017-12-12 15:44:04 +01:00
const isActive = this.props.history.location.hash.split('::')[1] === link.name;
2017-12-12 14:30:24 +01:00
return (
2017-12-12 17:05:43 +01:00
<div
key={link.name}
className={cn(isActive ? styles.navLink : '', link.name !== 'description' ? styles.notAllowed : '')}
onClick={() => {
if (link.name === 'description') {
this.props.history.push({ pathname: this.props.history.location.pathname, hash: `${this.props.plugin.id}::${link.name}` });
}
}}
2017-12-12 17:49:06 +01:00
style={isActive ? { paddingTop: '4px'} : { paddingTop: '6px' }}
2017-12-12 17:05:43 +01:00
>
2017-12-12 14:30:24 +01:00
<FormattedMessage id={link.content} />
</div>
);
})}
</div>
2017-12-12 16:18:48 +01:00
<div className={styles.pluginDescription}>
{descriptions.long}
2017-12-12 16:18:48 +01:00
</div>
2017-12-12 14:30:24 +01:00
</ModalBody>
</Modal>
);
}
}
InstallPluginPopup.contextTypes = {
downloadPlugin: PropTypes.func.isRequired,
};
2017-12-12 14:30:24 +01:00
InstallPluginPopup.defaultProps = {
description: {
short: 'app.Components.InstallPluginPopup.noDescription',
},
};
2017-12-12 14:30:24 +01:00
InstallPluginPopup.propTypes = {
description: PropTypes.shape({
long: PropTypes.string,
short: PropTypes.string,
}),
2017-12-12 14:30:24 +01:00
history: PropTypes.object.isRequired,
isAlreadyInstalled: PropTypes.bool.isRequired,
2017-12-12 14:30:24 +01:00
isOpen: PropTypes.bool.isRequired,
plugin: PropTypes.object.isRequired,
};
export default InstallPluginPopup;