2021-08-02 21:38:14 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2022-04-25 05:49:11 +00:00
|
|
|
import { useSelect } from '@wordpress/data';
|
2021-08-02 21:38:14 +00:00
|
|
|
import { useUser, OPTIONS_STORE_NAME } from '@woocommerce/data';
|
|
|
|
|
|
|
|
const SHOW_MARKETPLACE_SUGGESTION_OPTION =
|
|
|
|
'woocommerce_show_marketplace_suggestions';
|
|
|
|
|
|
|
|
const RecommendationsEligibilityWrapper: React.FC = ( { children } ) => {
|
|
|
|
const { currentUserCan } = useUser();
|
|
|
|
|
2022-04-25 05:49:11 +00:00
|
|
|
const isMarketplaceSuggestionsEnabled = useSelect( ( select ) => {
|
2022-06-21 08:37:34 +00:00
|
|
|
const { getOption, hasFinishedResolution } =
|
|
|
|
select( OPTIONS_STORE_NAME );
|
2022-04-25 05:49:11 +00:00
|
|
|
|
|
|
|
const hasFinishedResolving = hasFinishedResolution( 'getOption', [
|
|
|
|
SHOW_MARKETPLACE_SUGGESTION_OPTION,
|
|
|
|
] );
|
|
|
|
const canShowMarketplaceSuggestions =
|
|
|
|
getOption( SHOW_MARKETPLACE_SUGGESTION_OPTION ) !== 'no';
|
|
|
|
|
|
|
|
return hasFinishedResolving && canShowMarketplaceSuggestions;
|
|
|
|
} );
|
2021-08-02 21:38:14 +00:00
|
|
|
|
|
|
|
if ( ! currentUserCan( 'install_plugins' ) ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! isMarketplaceSuggestionsEnabled ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return <>{ children }</>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default RecommendationsEligibilityWrapper;
|