2020-03-28 13:48:27 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Component } from '@wordpress/element';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { Link } from '@woocommerce/components';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { Button, ProductIcon } from '../../components';
|
|
|
|
import { recordEvent } from 'lib/tracks';
|
|
|
|
|
|
|
|
class InstalledExtensionRow extends Component {
|
|
|
|
constructor( props ) {
|
|
|
|
super( props );
|
|
|
|
|
|
|
|
this.onActivateClick = this.onActivateClick.bind( this );
|
|
|
|
this.onFinishSetupClick = this.onFinishSetupClick.bind( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
getLinks() {
|
|
|
|
const { docsUrl, settingsUrl, supportUrl, dashboardUrl } = this.props;
|
|
|
|
const links = [];
|
|
|
|
|
|
|
|
if ( docsUrl ) {
|
|
|
|
links.push( {
|
|
|
|
key: 'docs',
|
|
|
|
href: docsUrl,
|
|
|
|
text: __( 'Docs', 'woocommerce-admin' ),
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
if ( supportUrl ) {
|
|
|
|
links.push( {
|
|
|
|
key: 'support',
|
|
|
|
href: supportUrl,
|
|
|
|
text: __( 'Get support', 'woocommerce-admin' ),
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
if ( settingsUrl ) {
|
|
|
|
links.push( {
|
|
|
|
key: 'settings',
|
|
|
|
href: settingsUrl,
|
|
|
|
text: __( 'Settings', 'woocommerce-admin' ),
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
if ( dashboardUrl ) {
|
|
|
|
links.push( {
|
|
|
|
key: 'dashboard',
|
|
|
|
href: dashboardUrl,
|
|
|
|
text: __( 'Dashboard', 'woocommerce-admin' ),
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ul className="woocommerce-marketing-installed-extensions-card__item-links">
|
|
|
|
{ links.map( ( link ) => {
|
|
|
|
return (
|
|
|
|
<li key={ link.key }>
|
|
|
|
<Link
|
|
|
|
href={ link.href }
|
|
|
|
type="external"
|
|
|
|
onClick={ this.onLinkClick.bind( this, link ) }
|
|
|
|
>
|
|
|
|
{ link.text }
|
|
|
|
</Link>
|
|
|
|
</li>
|
2020-06-11 19:22:20 +00:00
|
|
|
);
|
2020-03-28 13:48:27 +00:00
|
|
|
} ) }
|
|
|
|
</ul>
|
2020-06-11 19:22:20 +00:00
|
|
|
);
|
2020-03-28 13:48:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onLinkClick( link ) {
|
|
|
|
const { name } = this.props;
|
|
|
|
recordEvent( 'marketing_installed_options', { name, link: link.key } );
|
|
|
|
}
|
|
|
|
|
|
|
|
onActivateClick() {
|
|
|
|
const { activatePlugin, name } = this.props;
|
|
|
|
recordEvent( 'marketing_installed_activate', { name } );
|
|
|
|
activatePlugin();
|
|
|
|
}
|
|
|
|
|
|
|
|
onFinishSetupClick() {
|
|
|
|
const { name } = this.props;
|
|
|
|
recordEvent( 'marketing_installed_finish_setup', { name } );
|
|
|
|
}
|
|
|
|
|
|
|
|
getActivateButton() {
|
|
|
|
const { isLoading } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Button
|
2020-06-11 19:22:20 +00:00
|
|
|
isSecondary
|
2020-03-28 13:48:27 +00:00
|
|
|
onClick={ this.onActivateClick }
|
|
|
|
disabled={ isLoading }
|
|
|
|
>
|
|
|
|
{ __( 'Activate', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
2020-06-11 19:22:20 +00:00
|
|
|
);
|
2020-03-28 13:48:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getFinishSetupButton() {
|
|
|
|
return (
|
|
|
|
<Button
|
2020-06-11 19:22:20 +00:00
|
|
|
isSecondary
|
2020-03-28 13:48:27 +00:00
|
|
|
href={ this.props.settingsUrl }
|
|
|
|
onClick={ this.onFinishSetupClick }
|
|
|
|
>
|
|
|
|
{ __( 'Finish setup', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
2020-06-11 19:22:20 +00:00
|
|
|
);
|
2020-03-28 13:48:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2020-07-16 05:52:06 +00:00
|
|
|
const { name, description, status, slug } = this.props;
|
2020-03-28 13:48:27 +00:00
|
|
|
let actions = null;
|
|
|
|
|
|
|
|
switch ( status ) {
|
|
|
|
case 'installed':
|
|
|
|
actions = this.getActivateButton();
|
|
|
|
break;
|
|
|
|
case 'activated':
|
|
|
|
actions = this.getFinishSetupButton();
|
|
|
|
break;
|
|
|
|
case 'configured':
|
|
|
|
actions = this.getLinks();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="woocommerce-marketing-installed-extensions-card__item">
|
2020-07-16 05:52:06 +00:00
|
|
|
<ProductIcon product={ slug } />
|
2020-04-17 18:27:22 +00:00
|
|
|
<div className="woocommerce-marketing-installed-extensions-card__item-text-and-actions">
|
|
|
|
<div className="woocommerce-marketing-installed-extensions-card__item-text">
|
|
|
|
<h4>{ name }</h4>
|
|
|
|
{ status === 'configured' || (
|
2020-06-11 19:22:20 +00:00
|
|
|
<p className="woocommerce-marketing-installed-extensions-card__item-description">
|
|
|
|
{ description }
|
|
|
|
</p>
|
2020-04-17 18:27:22 +00:00
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
<div className="woocommerce-marketing-installed-extensions-card__item-actions">
|
|
|
|
{ actions }
|
|
|
|
</div>
|
2020-03-28 13:48:27 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-06-11 19:22:20 +00:00
|
|
|
);
|
2020-03-28 13:48:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InstalledExtensionRow.defaultProps = {
|
|
|
|
isLoading: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
InstalledExtensionRow.propTypes = {
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
slug: PropTypes.string.isRequired,
|
|
|
|
description: PropTypes.string.isRequired,
|
|
|
|
status: PropTypes.string.isRequired,
|
|
|
|
settingsUrl: PropTypes.string,
|
|
|
|
docsUrl: PropTypes.string,
|
|
|
|
supportUrl: PropTypes.string,
|
|
|
|
dashboardUrl: PropTypes.string,
|
|
|
|
activatePlugin: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default InstalledExtensionRow;
|