woocommerce/plugins/woocommerce-admin/client/shipping/woocommerce-services-item.tsx

98 lines
2.6 KiB
TypeScript
Raw Normal View History

/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
2022-04-19 17:45:10 +00:00
import {
useSelect,
useDispatch,
select as wpDataSelect,
} from '@wordpress/data';
import { Button, ExternalLink } from '@wordpress/components';
import { Pill } from '@woocommerce/components';
import { PLUGINS_STORE_NAME } from '@woocommerce/data';
import { getAdminLink } from '@woocommerce/settings';
/**
* Internal dependencies
*/
import './woocommerce-services-item.scss';
import WooIcon from './woo-icon.svg';
import { getAdminSetting } from '../utils/admin-settings';
const WooCommerceServicesItem: React.FC< {
pluginsBeingSetup: Array< string >;
onSetupClick: ( slugs: string[] ) => PromiseLike< void >;
} > = ( { onSetupClick, pluginsBeingSetup } ) => {
const wcAdminAssetUrl = getAdminSetting( 'wcAdminAssetUrl', '' );
const { createSuccessNotice } = useDispatch( 'core/notices' );
2022-04-19 17:45:10 +00:00
const isSiteConnectedToJetpack = useSelect(
( select: typeof wpDataSelect ) =>
select( PLUGINS_STORE_NAME ).isJetpackConnected()
);
const handleSetupClick = () => {
onSetupClick( [ 'woocommerce-services' ] ).then( () => {
const actions = [];
if ( ! isSiteConnectedToJetpack ) {
actions.push( {
url: getAdminLink( 'plugins.php' ),
label: __(
'Finish the setup by connecting your store to Jetpack.',
'woocommerce'
),
} );
}
createSuccessNotice(
__( '🎉 WooCommerce Shipping is installed!', 'woocommerce' ),
{
actions,
}
);
} );
};
return (
<div className="woocommerce-list__item-inner woocommerce-services-item">
<div className="woocommerce-list__item-before">
<img
className="woocommerce-services-item__logo"
src={ WooIcon }
alt=""
/>
</div>
<div className="woocommerce-list__item-text">
<span className="woocommerce-list__item-title">
{ __( 'Woocommerce Shipping', 'woocommerce' ) }
<Pill>{ __( 'Recommended', 'woocommerce' ) }</Pill>
</span>
<span className="woocommerce-list__item-content">
{ __(
'Print USPS and DHL Express labels straight from your WooCommerce dashboard and save on shipping.',
'woocommerce'
) }
<br />
<ExternalLink href="https://woocommerce.com/woocommerce-shipping/">
{ __( 'Learn more', 'woocommerce' ) }
</ExternalLink>
</span>
</div>
<div className="woocommerce-list__item-after">
<Button
isSecondary
onClick={ handleSetupClick }
isBusy={ pluginsBeingSetup.includes(
'woocommerce-services'
) }
disabled={ pluginsBeingSetup.length > 0 }
>
{ __( 'Get started', 'woocommerce' ) }
</Button>
</div>
</div>
);
};
export default WooCommerceServicesItem;