-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathUserCreate.tsx
76 lines (71 loc) · 2.01 KB
/
UserCreate.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* eslint react/jsx-key: off */
import * as React from 'react';
import {
Create,
FormTab,
SaveButton,
AutocompleteInput,
TabbedForm,
TextInput,
Toolbar,
required,
} from 'react-admin';
import Aside from './Aside';
const UserEditToolbar = ({
permissions,
hasList,
hasEdit,
hasShow,
hasCreate,
...props
}) => (
<Toolbar {...props}>
<SaveButton
label="user.action.save_and_show"
redirect="show"
submitOnEnter={true}
/>
{permissions === 'admin' && (
<SaveButton
label="user.action.save_and_add"
redirect={false}
submitOnEnter={false}
variant="text"
/>
)}
</Toolbar>
);
const isValidName = async value =>
new Promise(resolve =>
setTimeout(resolve(value === 'Admin' ? "Can't be Admin" : undefined))
);
const UserCreate = ({ permissions, ...props }) => (
<Create {...props} aside={<Aside />}>
<TabbedForm
toolbar={<UserEditToolbar permissions={permissions} {...props} />}
>
<FormTab label="user.form.summary" path="">
<TextInput
source="name"
defaultValue="Slim Shady"
autoFocus
validate={[required(), isValidName]}
/>
</FormTab>
{permissions === 'admin' && (
<FormTab label="user.form.security" path="security">
<AutocompleteInput
source="role"
choices={[
{ id: '', name: 'None' },
{ id: 'admin', name: 'Admin' },
{ id: 'user', name: 'User' },
{ id: 'user_simple', name: 'UserSimple' },
]}
/>
</FormTab>
)}
</TabbedForm>
</Create>
);
export default UserCreate;