Download wp-calypso/packages/help-center/src/hooks/use-action-hooks.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.19 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/help-center/src/hooks/use-action-hooks.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/packages/help-center/src/hooks/use-action-hooks.ts
-
curl -L -o use-action-hooks.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/help-center/src/hooks/use-action-hooks.ts
2.19 kB
| import { localizeUrl } from '@automattic/i18n-utils'; | |
| import { useDispatch } from '@wordpress/data'; | |
| import { useEffect } from '@wordpress/element'; | |
| import { useResetSupportInteraction } from './use-reset-support-interaction'; | |
| /** | |
| * Add your conditions here to open the Help Center automatically when they're met. | |
| */ | |
| export const useActionHooks = () => { | |
| const { setShowHelpCenter, setShowSupportDoc, setNavigateToRoute, setNewMessagingChat } = | |
| useDispatch( 'automattic/help-center' ); | |
| const resetSupportInteraction = useResetSupportInteraction(); | |
| const queryParams = new URLSearchParams( window.location.search ); | |
| const actionHooks = [ | |
| /** | |
| * Open to the support doc for the Subscribe block. | |
| */ | |
| { | |
| condition() { | |
| return queryParams.get( 'help-center' ) === 'subscribe-block'; | |
| }, | |
| action() { | |
| setShowHelpCenter( true ); | |
| setShowSupportDoc( | |
| localizeUrl( 'https://wordpress.com/support/wordpress-editor/blocks/subscribe-block/' ), | |
| 170164 // post id of subscribe block support doc page | |
| ); | |
| }, | |
| }, | |
| /** | |
| * Open Help Center. | |
| */ | |
| { | |
| condition() { | |
| return queryParams.get( 'help-center' ) === 'home'; | |
| }, | |
| action() { | |
| setShowHelpCenter( true ); | |
| }, | |
| }, | |
| /** | |
| * Open to Wapuu chat. | |
| */ | |
| { | |
| condition() { | |
| return queryParams.get( 'help-center' ) === 'wapuu'; | |
| }, | |
| async action() { | |
| await resetSupportInteraction(); | |
| setNavigateToRoute( '/odie' ); | |
| setShowHelpCenter( true ); | |
| }, | |
| }, | |
| /** | |
| * Open to Chat with Happiness Engineer. | |
| */ | |
| { | |
| 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 ); | |
| // Only want to run this once | |
| // eslint-disable-next-line react-hooks/exhaustive-deps | |
| }, [] ); | |
| }; | |