|
1 | 1 | 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" |
4 | 4 | import { mockApiError } from "testHelpers/entities"
|
5 | 5 |
|
6 |
| -export default { |
| 6 | +const meta: Meta<typeof CreateUserForm> = { |
7 | 7 | title: "components/CreateUserForm",
|
8 | 8 | component: CreateUserForm,
|
| 9 | + args: { |
| 10 | + onCancel: action("cancel"), |
| 11 | + onSubmit: action("submit"), |
| 12 | + isLoading: false, |
| 13 | + }, |
9 | 14 | }
|
10 | 15 |
|
11 |
| -const Template: Story<CreateUserFormProps> = (args: CreateUserFormProps) => ( |
12 |
| - <CreateUserForm {...args} /> |
13 |
| -) |
| 16 | +export default meta |
| 17 | +type Story = StoryObj<typeof CreateUserForm> |
14 | 18 |
|
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 | + }, |
20 | 27 | }
|
21 | 28 |
|
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 | + }, |
30 | 35 | }
|
31 | 36 |
|
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 | + }, |
37 | 41 | }
|
0 commit comments