-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathuseGetOAuth2TokenMutation.ts
More file actions
55 lines (48 loc) · 1.22 KB
/
useGetOAuth2TokenMutation.ts
File metadata and controls
55 lines (48 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { useMutation } from 'react-query'
import { getOAuth2Token } from '@opentrons/api-client'
import { useHost } from '../../api'
import type {
UseMutateFunction,
UseMutationOptions,
UseMutationResult,
} from 'react-query'
import type {
HostConfig,
OAuth2TokenResponse,
RefreshRequest,
Response,
ROPCRequest,
} from '@opentrons/api-client'
export type GetOAuth2TokenMutationResult = UseMutationResult<
Response<OAuth2TokenResponse>,
unknown,
ROPCRequest | RefreshRequest
> & {
getOAuth2Token: UseMutateFunction<
Response<OAuth2TokenResponse>,
unknown,
ROPCRequest | RefreshRequest
>
}
export type GetOAuth2TokenMutationOptions = UseMutationOptions<
Response<OAuth2TokenResponse>,
unknown,
ROPCRequest | RefreshRequest
>
export function useGetOAuth2TokenMutation(
options: GetOAuth2TokenMutationOptions = {},
hostOverride?: HostConfig | null
): GetOAuth2TokenMutationResult {
const contextHost = useHost()
const host =
hostOverride != null ? { ...contextHost, ...hostOverride } : contextHost
const mutation = useMutation(
[host, 'auth/oauth2/token'],
body => getOAuth2Token(host!, body),
options
)
return {
...mutation,
getOAuth2Token: mutation.mutate,
}
}