woocommerce/plugins/woocommerce-blocks/assets/js/editor-components/incompatible-extension-notice/use-incompatible-extensions...

35 lines
818 B
TypeScript

/**
* External dependencies
*/
import { getSetting } from '@woocommerce/settings';
export const useIncompatibleExtensionNotice = (): [
{ [ k: string ]: string } | null,
string[],
number
] => {
interface GlobalIncompatibleExtensions {
id: string;
title: string;
}
const incompatibleExtensions: Record< string, string > = {};
if ( getSetting( 'incompatibleExtensions' ) ) {
getSetting< GlobalIncompatibleExtensions[] >(
'incompatibleExtensions'
).forEach( ( extension ) => {
incompatibleExtensions[ extension.id ] = extension.title;
} );
}
const incompatibleExtensionSlugs = Object.keys( incompatibleExtensions );
const incompatibleExtensionCount = incompatibleExtensionSlugs.length;
return [
incompatibleExtensions,
incompatibleExtensionSlugs,
incompatibleExtensionCount,
];
};