@@ -15,7 +15,7 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
15
15
const handleDelete = ( ) => {
16
16
if ( window . confirm ( "Are you sure you want to delete this item?" ) ) {
17
17
try {
18
- fetch ( { { { { lc} } } [ '@id' ] } , { method : "DELETE" } ) ;
18
+ fetch ( { { { lc} } } [ '@id' ] , { method : "DELETE" } ) ;
19
19
router . push ( "/{{{name}}}" ) ;
20
20
} catch ( error ) {
21
21
setError ( "Error when deleting the resource." ) ;
@@ -31,22 +31,20 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
31
31
initialValues = { { { { lc} } } ?? new { { { lc} } } ( ) }
32
32
validate= { ( values ) => {
33
33
const errors = { } ;
34
- //set your validation logic here
34
+ // add your validation logic here
35
35
return errors ;
36
36
} }
37
37
onSubmit = { ( values , { setSubmitting, setStatus } ) => {
38
38
const isCreation = ! { { { lc} } } [ "@id" ] ;
39
39
try {
40
- fetch ( isCreation ? "/{{{name}}}" : { { { lc} } } [ "@id" ] ,
41
- {
42
- method : isCreation ? "POST" : "PATCH" ,
43
- body : JSON . stringify ( values ) ,
44
- }
45
- ) ;
40
+ fetch ( isCreation ? "/{{{name}}}" : { { { lc} } } [ "@id" ] , {
41
+ method : isCreation ? "POST" : "PATCH" ,
42
+ body : JSON . stringify ( values ) ,
43
+ } ) ;
46
44
setStatus ( {
47
- isValid : true ,
48
- msg : `Element ${ isCreation ? 'created' : 'updated' } .` ,
49
- } ) ;
45
+ isValid : true ,
46
+ msg : `Element ${ isCreation ? 'created' : 'updated' } .` ,
47
+ } ) ;
50
48
router . push ( "/{{{name}}}" ) ;
51
49
} catch ( error ) {
52
50
setStatus ( {
@@ -67,40 +65,40 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
67
65
} ) => (
68
66
< form onSubmit = { handleSubmit } >
69
67
{ { #each fields} }
70
- < div className = ' form-group' >
68
+ < div className = " form-group" >
71
69
< label > { { name} } </ label >
72
70
< input
73
- className = ' form-control'
74
- type = ' text'
75
- name = ' isbn'
71
+ className = " form-control"
72
+ type = " text"
73
+ name = " isbn"
76
74
onChange = { handleChange }
77
75
onBlur = { handleBlur }
78
76
value = { values . { { name } } }
79
77
required
80
78
/>
81
79
</ div >
82
- { /* { errors.{{name}} && touched.{{name}} && errors.{{name}} */ }
80
+ { errors . { { name } } && touched . { { name} } && errors . { { name} } }
83
81
{ { / each} }
84
82
{ status && status . msg && (
85
83
< div
86
84
className = { `alert ${
87
85
status . isValid ? "alert-success" : "alert-danger"
88
86
} `}
89
- role = ' alert'
87
+ role = " alert"
90
88
>
91
89
{ status . msg }
92
90
</ div >
93
91
) }
94
92
95
93
{ error && (
96
- < div className = ' alert alert-danger' role = ' alert' >
94
+ < div className = " alert alert-danger" role = " alert" >
97
95
{ error }
98
96
</ div >
99
97
) }
100
98
101
99
< button
102
- type = ' submit'
103
- className = ' btn btn-success'
100
+ type = " submit"
101
+ className = " btn btn-success"
104
102
disabled = { isSubmitting }
105
103
>
106
104
Submit
@@ -109,10 +107,10 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
109
107
) }
110
108
</Formik >
111
109
< Link href = "/{{{name}}}" >
112
- < a className = ' btn btn-primary' > Back to list</ a >
110
+ < a className = " btn btn-primary" > Back to list</ a >
113
111
</ Link >
114
112
{ { { { lc} } } && (
115
- < button className = ' btn btn-danger' onClick = { handleDelete } >
113
+ < button className = " btn btn-danger" onClick = { handleDelete } >
116
114
< a > Delete</ a >
117
115
</ button >
118
116
) }
0 commit comments