@@ -2,6 +2,7 @@ import Box from "@material-ui/core/Box"
2
2
import Button from "@material-ui/core/Button"
3
3
import CircularProgress from "@material-ui/core/CircularProgress"
4
4
import { useActor } from "@xstate/react"
5
+ import { ErrorSummary } from "components/ErrorSummary/ErrorSummary"
5
6
import React , { useContext , useEffect } from "react"
6
7
import { CodeExample } from "../../../components/CodeExample/CodeExample"
7
8
import { ConfirmDialog } from "../../../components/ConfirmDialog/ConfirmDialog"
@@ -19,12 +20,13 @@ export const Language = {
19
20
"You will need to replace the public SSH key on services you use it with, and you'll need to rebuild existing workspaces." ,
20
21
confirmLabel : "Confirm" ,
21
22
cancelLabel : "Cancel" ,
23
+ errorRegenerateSSHKey : "Error on regenerate the SSH Key" ,
22
24
}
23
25
24
26
export const SSHKeysPage : React . FC = ( ) => {
25
27
const xServices = useContext ( XServiceContext )
26
28
const [ authState , authSend ] = useActor ( xServices . authXService )
27
- const { sshKey } = authState . context
29
+ const { sshKey, getSSHKeyError , regenerateSSHKeyError } = authState . context
28
30
29
31
useEffect ( ( ) => {
30
32
authSend ( { type : "GET_SSH_KEY" } )
@@ -33,27 +35,39 @@ export const SSHKeysPage: React.FC = () => {
33
35
return (
34
36
< >
35
37
< Section title = { Language . title } description = { Language . description } >
36
- { ! sshKey && (
38
+ { authState . matches ( "signedIn.ssh.gettingSSHKey" ) && (
37
39
< Box p = { 4 } >
38
40
< CircularProgress size = { 26 } />
39
41
</ Box >
40
42
) }
41
43
42
- { sshKey && (
43
- < Stack >
44
- < CodeExample code = { sshKey . public_key . trim ( ) } />
45
- < div >
46
- < Button
47
- variant = "outlined"
48
- onClick = { ( ) => {
49
- authSend ( { type : "REGENERATE_SSH_KEY" } )
50
- } }
51
- >
52
- { Language . regenerateLabel }
53
- </ Button >
54
- </ div >
55
- </ Stack >
56
- ) }
44
+ < Stack >
45
+ { /* Regenerating the key is not an option if getSSHKey fails.
46
+ Only one of the error messages will exist at a single time */ }
47
+ { getSSHKeyError && < ErrorSummary error = { getSSHKeyError } /> }
48
+ { regenerateSSHKeyError && (
49
+ < ErrorSummary
50
+ error = { regenerateSSHKeyError }
51
+ defaultMessage = { Language . errorRegenerateSSHKey }
52
+ dismissible
53
+ />
54
+ ) }
55
+ { authState . matches ( "signedIn.ssh.loaded" ) && sshKey && (
56
+ < >
57
+ < CodeExample code = { sshKey . public_key . trim ( ) } />
58
+ < div >
59
+ < Button
60
+ variant = "outlined"
61
+ onClick = { ( ) => {
62
+ authSend ( { type : "REGENERATE_SSH_KEY" } )
63
+ } }
64
+ >
65
+ { Language . regenerateLabel }
66
+ </ Button >
67
+ </ div >
68
+ </ >
69
+ ) }
70
+ </ Stack >
57
71
</ Section >
58
72
59
73
< ConfirmDialog
0 commit comments