mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Merge pull request #2928 from woocommerce/PCP-3931-resolve-merge-conflicts
Implement logic for Feature-Refresh button, fix (3931)
This commit is contained in:
commit
24fb109f0d
4 changed files with 61 additions and 93 deletions
|
@ -11,56 +11,42 @@ const FeatureSettingsBlock = ( { title, description, ...props } ) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<span className="ppcp-r-feature-item__notes">
|
||||||
<span className="ppcp-r-feature-item__notes">
|
{ notes.map( ( note, index ) => (
|
||||||
{ notes.map( ( note, index ) => (
|
<span key={ index }>{ note }</span>
|
||||||
<span key={ index }>{ note }</span>
|
) ) }
|
||||||
) ) }
|
</span>
|
||||||
</span>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingsBlock
|
<SettingsBlock { ...props } className="ppcp-r-settings-block__feature">
|
||||||
{ ...props }
|
<Header>
|
||||||
className="ppcp-r-settings-block__feature"
|
<Title>
|
||||||
components={ [
|
{ title }
|
||||||
() => (
|
{ props.actionProps?.enabled && (
|
||||||
<>
|
<TitleBadge { ...props.actionProps?.badge } />
|
||||||
<Header>
|
) }
|
||||||
<Title>
|
</Title>
|
||||||
{ title }
|
<Description className="ppcp-r-settings-block__feature__description">
|
||||||
{ props.actionProps?.enabled && (
|
{ description }
|
||||||
<TitleBadge
|
{ printNotes() }
|
||||||
{ ...props.actionProps?.badge }
|
</Description>
|
||||||
/>
|
</Header>
|
||||||
) }
|
<Action>
|
||||||
</Title>
|
<div className="ppcp-r-feature-item__buttons">
|
||||||
<Description className="ppcp-r-settings-block__feature__description">
|
{ props.actionProps?.buttons.map( ( button ) => (
|
||||||
{ description }
|
<Button
|
||||||
{ printNotes() }
|
href={ button.url }
|
||||||
</Description>
|
key={ button.text }
|
||||||
</Header>
|
variant={ button.type }
|
||||||
<Action>
|
>
|
||||||
<div className="ppcp-r-feature-item__buttons">
|
{ button.text }
|
||||||
{ props.actionProps?.buttons.map(
|
</Button>
|
||||||
( button ) => (
|
) ) }
|
||||||
<Button
|
</div>
|
||||||
href={ button.url }
|
</Action>
|
||||||
key={ button.text }
|
</SettingsBlock>
|
||||||
variant={ button.type }
|
|
||||||
>
|
|
||||||
{ button.text }
|
|
||||||
</Button>
|
|
||||||
)
|
|
||||||
) }
|
|
||||||
</div>
|
|
||||||
</Action>
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
] }
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { useState } from '@wordpress/element';
|
import { useState } from '@wordpress/element';
|
||||||
import { Button } from '@wordpress/components';
|
import { Button, Icon } from '@wordpress/components';
|
||||||
|
import { useDispatch } from '@wordpress/data';
|
||||||
|
import { reusableBlock } from '@wordpress/icons';
|
||||||
|
|
||||||
import SettingsCard from '../../ReusableComponents/SettingsCard';
|
import SettingsCard from '../../ReusableComponents/SettingsCard';
|
||||||
import TodoSettingsBlock from '../../ReusableComponents/SettingsBlocks/TodoSettingsBlock';
|
import TodoSettingsBlock from '../../ReusableComponents/SettingsBlocks/TodoSettingsBlock';
|
||||||
import FeatureSettingsBlock from '../../ReusableComponents/SettingsBlocks/FeatureSettingsBlock';
|
import FeatureSettingsBlock from '../../ReusableComponents/SettingsBlocks/FeatureSettingsBlock';
|
||||||
import { TITLE_BADGE_POSITIVE } from '../../ReusableComponents/TitleBadge';
|
import { TITLE_BADGE_POSITIVE } from '../../ReusableComponents/TitleBadge';
|
||||||
import data from '../../../utils/data';
|
|
||||||
import { useMerchantInfo } from '../../../data/common/hooks';
|
import { useMerchantInfo } from '../../../data/common/hooks';
|
||||||
import { useDispatch } from '@wordpress/data';
|
|
||||||
import { STORE_NAME } from '../../../data/common';
|
import { STORE_NAME } from '../../../data/common';
|
||||||
|
|
||||||
const TabOverview = () => {
|
const TabOverview = () => {
|
||||||
|
@ -31,6 +32,7 @@ const TabOverview = () => {
|
||||||
|
|
||||||
const result = await refreshFeatureStatuses();
|
const result = await refreshFeatureStatuses();
|
||||||
|
|
||||||
|
// TODO: Implement the refresh logic, remove this debug code -- PCP-4024
|
||||||
if ( result && ! result.success ) {
|
if ( result && ! result.success ) {
|
||||||
console.error(
|
console.error(
|
||||||
'Failed to refresh features:',
|
'Failed to refresh features:',
|
||||||
|
@ -88,7 +90,7 @@ const TabOverview = () => {
|
||||||
onClick={ refreshHandler }
|
onClick={ refreshHandler }
|
||||||
disabled={ isRefreshing }
|
disabled={ isRefreshing }
|
||||||
>
|
>
|
||||||
{ data().getImage( 'icon-refresh.svg' ) }
|
<Icon icon={ reusableBlock } size={ 18 } />
|
||||||
{ isRefreshing
|
{ isRefreshing
|
||||||
? __(
|
? __(
|
||||||
'Refreshing…',
|
'Refreshing…',
|
||||||
|
@ -127,6 +129,7 @@ const TabOverview = () => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: This list should be refactored into a separate module, maybe utils/thingsToDoNext.js
|
||||||
const todosDataDefault = [
|
const todosDataDefault = [
|
||||||
{
|
{
|
||||||
value: 'paypal_later_messaging',
|
value: 'paypal_later_messaging',
|
||||||
|
@ -162,6 +165,7 @@ const todosDataDefault = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// TODO: Hardcoding this list here is not the best idea. Can we move this to a REST API response?
|
||||||
const featuresDefault = [
|
const featuresDefault = [
|
||||||
{
|
{
|
||||||
id: 'save_paypal_and_venmo',
|
id: 'save_paypal_and_venmo',
|
||||||
|
|
|
@ -187,7 +187,13 @@ export const connectViaIdAndSecret = function* () {
|
||||||
* @return {Action} The action.
|
* @return {Action} The action.
|
||||||
*/
|
*/
|
||||||
export const refreshMerchantData = function* () {
|
export const refreshMerchantData = function* () {
|
||||||
return yield { type: ACTION_TYPES.DO_REFRESH_MERCHANT };
|
const result = yield { type: ACTION_TYPES.DO_REFRESH_MERCHANT };
|
||||||
|
|
||||||
|
if ( result.success && result.merchant ) {
|
||||||
|
yield hydrate( result );
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -201,7 +207,9 @@ export const refreshFeatureStatuses = function* () {
|
||||||
const result = yield { type: ACTION_TYPES.DO_REFRESH_FEATURES };
|
const result = yield { type: ACTION_TYPES.DO_REFRESH_FEATURES };
|
||||||
|
|
||||||
if ( result && result.success ) {
|
if ( result && result.success ) {
|
||||||
return yield dispatch( STORE_NAME ).refreshMerchantData();
|
// TODO: Review if we can get the updated feature details in the result.data instead of
|
||||||
|
// doing a second refreshMerchantData() request.
|
||||||
|
yield refreshMerchantData();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -7,11 +7,9 @@
|
||||||
* @file
|
* @file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { dispatch } from '@wordpress/data';
|
|
||||||
import apiFetch from '@wordpress/api-fetch';
|
import apiFetch from '@wordpress/api-fetch';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
STORE_NAME,
|
|
||||||
REST_PERSIST_PATH,
|
REST_PERSIST_PATH,
|
||||||
REST_MANUAL_CONNECTION_PATH,
|
REST_MANUAL_CONNECTION_PATH,
|
||||||
REST_CONNECTION_URL_PATH,
|
REST_CONNECTION_URL_PATH,
|
||||||
|
@ -23,7 +21,7 @@ import ACTION_TYPES from './action-types';
|
||||||
export const controls = {
|
export const controls = {
|
||||||
async [ ACTION_TYPES.DO_PERSIST_DATA ]( { data } ) {
|
async [ ACTION_TYPES.DO_PERSIST_DATA ]( { data } ) {
|
||||||
try {
|
try {
|
||||||
return await apiFetch( {
|
await apiFetch( {
|
||||||
path: REST_PERSIST_PATH,
|
path: REST_PERSIST_PATH,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data,
|
data,
|
||||||
|
@ -34,10 +32,8 @@ export const controls = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async [ ACTION_TYPES.DO_SANDBOX_LOGIN ]() {
|
async [ ACTION_TYPES.DO_SANDBOX_LOGIN ]() {
|
||||||
let result = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await apiFetch( {
|
return apiFetch( {
|
||||||
path: REST_CONNECTION_URL_PATH,
|
path: REST_CONNECTION_URL_PATH,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: {
|
data: {
|
||||||
|
@ -46,20 +42,16 @@ export const controls = {
|
||||||
},
|
},
|
||||||
} );
|
} );
|
||||||
} catch ( e ) {
|
} catch ( e ) {
|
||||||
result = {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: e,
|
error: e,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async [ ACTION_TYPES.DO_PRODUCTION_LOGIN ]( { products } ) {
|
async [ ACTION_TYPES.DO_PRODUCTION_LOGIN ]( { products } ) {
|
||||||
let result = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await apiFetch( {
|
return apiFetch( {
|
||||||
path: REST_CONNECTION_URL_PATH,
|
path: REST_CONNECTION_URL_PATH,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: {
|
data: {
|
||||||
|
@ -68,13 +60,11 @@ export const controls = {
|
||||||
},
|
},
|
||||||
} );
|
} );
|
||||||
} catch ( e ) {
|
} catch ( e ) {
|
||||||
result = {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: e,
|
error: e,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async [ ACTION_TYPES.DO_MANUAL_CONNECTION ]( {
|
async [ ACTION_TYPES.DO_MANUAL_CONNECTION ]( {
|
||||||
|
@ -82,10 +72,8 @@ export const controls = {
|
||||||
clientSecret,
|
clientSecret,
|
||||||
useSandbox,
|
useSandbox,
|
||||||
} ) {
|
} ) {
|
||||||
let result = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await apiFetch( {
|
return await apiFetch( {
|
||||||
path: REST_MANUAL_CONNECTION_PATH,
|
path: REST_MANUAL_CONNECTION_PATH,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: {
|
data: {
|
||||||
|
@ -95,54 +83,36 @@ export const controls = {
|
||||||
},
|
},
|
||||||
} );
|
} );
|
||||||
} catch ( e ) {
|
} catch ( e ) {
|
||||||
result = {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: e,
|
error: e,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async [ ACTION_TYPES.DO_REFRESH_MERCHANT ]() {
|
async [ ACTION_TYPES.DO_REFRESH_MERCHANT ]() {
|
||||||
let result = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await apiFetch( { path: REST_HYDRATE_MERCHANT_PATH } );
|
return await apiFetch( { path: REST_HYDRATE_MERCHANT_PATH } );
|
||||||
|
|
||||||
if ( result.success && result.merchant ) {
|
|
||||||
await dispatch( STORE_NAME ).hydrate( result );
|
|
||||||
}
|
|
||||||
} catch ( e ) {
|
} catch ( e ) {
|
||||||
result = {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: e,
|
error: e,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async [ ACTION_TYPES.DO_REFRESH_FEATURES ]() {
|
async [ ACTION_TYPES.DO_REFRESH_FEATURES ]() {
|
||||||
let result = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await apiFetch( {
|
return await apiFetch( {
|
||||||
path: REST_REFRESH_FEATURES_PATH,
|
path: REST_REFRESH_FEATURES_PATH,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
} );
|
} );
|
||||||
|
|
||||||
if ( result.success ) {
|
|
||||||
result = await dispatch( STORE_NAME ).refreshMerchantData();
|
|
||||||
}
|
|
||||||
} catch ( e ) {
|
} catch ( e ) {
|
||||||
result = {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: e,
|
error: e,
|
||||||
message: e.message,
|
message: e.message,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue