import { Form, MarkdownInput } from '@/components/form' import { gql, useMutation } from '@apollo/client' import styles from './reply.module.css' import { commentSchema } from '@/lib/validate' import { useToast } from './toast' import { toastUpsertSuccessMessages } from '@/lib/form' import { FeeButtonProvider } from './fee-button' import { ItemButtonBar } from './post' export default function CommentEdit ({ comment, editThreshold, onSuccess, onCancel }) { const toaster = useToast() const [upsertComment] = useMutation( gql` mutation upsertComment($id: ID! $text: String!) { upsertComment(id: $id, text: $text) { text deleteScheduledAt reminderScheduledAt } }`, { update (cache, { data: { upsertComment } }) { cache.modify({ id: `Item:${comment.id}`, fields: { text () { return upsertComment.text } } }) } } ) return (
{ const { data, error } = await upsertComment({ variables: { ...values, id: comment.id } }) if (error) { throw new Error({ message: error.toString() }) } toastUpsertSuccessMessages(toaster, data, 'upsertComment', true, values.text) if (onSuccess) { onSuccess() } }} >
) }