Skip to content

Commit 6ae13b1

Browse files
committed
fix: show errors on SSH Key page
1 parent df20dd7 commit 6ae13b1

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

site/src/pages/UserSettingsPage/SSHKeysPage/SSHKeysPage.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe("SSH keys Page", () => {
8585
fireEvent.click(confirmButton)
8686

8787
// Check if the error message is displayed
88-
await screen.findByText(authXServiceLanguage.errorRegenerateSSHKey)
88+
await screen.findByText(SSHKeysPageLanguage.errorRegenerateSSHKey)
8989

9090
// Check if the API was called correctly
9191
expect(API.regenerateUserSSHKey).toBeCalledTimes(1)

site/src/pages/UserSettingsPage/SSHKeysPage/SSHKeysPage.tsx

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Box from "@material-ui/core/Box"
22
import Button from "@material-ui/core/Button"
33
import CircularProgress from "@material-ui/core/CircularProgress"
44
import { useActor } from "@xstate/react"
5+
import { ErrorSummary } from "components/ErrorSummary/ErrorSummary"
56
import React, { useContext, useEffect } from "react"
67
import { CodeExample } from "../../../components/CodeExample/CodeExample"
78
import { ConfirmDialog } from "../../../components/ConfirmDialog/ConfirmDialog"
@@ -19,12 +20,13 @@ export const Language = {
1920
"You will need to replace the public SSH key on services you use it with, and you'll need to rebuild existing workspaces.",
2021
confirmLabel: "Confirm",
2122
cancelLabel: "Cancel",
23+
errorRegenerateSSHKey: "Error on regenerate the SSH Key",
2224
}
2325

2426
export const SSHKeysPage: React.FC = () => {
2527
const xServices = useContext(XServiceContext)
2628
const [authState, authSend] = useActor(xServices.authXService)
27-
const { sshKey } = authState.context
29+
const { sshKey, getSSHKeyError, regenerateSSHKeyError } = authState.context
2830

2931
useEffect(() => {
3032
authSend({ type: "GET_SSH_KEY" })
@@ -33,27 +35,39 @@ export const SSHKeysPage: React.FC = () => {
3335
return (
3436
<>
3537
<Section title={Language.title} description={Language.description}>
36-
{!sshKey && (
38+
{authState.matches("signedIn.ssh.gettingSSHKey") && (
3739
<Box p={4}>
3840
<CircularProgress size={26} />
3941
</Box>
4042
)}
4143

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>
5771
</Section>
5872

5973
<ConfirmDialog

site/src/xServices/auth/authXService.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { assign, createMachine } from "xstate"
22
import * as API from "../../api/api"
33
import * as TypesGen from "../../api/typesGenerated"
4-
import { displayError, displaySuccess } from "../../components/GlobalSnackbar/utils"
4+
import { displaySuccess } from "../../components/GlobalSnackbar/utils"
55

66
export const Language = {
77
successProfileUpdate: "Updated settings.",
88
successSecurityUpdate: "Updated password.",
99
successRegenerateSSHKey: "SSH Key regenerated successfully",
10-
errorRegenerateSSHKey: "Error on regenerate the SSH Key",
1110
}
1211

1312
export const checks = {
@@ -130,7 +129,7 @@ const sshState = {
130129
],
131130
onError: [
132131
{
133-
actions: ["assignRegenerateSSHKeyError", "notifySSHKeyRegenerationError"],
132+
actions: ["assignRegenerateSSHKeyError"],
134133
target: "#authState.signedIn.ssh.loaded.idle",
135134
},
136135
],
@@ -488,9 +487,6 @@ export const authMachine =
488487
notifySuccessSSHKeyRegenerated: () => {
489488
displaySuccess(Language.successRegenerateSSHKey)
490489
},
491-
notifySSHKeyRegenerationError: () => {
492-
displayError(Language.errorRegenerateSSHKey)
493-
},
494490
},
495491
},
496492
)

0 commit comments

Comments
 (0)