1
- import { Story } from "@storybook/react" ;
2
- import { ScheduleForm , ScheduleFormProps } from "./ScheduleForm" ;
1
+ import type { Meta , StoryObj } from "@storybook/react" ;
2
+ import { ScheduleForm } from "./ScheduleForm" ;
3
3
import { mockApiError } from "testHelpers/entities" ;
4
+ import { action } from "@storybook/addon-actions" ;
4
5
5
- export default {
6
- title : "pages/UserSettingsPage/SchedulePage/ScheduleForm" ,
7
- component : ScheduleForm ,
8
- argTypes : {
9
- onSubmit : { action : "Submit" } ,
10
- } ,
11
- } ;
12
-
13
- const Template : Story < ScheduleFormProps > = ( args : ScheduleFormProps ) => (
14
- < ScheduleForm { ...args } />
15
- ) ;
16
-
17
- export const ExampleDefault = Template . bind ( { } ) ;
18
- ExampleDefault . args = {
6
+ const defaultArgs = {
19
7
submitting : false ,
20
8
initialValues : {
21
9
raw_schedule : "CRON_TZ=Australia/Sydney 0 2 * * *" ,
@@ -25,41 +13,53 @@ ExampleDefault.args = {
25
13
next : "2023-09-05T02:00:00+10:00" ,
26
14
} ,
27
15
updateErr : undefined ,
28
- onSubmit : ( ) => {
29
- return Promise . resolve ( ) ;
30
- } ,
31
16
now : new Date ( "2023-09-04T15:00:00+10:00" ) ,
17
+ onSubmit : action ( "onSubmit" ) ,
32
18
} ;
33
19
34
- export const ExampleUserSet = Template . bind ( { } ) ;
35
- ExampleUserSet . args = {
36
- ...ExampleDefault . args ,
37
- initialValues : {
38
- raw_schedule : "CRON_TZ=America/Chicago 0 2 * * *" ,
39
- user_set : true ,
40
- time : "02:00" ,
41
- timezone : "America/Chicago" ,
42
- next : "2023-09-05T02:00:00-05:00" ,
20
+ const meta : Meta < typeof ScheduleForm > = {
21
+ title : "pages/UserSettingsPage/ScheduleForm" ,
22
+ component : ScheduleForm ,
23
+ args : defaultArgs ,
24
+ } ;
25
+ export default meta ;
26
+
27
+ type Story = StoryObj < typeof ScheduleForm > ;
28
+
29
+ export const ExampleDefault : Story = { } ;
30
+
31
+ export const ExampleUserSet : Story = {
32
+ args : {
33
+ ...defaultArgs ,
34
+ initialValues : {
35
+ raw_schedule : "CRON_TZ=America/Chicago 0 2 * * *" ,
36
+ user_set : true ,
37
+ time : "02:00" ,
38
+ timezone : "America/Chicago" ,
39
+ next : "2023-09-05T02:00:00-05:00" ,
40
+ } ,
41
+ now : new Date ( "2023-09-04T15:00:00-05:00" ) ,
43
42
} ,
44
- now : new Date ( "2023-09-04T15:00:00-05:00" ) ,
45
43
} ;
46
44
47
- export const Submitting = Template . bind ( { } ) ;
48
- Submitting . args = {
49
- ...ExampleDefault . args ,
50
- submitting : true ,
45
+ export const Submitting : Story = {
46
+ args : {
47
+ ...defaultArgs ,
48
+ submitting : true ,
49
+ } ,
51
50
} ;
52
51
53
- export const WithError = Template . bind ( { } ) ;
54
- WithError . args = {
55
- ...ExampleDefault . args ,
56
- updateErr : mockApiError ( {
57
- message : "Invalid schedule" ,
58
- validations : [
59
- {
60
- field : "schedule" ,
61
- detail : "Could not validate cron schedule." ,
62
- } ,
63
- ] ,
64
- } ) ,
52
+ export const WithError : Story = {
53
+ args : {
54
+ ...defaultArgs ,
55
+ updateErr : mockApiError ( {
56
+ message : "Invalid schedule" ,
57
+ validations : [
58
+ {
59
+ field : "schedule" ,
60
+ detail : "Could not validate cron schedule." ,
61
+ } ,
62
+ ] ,
63
+ } ) ,
64
+ } ,
65
65
} ;
0 commit comments