mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Use the features from endpoint
This commit is contained in:
parent
f5acc09f24
commit
24129f3f60
1 changed files with 10 additions and 22 deletions
|
@ -1,7 +1,7 @@
|
||||||
import { __, sprintf } from '@wordpress/i18n';
|
import { __, sprintf } from '@wordpress/i18n';
|
||||||
import { useState, useMemo } from '@wordpress/element';
|
import { useState, useMemo, useEffect } from '@wordpress/element';
|
||||||
import { Button, Icon } from '@wordpress/components';
|
import { Button, Icon } from '@wordpress/components';
|
||||||
import { useDispatch } from '@wordpress/data';
|
import { useDispatch, useSelect } from '@wordpress/data';
|
||||||
import { reusableBlock } from '@wordpress/icons';
|
import { reusableBlock } from '@wordpress/icons';
|
||||||
import { store as noticesStore } from '@wordpress/notices';
|
import { store as noticesStore } from '@wordpress/notices';
|
||||||
|
|
||||||
|
@ -16,15 +16,15 @@ import { useTodos } from '../../../../data/todos/hooks';
|
||||||
import { useMerchantInfo } from '../../../../data/common/hooks';
|
import { useMerchantInfo } from '../../../../data/common/hooks';
|
||||||
import { STORE_NAME as COMMON_STORE_NAME } from '../../../../data/common';
|
import { STORE_NAME as COMMON_STORE_NAME } from '../../../../data/common';
|
||||||
import { STORE_NAME as TODOS_STORE_NAME } from '../../../../data/todos';
|
import { STORE_NAME as TODOS_STORE_NAME } from '../../../../data/todos';
|
||||||
import { CommonHooks, TodosHooks } from '../../../../data';
|
import { CommonHooks, TodosHooks, FeaturesHooks } from '../../../../data';
|
||||||
|
|
||||||
import { getFeatures } from '../Components/Overview/features-config';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
NOTIFICATION_ERROR,
|
NOTIFICATION_ERROR,
|
||||||
NOTIFICATION_SUCCESS,
|
NOTIFICATION_SUCCESS,
|
||||||
} from '../../../ReusableComponents/Icons';
|
} from '../../../ReusableComponents/Icons';
|
||||||
import SpinnerOverlay from '../../../ReusableComponents/SpinnerOverlay';
|
import SpinnerOverlay from '../../../ReusableComponents/SpinnerOverlay';
|
||||||
|
import { useFeatures } from '../../../../data/features/hooks';
|
||||||
|
import { featureButtonOnClickMap } from '../../../../data/features/actions';
|
||||||
|
|
||||||
const TabOverview = () => {
|
const TabOverview = () => {
|
||||||
const { isReady: areTodosReady } = TodosHooks.useTodos();
|
const { isReady: areTodosReady } = TodosHooks.useTodos();
|
||||||
|
@ -123,23 +123,11 @@ const OverviewFeatures = () => {
|
||||||
useDispatch( COMMON_STORE_NAME );
|
useDispatch( COMMON_STORE_NAME );
|
||||||
const { createSuccessNotice, createErrorNotice } =
|
const { createSuccessNotice, createErrorNotice } =
|
||||||
useDispatch( noticesStore );
|
useDispatch( noticesStore );
|
||||||
|
const { features, fetchFeatures } = useFeatures();
|
||||||
|
|
||||||
// Get the features data with access to setActiveModal
|
useEffect( () => {
|
||||||
const featuresData = useMemo(
|
fetchFeatures( setActiveModal );
|
||||||
() => getFeatures( setActiveModal ),
|
}, [ fetchFeatures, setActiveModal ] );
|
||||||
[ setActiveModal ]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Map merchant features status to the config
|
|
||||||
const features = useMemo( () => {
|
|
||||||
return featuresData.map( ( feature ) => {
|
|
||||||
const merchantFeature = merchantFeatures?.[ feature.id ];
|
|
||||||
return {
|
|
||||||
...feature,
|
|
||||||
enabled: merchantFeature?.enabled ?? false,
|
|
||||||
};
|
|
||||||
} );
|
|
||||||
}, [ featuresData, merchantFeatures ] );
|
|
||||||
|
|
||||||
const refreshHandler = async () => {
|
const refreshHandler = async () => {
|
||||||
setIsRefreshing( true );
|
setIsRefreshing( true );
|
||||||
|
@ -201,7 +189,7 @@ const OverviewFeatures = () => {
|
||||||
title={ feature.title }
|
title={ feature.title }
|
||||||
description={ feature.description }
|
description={ feature.description }
|
||||||
buttons={ feature.buttons }
|
buttons={ feature.buttons }
|
||||||
enabled={ feature.enabled }
|
enabled={ feature.isEligible }
|
||||||
notes={ feature.notes }
|
notes={ feature.notes }
|
||||||
/>
|
/>
|
||||||
) ) }
|
) ) }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue