2019-12-20 12:58:38 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
|
|
|
import { Component } from '@wordpress/element';
|
|
|
|
import { compose } from '@wordpress/compose';
|
|
|
|
import { Button, Modal } from '@wordpress/components';
|
|
|
|
import { find } from 'lodash';
|
|
|
|
import { decodeEntities } from '@wordpress/html-entities';
|
2020-05-28 08:51:40 +00:00
|
|
|
import { withSelect } from '@wordpress/data';
|
2019-12-20 12:58:38 +00:00
|
|
|
import { getSetting } from '@woocommerce/wc-admin-settings';
|
|
|
|
import { List } from '@woocommerce/components';
|
2020-05-28 08:51:40 +00:00
|
|
|
import { ONBOARDING_STORE_NAME, PLUGINS_STORE_NAME } from '@woocommerce/data';
|
2020-08-20 04:59:52 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2019-12-20 12:58:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-08-13 02:05:22 +00:00
|
|
|
import { getProductIdsForCart } from '../utils';
|
|
|
|
import sanitizeHTML from '../../lib/sanitize-html';
|
|
|
|
import { getInAppPurchaseUrl } from '../../lib/in-app-purchase';
|
2019-12-20 12:58:38 +00:00
|
|
|
|
|
|
|
class CartModal extends Component {
|
|
|
|
constructor( props ) {
|
|
|
|
super( props );
|
|
|
|
this.state = {
|
|
|
|
purchaseNowButtonBusy: false,
|
|
|
|
purchaseLaterButtonBusy: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onClickPurchaseNow() {
|
|
|
|
const { productIds, onClickPurchaseNow } = this.props;
|
|
|
|
this.setState( { purchaseNowButtonBusy: true } );
|
|
|
|
if ( ! productIds.length ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-02 02:36:25 +00:00
|
|
|
recordEvent( 'tasklist_modal_proceed_checkout', {
|
|
|
|
product_ids: productIds,
|
2020-03-03 09:44:26 +00:00
|
|
|
purchase_install: true,
|
2020-01-02 02:36:25 +00:00
|
|
|
} );
|
|
|
|
|
2020-05-20 05:33:58 +00:00
|
|
|
const url = getInAppPurchaseUrl( 'https://woocommerce.com/cart', {
|
2019-12-20 12:58:38 +00:00
|
|
|
'wccom-replace-with': productIds.join( ',' ),
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( onClickPurchaseNow ) {
|
|
|
|
onClickPurchaseNow( url );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.location = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
onClickPurchaseLater() {
|
2020-01-02 02:36:25 +00:00
|
|
|
const { productIds } = this.props;
|
|
|
|
|
|
|
|
recordEvent( 'tasklist_modal_proceed_checkout', {
|
|
|
|
product_ids: productIds,
|
|
|
|
purchase_install: false,
|
|
|
|
} );
|
|
|
|
|
2019-12-20 12:58:38 +00:00
|
|
|
this.setState( { purchaseLaterButtonBusy: true } );
|
|
|
|
this.props.onClickPurchaseLater();
|
|
|
|
}
|
|
|
|
|
2020-01-02 02:36:25 +00:00
|
|
|
onClose() {
|
|
|
|
const { onClose, productIds } = this.props;
|
|
|
|
|
|
|
|
recordEvent( 'tasklist_modal_proceed_checkout', {
|
|
|
|
product_ids: productIds,
|
|
|
|
purchase_install: false,
|
|
|
|
} );
|
|
|
|
|
|
|
|
onClose();
|
|
|
|
}
|
|
|
|
|
2019-12-20 12:58:38 +00:00
|
|
|
renderProducts() {
|
|
|
|
const { productIds } = this.props;
|
2020-02-14 02:23:21 +00:00
|
|
|
const { productTypes = {}, themes = [] } = getSetting(
|
|
|
|
'onboarding',
|
|
|
|
{}
|
|
|
|
);
|
2019-12-20 12:58:38 +00:00
|
|
|
const listItems = [];
|
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
productIds.forEach( ( productId ) => {
|
|
|
|
const productInfo = find( productTypes, ( productType ) => {
|
2019-12-20 12:58:38 +00:00
|
|
|
return productType.product === productId;
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( productInfo ) {
|
|
|
|
listItems.push( {
|
|
|
|
title: productInfo.label,
|
|
|
|
content: productInfo.description,
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
const themeInfo = find( themes, ( theme ) => {
|
2019-12-20 12:58:38 +00:00
|
|
|
return theme.id === productId;
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( themeInfo ) {
|
|
|
|
listItems.push( {
|
|
|
|
title: sprintf(
|
|
|
|
__( '%s — %s per year', 'woocommerce-admin' ),
|
|
|
|
themeInfo.title,
|
|
|
|
decodeEntities( themeInfo.price )
|
|
|
|
),
|
2020-02-14 02:23:21 +00:00
|
|
|
content: (
|
|
|
|
<span
|
|
|
|
dangerouslySetInnerHTML={ sanitizeHTML(
|
|
|
|
themeInfo.excerpt
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
),
|
2019-12-20 12:58:38 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
return <List items={ listItems } />;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { purchaseNowButtonBusy, purchaseLaterButtonBusy } = this.state;
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
title={ __(
|
2020-12-01 11:55:27 +00:00
|
|
|
'Would you like to add the following paid features to your store now?',
|
2019-12-20 12:58:38 +00:00
|
|
|
'woocommerce-admin'
|
|
|
|
) }
|
2020-01-02 02:36:25 +00:00
|
|
|
onRequestClose={ () => this.onClose() }
|
2019-12-20 12:58:38 +00:00
|
|
|
className="woocommerce-cart-modal"
|
|
|
|
>
|
|
|
|
{ this.renderProducts() }
|
|
|
|
|
|
|
|
<p className="woocommerce-cart-modal__help-text">
|
|
|
|
{ __(
|
|
|
|
"You won't have access to this functionality until the extensions have been purchased and installed.",
|
|
|
|
'woocommerce-admin'
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<div className="woocommerce-cart-modal__actions">
|
|
|
|
<Button
|
|
|
|
isLink
|
|
|
|
isBusy={ purchaseLaterButtonBusy }
|
|
|
|
onClick={ () => this.onClickPurchaseLater() }
|
|
|
|
>
|
|
|
|
{ __( "I'll do it later", 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
<Button
|
|
|
|
isPrimary
|
|
|
|
isBusy={ purchaseNowButtonBusy }
|
|
|
|
onClick={ () => this.onClickPurchaseNow() }
|
|
|
|
>
|
2020-12-01 11:55:27 +00:00
|
|
|
{ __( 'Buy now', 'woocommerce-admin' ) }
|
2019-12-20 12:58:38 +00:00
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default compose(
|
2020-02-14 02:23:21 +00:00
|
|
|
withSelect( ( select ) => {
|
2020-05-25 00:26:08 +00:00
|
|
|
const { getInstalledPlugins } = select( PLUGINS_STORE_NAME );
|
2020-05-28 08:51:40 +00:00
|
|
|
const { getProfileItems } = select( ONBOARDING_STORE_NAME );
|
2019-12-20 12:58:38 +00:00
|
|
|
const profileItems = getProfileItems();
|
2020-05-25 00:26:08 +00:00
|
|
|
const installedPlugins = getInstalledPlugins();
|
|
|
|
const productIds = getProductIdsForCart(
|
|
|
|
profileItems,
|
|
|
|
false,
|
|
|
|
installedPlugins
|
|
|
|
);
|
2019-12-20 12:58:38 +00:00
|
|
|
|
|
|
|
return { profileItems, productIds };
|
|
|
|
} )
|
|
|
|
)( CartModal );
|