-
Notifications
You must be signed in to change notification settings - Fork 3
12 Authors
JP Barbosa edited this page Apr 28, 2021
·
3 revisions
code ./src/pages/Author/index.tsx
import { Author } from '../../interfaces/RecordEntities';
import { RecordIndex } from '../Record';
import { AuthorListItem } from './ListItem';
import { AuthorFormFields } from './FormFields';
export const AuthorIndex: React.FC = () => {
const apiOptions = {};
const emptyRecord = {
name: '',
};
return (
<RecordIndex<Author>
ListItem={AuthorListItem}
apiPath="authors"
apiOptions={apiOptions}
emptyRecord={emptyRecord}
FormFields={AuthorFormFields}
/>
);
};
code ./src/Pages/Author/ListItem.tsx
import { Author } from '../../interfaces/RecordEntities';
import { ListItemProps } from '../../interfaces/PagesProps';
type IProps = ListItemProps<Author>;
export const AuthorListItem: React.FC<IProps> = ({ record }) => {
return <div className="title">{record.name}</div>;
};
code ./src/Pages/Author/FormFields.tsx
import { Author } from '../../interfaces/RecordEntities';
import { FormFieldsProps } from '../../interfaces/PagesProps';
type IProps = FormFieldsProps<Author>;
export const AuthorFormFields: React.FC<IProps> = ({
formState,
handleChange,
}) => {
return (
<div>
<div>
<label>Name</label>
<input
type="text"
name="name"
value={formState.name}
onChange={handleChange}
/>
</div>
</div>
);
};
code ./src/App.tsx
...
import { AuthorIndex } from './pages/Author';
const App: React.FC = () => {
...
const renderSwitch = () => {
switch (page) {
...
case Page.Authors:
return <AuthorIndex />;
...
}
};
...
};
export default App;
yarn start
git add .
git commit -m "Authors"