2022-04-26 05:22:01 +00:00
/ * *
* External dependencies
* /
import { __ } from '@wordpress/i18n' ;
2022-05-10 05:43:47 +00:00
import {
createInterpolateElement ,
useEffect ,
useState ,
} from '@wordpress/element' ;
2022-05-05 05:04:27 +00:00
import { Button , Card , CardBody , Notice } from '@wordpress/components' ;
2022-05-09 05:10:17 +00:00
import { PLUGINS_STORE_NAME , OPTIONS_STORE_NAME } from '@woocommerce/data' ;
2022-04-26 05:37:32 +00:00
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
* /
2022-05-05 05:04:27 +00:00
import Visa from './cards/visa.js' ;
import MasterCard from './cards/mastercard.js' ;
import Amex from './cards/amex.js' ;
import DinersClub from './cards/diners.js' ;
import Discover from './cards/discover.js' ;
import JCB from './cards/jcb.js' ;
import UnionPay from './cards/unionpay.js' ;
2022-04-26 05:22:01 +00:00
import './style.scss' ;
2022-04-29 05:05:15 +00:00
declare global {
interface Window {
wcWcpaySubscriptions : {
newSubscriptionProductUrl : string ;
onboardingUrl : string ;
2022-05-09 03:41:16 +00:00
noThanksUrl : string ;
dismissOptionKey : string ;
2022-04-29 05:05:15 +00:00
} ;
}
}
const {
newSubscriptionProductUrl ,
onboardingUrl ,
2022-05-09 03:41:16 +00:00
noThanksUrl ,
dismissOptionKey ,
2022-04-29 05:05:15 +00:00
} = window . wcWcpaySubscriptions ;
2022-05-05 05:04:27 +00:00
type setHasErrorFunction = React . Dispatch < React . SetStateAction < boolean > > ;
2022-05-03 04:10:18 +00:00
2022-05-05 05:04:27 +00:00
const ErrorNotice = ( ) = > {
2022-05-03 04:10:18 +00:00
return (
< Notice
className = "wcpay-empty-subscriptions__error"
status = "error"
isDismissible = { false }
>
{ createInterpolateElement (
__ (
2022-05-03 06:47:14 +00:00
'Installing WooCommerce Payments failed. To continue with WooCommerce Payments built-in subscriptions functionality, please install <a>WooCommerce Payments</a> manually.' ,
2022-05-04 01:15:56 +00:00
'woocommerce'
2022-05-03 04:10:18 +00:00
) ,
{
a : (
// eslint-disable-next-line jsx-a11y/anchor-has-content
< a
2022-05-03 06:18:46 +00:00
href = "https://wordpress.org/plugins/woocommerce-payments/"
2022-05-03 04:10:18 +00:00
target = "_blank"
rel = "noreferrer"
/ >
) ,
}
) }
< / Notice >
) ;
} ;
2022-05-09 03:41:16 +00:00
const NoThanksButton = ( ) = > {
const [ isNoThanksClicked , setIsNoThanksClicked ] = useState ( false ) ;
2022-05-09 05:10:17 +00:00
const { updateOptions } = useDispatch ( OPTIONS_STORE_NAME ) ;
2022-05-09 03:41:16 +00:00
return (
< Button
isBusy = { isNoThanksClicked }
isSecondary
onClick = { ( ) = > {
setIsNoThanksClicked ( true ) ;
recordEvent (
'wccore_subscriptions_empty_state_no_thanks_click' ,
{ }
) ;
2022-05-09 05:10:17 +00:00
updateOptions ( {
[ dismissOptionKey ] : 'yes' ,
2022-05-10 01:11:07 +00:00
// @ts-expect-error updateOptions returns a Promise, but it is not typed in source.
2022-05-09 03:41:16 +00:00
} ) . then ( ( ) = > {
window . location . href = noThanksUrl ;
} ) ;
} }
>
{ __ ( 'No thanks' , 'woocommerce' ) }
< / Button >
) ;
} ;
2022-05-05 05:04:27 +00:00
type GetStartedButtonProps = {
setHasError : setHasErrorFunction ;
} ;
2022-04-26 05:22:01 +00:00
2022-05-05 05:04:27 +00:00
const GetStartedButton : React.FC < GetStartedButtonProps > = ( {
setHasError ,
} ) = > {
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 (
2022-05-09 03:41:16 +00:00
< Button
disabled = { isGettingStarted }
isBusy = { isGettingStarted }
isPrimary
onClick = { ( ) = > {
setIsGettingStarted ( true ) ;
recordEvent (
'wccore_subscriptions_empty_state_get_started_click' ,
{ }
) ;
installAndActivatePlugins ( [ 'woocommerce-payments' ] )
. then ( ( ) = > {
/ *
* TODO :
* Navigate to either newSubscriptionProductUrl or onboardingUrl
* depending on the which treatment the user is assigned to .
* /
// eslint-disable-next-line no-console
console . log ( 'It was a success!' ) ;
} )
. catch ( ( ) = > {
setIsGettingStarted ( false ) ;
setHasError ( true ) ;
} ) ;
} }
>
{ __ ( 'Get started' , 'woocommerce' ) }
< / Button >
2022-04-26 05:22:01 +00:00
) ;
2022-04-22 06:11:24 +00:00
} ;
2022-05-05 05:04:27 +00:00
const StepNumber : React.FC = ( { children } ) = > (
< span className = "wcpay-empty-subscriptions-page-step-number" >
{ children }
< / span >
) ;
const TermsOfService = ( ) = > (
< span className = "wcpay-empty-subscriptions-page-terms-of-service" >
{ createInterpolateElement (
__ (
'By clicking “Get started”, the WooCommerce Payments plugin will be installed and you agree to the <a>Terms of Service</a>' ,
'woocommerce'
) ,
{
a : (
// eslint-disable-next-line jsx-a11y/anchor-has-content
< a
href = "https://wordpress.com/tos/"
target = "_blank"
rel = "noreferrer"
/ >
) ,
}
) }
< / span >
) ;
2022-05-03 04:10:18 +00:00
2022-05-05 05:04:27 +00:00
type MainContentProps = {
setHasError : setHasErrorFunction ;
} ;
const MainContent : React.FC < MainContentProps > = ( { setHasError } ) = > {
2022-05-03 04:10:18 +00:00
return (
2022-05-05 05:04:27 +00:00
< >
< h2 >
{ __ ( 'Start selling subscriptions today' , 'woocommerce' ) }
< / h2 >
< p >
2022-05-03 04:10:18 +00:00
{ __ (
2022-05-09 00:47:06 +00:00
'With WooCommerce Payments, you can sell subscriptions with no setup costs or monthly fees. Create subscription products, track recurring revenue, and manage subscribers directly from your store’ s dashboard.' ,
2022-05-04 01:15:56 +00:00
'woocommerce'
2022-05-03 04:10:18 +00:00
) }
2022-05-05 05:04:27 +00:00
< br / >
< a
href = "https://woocommerce.com/document/payments/subscriptions/"
target = "_blank"
rel = "noreferrer"
>
{ __ ( 'Learn more' , 'woocommerce' ) }
< / a >
< / p >
< h3 > { __ ( 'Accepted payment methods' , 'woocommerce' ) } < / h3 >
< div className = "wcpay-empty-subscriptions-page-payment-methods" >
< Visa / >
< MasterCard / >
< Amex / >
< DinersClub / >
< Discover / >
< UnionPay / >
< JCB / >
< / div >
< hr / >
< p className = "subscriptions__action" >
< TermsOfService / >
2022-05-03 04:10:18 +00:00
< / p >
2022-05-05 05:04:27 +00:00
2022-05-09 03:41:16 +00:00
< div className = "wcpay-empty-subscriptions__button_container" >
< GetStartedButton setHasError = { setHasError } / >
2022-05-09 04:56:59 +00:00
< NoThanksButton / >
2022-05-09 03:41:16 +00:00
< / div >
2022-05-05 05:04:27 +00:00
< / >
) ;
} ;
const OnboardingSteps = ( ) = > (
< >
< h2 >
{ __ (
'You’ re only steps away from selling subscriptions' ,
'woocommerce'
) }
< / h2 >
< div className = "subscriptions-page-onboarding-steps" >
< div className = "subscriptions-page-onboarding-steps-item" >
< StepNumber > 1 < / StepNumber >
< h3 >
{ __ ( 'Create and connect your account' , 'woocommerce' ) }
< / h3 >
< p >
{ __ (
'To ensure safe and secure transactions, a WordPress.com account is required.' ,
'woocommerce'
) }
< / p >
< / div >
< div className = "subscriptions-page-onboarding-steps-item" >
< StepNumber > 2 < / StepNumber >
< h3 >
{ __ ( 'Provide a few business details' , 'woocommerce' ) }
< / h3 >
< p >
{ __ (
'Next we’ ll ask you to verify your business and payment details to enable deposits.' ,
'woocommerce'
) }
< / p >
< / div >
< div className = "subscriptions-page-onboarding-steps-item" >
< StepNumber > 3 < / StepNumber >
< h3 > { __ ( 'Create subscriptions' , 'woocommerce' ) } < / h3 >
< p >
{ __ (
'Finally, publish subscription products to offer on your store.' ,
'woocommerce'
) }
< / p >
< / div >
2022-05-03 04:10:18 +00:00
< / div >
2022-05-05 05:04:27 +00:00
< / >
) ;
const SubscriptionsPage = ( ) = > {
const [ hasError , setHasError ] = useState ( false ) ;
2022-05-10 05:43:47 +00:00
useEffect ( ( ) = > {
recordEvent ( 'wccore_subscriptions_empty_state_view' ) ;
} , [ ] ) ;
2022-05-05 05:04:27 +00:00
return (
< >
{ hasError && < ErrorNotice / > }
< div className = "subscriptions-page" >
< div className = "subscriptions" >
< Card className = "subscriptions__card" >
< CardBody >
< div className = "content" >
< MainContent setHasError = { setHasError } / >
< / div >
< / CardBody >
< / Card >
< Card className = "subscriptions__steps" >
< CardBody >
< OnboardingSteps / >
< / CardBody >
< / Card >
< / div >
< / div >
< / >
2022-05-03 04:10:18 +00:00
) ;
} ;
2022-04-26 05:22:01 +00:00
2022-04-22 06:11:24 +00:00
export default SubscriptionsPage ;