1
- import { useMachine } from "@xstate/react" ;
2
- import { PropsWithChildren , FC } from "react" ;
3
- import { sshKeyMachine } from "xServices/sshKey/sshKeyXService" ;
1
+ import { PropsWithChildren , FC , useState } from "react" ;
4
2
import { ConfirmDialog } from "../../../components/Dialogs/ConfirmDialog/ConfirmDialog" ;
5
3
import { Section } from "../../../components/SettingsLayout/Section" ;
6
4
import { SSHKeysPageView } from "./SSHKeysPageView" ;
5
+ import { useRegenerateUserSSHKey , useUserSSHKey } from "api/queries/sshKeys" ;
6
+ import { displaySuccess } from "components/GlobalSnackbar/utils" ;
7
7
8
8
export const Language = {
9
9
title : "SSH keys" ,
@@ -15,40 +15,40 @@ export const Language = {
15
15
} ;
16
16
17
17
export const SSHKeysPage : FC < PropsWithChildren < unknown > > = ( ) => {
18
- const [ sshState , sshSend ] = useMachine ( sshKeyMachine ) ;
19
- const isLoading = sshState . matches ( "gettingSSHKey" ) ;
20
- const hasLoaded = sshState . matches ( "loaded" ) ;
21
- const { getSSHKeyError, regenerateSSHKeyError, sshKey } = sshState . context ;
22
-
23
- const onRegenerateClick = ( ) => {
24
- sshSend ( { type : "REGENERATE_SSH_KEY" } ) ;
25
- } ;
18
+ const [ isConfirmingRegeneration , setIsConfirmingRegeneration ] =
19
+ useState ( false ) ;
20
+ const userSSHKeyQuery = useUserSSHKey ( "me" ) ;
21
+ const regenerateUserSSHKeyMutation = useRegenerateUserSSHKey ( "me" , ( ) => {
22
+ displaySuccess ( "SSH Key regenerated successfully." ) ;
23
+ setIsConfirmingRegeneration ( false ) ;
24
+ } ) ;
26
25
27
26
return (
28
27
< >
29
28
< Section title = { Language . title } >
30
29
< SSHKeysPageView
31
- isLoading = { isLoading }
32
- hasLoaded = { hasLoaded }
33
- getSSHKeyError = { getSSHKeyError }
34
- regenerateSSHKeyError = { regenerateSSHKeyError }
35
- sshKey = { sshKey }
36
- onRegenerateClick = { onRegenerateClick }
30
+ isLoading = { userSSHKeyQuery . isLoading }
31
+ getSSHKeyError = { userSSHKeyQuery . error }
32
+ regenerateSSHKeyError = { regenerateUserSSHKeyMutation . error }
33
+ sshKey = { userSSHKeyQuery . data }
34
+ onRegenerateClick = { ( ) => {
35
+ setIsConfirmingRegeneration ( true ) ;
36
+ } }
37
37
/>
38
38
</ Section >
39
39
40
40
< ConfirmDialog
41
41
type = "delete"
42
42
hideCancel = { false }
43
- open = { sshState . matches ( "confirmSSHKeyRegenerate" ) }
44
- confirmLoading = { sshState . matches ( "regeneratingSSHKey" ) }
43
+ open = { isConfirmingRegeneration }
44
+ confirmLoading = { regenerateUserSSHKeyMutation . isLoading }
45
45
title = { Language . regenerateDialogTitle }
46
46
confirmText = { Language . confirmLabel }
47
47
onConfirm = { ( ) => {
48
- sshSend ( { type : "CONFIRM_REGENERATE_SSH_KEY" } ) ;
48
+ regenerateUserSSHKeyMutation . mutate ( ) ;
49
49
} }
50
50
onClose = { ( ) => {
51
- sshSend ( { type : "CANCEL_REGENERATE_SSH_KEY" } ) ;
51
+ setIsConfirmingRegeneration ( false ) ;
52
52
} }
53
53
description = { < > { Language . regenerateDialogMessage } </ > }
54
54
/>
0 commit comments