Download wp-calypso/client/data/hosting/use-add-hosting-trial-mutation.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/hosting/use-add-hosting-trial-mutation.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/data/hosting/use-add-hosting-trial-mutation.ts
-
curl -L -o use-add-hosting-trial-mutation.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/hosting/use-add-hosting-trial-mutation.ts
1.07 kB
| import { useMutation, UseMutationOptions } from '@tanstack/react-query'; | |
| import { useCallback } from 'react'; | |
| import wp from 'calypso/lib/wp'; | |
| export const HOSTING_INTENT_MIGRATE = 'migrate'; | |
| type HostingIntent = typeof HOSTING_INTENT_MIGRATE; | |
| interface Variables { | |
| siteId: number; | |
| planSlug: string; | |
| hostingIntent?: HostingIntent; | |
| } | |
| export default function useAddHostingTrialMutation( | |
| options: UseMutationOptions< unknown, unknown, Variables > = {} | |
| ) { | |
| const mutation = useMutation( { | |
| mutationFn: async ( { siteId, planSlug, hostingIntent }: Variables ) => { | |
| const body = hostingIntent ? { hosting_intent: hostingIntent } : undefined; | |
| return wp.req.post( { | |
| path: `/sites/${ siteId }/hosting/trial/add/${ planSlug }`, | |
| apiNamespace: 'wpcom/v2', | |
| body, | |
| } ); | |
| }, | |
| ...options, | |
| } ); | |
| const { mutate } = mutation; | |
| const addHostingTrial = useCallback( | |
| ( siteId: number, planSlug: string, hostingIntent?: HostingIntent ) => | |
| mutate( { siteId, planSlug, hostingIntent } ), | |
| [ mutate ] | |
| ); | |
| return { addHostingTrial, ...mutation }; | |
| } | |