Skip to content

Commit cb75974

Browse files
committed
Adding Creation and Editing Capabilities
Add and enable <PostCreate> component in the app
1 parent b894d95 commit cb75974

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import React from 'react';
22
import { Admin, Resource } from 'react-admin';
3-
import { PostList, PostEdit } from './posts';
3+
import { PostList, PostEdit, PostCreate } from './posts';
44
import { UserList } from './users';
55
import jsonServerProvider from 'ra-data-json-server';
66

77
const dataProvider = jsonServerProvider('http://jsonplaceholder.typicode.com');
88
const App = () => (
99
<Admin dataProvider={dataProvider}>
1010
<Resource name="users" list={UserList} />
11-
<Resource name="posts" list={PostList} edit={PostEdit} />
11+
<Resource name="posts" list={PostList} edit={PostEdit} create={PostCreate} />
1212
</Admin>
1313
);
1414

src/posts.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { List,
88
SimpleForm,
99
ReferenceInput,
1010
SelectInput,
11-
TextInput
11+
TextInput,
12+
Create
1213
} from 'react-admin';
1314

1415
export const PostList = props => (
@@ -36,3 +37,15 @@ export const PostEdit = props => (
3637
</SimpleForm>
3738
</Edit>
3839
);
40+
41+
export const PostCreate = props => (
42+
<Create {...props}>
43+
<SimpleForm>
44+
<ReferenceInput source="userId" reference="users">
45+
<SelectInput optionText="name" />
46+
</ReferenceInput>
47+
<TextInput source="title" />
48+
<TextInput multiline source="body" />
49+
</SimpleForm>
50+
</Create>
51+
);

0 commit comments

Comments
 (0)