-
Notifications
You must be signed in to change notification settings - Fork 5
/
NewUser.tsx
44 lines (37 loc) · 977 Bytes
/
NewUser.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
import type { CreateUserInput } from 'types/graphql'
import { navigate, routes } from '@redwoodjs/router'
import { useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'
import UserForm from 'src/components/User/UserForm'
const CREATE_USER_MUTATION = gql`
mutation CreateUserMutation($input: CreateUserInput!) {
createUser(input: $input) {
id
}
}
`
const NewUser = () => {
const [createUser, { loading, error }] = useMutation(CREATE_USER_MUTATION, {
onCompleted: () => {
toast.success('User created')
navigate(routes.users())
},
onError: (error) => {
toast.error(error.message)
},
})
const onSave = (input: CreateUserInput) => {
createUser({ variables: { input } })
}
return (
<div>
<header>
<h2>New User</h2>
</header>
<div>
<UserForm onSave={onSave} loading={loading} error={error} />
</div>
</div>
)
}
export default NewUser