quintodrome/ui/src/user/UserCreate.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
1.7 KiB
JavaScript
Raw Normal View History

import React, { useCallback } from 'react'
2020-01-19 17:39:37 -09:00
import {
BooleanInput,
Create,
TextInput,
PasswordInput,
required,
2020-01-20 05:54:29 -09:00
email,
2020-01-19 17:39:37 -09:00
SimpleForm,
2020-04-27 19:22:17 -08:00
useTranslate,
useMutation,
useNotify,
useRedirect,
2020-01-19 17:39:37 -09:00
} from 'react-admin'
import { Title } from '../common'
2020-01-19 17:39:37 -09:00
2020-04-27 19:22:17 -08:00
const UserCreate = (props) => {
const translate = useTranslate()
const [mutate] = useMutation()
const notify = useNotify()
const redirect = useRedirect()
2020-04-27 19:22:17 -08:00
const resourceName = translate('resources.user.name', { smart_count: 1 })
const title = translate('ra.page.create', {
name: `${resourceName}`,
})
const save = useCallback(
async (values) => {
try {
await mutate(
{
type: 'create',
resource: 'user',
payload: { data: values },
},
{ returnPromise: true },
)
notify('resources.user.notifications.created', 'info', {
smart_count: 1,
})
redirect('/user')
} catch (error) {
if (error.body.errors) {
return error.body.errors
}
}
},
[mutate, notify, redirect],
)
2020-04-27 19:22:17 -08:00
return (
<Create title={<Title subTitle={title} />} {...props}>
<SimpleForm save={save} variant={'outlined'}>
<TextInput
spellCheck={false}
source="userName"
validate={[required()]}
/>
2020-04-27 19:22:17 -08:00
<TextInput source="name" validate={[required()]} />
<TextInput spellCheck={false} source="email" validate={[email()]} />
<PasswordInput
spellCheck={false}
source="password"
validate={[required()]}
/>
2020-04-27 19:22:17 -08:00
<BooleanInput source="isAdmin" defaultValue={false} />
</SimpleForm>
</Create>
)
}
2020-01-19 17:39:37 -09:00
export default UserCreate