bunch of stuff
This commit is contained in:
38
web/src/components/NewPost/NewPost.js
Normal file
38
web/src/components/NewPost/NewPost.js
Normal file
@@ -0,0 +1,38 @@
|
||||
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
|
||||
Reference in New Issue
Block a user