Skip to content

added title meta tag #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 69 additions & 62 deletions templates/next/components/foo/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FunctionComponent, useState } from "react";
import Link from "next/link";
import { useRouter } from "next/router";
import Head from "next/head";
import { Formik } from "formik";
import { fetch } from "../../utils/dataAccess";
import { {{{ucf}}} } from '../../types/{{{ucf}}}';
Expand All @@ -27,15 +28,21 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {

return (
<div>
{ {{{lc}}} ? <h1>Edit {{{ucf}}} { {{{lc}}}['@id'] }</h1> : <h1>Create {{{ucf}}}</h1>}
<Formik
initialValues={ {{~lc}} ? {...{{lc~}} } : new {{{ucf}}}()}
validate={(values) => {
const errors = {};
// add your validation logic here
<div>
<Head>
<title>{ {{{lc}}} ? `Edit {{{ucf}}} ${ {{{~lc}}}['@id']}` : `Create {{{ucf}}}` }</title>
<meta property="og:title" content="{{{lc}}} ? `Edit {{{ucf}}} ${ {{{~lc}}}['@id']}` : `Create {{{ucf}}}`" />
</Head>
</div>
<h1>{{{lc}}} ? `Edit {{{ucf}}} ${ {{{~lc}}}['@id']}` : `Create {{{ucf}}}`</h1>
<Formik
initialValues={ {{~lc}} ? {...{{lc~}} } : new {{{ucf}}}()}
validate={(values) => {
const errors = {};
// add your validation logic here
return errors;
}}
onSubmit={async (values, { setSubmitting, setStatus }) => {
}}
onSubmit={async (values, { setSubmitting, setStatus }) => {
const isCreation = !values["@id"];
try {
await fetch(isCreation ? "/{{{name}}}" : values["@id"], {
Expand All @@ -53,24 +60,24 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
msg: `Error when ${isCreation ? 'creating': 'updating'} the resource.`,
});
}
setSubmitting(false);
}}
>
{({
values,
setSubmitting(false);
}}
>
{({
values,
status,
errors,
touched,
handleChange,
handleBlur,
handleSubmit,
isSubmitting,
}) => (
<form onSubmit={handleSubmit}>
handleChange,
handleBlur,
handleSubmit,
isSubmitting,
}) => (
<form onSubmit={handleSubmit}>
{{#each formFields}}
<div className="form-group">
<label className="form-control-label" htmlFor="{{lc}}_{{name}}">{{name}}</label>
<input
<div className="form-group">
<label className="form-control-label" htmlFor="{{lc}}_{{name}}">{{name}}</label>
<input
name="{{name}}"
id="{{lc}}_{{name}}"
value={ values.{{name}} ?? "" }
Expand All @@ -80,48 +87,48 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
{{#if required}}required={true}{{/if}}
className={`form-control${errors.{{name}} && touched.{{name}} ? ' is-invalid' : ''}`}
aria-invalid={errors.{{name}} && touched.{{name~}} }
onChange={handleChange}
onBlur={handleBlur}
/>
</div>
{ errors.{{name}} && touched.{{name}} && <div className="invalid-feedback">{ errors.{{name}} }</div> }
onChange={handleChange}
onBlur={handleBlur}
/>
</div>
{ errors.{{name}} && touched.{{name}} && <div className="invalid-feedback">{ errors.{{name}} }</div> }
{{/each}}

{status && status.msg && (
<div
className={`alert ${
status.isValid ? "alert-success" : "alert-danger"
}`}
role="alert"
>
{status.msg}
</div>
)}
{status && status.msg && (
<div
className={`alert ${
status.isValid ? "alert-success" : "alert-danger"
}`}
role="alert"
>
{status.msg}
</div>
)}

{error && (
<div className="alert alert-danger" role="alert">
{error}
</div>
)}
{error && (
<div className="alert alert-danger" role="alert">
{error}
</div>
)}

<button
type="submit"
className="btn btn-success"
disabled={isSubmitting}
>
Submit
</button>
</form>
)}
</Formik>
<Link href="/{{{name}}}">
<a className="btn btn-primary">Back to list</a>
</Link>
{ {{{lc}}} && (
<button className="btn btn-danger" onClick={handleDelete}>
<a>Delete</a>
</button>
)}
</div>
);
<button
type="submit"
className="btn btn-success"
disabled={isSubmitting}
>
Submit
</button>
</form>
)}
</Formik>
<Link href="/{{{name}}}">
<a className="btn btn-primary">Back to list</a>
</Link>
{ {{{lc}}} && (
<button className="btn btn-danger" onClick={handleDelete}>
<a>Delete</a>
</button>
)}
</div>
);
};
9 changes: 9 additions & 0 deletions templates/next/components/foo/List.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FunctionComponent } from "react";
import Link from "next/link";
import Head from "next/head";
import ReferenceLinks from "../../components/common/ReferenceLinks";
import { {{{ucf}}} } from '../../types/{{{ucf}}}';

Expand All @@ -9,6 +10,12 @@ interface Props {

export const List: FunctionComponent<Props> = ({ {{{name}}} }) => (
<div>
<div>
<Head>
<title>{{{ucf}}} List</title>
<meta property="og:title" content="{{{ucf}}} List" key="title" />
</Head>
</div>
<h1>{{{ucf}}} List</h1>
<Link href="/{{{name}}}/create">
<a className="btn btn-primary">Create</a>
Expand All @@ -31,6 +38,8 @@ export const List: FunctionComponent<Props> = ({ {{{name}}} }) => (
<td>{{#if reference}}<ReferenceLinks items={ {{{../lc}}}['{{{name}}}'] } type="{{{reference.title}}}" />{{else}}{ {{{../lc}}}['{{{name}}}'] }{{/if}}</td>
{{/each}}
<td><ReferenceLinks items={ {{{lc}}}['@id'] } type="{{{lc}}}" useIcon={true} /></td>
<br></br>
<Link href={`${ {{~lc}}["@id"]}/edit`}>Edit</Link>
</tr>
))}
</tbody>
Expand Down
11 changes: 9 additions & 2 deletions templates/next/components/foo/Show.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FunctionComponent, useState } from 'react';
import Link from 'next/link';
import Head from "next/head";
import { useRouter } from "next/router";
import { fetch } from "../../utils/dataAccess";
import { ReferenceLinks } from '../common/ReferenceLinks';
Expand All @@ -26,8 +27,14 @@ export const Show: FunctionComponent<Props> = ({ {{{lc}}} }) => {
};

return (
<div>
<h1>Show { {{{lc}}}['@id'] }</h1>
<h1>
<div>
<Head>
<title>{`Show {{{ucf}}} ${ {{{~lc}}}['@id']}`}</title>
<meta property="og:title" content=`Show {{{ucf}}} ${ {{{~lc}}}['@id']}` key="title" />
</Head>
</div>
<h1>{`Show {{{ucf}}} ${ {{{~lc}}}['@id']}`}</h1>
<table className="table table-responsive table-striped table-hover">
<thead>
<tr>
Expand Down