2025-01-20 16:37:39 +01:00
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
2025-01-02 13:55:32 +01:00
|
|
|
import { useState, useMemo } 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';
|
2025-01-09 13:04:34 +01:00
|
|
|
import { store as noticesStore } from '@wordpress/notices';
|
2024-12-17 15:04:26 +01:00
|
|
|
|
2025-01-23 13:28:57 +01:00
|
|
|
import {
|
|
|
|
TodoSettingsBlock,
|
|
|
|
FeatureSettingsBlock,
|
2025-01-23 19:59:45 +01:00
|
|
|
} from '../../../ReusableComponents/SettingsBlocks';
|
2025-01-20 16:37:39 +01:00
|
|
|
import SettingsCard from '../../../ReusableComponents/SettingsCard';
|
|
|
|
import { TITLE_BADGE_POSITIVE } from '../../../ReusableComponents/TitleBadge';
|
|
|
|
import { useMerchantInfo } from '../../../../data/common/hooks';
|
|
|
|
import { STORE_NAME } from '../../../../data/common';
|
2025-01-24 13:11:21 +01:00
|
|
|
import { getFeatures } from '../Components/Overview/features-config';
|
2025-01-23 19:59:45 +01:00
|
|
|
import { todosData } from '../todo-items';
|
|
|
|
|
2025-01-09 13:43:43 +01:00
|
|
|
import {
|
|
|
|
NOTIFICATION_ERROR,
|
|
|
|
NOTIFICATION_SUCCESS,
|
2025-01-20 16:37:39 +01:00
|
|
|
} from '../../../ReusableComponents/Icons';
|
2024-10-25 14:35:16 +02:00
|
|
|
|
2024-11-19 16:09:40 +01:00
|
|
|
const TabOverview = () => {
|
2025-01-24 13:07:32 +01:00
|
|
|
return (
|
|
|
|
<div className="ppcp-r-tab-overview">
|
|
|
|
{ todosData.length > 0 && (
|
|
|
|
<SettingsCard
|
|
|
|
className="ppcp-r-tab-overview-todo"
|
|
|
|
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'
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
<TodoSettingsBlock todosData={ todosData } />
|
|
|
|
</SettingsCard>
|
|
|
|
) }
|
|
|
|
|
|
|
|
<OverviewFeatures />
|
|
|
|
<OverviewHelp />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default TabOverview;
|
2024-12-16 13:12:38 +01:00
|
|
|
|
2025-01-24 13:07:32 +01:00
|
|
|
const OverviewFeatures = () => {
|
|
|
|
const [ isRefreshing, setIsRefreshing ] = useState( false );
|
2025-01-21 13:04:30 +01:00
|
|
|
const { merchant, features: merchantFeatures } = useMerchantInfo();
|
2025-01-02 13:55:32 +01:00
|
|
|
const { refreshFeatureStatuses, setActiveModal } =
|
|
|
|
useDispatch( STORE_NAME );
|
2025-01-09 13:43:43 +01:00
|
|
|
const { createSuccessNotice, createErrorNotice } =
|
|
|
|
useDispatch( noticesStore );
|
2024-12-16 13:12:38 +01:00
|
|
|
|
2025-01-02 13:55:32 +01:00
|
|
|
// Get the features data with access to setActiveModal
|
|
|
|
const featuresData = useMemo(
|
2025-01-24 13:10:20 +01:00
|
|
|
() => getFeatures( setActiveModal ),
|
2025-01-02 13:55:32 +01:00
|
|
|
[ setActiveModal ]
|
|
|
|
);
|
|
|
|
|
|
|
|
// Map merchant features status to our config
|
|
|
|
const features = useMemo( () => {
|
|
|
|
return featuresData.map( ( feature ) => {
|
2025-01-09 12:41:21 +01:00
|
|
|
const merchantFeature = merchantFeatures?.[ feature.id ];
|
2025-01-02 13:55:32 +01:00
|
|
|
return {
|
|
|
|
...feature,
|
|
|
|
enabled: merchantFeature?.enabled ?? false,
|
|
|
|
};
|
|
|
|
} );
|
2025-01-09 12:41:21 +01:00
|
|
|
}, [ featuresData, merchantFeatures ] );
|
2024-12-16 13:12:38 +01:00
|
|
|
|
|
|
|
const refreshHandler = async () => {
|
|
|
|
setIsRefreshing( true );
|
2025-01-24 13:07:32 +01:00
|
|
|
|
2025-01-02 13:55:32 +01:00
|
|
|
try {
|
|
|
|
const result = await refreshFeatureStatuses();
|
|
|
|
if ( result && ! result.success ) {
|
2025-01-21 15:49:34 +01:00
|
|
|
const errorMessage = sprintf(
|
|
|
|
/* translators: %s: error message */
|
|
|
|
__(
|
|
|
|
'Operation failed: %s Check WooCommerce logs for more details.',
|
|
|
|
'woocommerce-paypal-payments'
|
|
|
|
),
|
|
|
|
result.message ||
|
|
|
|
__( 'Unknown error', 'woocommerce-paypal-payments' )
|
|
|
|
);
|
2024-12-16 13:12:38 +01:00
|
|
|
|
2025-01-21 15:49:34 +01:00
|
|
|
createErrorNotice( errorMessage, {
|
|
|
|
icon: NOTIFICATION_ERROR,
|
|
|
|
} );
|
|
|
|
console.error(
|
|
|
|
'Failed to refresh features:',
|
|
|
|
result.message || 'Unknown error'
|
|
|
|
);
|
2025-01-10 12:39:29 +01:00
|
|
|
} else {
|
2025-01-21 15:49:34 +01:00
|
|
|
createSuccessNotice(
|
|
|
|
__(
|
|
|
|
'Features refreshed successfully.',
|
|
|
|
'woocommerce-paypal-payments'
|
|
|
|
),
|
|
|
|
{
|
|
|
|
icon: NOTIFICATION_SUCCESS,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
console.log( 'Features refreshed successfully.' );
|
|
|
|
}
|
2025-01-02 13:55:32 +01:00
|
|
|
} finally {
|
|
|
|
setIsRefreshing( false );
|
2024-12-16 13:12:38 +01:00
|
|
|
}
|
|
|
|
};
|
2024-10-25 14:35:16 +02:00
|
|
|
|
|
|
|
return (
|
2025-01-24 13:07:32 +01:00
|
|
|
<SettingsCard
|
|
|
|
className="ppcp-r-tab-overview-features"
|
|
|
|
title={ __( 'Features', 'woocommerce-paypal-payments' ) }
|
|
|
|
description={
|
|
|
|
<>
|
|
|
|
<p>
|
|
|
|
{ __(
|
|
|
|
'Enable additional features and capabilities on your WooCommerce store.',
|
2024-12-18 11:01:40 +01:00
|
|
|
'woocommerce-paypal-payments'
|
|
|
|
) }
|
2025-01-24 13:07:32 +01:00
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
{ __(
|
|
|
|
'Click Refresh to update your current features after making changes.',
|
2024-12-18 11:01:40 +01:00
|
|
|
'woocommerce-paypal-payments'
|
|
|
|
) }
|
2025-01-24 13:07:32 +01:00
|
|
|
</p>
|
|
|
|
<Button
|
|
|
|
variant="tertiary"
|
|
|
|
onClick={ refreshHandler }
|
|
|
|
disabled={ isRefreshing }
|
|
|
|
>
|
|
|
|
<Icon icon={ reusableBlock } size={ 18 } />
|
|
|
|
{ isRefreshing
|
|
|
|
? __( 'Refreshing…', 'woocommerce-paypal-payments' )
|
|
|
|
: __( 'Refresh', 'woocommerce-paypal-payments' ) }
|
|
|
|
</Button>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
contentItems={ features.map( ( feature ) => {
|
|
|
|
return (
|
2024-12-18 11:01:40 +01:00
|
|
|
<FeatureSettingsBlock
|
2025-01-24 13:07:32 +01:00
|
|
|
key={ feature.id }
|
|
|
|
title={ feature.title }
|
|
|
|
description={ feature.description }
|
2024-12-18 11:01:40 +01:00
|
|
|
actionProps={ {
|
2025-01-24 13:07:32 +01:00
|
|
|
buttons: feature.buttons
|
|
|
|
.filter(
|
|
|
|
( button ) =>
|
|
|
|
! 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,
|
|
|
|
} ) ),
|
|
|
|
isBusy: isRefreshing,
|
|
|
|
enabled: feature.enabled,
|
|
|
|
notes: feature.notes,
|
|
|
|
badge: feature.enabled
|
|
|
|
? {
|
|
|
|
text: __(
|
|
|
|
'Active',
|
|
|
|
'woocommerce-paypal-payments'
|
|
|
|
),
|
|
|
|
type: TITLE_BADGE_POSITIVE,
|
|
|
|
}
|
|
|
|
: undefined,
|
2024-12-18 11:01:40 +01:00
|
|
|
} }
|
2025-01-24 13:07:32 +01:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
/>
|
2024-10-25 14:35:16 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2025-01-24 13:07:32 +01:00
|
|
|
const OverviewHelp = () => {
|
|
|
|
return (
|
|
|
|
<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: 'https://woocommerce.com/document/woocommerce-paypal-payments/ ',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
} }
|
|
|
|
/>,
|
|
|
|
<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: 'https://woocommerce.com/document/woocommerce-paypal-payments/#get-help ',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
} }
|
|
|
|
/>,
|
|
|
|
] }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|