Skip to content

Commit 31694a5

Browse files
authored
ref: Migrate useRevokeUserToken to TSQ V5 (#3719)
1 parent 804b7f1 commit 31694a5

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

src/pages/AccountSettings/tabs/Access/TokensTable.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import userEvent from '@testing-library/user-event'
33
import { MemoryRouter, Route } from 'react-router-dom'
44
import { type Mock } from 'vitest'
55

6-
import { useRevokeUserToken } from 'services/access'
6+
import { useRevokeUserToken } from 'services/access/useRevokeUserToken'
77

88
import TokensTable from './TokensTable'
99

10-
vi.mock('services/access')
10+
vi.mock('services/access/useRevokeUserToken')
1111
const mockedUseRevokeUserToken = useRevokeUserToken as Mock
1212

1313
window.confirm = () => true

src/pages/AccountSettings/tabs/Access/TokensTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import isNull from 'lodash/isNull'
88
import { useCallback, useMemo } from 'react'
99
import { useParams } from 'react-router-dom'
1010

11-
import { useRevokeUserToken } from 'services/access'
1211
import { UserToken } from 'services/access/SessionsQueryOpts'
12+
import { useRevokeUserToken } from 'services/access/useRevokeUserToken'
1313
import { cn } from 'shared/utils/cn'
1414
import Button from 'ui/Button'
1515

src/services/access/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from './useDeleteSession'
2-
export * from './useRevokeUserToken'
32
export * from './useGenerateUserToken'

src/services/access/useRevokeUserToken.test.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
1+
import {
2+
QueryClientProvider as QueryClientProviderV5,
3+
QueryClient as QueryClientV5,
4+
} from '@tanstack/react-queryV5'
25
import { renderHook, waitFor } from '@testing-library/react'
36
import { graphql, HttpResponse } from 'msw'
47
import { setupServer } from 'msw/node'
58
import { MemoryRouter, Route } from 'react-router-dom'
69

7-
import { useRevokeUserToken } from './index'
10+
import { useRevokeUserToken } from './useRevokeUserToken'
811

9-
const queryClient = new QueryClient({
12+
const queryClientV5 = new QueryClientV5({
1013
defaultOptions: { queries: { retry: false } },
1114
})
1215
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
13-
<MemoryRouter initialEntries={['/gh']}>
14-
<Route path="/:provider">
15-
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
16-
</Route>
17-
</MemoryRouter>
16+
<QueryClientProviderV5 client={queryClientV5}>
17+
<MemoryRouter initialEntries={['/gh']}>
18+
<Route path="/:provider">{children}</Route>
19+
</MemoryRouter>
20+
</QueryClientProviderV5>
1821
)
1922

2023
const provider = 'gh'
@@ -26,7 +29,7 @@ beforeAll(() => {
2629

2730
beforeEach(() => {
2831
server.resetHandlers()
29-
queryClient.clear()
32+
queryClientV5.clear()
3033
})
3134

3235
afterAll(() => {
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { useMutation, useQueryClient } from '@tanstack/react-query'
1+
import {
2+
useMutation as useMutationV5,
3+
useQueryClient as useQueryClientV5,
4+
} from '@tanstack/react-queryV5'
25

36
import Api from 'shared/api'
47

5-
const query = `
6-
mutation RevokeUserToken($input: RevokeUserTokenInput!) {
8+
import { SessionsQueryOpts } from './SessionsQueryOpts'
9+
10+
const query = `mutation RevokeUserToken($input: RevokeUserTokenInput!) {
711
revokeUserToken(input: $input) {
812
error {
913
__typename
@@ -12,8 +16,8 @@ mutation RevokeUserToken($input: RevokeUserTokenInput!) {
1216
}`
1317

1418
export function useRevokeUserToken({ provider }: { provider: string }) {
15-
const queryClient = useQueryClient()
16-
return useMutation({
19+
const queryClient = useQueryClientV5()
20+
return useMutationV5({
1721
mutationFn: ({ tokenid }: { tokenid: string }) => {
1822
return Api.graphqlMutation({
1923
provider,
@@ -22,10 +26,13 @@ export function useRevokeUserToken({ provider }: { provider: string }) {
2226
input: { tokenid },
2327
},
2428
mutationPath: 'revokeUserToken',
25-
}).then(() => {
26-
queryClient.invalidateQueries(['sessions'])
2729
})
2830
},
29-
useErrorBoundary: true,
31+
throwOnError: true,
32+
onSuccess: () => {
33+
queryClient.invalidateQueries({
34+
queryKey: SessionsQueryOpts({ provider }).queryKey,
35+
})
36+
},
3037
})
3138
}

0 commit comments

Comments
 (0)