2022-12-27 14:01:46 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
|
|
import { OPTIONS_STORE_NAME } from '@woocommerce/data';
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
|
|
|
|
2022-12-27 14:13:21 +00:00
|
|
|
type UseIntroductionBanner = {
|
2022-12-27 14:01:46 +00:00
|
|
|
loading: boolean;
|
|
|
|
isIntroductionBannerDismissed: boolean;
|
|
|
|
dismissIntroductionBanner: () => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
const OPTION_NAME =
|
|
|
|
'woocommerce_marketing_overview_multichannel_banner_dismissed';
|
|
|
|
const OPTION_VALUE = 'yes';
|
|
|
|
|
2022-12-27 14:13:21 +00:00
|
|
|
export const useIntroductionBanner = (): UseIntroductionBanner => {
|
2022-12-27 14:01:46 +00:00
|
|
|
const { updateOptions } = useDispatch( OPTIONS_STORE_NAME );
|
|
|
|
|
|
|
|
const dismissIntroductionBanner = () => {
|
|
|
|
updateOptions( {
|
|
|
|
[ OPTION_NAME ]: OPTION_VALUE,
|
|
|
|
} );
|
|
|
|
recordEvent( 'marketing_multichannel_banner_dismissed', {} );
|
|
|
|
};
|
|
|
|
|
|
|
|
return useSelect( ( select ) => {
|
|
|
|
const { getOption, isOptionsUpdating, hasFinishedResolution } =
|
|
|
|
select( OPTIONS_STORE_NAME );
|
|
|
|
const isUpdateRequesting = isOptionsUpdating();
|
|
|
|
|
|
|
|
return {
|
|
|
|
loading: ! hasFinishedResolution( 'getOption', [ OPTION_NAME ] ),
|
|
|
|
isIntroductionBannerDismissed:
|
|
|
|
getOption( OPTION_NAME ) === OPTION_VALUE || isUpdateRequesting,
|
|
|
|
dismissIntroductionBanner,
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
};
|