mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Merge pull request #2971 from woocommerce/fix/PCP-4072
Success and error messages for "Refresh" button
This commit is contained in:
commit
a2abcc5f72
2 changed files with 38 additions and 5 deletions
|
@ -24,6 +24,7 @@ const FeatureSettingsBlock = ( { title, description, ...props } ) => {
|
||||||
<Button
|
<Button
|
||||||
className={ button.class ? button.class : '' }
|
className={ button.class ? button.class : '' }
|
||||||
key={ button.text }
|
key={ button.text }
|
||||||
|
isBusy={ props.actionProps?.isBusy }
|
||||||
variant={ button.type }
|
variant={ button.type }
|
||||||
onClick={ button.onClick }
|
onClick={ button.onClick }
|
||||||
>
|
>
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { useState, useMemo } from '@wordpress/element';
|
||||||
import { Button, Icon } from '@wordpress/components';
|
import { Button, Icon } from '@wordpress/components';
|
||||||
import { useDispatch } from '@wordpress/data';
|
import { useDispatch } from '@wordpress/data';
|
||||||
import { reusableBlock } from '@wordpress/icons';
|
import { reusableBlock } from '@wordpress/icons';
|
||||||
|
import { store as noticesStore } from '@wordpress/notices';
|
||||||
|
|
||||||
import SettingsCard from '../../ReusableComponents/SettingsCard';
|
import SettingsCard from '../../ReusableComponents/SettingsCard';
|
||||||
import TodoSettingsBlock from '../../ReusableComponents/SettingsBlocks/TodoSettingsBlock';
|
import TodoSettingsBlock from '../../ReusableComponents/SettingsBlocks/TodoSettingsBlock';
|
||||||
|
@ -12,6 +13,10 @@ import { useMerchantInfo } from '../../../data/common/hooks';
|
||||||
import { STORE_NAME } from '../../../data/common';
|
import { STORE_NAME } from '../../../data/common';
|
||||||
import Features from './TabSettingsElements/Blocks/Features';
|
import Features from './TabSettingsElements/Blocks/Features';
|
||||||
import { todosData } from '../../../data/settings/tab-overview-todos-data';
|
import { todosData } from '../../../data/settings/tab-overview-todos-data';
|
||||||
|
import {
|
||||||
|
NOTIFICATION_ERROR,
|
||||||
|
NOTIFICATION_SUCCESS,
|
||||||
|
} from '../../ReusableComponents/Icons';
|
||||||
|
|
||||||
const TabOverview = () => {
|
const TabOverview = () => {
|
||||||
const [ isRefreshing, setIsRefreshing ] = useState( false );
|
const [ isRefreshing, setIsRefreshing ] = useState( false );
|
||||||
|
@ -19,6 +24,8 @@ const TabOverview = () => {
|
||||||
const { merchant, merchantFeatures } = useMerchantInfo();
|
const { merchant, merchantFeatures } = useMerchantInfo();
|
||||||
const { refreshFeatureStatuses, setActiveModal } =
|
const { refreshFeatureStatuses, setActiveModal } =
|
||||||
useDispatch( STORE_NAME );
|
useDispatch( STORE_NAME );
|
||||||
|
const { createSuccessNotice, createErrorNotice } =
|
||||||
|
useDispatch( noticesStore );
|
||||||
|
|
||||||
// Get the features data with access to setActiveModal
|
// Get the features data with access to setActiveModal
|
||||||
const featuresData = useMemo(
|
const featuresData = useMemo(
|
||||||
|
@ -42,11 +49,35 @@ const TabOverview = () => {
|
||||||
try {
|
try {
|
||||||
const result = await refreshFeatureStatuses();
|
const result = await refreshFeatureStatuses();
|
||||||
if ( result && ! result.success ) {
|
if ( result && ! result.success ) {
|
||||||
console.error(
|
const errorMessage = sprintf(
|
||||||
'Failed to refresh features:',
|
/* translators: %s: error message */
|
||||||
result.message || 'Unknown error'
|
__(
|
||||||
);
|
'Operation failed: %s Check WooCommerce logs for more details.',
|
||||||
}
|
'woocommerce-paypal-payments'
|
||||||
|
),
|
||||||
|
result.message ||
|
||||||
|
__( 'Unknown error', 'woocommerce-paypal-payments' )
|
||||||
|
);
|
||||||
|
|
||||||
|
createErrorNotice( errorMessage, {
|
||||||
|
icon: NOTIFICATION_ERROR,
|
||||||
|
} );
|
||||||
|
console.error(
|
||||||
|
'Failed to refresh features:',
|
||||||
|
result.message || 'Unknown error'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
createSuccessNotice(
|
||||||
|
__(
|
||||||
|
'Features refreshed successfully.',
|
||||||
|
'woocommerce-paypal-payments'
|
||||||
|
),
|
||||||
|
{
|
||||||
|
icon: NOTIFICATION_SUCCESS,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
console.log( 'Features refreshed successfully.' );
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setIsRefreshing( false );
|
setIsRefreshing( false );
|
||||||
}
|
}
|
||||||
|
@ -130,6 +161,7 @@ const TabOverview = () => {
|
||||||
: button.urls.live
|
: button.urls.live
|
||||||
: button.url,
|
: button.url,
|
||||||
} ) ),
|
} ) ),
|
||||||
|
isBusy: isRefreshing,
|
||||||
enabled: feature.enabled,
|
enabled: feature.enabled,
|
||||||
notes: feature.notes,
|
notes: feature.notes,
|
||||||
badge: feature.enabled
|
badge: feature.enabled
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue