import { useMutation } from "@apollo/react-hooks"
import { USER_DELETE } from './graphql'
import { SyntheticEvent } from "react"

interface DeleteUserProps {
  user: {
    id: string
  }
  title?: string
}

const DeleteUserButton = ({ title, user: { id } }: DeleteUserProps) => {
  const [deleteUser, { loading, error }] = useMutation(USER_DELETE)
  return (
    <button onClick={(event: SyntheticEvent) => {
      deleteUser({ variables: { id } })
    }}>{title || 'Delete user'}</button>
  )
}

export default DeleteUserButton