2022-04-26 05:22:01 +00:00
|
|
|
|
/**
|
|
|
|
|
* External dependencies
|
|
|
|
|
*/
|
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
|
import { createInterpolateElement, useState } from '@wordpress/element';
|
2022-05-03 04:10:18 +00:00
|
|
|
|
import { Button, Notice } from '@wordpress/components';
|
2022-04-26 05:37:32 +00:00
|
|
|
|
import { PLUGINS_STORE_NAME } from '@woocommerce/data';
|
|
|
|
|
import { useDispatch } from '@wordpress/data';
|
2022-04-27 00:18:11 +00:00
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2022-04-26 05:22:01 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Internal dependencies
|
|
|
|
|
*/
|
|
|
|
|
import unconnectedImage from './subscriptions-empty-state-unconnected.svg';
|
|
|
|
|
import './style.scss';
|
|
|
|
|
|
2022-04-29 05:05:15 +00:00
|
|
|
|
declare global {
|
|
|
|
|
interface Window {
|
|
|
|
|
wcWcpaySubscriptions: {
|
|
|
|
|
newSubscriptionProductUrl: string;
|
|
|
|
|
onboardingUrl: string;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
newSubscriptionProductUrl,
|
|
|
|
|
onboardingUrl,
|
|
|
|
|
} = window.wcWcpaySubscriptions;
|
|
|
|
|
|
2022-05-03 04:10:18 +00:00
|
|
|
|
const ErrorNotice = ( { isError }: { isError: boolean } ) => {
|
|
|
|
|
if ( ! isError ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Notice
|
|
|
|
|
className="wcpay-empty-subscriptions__error"
|
|
|
|
|
status="error"
|
|
|
|
|
isDismissible={ false }
|
|
|
|
|
>
|
|
|
|
|
{ createInterpolateElement(
|
|
|
|
|
__(
|
|
|
|
|
'WooCommerce Payments failed to install. To continue with WooCommerce Payments built-in subscriptions functionality, please install <a>WooCommerce Payments</a> manually.',
|
|
|
|
|
'woocommerce-payments'
|
|
|
|
|
),
|
|
|
|
|
{
|
|
|
|
|
a: (
|
|
|
|
|
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
|
|
|
<a
|
|
|
|
|
href="https://woocommerce.com/payments"
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noreferrer"
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
}
|
|
|
|
|
) }
|
|
|
|
|
</Notice>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-26 05:22:01 +00:00
|
|
|
|
const TOS = () => (
|
|
|
|
|
<p className="wcpay-empty-subscriptions__tos">
|
|
|
|
|
{ createInterpolateElement(
|
|
|
|
|
__(
|
|
|
|
|
'By clicking "Get started", you agree to the <a>Terms of Service</a>',
|
|
|
|
|
'woocommerce-payments'
|
|
|
|
|
),
|
|
|
|
|
{
|
|
|
|
|
a: (
|
|
|
|
|
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
|
|
|
<a
|
|
|
|
|
href="https://wordpress.com/tos/"
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noreferrer"
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
}
|
|
|
|
|
) }
|
|
|
|
|
</p>
|
|
|
|
|
);
|
|
|
|
|
|
2022-05-03 04:10:18 +00:00
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
|
|
|
const GetStartedButton = ( { setIsError }: { setIsError: Function } ) => {
|
2022-04-26 05:22:01 +00:00
|
|
|
|
const [ isGettingStarted, setIsGettingStarted ] = useState( false );
|
2022-04-26 05:37:32 +00:00
|
|
|
|
const { installAndActivatePlugins } = useDispatch( PLUGINS_STORE_NAME );
|
2022-04-26 05:22:01 +00:00
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="wcpay-empty-subscriptions__button_container">
|
|
|
|
|
<Button
|
|
|
|
|
disabled={ isGettingStarted }
|
|
|
|
|
isBusy={ isGettingStarted }
|
|
|
|
|
isPrimary
|
|
|
|
|
onClick={ () => {
|
2022-04-27 00:18:11 +00:00
|
|
|
|
setIsGettingStarted( true );
|
|
|
|
|
recordEvent(
|
|
|
|
|
'wccore_subscriptions_empty_state_get_started_click',
|
|
|
|
|
{}
|
|
|
|
|
);
|
2022-04-26 05:37:32 +00:00
|
|
|
|
installAndActivatePlugins( [ 'woocommerce-payments' ] )
|
|
|
|
|
.then( () => {
|
2022-04-29 05:05:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* TODO:
|
|
|
|
|
* Navigate to either newSubscriptionProductUrl or onboardingUrl
|
|
|
|
|
* depending on the which treatment the user is assigned to.
|
|
|
|
|
*/
|
2022-05-03 04:10:18 +00:00
|
|
|
|
// eslint-disable-next-line no-console
|
2022-04-26 05:37:32 +00:00
|
|
|
|
console.log( 'It was a success!' );
|
|
|
|
|
} )
|
2022-05-03 04:10:18 +00:00
|
|
|
|
.catch( () => {
|
|
|
|
|
setIsGettingStarted( false );
|
|
|
|
|
setIsError( true );
|
2022-04-26 05:37:32 +00:00
|
|
|
|
} );
|
2022-04-26 05:22:01 +00:00
|
|
|
|
} }
|
|
|
|
|
>
|
|
|
|
|
{ __( 'Get started', 'woocommerce-payments' ) }
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2022-04-22 06:11:24 +00:00
|
|
|
|
};
|
|
|
|
|
|
2022-05-03 04:10:18 +00:00
|
|
|
|
const SubscriptionsPage = () => {
|
|
|
|
|
const [ isError, setIsError ] = useState( false );
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="wcpay-empty-subscriptions__container">
|
|
|
|
|
<ErrorNotice isError={ isError } />
|
|
|
|
|
<img src={ unconnectedImage } alt="" />
|
|
|
|
|
<p className="wcpay-empty-subscriptions__description">
|
|
|
|
|
{ __(
|
|
|
|
|
'Track recurring revenue and manage active subscriptions directly from your store’s dashboard — powered by WooCommerce Payments.',
|
|
|
|
|
'woocommerce-payments'
|
|
|
|
|
) }
|
|
|
|
|
</p>
|
|
|
|
|
<TOS />
|
|
|
|
|
<GetStartedButton setIsError={ setIsError } />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
2022-04-26 05:22:01 +00:00
|
|
|
|
|
2022-04-22 06:11:24 +00:00
|
|
|
|
export default SubscriptionsPage;
|