Skip to content

Commit 1fc43b3

Browse files
fix: react-query mutation function signatures (#60211)
1 parent 20129e0 commit 1fc43b3

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

web/packages/teleport/src/Bots/Edit/EditDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343
import Validation from 'shared/components/Validation';
4444
import { requiredField } from 'shared/components/Validation/rules';
4545

46-
import { editBot, fetchRoles } from 'teleport/services/bot/bot';
46+
import { editBotMutationFunction, fetchRoles } from 'teleport/services/bot/bot';
4747
import { FlatBot } from 'teleport/services/bot/types';
4848
import useTeleport from 'teleport/useTeleport';
4949

@@ -82,7 +82,7 @@ export function EditDialog(props: {
8282
error: saveError,
8383
isPending: isSubmitting,
8484
} = useMutation({
85-
mutationFn: editBot,
85+
mutationFn: editBotMutationFunction,
8686
onSuccess: newData => {
8787
const key = createGetBotQueryKey({ botName: newData.name });
8888
queryClient.setQueryData(key, newData);

web/packages/teleport/src/lib/locks/useResourceLock.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import { useCallback } from 'react';
2121

2222
import { LockResourceKind } from 'teleport/LocksV2/NewLock/common';
2323
import {
24-
createLock,
25-
deleteLock,
24+
createLockMutationFn,
25+
deleteLockMutationFn,
2626
listLocks,
2727
} from 'teleport/services/locks/locks';
2828
import { createQueryHook } from 'teleport/services/queryHelpers';
@@ -70,7 +70,7 @@ export function useResourceLock(opts: {
7070
isPending: unlockPending,
7171
error: unlockError,
7272
} = useMutation({
73-
mutationFn: deleteLock,
73+
mutationFn: deleteLockMutationFn,
7474
onSuccess: (_, vars) => {
7575
queryClient.setQueryData(listLocksQueryKey(queryVars), existingLocks => {
7676
return existingLocks?.filter(lock => lock.name !== vars.uuid);
@@ -83,7 +83,7 @@ export function useResourceLock(opts: {
8383
isPending: lockPending,
8484
error: lockError,
8585
} = useMutation({
86-
mutationFn: createLock,
86+
mutationFn: createLockMutationFn,
8787
onSuccess: newLock => {
8888
queryClient.setQueryData(listLocksQueryKey(queryVars), existingLocks => {
8989
return existingLocks ? [...existingLocks, newLock] : [newLock];
@@ -95,7 +95,7 @@ export function useResourceLock(opts: {
9595
// locks may affect other resources
9696
const canUnlock =
9797
hasRemovePermission &&
98-
data &&
98+
!!data &&
9999
data.length > 0 &&
100100
data.reduce(
101101
(acc, lock) =>

web/packages/teleport/src/services/bot/bot.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19+
import { MutationFunction } from '@tanstack/react-query';
20+
1921
import cfg from 'teleport/config';
2022
import api from 'teleport/services/api';
2123
import {
@@ -140,6 +142,11 @@ export async function fetchRoles(
140142
);
141143
}
142144

145+
export const editBotMutationFunction: MutationFunction<
146+
FlatBot,
147+
{ botName: string; req: EditBotRequest }
148+
> = vars => editBot(vars);
149+
143150
export async function editBot(
144151
variables: { botName: string; req: EditBotRequest },
145152
signal?: AbortSignal

web/packages/teleport/src/services/locks/locks.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19+
import { MutationFunction } from '@tanstack/react-query';
20+
1921
import cfg from 'teleport/config';
2022
import api from 'teleport/services/api';
2123

@@ -65,6 +67,13 @@ export async function listLocks(
6567
}
6668
}
6769

70+
export const createLockMutationFn: MutationFunction<
71+
Lock,
72+
CreateLockRequest
73+
> = vars => {
74+
return createLock(vars);
75+
};
76+
6877
export async function createLock(
6978
variables: CreateLockRequest,
7079
signal?: AbortSignal
@@ -77,6 +86,13 @@ export async function createLock(
7786
return makeLock(json);
7887
}
7988

89+
export const deleteLockMutationFn: MutationFunction<
90+
unknown,
91+
{ uuid: string }
92+
> = vars => {
93+
return deleteLock(vars);
94+
};
95+
8096
export async function deleteLock(
8197
variables: { uuid: string },
8298
signal?: AbortSignal

0 commit comments

Comments
 (0)