@@ -15,7 +15,7 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
1515 const handleDelete = ( ) => {
1616 if ( window . confirm ( "Are you sure you want to delete this item?" ) ) {
1717 try {
18- fetch ( { { { { lc} } } [ '@id' ] } , { method : "DELETE" } ) ;
18+ fetch ( { { { lc} } } [ '@id' ] , { method : "DELETE" } ) ;
1919 router . push ( "/{{{name}}}" ) ;
2020 } catch ( error ) {
2121 setError ( "Error when deleting the resource." ) ;
@@ -31,22 +31,20 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
3131 initialValues = { { { { lc} } } ?? new { { { lc} } } ( ) }
3232 validate= { ( values ) => {
3333 const errors = { } ;
34- //set your validation logic here
34+ // add your validation logic here
3535 return errors ;
3636 } }
3737 onSubmit = { ( values , { setSubmitting, setStatus } ) => {
3838 const isCreation = ! { { { lc} } } [ "@id" ] ;
3939 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+ } ) ;
4644 setStatus ( {
47- isValid : true ,
48- msg : `Element ${ isCreation ? 'created' : 'updated' } .` ,
49- } ) ;
45+ isValid : true ,
46+ msg : `Element ${ isCreation ? 'created' : 'updated' } .` ,
47+ } ) ;
5048 router . push ( "/{{{name}}}" ) ;
5149 } catch ( error ) {
5250 setStatus ( {
@@ -67,40 +65,40 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
6765 } ) => (
6866 < form onSubmit = { handleSubmit } >
6967{ { #each fields} }
70- < div className = ' form-group' >
68+ < div className = " form-group" >
7169 < label > { { name} } </ label >
7270 < input
73- className = ' form-control'
74- type = ' text'
75- name = ' isbn'
71+ className = " form-control"
72+ type = " text"
73+ name = " isbn"
7674 onChange = { handleChange }
7775 onBlur = { handleBlur }
7876 value = { values . { { name } } }
7977 required
8078 />
8179 </ div >
82- { /* { errors.{{name}} && touched.{{name}} && errors.{{name}} */ }
80+ { errors . { { name } } && touched . { { name} } && errors . { { name} } }
8381{ { / each} }
8482 { status && status . msg && (
8583 < div
8684 className = { `alert ${
8785 status . isValid ? "alert-success" : "alert-danger"
8886 } `}
89- role = ' alert'
87+ role = " alert"
9088 >
9189 { status . msg }
9290 </ div >
9391 ) }
9492
9593 { error && (
96- < div className = ' alert alert-danger' role = ' alert' >
94+ < div className = " alert alert-danger" role = " alert" >
9795 { error }
9896 </ div >
9997 ) }
10098
10199 < button
102- type = ' submit'
103- className = ' btn btn-success'
100+ type = " submit"
101+ className = " btn btn-success"
104102 disabled = { isSubmitting }
105103 >
106104 Submit
@@ -109,10 +107,10 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
109107 ) }
110108 </Formik >
111109 < Link href = "/{{{name}}}" >
112- < a className = ' btn btn-primary' > Back to list</ a >
110+ < a className = " btn btn-primary" > Back to list</ a >
113111 </ Link >
114112 { { { { lc} } } && (
115- < button className = ' btn btn-danger' onClick = { handleDelete } >
113+ < button className = " btn btn-danger" onClick = { handleDelete } >
116114 < a > Delete</ a >
117115 </ button >
118116 ) }
0 commit comments