2021-09-21 19:33:44 +00:00
/ * *
* External dependencies
* /
import { _ _ } from '@wordpress/i18n' ;
2022-02-21 02:34:25 +00:00
import interpolateComponents from '@automattic/interpolate-components' ;
2021-09-21 19:33:44 +00:00
import { Link , Pill } from '@woocommerce/components' ;
import { recordEvent } from '@woocommerce/tracks' ;
import { Text } from '@woocommerce/experimental' ;
import {
WCPayCard ,
WCPayCardHeader ,
WCPayCardFooter ,
WCPayCardBody ,
SetupRequired ,
} from '@woocommerce/onboarding' ;
2022-02-28 19:40:45 +00:00
import { useDispatch } from '@wordpress/data' ;
2021-09-21 19:33:44 +00:00
/ * *
* Internal dependencies
* /
import { Action } from '../Action' ;
2022-02-28 19:40:45 +00:00
import { connectWcpay } from './utils' ;
2021-09-21 19:33:44 +00:00
const TosPrompt = ( ) =>
interpolateComponents ( {
mixedString : _ _ (
'Upon clicking "Get started", you agree to the {{link}}Terms of service{{/link}}. Next we’ ll ask you to share a few details about your business to create your account.' ,
2022-03-30 09:00:04 +00:00
'woocommerce'
2021-09-21 19:33:44 +00:00
) ,
components : {
link : (
< Link
href = { 'https://wordpress.com/tos/' }
target = "_blank"
type = "external"
/ >
) ,
} ,
} ) ;
export const Suggestion = ( { paymentGateway , onSetupCallback = null } ) => {
const {
description ,
id ,
needsSetup ,
installed ,
enabled : isEnabled ,
installed : isInstalled ,
} = paymentGateway ;
2022-02-28 19:40:45 +00:00
const { createNotice } = useDispatch ( 'core/notices' ) ;
// When the WC Pay is installed and onSetupCallback is null
// Overwrite onSetupCallback to redirect to the setup page
// when the user clicks on the "Finish setup" button.
// WC Pay doesn't need to be configured in WCA.
// It should be configured in its onboarding flow.
if ( installed && onSetupCallback === null ) {
onSetupCallback = ( ) => {
connectWcpay ( createNotice ) ;
} ;
}
2021-09-21 19:33:44 +00:00
return (
< WCPayCard >
< WCPayCardHeader >
{ installed && needsSetup ? (
< SetupRequired / >
) : (
2022-03-30 09:00:04 +00:00
< Pill > { _ _ ( 'Recommended' , 'woocommerce' ) } < / P i l l >
2021-09-21 19:33:44 +00:00
) }
< / W C P a y C a r d H e a d e r >
< WCPayCardBody
description = { description }
onLinkClick = { ( ) => {
recordEvent ( 'tasklist_payment_learn_more' ) ;
} }
/ >
< WCPayCardFooter >
< >
< Text lineHeight = "1.5em" >
< TosPrompt / >
< / T e x t >
< Action
id = { id }
hasSetup = { true }
needsSetup = { needsSetup }
isEnabled = { isEnabled }
isRecommended = { true }
isInstalled = { isInstalled }
hasPlugins = { true }
2022-03-30 09:00:04 +00:00
setupButtonText = { _ _ ( 'Get started' , 'woocommerce' ) }
2021-09-21 19:33:44 +00:00
onSetupCallback = { onSetupCallback }
/ >
< / >
< / W C P a y C a r d F o o t e r >
< / W C P a y C a r d >
) ;
} ;