import { useMutation } from '@apollo/client'
import { gql } from 'apollo-server-micro'
import { useState } from 'react'
import { Alert, Button, Dropdown } from 'react-bootstrap'
import { useShowModal } from './modal'
export default function Delete ({ itemId, children, onDelete }) {
const showModal = useShowModal()
const [deleteItem] = useMutation(
gql`
mutation deleteItem($id: ID!) {
deleteItem(id: $id) {
text
title
url
pollCost
deletedAt
}
}`, {
update (cache, { data: { deleteItem } }) {
cache.modify({
id: `Item:${itemId}`,
fields: {
text: () => deleteItem.text,
title: () => deleteItem.title,
url: () => deleteItem.url,
pollCost: () => deleteItem.pollCost,
deletedAt: () => deleteItem.deletedAt
}
})
}
}
)
return (
{
showModal(onClose => {
return (
Are you sure? This is a gone forever kind of delete.