Download wp-calypso/client/landing/stepper/hooks/use-plugin-installation.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 926 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/landing/stepper/hooks/use-plugin-installation.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/landing/stepper/hooks/use-plugin-installation.ts
-
curl -L -o use-plugin-installation.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/landing/stepper/hooks/use-plugin-installation.ts
926 Bytes
| import { useMutation } from '@tanstack/react-query'; | |
| import wpcom from 'calypso/lib/wp'; | |
| import { DEFAULT_RETRY, Options } from './use-plugin-auto-installation'; | |
| interface WPError { | |
| name: string; | |
| } | |
| const installPlugin = async ( siteId: number, pluginSlug: string ) => { | |
| try { | |
| const response = await wpcom.req.post( | |
| { | |
| path: `/sites/${ siteId }/plugins/${ pluginSlug }/install`, | |
| }, | |
| { apiVersion: '1.2', http_envelope: 1 }, | |
| {} | |
| ); | |
| return response; | |
| } catch ( error ) { | |
| if ( ( error as WPError ).name === 'PluginAlreadyInstalledError' ) { | |
| return 'success'; | |
| } | |
| throw error; | |
| } | |
| }; | |
| export const usePluginInstallation = ( pluginSlug: string, siteId?: number, options?: Options ) => { | |
| return useMutation( { | |
| mutationKey: [ 'onboarding-site-plugin-installation', siteId, pluginSlug ], | |
| mutationFn: async () => installPlugin( siteId!, pluginSlug ), | |
| retry: options?.retry ?? DEFAULT_RETRY, | |
| } ); | |
| }; | |