react-code-dataset
/
wp-calypso
/client
/sites
/deployments
/components
/installations-dropdown
/use-save-github-credentials-mutation.ts
| import { useMutation } from '@tanstack/react-query'; | |
| import { useCallback } from 'react'; | |
| import wp from 'calypso/lib/wp'; | |
| interface MutationVariables { | |
| accessToken: string; | |
| } | |
| export const useSaveGitHubCredentialsMutation = () => { | |
| const mutation = useMutation( { | |
| mutationFn: async ( { accessToken }: MutationVariables ) => | |
| wp.req.post( | |
| { | |
| path: '/hosting/github/accounts', | |
| apiNamespace: 'wpcom/v2', | |
| }, | |
| { | |
| access_token: accessToken, | |
| } | |
| ), | |
| } ); | |
| const { mutateAsync, isPending } = mutation; | |
| const saveGitHubCredentials = useCallback( | |
| ( args: MutationVariables ) => mutateAsync( args ), | |
| [ mutateAsync ] | |
| ); | |
| return { saveGitHubCredentials, isPending }; | |
| }; | |