import { useMutation } from 'react-apollo'
import { USER_LOGOUT, CURRENT_USER } from './graphql'

interface LogoutButtonProps {
  title?: string
}

const LogoutButton = ({ title }: LogoutButtonProps) => {
  const [logout, { loading, error }] = useMutation(USER_LOGOUT)

  return (
    <button disabled={loading} onClick={() => {
      logout({ refetchQueries: [{ query: CURRENT_USER }] })
    }}>{title || 'Log out'}</button>
  )
}

export default LogoutButton
