2024-10-25 14:35:16 +02:00
import SettingsCard from '../../ReusableComponents/SettingsCard' ;
import { _ _ } from '@wordpress/i18n' ;
import {
PayPalCheckbox ,
handleCheckboxState ,
} from '../../ReusableComponents/Fields' ;
import { useState } from '@wordpress/element' ;
import data from '../../../utils/data' ;
2024-10-28 12:26:13 +01:00
import { Button } from '@wordpress/components' ;
import TitleBadge , {
TITLE _BADGE _NEGATIVE ,
TITLE _BADGE _POSITIVE ,
} from '../../ReusableComponents/TitleBadge' ;
2024-11-11 14:02:49 +01:00
import ConnectionInfo , {
connectionStatusDataDefault ,
} from '../../ReusableComponents/ConnectionInfo' ;
2024-10-25 14:35:16 +02:00
const TabDashboard = ( ) => {
const [ todos , setTodos ] = useState ( [ ] ) ;
const [ todosData , setTodosData ] = useState ( todosDataDefault ) ;
return (
< div className = "ppcp-r-tab-dashboard" >
2024-10-28 12:26:13 +01:00
{ todosData . length > 0 && (
< SettingsCard
className = "ppcp-r-tab-dashboard-todo"
icon = "icon-dashboard-list.svg"
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'
) }
>
< div className = "ppcp-r-todo-items" >
{ todosData . map ( ( todo ) => (
< TodoItem
name = "todo_items"
key = { todo . value }
value = { todo . value }
currentValue = { todos }
changeCallback = { setTodos }
description = { todo . description }
changeTodos = { setTodosData }
todosData = { todosData }
/ >
) ) }
< / d i v >
< / S e t t i n g s C a r d >
) }
2024-10-25 14:35:16 +02:00
< SettingsCard
className = "ppcp-r-tab-dashboard-support"
icon = "icon-dashboard-support.svg"
title = { _ _ ( 'Status' , 'woocommerce-paypal-payments' ) }
description = { _ _ (
'Your PayPal account connection details, along with available products and features.' ,
'woocommerce-paypal-payments'
) }
>
2024-10-28 12:26:13 +01:00
< ConnectionStatus
2024-11-11 14:02:49 +01:00
connectionData = { connectionStatusDataDefault }
2024-10-28 12:26:13 +01:00
/ >
< FeaturesRefresh / >
2024-10-25 14:35:16 +02:00
{ featuresDefault . map ( ( feature ) => {
return (
2024-10-28 12:26:13 +01:00
< FeatureItem key = { feature . id } feature = { feature } / >
2024-10-25 14:35:16 +02:00
) ;
} ) }
< / S e t t i n g s C a r d >
< / d i v >
) ;
} ;
2024-11-11 14:02:49 +01:00
const ConnectionStatus = ( { connectionData } ) => {
2024-10-28 12:26:13 +01:00
return (
< div className = "ppcp-r-connection-status" >
< div className = "ppcp-r-connection-status__status" >
< div className = "ppcp-r-connection-status__status-status" >
< strong >
{ _ _ ( 'Connection' , 'woocommerce-paypal-payments' ) }
< / s t r o n g >
{ connectionData . connectionStatus ? (
< TitleBadge
type = { TITLE _BADGE _POSITIVE }
text = { _ _ (
'Activated' ,
'woocommerce-paypal-payments'
) }
/ >
) : (
< TitleBadge
type = { TITLE _BADGE _NEGATIVE }
text = { _ _ (
'Not Activated' ,
'woocommerce-paypal-payments'
) }
/ >
) }
< / d i v >
< div className = "ppcp-r-connection-status__status-label" >
< span >
{ _ _ (
'PayPal Account Details' ,
'woocommerce-paypal-payments'
) }
< / s p a n >
< / d i v >
< / d i v >
{ connectionData . connectionStatus && (
2024-11-11 14:02:49 +01:00
< ConnectionInfo
connectionStatusDataDefault = { connectionStatusDataDefault }
/ >
2024-10-28 12:26:13 +01:00
) }
< / d i v >
) ;
} ;
const FeaturesRefresh = ( ) => {
return (
< div className = "ppcp-r-feature-refresh" >
< div className = "ppcp-r-feature-refresh__content" >
< span className = "ppcp-r-feature-refresh__content-title" >
{ _ _ ( 'Features' , 'woocommerce-paypal-payments' ) }
< / s p a n >
< p >
{ _ _ (
'After making changes to your PayPal account, click Refresh to update your store features.' ,
'woocommerce-paypal-payments'
) }
< / p >
< / d i v >
< Button variant = "tertiary" >
{ data ( ) . getImage ( 'icon-refresh.svg' ) }
{ _ _ ( 'Refresh' , 'woocommerce-paypal-payments' ) }
< / B u t t o n >
< / d i v >
) ;
} ;
2024-10-25 14:35:16 +02:00
const TodoItem = ( props ) => {
return (
< div className = "ppcp-r-todo-item" >
< div className = "ppcp-r-todo-item__inner" >
< PayPalCheckbox
{ ... {
... props ,
handleCheckboxState ,
} }
/ > { ' ' }
< p > { props . description } < / p >
< / d i v >
< div
className = "ppcp-r-todo-item__close"
onClick = { ( ) =>
removeTodo (
props . value ,
props . todosData ,
props . changeTodos
)
}
>
{ data ( ) . getImage ( 'icon-close.svg' ) }
< / d i v >
< / d i v >
) ;
} ;
2024-10-28 12:26:13 +01:00
const FeatureItem = ( { feature } ) => {
const printNotes = ( ) => {
if ( ! feature ? . notes ) {
return null ;
}
if ( Array . isArray ( feature . notes ) && feature . notes . length === 0 ) {
return null ;
}
return (
< >
< br / >
< br / >
< span className = "ppcp-r-feature-item__notes" >
{ feature . notes . map ( ( note , index ) => {
return < span key = { index } > { note } < / s p a n > ;
} ) }
< / s p a n >
< / >
) ;
} ;
2024-10-25 14:35:16 +02:00
return (
< div className = "ppcp-r-feature-item" >
< span className = "ppcp-r-feature-item__title" >
2024-10-28 12:26:13 +01:00
{ feature . title }
{ feature ? . featureStatus && (
< TitleBadge
text = { _ _ (
'Activated' ,
'woocommerce-paypal-payments'
) }
type = { TITLE _BADGE _POSITIVE }
/ >
2024-10-25 14:35:16 +02:00
) }
< / s p a n >
< p className = "ppcp-r-feature-item__description" >
2024-10-28 12:26:13 +01:00
{ feature . description }
{ printNotes ( ) }
2024-10-25 14:35:16 +02:00
< / p >
< div className = "ppcp-r-feature-item__buttons" >
2024-10-28 12:26:13 +01:00
{ feature . buttons . map ( ( button ) => {
2024-10-25 14:35:16 +02:00
return (
2024-10-28 12:26:13 +01:00
< Button
href = { button . url }
key = { button . text }
variant = { button . type }
>
2024-10-25 14:35:16 +02:00
{ button . text }
< / B u t t o n >
) ;
} ) }
< / d i v >
< / d i v >
) ;
} ;
const removeTodo = ( todoValue , todosData , changeTodos ) => {
changeTodos ( todosData . filter ( ( todo ) => todo . value !== todoValue ) ) ;
} ;
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'
) ,
} ,
] ;
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 : [
{
type : 'primary' ,
text : _ _ ( 'Configure' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
{
type : 'secondary' ,
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'
) ,
2024-10-28 12:26:13 +01:00
featureStatus : true ,
2024-10-25 14:35:16 +02:00
description : _ _ (
'Process major credit and debit cards including Visa, Mastercard, American Express and Discover.' ,
'woocommerce-paypal-payments'
) ,
buttons : [
{
type : 'primary' ,
text : _ _ ( 'Configure' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
{
type : 'secondary' ,
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 : [
{
type : 'primary' ,
text : _ _ ( 'Apply' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
{
type : 'secondary' ,
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'
) ,
2024-10-28 12:26:13 +01:00
featureStatus : true ,
2024-10-25 14:35:16 +02:00
buttons : [
{
type : 'primary' ,
text : _ _ ( 'Configure' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
{
type : 'secondary' ,
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 : [
{
type : 'primary' ,
text : _ _ (
'Domain registration' ,
'woocommerce-paypal-payments'
) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
{
type : 'secondary' ,
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 : [
{
type : 'primary' ,
text : _ _ ( 'Configure' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
{
type : 'secondary' ,
text : _ _ ( 'Learn more' , 'woocommerce-paypal-payments' ) ,
2024-10-28 12:26:13 +01:00
url : '#' ,
2024-10-25 14:35:16 +02:00
} ,
] ,
} ,
] ;
export default TabDashboard ;