@@ -2,8 +2,9 @@ import { PropsWithChildren, FC, useState } from "react";
2
2
import { ConfirmDialog } from "../../../components/Dialogs/ConfirmDialog/ConfirmDialog" ;
3
3
import { Section } from "../../../components/SettingsLayout/Section" ;
4
4
import { SSHKeysPageView } from "./SSHKeysPageView" ;
5
- import { useRegenerateUserSSHKey , useUserSSHKey } from "api/queries/sshKeys" ;
5
+ import { regenerateUserSSHKey , userSSHKey } from "api/queries/sshKeys" ;
6
6
import { displaySuccess } from "components/GlobalSnackbar/utils" ;
7
+ import { useMutation , useQuery , useQueryClient } from "@tanstack/react-query" ;
7
8
8
9
export const Language = {
9
10
title : "SSH keys" ,
@@ -17,10 +18,19 @@ export const Language = {
17
18
export const SSHKeysPage : FC < PropsWithChildren < unknown > > = ( ) => {
18
19
const [ isConfirmingRegeneration , setIsConfirmingRegeneration ] =
19
20
useState ( false ) ;
20
- const userSSHKeyQuery = useUserSSHKey ( "me" ) ;
21
- const regenerateUserSSHKeyMutation = useRegenerateUserSSHKey ( "me" , ( ) => {
22
- displaySuccess ( "SSH Key regenerated successfully." ) ;
23
- setIsConfirmingRegeneration ( false ) ;
21
+ const queryClient = useQueryClient ( ) ;
22
+ const userSSHKeyQuery = useQuery ( userSSHKey ( "me" ) ) ;
23
+ const regenerateSSHKeyMutationOptions = regenerateUserSSHKey (
24
+ "me" ,
25
+ queryClient ,
26
+ ) ;
27
+ const regenerateSSHKeyMutation = useMutation ( {
28
+ ...regenerateSSHKeyMutationOptions ,
29
+ onSuccess : ( newKey ) => {
30
+ regenerateSSHKeyMutationOptions . onSuccess ( newKey ) ;
31
+ displaySuccess ( "SSH Key regenerated successfully." ) ;
32
+ setIsConfirmingRegeneration ( false ) ;
33
+ } ,
24
34
} ) ;
25
35
26
36
return (
@@ -29,7 +39,7 @@ export const SSHKeysPage: FC<PropsWithChildren<unknown>> = () => {
29
39
< SSHKeysPageView
30
40
isLoading = { userSSHKeyQuery . isLoading }
31
41
getSSHKeyError = { userSSHKeyQuery . error }
32
- regenerateSSHKeyError = { regenerateUserSSHKeyMutation . error }
42
+ regenerateSSHKeyError = { regenerateSSHKeyMutation . error }
33
43
sshKey = { userSSHKeyQuery . data }
34
44
onRegenerateClick = { ( ) => {
35
45
setIsConfirmingRegeneration ( true ) ;
@@ -41,11 +51,11 @@ export const SSHKeysPage: FC<PropsWithChildren<unknown>> = () => {
41
51
type = "delete"
42
52
hideCancel = { false }
43
53
open = { isConfirmingRegeneration }
44
- confirmLoading = { regenerateUserSSHKeyMutation . isLoading }
54
+ confirmLoading = { regenerateSSHKeyMutation . isLoading }
45
55
title = { Language . regenerateDialogTitle }
46
56
confirmText = { Language . confirmLabel }
47
57
onConfirm = { ( ) => {
48
- regenerateUserSSHKeyMutation . mutate ( ) ;
58
+ regenerateSSHKeyMutation . mutate ( ) ;
49
59
} }
50
60
onClose = { ( ) => {
51
61
setIsConfirmingRegeneration ( false ) ;
0 commit comments