39 lines
991 B
JavaScript
39 lines
991 B
JavaScript
import { useMutation, useFlash } from '@redwoodjs/web'
|
|
import { navigate, routes } from '@redwoodjs/router'
|
|
import PostForm from 'src/components/PostForm'
|
|
|
|
const CREATE_POST_MUTATION = gql`
|
|
mutation CreatePostMutation($input: CreatePostInput!) {
|
|
createPost(input: $input) {
|
|
id
|
|
}
|
|
}
|
|
`
|
|
|
|
const NewPost = () => {
|
|
const { addMessage } = useFlash()
|
|
const [createPost, { loading, error }] = useMutation(CREATE_POST_MUTATION, {
|
|
onCompleted: () => {
|
|
navigate(routes.posts())
|
|
addMessage('Post created.', { classes: 'rw-flash-success' })
|
|
},
|
|
})
|
|
|
|
const onSave = (input) => {
|
|
createPost({ variables: { input } })
|
|
}
|
|
|
|
return (
|
|
<div className="rw-segment">
|
|
<header className="rw-segment-header">
|
|
<h2 className="rw-heading rw-heading-secondary">New Post</h2>
|
|
</header>
|
|
<div className="rw-segment-main">
|
|
<PostForm onSave={onSave} loading={loading} error={error} />
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default NewPost
|