11import { FunctionComponent , useState } from "react" ;
22import Link from "next/link" ;
33import { useRouter } from "next/router" ;
4+ import Head from "next/head" ;
45import { Formik } from "formik" ;
56import { fetch } from "../../utils/dataAccess" ;
67import { { { { ucf } } } } from '../../types/{{{ucf}}}' ;
@@ -27,15 +28,21 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
2728
2829 return (
2930 < div >
30- { { { { lc} } } ? < h1 > Edit { { { ucf} } } { { { { lc} } } [ '@id' ] } </h1 > : < h1 > Create { { { ucf} } } </ h1 > }
31- < Formik
32- initialValues = { { { ~ lc} } ? { ...{ { lc ~ } } } : new { { { ucf} } } ( ) }
33- validate= { ( values ) => {
34- const errors = { } ;
35- // add your validation logic here
31+ < div >
32+ < Head >
33+ < title > { { { { lc} } } ? `Edit {{{ucf}}} ${ { { { ~ lc } }}['@id']}` : `Create {{{ucf}}}` } </ title >
34+ < meta property = "og:title" content = "{{{lc}}} ? `Edit {{{ucf}}} ${ {{{~lc}}}['@id']}` : `Create {{{ucf}}}`" />
35+ </ Head >
36+ </ div >
37+ < h1 > { { { lc} } } ? `Edit {{{ucf}}} ${ { { { ~ lc } }}['@id']}` : `Create {{{ucf}}}` < / h 1 >
38+ < Formik
39+ initialValues = { { { ~ lc} } ? { ...{ { lc~ } } } : new { { { ucf} } } ( ) }
40+ validate= { ( values ) => {
41+ const errors = { } ;
42+ // add your validation logic here
3643 return errors ;
37- } }
38- onSubmit = { async ( values , { setSubmitting, setStatus } ) => {
44+ } }
45+ onSubmit = { async ( values , { setSubmitting, setStatus } ) => {
3946 const isCreation = ! values [ "@id" ] ;
4047 try {
4148 await fetch ( isCreation ? "/{{{name}}}" : values [ "@id" ] , {
@@ -53,24 +60,24 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
5360 msg : `Error when ${ isCreation ? 'creating' : 'updating' } the resource.` ,
5461 } ) ;
5562 }
56- setSubmitting ( false ) ;
57- } }
58- >
59- { ( {
60- values,
63+ setSubmitting ( false ) ;
64+ } }
65+ >
66+ { ( {
67+ values,
6168 status,
6269 errors,
6370 touched,
64- handleChange,
65- handleBlur,
66- handleSubmit,
67- isSubmitting,
68- } ) => (
69- < form onSubmit = { handleSubmit } >
71+ handleChange,
72+ handleBlur,
73+ handleSubmit,
74+ isSubmitting,
75+ } ) => (
76+ < form onSubmit = { handleSubmit } >
7077 { { #each formFields} }
71- < div className = "form-group" >
72- < label className = "form-control-label" htmlFor = "{{lc}}_{{name}}" > { { name} } </ label >
73- < input
78+ < div className = "form-group" >
79+ < label className = "form-control-label" htmlFor = "{{lc}}_{{name}}" > { { name} } </ label >
80+ < input
7481 name = "{{name}}"
7582 id = "{{lc}}_{{name}}"
7683 value = { values . { { name } } ?? "" }
@@ -80,48 +87,48 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
8087 { { #if required} } required = { true } { { / i f } }
8188 className = { `form-control${ errors . { { name } } && touched.{{name}} ? ' is-invalid' : ''}` }
8289 aria-invalid = { errors . { { name } } && touched . { { name~ } } }
83- onChange = { handleChange }
84- onBlur = { handleBlur }
85- />
86- </ div >
87- { errors . { { name } } && touched . { { name} } && < div className = "invalid-feedback" > { errors . { { name } } } </ div > }
90+ onChange = { handleChange }
91+ onBlur = { handleBlur }
92+ />
93+ </ div >
94+ { errors . { { name } } && touched . { { name} } && < div className = "invalid-feedback" > { errors . { { name } } } </ div > }
8895 { { / each} }
8996
90- { status && status . msg && (
91- < div
92- className = { `alert ${
93- status . isValid ? "alert-success" : "alert-danger"
94- } `}
95- role = "alert"
96- >
97- { status . msg }
98- </ div >
99- ) }
97+ { status && status . msg && (
98+ < div
99+ className = { `alert ${
100+ status . isValid ? "alert-success" : "alert-danger"
101+ } `}
102+ role = "alert"
103+ >
104+ { status . msg }
105+ </ div >
106+ ) }
100107
101- { error && (
102- < div className = "alert alert-danger" role = "alert" >
103- { error }
104- </ div >
105- ) }
108+ { error && (
109+ < div className = "alert alert-danger" role = "alert" >
110+ { error }
111+ </ div >
112+ ) }
106113
107- < button
108- type = "submit"
109- className = "btn btn-success"
110- disabled = { isSubmitting }
111- >
112- Submit
113- </ button >
114- </ form >
115- ) }
116- < / Formik >
117- < Link href = "/{{{name}}}" >
118- < a className = "btn btn-primary" > Back to list</ a >
119- < / L i n k >
120- { { { { lc} } } && (
121- < button className = "btn btn-danger" onClick = { handleDelete } >
122- < a > Delete</ a >
123- </ button >
124- ) }
125- < / d i v >
126- ) ;
114+ < button
115+ type = "submit"
116+ className = "btn btn-success"
117+ disabled = { isSubmitting }
118+ >
119+ Submit
120+ </ button >
121+ </ form >
122+ ) }
123+ < / Formik >
124+ < Link href = "/{{{name}}}" >
125+ < a className = "btn btn-primary" > Back to list</ a >
126+ < / L i n k >
127+ { { { { lc} } } && (
128+ < button className = "btn btn-danger" onClick = { handleDelete } >
129+ < a > Delete</ a >
130+ </ button >
131+ ) }
132+ < / d i v >
133+ ) ;
127134} ;
0 commit comments