import type { EditPostById, UpdatePostInput, UpdatePostMutationVariables, } from 'types/graphql' import { navigate, routes } from '@redwoodjs/router' import type { CellSuccessProps, CellFailureProps, TypedDocumentNode, } from '@redwoodjs/web' import { useMutation } from '@redwoodjs/web' import { toast } from '@redwoodjs/web/toast' import PostForm from 'src/components/Post/PostForm' export const QUERY: TypedDocumentNode = gql` query EditPostById($id: Int!) { post: post(id: $id) { id title body createdAt updatedAt } } ` const UPDATE_POST_MUTATION: TypedDocumentNode< EditPostById, UpdatePostMutationVariables > = gql` mutation UpdatePostMutation($id: Int!, $input: UpdatePostInput!) { updatePost(id: $id, input: $input) { id title body createdAt updatedAt } } ` export const Loading = () =>
Loading...
export const Failure = ({ error }: CellFailureProps) => (
{error?.message}
) export const Success = ({ post }: CellSuccessProps) => { const [updatePost, { loading, error }] = useMutation(UPDATE_POST_MUTATION, { onCompleted: () => { toast.success('Post updated') navigate(routes.posts()) }, onError: (error) => { toast.error(error.message) }, }) const onSave = (input: UpdatePostInput, id: EditPostById['post']['id']) => { updatePost({ variables: { id, input } }) } return (

Edit Post {post?.id}

) }