import { __ } from '@wordpress/i18n'; import { useState, useMemo } from '@wordpress/element'; import { Button, Icon } from '@wordpress/components'; import { useDispatch } from '@wordpress/data'; import { reusableBlock } from '@wordpress/icons'; import SettingsCard from '../../ReusableComponents/SettingsCard'; import TodoSettingsBlock from '../../ReusableComponents/SettingsBlocks/TodoSettingsBlock'; import FeatureSettingsBlock from '../../ReusableComponents/SettingsBlocks/FeatureSettingsBlock'; import { TITLE_BADGE_POSITIVE } from '../../ReusableComponents/TitleBadge'; import { useMerchantInfo } from '../../../data/common/hooks'; import { STORE_NAME } from '../../../data/common'; import Features from './TabSettingsElements/Blocks/Features'; const TabOverview = () => { const [ todos, setTodos ] = useState( [] ); const [ todosData, setTodosData ] = useState( todosDataDefault ); const [ isRefreshing, setIsRefreshing ] = useState( false ); const { merchantFeatures } = useMerchantInfo(); const { refreshFeatureStatuses, setActiveModal } = useDispatch( STORE_NAME ); // Get the features data with access to setActiveModal const featuresData = useMemo( () => Features.getFeatures( setActiveModal ), [ setActiveModal ] ); // Map merchant features status to our config const features = useMemo( () => { return featuresData.map( ( feature ) => { const merchantFeature = merchantFeatures?.[ feature.id ]; return { ...feature, enabled: merchantFeature?.enabled ?? false, }; } ); }, [ featuresData, merchantFeatures ] ); const refreshHandler = async () => { setIsRefreshing( true ); try { const result = await refreshFeatureStatuses(); if ( result && ! result.success ) { console.error( 'Failed to refresh features:', result.message || 'Unknown error' ); } } finally { setIsRefreshing( false ); } }; return (
{ todosData.length > 0 && ( ) }

{ __( 'Enable additional features and capabilities on your WooCommerce store.', 'woocommerce-paypal-payments' ) }

{ __( 'Click Refresh to update your current features after making changes.', 'woocommerce-paypal-payments' ) }

} contentItems={ features.map( ( feature ) => { return ( ! button.showWhen || // Learn more buttons ( feature.enabled && button.showWhen === 'enabled' ) || ( ! feature.enabled && button.showWhen === 'disabled' ) ) .map( ( button ) => ( { ...button, url: button.urls ? merchant?.isSandbox ? button.urls.sandbox : button.urls.live : button.url, } ) ), enabled: feature.enabled, notes: feature.notes, badge: feature.enabled ? { text: __( 'Active', 'woocommerce-paypal-payments' ), type: TITLE_BADGE_POSITIVE, } : undefined, } } /> ); } ) } /> , , ] } />
); }; // TODO: This list should be refactored into a separate module, maybe utils/thingsToDoNext.js 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' ), }, ]; export default TabOverview;