|
|
import { localizeUrl } from '@automattic/i18n-utils'; |
|
|
import { useDispatch } from '@wordpress/data'; |
|
|
import { useEffect } from '@wordpress/element'; |
|
|
import { useResetSupportInteraction } from './use-reset-support-interaction'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const useActionHooks = () => { |
|
|
const { setShowHelpCenter, setShowSupportDoc, setNavigateToRoute, setNewMessagingChat } = |
|
|
useDispatch( 'automattic/help-center' ); |
|
|
const resetSupportInteraction = useResetSupportInteraction(); |
|
|
const queryParams = new URLSearchParams( window.location.search ); |
|
|
|
|
|
const actionHooks = [ |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
condition() { |
|
|
return queryParams.get( 'help-center' ) === 'subscribe-block'; |
|
|
}, |
|
|
action() { |
|
|
setShowHelpCenter( true ); |
|
|
setShowSupportDoc( |
|
|
localizeUrl( 'https://wordpress.com/support/wordpress-editor/blocks/subscribe-block/' ), |
|
|
170164 |
|
|
); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
condition() { |
|
|
return queryParams.get( 'help-center' ) === 'home'; |
|
|
}, |
|
|
action() { |
|
|
setShowHelpCenter( true ); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
condition() { |
|
|
return queryParams.get( 'help-center' ) === 'wapuu'; |
|
|
}, |
|
|
async action() { |
|
|
await resetSupportInteraction(); |
|
|
setNavigateToRoute( '/odie' ); |
|
|
setShowHelpCenter( true ); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
condition() { |
|
|
return queryParams.get( 'help-center' ) === 'happiness-engineer'; |
|
|
}, |
|
|
action() { |
|
|
setNewMessagingChat( { |
|
|
initialMessage: queryParams.get( 'user-message' ) ?? '', |
|
|
siteUrl: queryParams.get( 'site-url' ) ?? '', |
|
|
siteId: queryParams.get( 'site-id' ) ?? '', |
|
|
} ); |
|
|
}, |
|
|
}, |
|
|
]; |
|
|
|
|
|
useEffect( () => { |
|
|
const timeout = setTimeout( () => { |
|
|
actionHooks.forEach( ( actionHook ) => { |
|
|
if ( actionHook.condition() ) { |
|
|
actionHook.action(); |
|
|
} |
|
|
} ); |
|
|
}, 0 ); |
|
|
return () => clearTimeout( timeout ); |
|
|
|
|
|
|
|
|
}, [] ); |
|
|
}; |
|
|
|