Skip to content

Commit 00cbb21

Browse files
fix(site): show error when user exists (#8864)
1 parent eddd4f8 commit 00cbb21

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
import { action } from "@storybook/addon-actions"
2-
import { Story } from "@storybook/react"
3-
import { CreateUserForm, CreateUserFormProps } from "./CreateUserForm"
2+
import { StoryObj, Meta } from "@storybook/react"
3+
import { CreateUserForm } from "./CreateUserForm"
44
import { mockApiError } from "testHelpers/entities"
55

6-
export default {
6+
const meta: Meta<typeof CreateUserForm> = {
77
title: "components/CreateUserForm",
88
component: CreateUserForm,
9+
args: {
10+
onCancel: action("cancel"),
11+
onSubmit: action("submit"),
12+
isLoading: false,
13+
},
914
}
1015

11-
const Template: Story<CreateUserFormProps> = (args: CreateUserFormProps) => (
12-
<CreateUserForm {...args} />
13-
)
16+
export default meta
17+
type Story = StoryObj<typeof CreateUserForm>
1418

15-
export const Ready = Template.bind({})
16-
Ready.args = {
17-
onCancel: action("cancel"),
18-
onSubmit: action("submit"),
19-
isLoading: false,
19+
export const Ready: Story = {}
20+
21+
export const FormError: Story = {
22+
args: {
23+
error: mockApiError({
24+
validations: [{ field: "username", detail: "Username taken" }],
25+
}),
26+
},
2027
}
2128

22-
export const FormError = Template.bind({})
23-
FormError.args = {
24-
onCancel: action("cancel"),
25-
onSubmit: action("submit"),
26-
isLoading: false,
27-
error: mockApiError({
28-
validations: [{ field: "username", detail: "Username taken" }],
29-
}),
29+
export const GeneralError: Story = {
30+
args: {
31+
error: mockApiError({
32+
message: "User already exists",
33+
}),
34+
},
3035
}
3136

32-
export const Loading = Template.bind({})
33-
Loading.args = {
34-
onCancel: action("cancel"),
35-
onSubmit: action("submit"),
36-
isLoading: true,
37+
export const Loading: Story = {
38+
args: {
39+
isLoading: true,
40+
},
3741
}

site/src/components/CreateUserForm/CreateUserForm.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
import { FormFooter } from "../FormFooter/FormFooter"
1212
import { FullPageForm } from "../FullPageForm/FullPageForm"
1313
import { Stack } from "../Stack/Stack"
14+
import { ErrorAlert } from "components/Alert/ErrorAlert"
15+
import { hasApiFieldErrors, isApiError } from "api/errors"
1416

1517
export const Language = {
1618
emailLabel: "Email",
@@ -62,6 +64,9 @@ export const CreateUserForm: FC<
6264

6365
return (
6466
<FullPageForm title="Create user">
67+
{isApiError(error) && !hasApiFieldErrors(error) && (
68+
<ErrorAlert error={error} sx={{ mb: 4 }} />
69+
)}
6570
<form onSubmit={form.handleSubmit} autoComplete="off">
6671
<Stack spacing={2.5}>
6772
<TextField

site/src/pages/UsersPage/CreateUserPage/CreateUserPage.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const CreateUserPage: FC = () => {
3030
<Helmet>
3131
<title>{pageTitle("Create User")}</title>
3232
</Helmet>
33+
3334
<CreateUserForm
3435
error={error}
3536
onSubmit={(user: TypesGen.CreateUserRequest) =>

0 commit comments

Comments
 (0)