2024-10-25 14:35:16 +02:00
import { _ _ } from '@wordpress/i18n' ;
import { useState } from '@wordpress/element' ;
2024-12-17 15:04:26 +01:00
import { Button , Icon } from '@wordpress/components' ;
import { useDispatch } from '@wordpress/data' ;
import { reusableBlock } from '@wordpress/icons' ;
2024-12-08 09:33:49 +01:00
import SettingsCard from '../../ReusableComponents/SettingsCard' ;
import TodoSettingsBlock from '../../ReusableComponents/SettingsBlocks/TodoSettingsBlock' ;
import FeatureSettingsBlock from '../../ReusableComponents/SettingsBlocks/FeatureSettingsBlock' ;
import { TITLE _BADGE _POSITIVE } from '../../ReusableComponents/TitleBadge' ;
2024-12-16 13:12:38 +01:00
import { useMerchantInfo } from '../../../data/common/hooks' ;
import { STORE _NAME } from '../../../data/common' ;
2024-10-25 14:35:16 +02:00
2024-11-19 16:09:40 +01:00
const TabOverview = ( ) => {
2024-10-25 14:35:16 +02:00
const [ todos , setTodos ] = useState ( [ ] ) ;
const [ todosData , setTodosData ] = useState ( todosDataDefault ) ;
2024-12-16 13:12:38 +01:00
const [ isRefreshing , setIsRefreshing ] = useState ( false ) ;
const { merchant } = useMerchantInfo ( ) ;
const { refreshFeatureStatuses } = useDispatch ( STORE _NAME ) ;
const features = featuresDefault . map ( ( feature ) => {
const merchantFeature = merchant ? . features ? . [ feature . id ] ;
return {
... feature ,
enabled : merchantFeature ? . enabled ? ? false ,
} ;
} ) ;
const refreshHandler = async ( ) => {
setIsRefreshing ( true ) ;
const result = await refreshFeatureStatuses ( ) ;
2024-12-17 15:05:05 +01:00
// TODO: Implement the refresh logic, remove this debug code -- PCP-4024
2024-12-16 13:12:38 +01:00
if ( result && ! result . success ) {
console . error (
'Failed to refresh features:' ,
result . message || 'Unknown error'
) ;
} else {
console . log ( 'Features refreshed successfully.' ) ;
}
setIsRefreshing ( false ) ;
} ;
2024-10-25 14:35:16 +02:00
return (
2024-11-19 16:09:40 +01:00
< div className = "ppcp-r-tab-overview" >
2024-10-28 12:26:13 +01:00
{ todosData . length > 0 && (
< SettingsCard
2024-11-19 16:09:40 +01:00
className = "ppcp-r-tab-overview-todo"
2024-10-28 12:26:13 +01:00
title = { _ _ (
'Things to do next' ,
'woocommerce-paypal-payments'
) }
description = { _ _ (
'Complete these tasks to keep your store updated with the latest products and services.' ,
'woocommerce-paypal-payments'
) }
>
2024-12-08 09:33:49 +01:00
< TodoSettingsBlock
todos = { todos }
setTodos = { setTodos }
todosData = { todosData }
setTodosData = { setTodosData }
/ >
2024-10-28 12:26:13 +01:00
< / S e t t i n g s C a r d >
) }
2024-10-25 14:35:16 +02:00
2024-12-08 09:33:49 +01:00
< SettingsCard
className = "ppcp-r-tab-overview-features"
title = { _ _ ( 'Features' , 'woocommerce-paypal-payments' ) }
description = {
2024-12-18 11:01:40 +01:00
< >
2024-12-16 13:12:38 +01:00
< p >
{ _ _ (
2024-12-18 11:01:40 +01:00
'Enable additional features and capabilities on your WooCommerce store.' ,
2024-12-16 13:12:38 +01:00
'woocommerce-paypal-payments'
) }
< / p >
< p >
{ _ _ (
2024-12-18 11:01:40 +01:00
'Click Refresh to update your current features after making changes.' ,
2024-12-16 13:12:38 +01:00
'woocommerce-paypal-payments'
) }
< / p >
< Button
variant = "tertiary"
onClick = { refreshHandler }
disabled = { isRefreshing }
>
2024-12-17 15:04:26 +01:00
< Icon icon = { reusableBlock } size = { 18 } / >
2024-12-16 13:12:38 +01:00
{ isRefreshing
? _ _ (
'Refreshing…' ,
'woocommerce-paypal-payments'
)
: _ _ (
'Refresh' ,
'woocommerce-paypal-payments'
) }
2024-12-08 09:33:49 +01:00
< / B u t t o n >
2024-12-18 11:01:40 +01:00
< / >
2024-10-25 14:35:16 +02:00
}
2024-12-16 13:12:38 +01:00
contentItems = { features . map ( ( feature ) => (
2024-12-08 09:33:49 +01:00
< FeatureSettingsBlock
key = { feature . id }
title = { feature . title }
description = { feature . description }
actionProps = { {
buttons : feature . buttons ,
2024-12-16 13:12:38 +01:00
enabled : feature . enabled ,
2024-12-08 09:33:49 +01:00
notes : feature . notes ,
2024-12-16 13:12:38 +01:00
badge : feature . enabled
? {
text : _ _ (
'Active' ,
'woocommerce-paypal-payments'
) ,
type : TITLE _BADGE _POSITIVE ,
}
: undefined ,
2024-12-08 09:33:49 +01:00
} }
2024-10-28 12:26:13 +01:00
/ >
2024-12-08 09:33:49 +01:00
) ) }
/ >
2024-12-18 11:01:40 +01:00
< SettingsCard
className = "ppcp-r-tab-overview-help"
title = { _ _ ( 'Help Center' , 'woocommerce-paypal-payments' ) }
description = { _ _ (
'Access detailed guides and responsive support to streamline setup and enhance your experience.' ,
'woocommerce-paypal-payments'
) }
contentItems = { [
< FeatureSettingsBlock
key = "documentation"
title = { _ _ (
'Documentation' ,
'woocommerce-paypal-payments'
) }
description = { _ _ (
'Find detailed guides and resources to help you set up, manage, and optimize your PayPal integration.' ,
'woocommerce-paypal-payments'
) }
actionProps = { {
buttons : [
{
type : 'tertiary' ,
text : _ _ (
'View full documentation' ,
'woocommerce-paypal-payments'
) ,
url : '#' ,
} ,
] ,
} }
/ > ,
< FeatureSettingsBlock
key = "support"
title = { _ _ ( 'Support' , 'woocommerce-paypal-payments' ) }
description = { _ _ (
'Need help? Access troubleshooting tips or contact our support team for personalized assistance.' ,
'woocommerce-paypal-payments'
) }
actionProps = { {
buttons : [
{
type : 'tertiary' ,
text : _ _ (
'View support options' ,
'woocommerce-paypal-payments'
) ,
url : '#' ,
} ,
] ,
} }
/ > ,
] }
/ >
2024-10-25 14:35:16 +02:00
< / d i v >
) ;
} ;
2024-12-17 15:05:05 +01:00
// TODO: This list should be refactored into a separate module, maybe utils/thingsToDoNext.js
2024-10-25 14:35:16 +02:00
const todosDataDefault = [
{
value : 'paypal_later_messaging' ,
description : _ _ (
'Enable Pay Later messaging' ,
'woocommerce-paypal-payments'
) ,
} ,
{
value : 'capture_authorized_payments' ,
description : _ _ (
'Capture authorized payments' ,
'woocommerce-paypal-payments'
) ,
} ,
{
value : 'enable_google_pay' ,
description : _ _ ( 'Enable Google Pay' , 'woocommerce-paypal-payments' ) ,
} ,
{
value : 'paypal_shortcut' ,
description : _ _ (
'Add PayPal shortcut to the Cart page' ,
'woocommerce-paypal-payments'
) ,
} ,
{
value : 'advanced_cards' ,
description : _ _ (
'Add Advanced Cards to Blocks Checkout' ,
'woocommerce-paypal-payments'
) ,
} ,
] ;
2024-12-17 15:05:05 +01:00
// TODO: Hardcoding this list here is not the best idea. Can we move this to a REST API response?
2024-10-25 14:35:16 +02:00
const featuresDefault = [
{
id : 'save_paypal_and_venmo' ,
title : _ _ ( 'Save PayPal and Venmo' , 'woocommerce-paypal-payments' ) ,
description : _ _ (
'Securely save PayPal and Venmo payment methods for subscriptions or return buyers.' ,
'woocommerce-paypal-payments'
) ,
buttons : [
{
2024-12-08 09:33:49 +01:00
type : 'secondary' ,
2024-10-25 14:35:16 +02:00
text : _ _ ( 'Configure' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
{
2024-12-08 09:33:49 +01:00
type : 'tertiary' ,
2024-10-25 14:35:16 +02:00
text : _ _ ( 'Learn more' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
] ,
} ,
{
id : 'advanced_credit_and_debit_cards' ,
title : _ _ (
'Advanced Credit and Debit Cards' ,
'woocommerce-paypal-payments'
) ,
description : _ _ (
'Process major credit and debit cards including Visa, Mastercard, American Express and Discover.' ,
'woocommerce-paypal-payments'
) ,
buttons : [
{
2024-12-08 09:33:49 +01:00
type : 'secondary' ,
2024-10-25 14:35:16 +02:00
text : _ _ ( 'Configure' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
{
2024-12-08 09:33:49 +01:00
type : 'tertiary' ,
2024-10-25 14:35:16 +02:00
text : _ _ ( 'Learn more' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
] ,
} ,
{
id : 'alternative_payment_methods' ,
title : _ _ (
'Alternative Payment Methods' ,
'woocommerce-paypal-payments'
) ,
description : _ _ (
'Offer global, country-specific payment options for your customers.' ,
'woocommerce-paypal-payments'
) ,
buttons : [
{
2024-12-08 09:33:49 +01:00
type : 'secondary' ,
2024-10-25 14:35:16 +02:00
text : _ _ ( 'Apply' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
{
2024-12-08 09:33:49 +01:00
type : 'tertiary' ,
2024-10-25 14:35:16 +02:00
text : _ _ ( 'Learn more' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
] ,
} ,
{
id : 'google_pay' ,
title : _ _ ( 'Google Pay' , 'woocommerce-paypal-payments' ) ,
description : _ _ (
'Let customers pay using their Google Pay wallet.' ,
'woocommerce-paypal-payments'
) ,
buttons : [
{
2024-12-08 09:33:49 +01:00
type : 'secondary' ,
2024-10-25 14:35:16 +02:00
text : _ _ ( 'Configure' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
{
2024-12-08 09:33:49 +01:00
type : 'tertiary' ,
2024-10-25 14:35:16 +02:00
text : _ _ ( 'Learn more' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
] ,
2024-10-28 12:26:13 +01:00
notes : [
_ _ ( '¹PayPal Q2 Earnings-2021.' , 'woocommerce-paypal-payments' ) ,
] ,
2024-10-25 14:35:16 +02:00
} ,
{
id : 'apple_pay' ,
title : _ _ ( 'Apple Pay' , 'woocommerce-paypal-payments' ) ,
description : _ _ (
'Let customers pay using their Apple Pay wallet.' ,
'woocommerce-paypal-payments'
) ,
buttons : [
{
2024-12-08 09:33:49 +01:00
type : 'secondary' ,
2024-10-25 14:35:16 +02:00
text : _ _ (
'Domain registration' ,
'woocommerce-paypal-payments'
) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
{
2024-12-08 09:33:49 +01:00
type : 'tertiary' ,
2024-10-25 14:35:16 +02:00
text : _ _ ( 'Learn more' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
] ,
} ,
{
id : 'pay_later_messaging' ,
title : _ _ ( 'Pay Later Messaging' , 'woocommerce-paypal-payments' ) ,
description : _ _ (
'Let customers know they can buy now and pay later with PayPal. Adding this messaging can boost conversion rates and increase cart sizes by 39%¹, with no extra cost to you—plus, you get paid up front.' ,
'woocommerce-paypal-payments'
) ,
buttons : [
{
2024-12-08 09:33:49 +01:00
type : 'secondary' ,
2024-10-25 14:35:16 +02:00
text : _ _ ( 'Configure' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
{
2024-12-08 09:33:49 +01:00
type : 'tertiary' ,
2024-10-25 14:35:16 +02:00
text : _ _ ( 'Learn more' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
] ,
} ,
] ;
2024-12-08 09:33:49 +01:00
2024-11-19 16:09:40 +01:00
export default TabOverview ;