import React, { useState } from 'react'; import { useHistory } from 'react-router'; import { useMutation, gql, useQuery } from '@apollo/client'; // import { APPOINTMENTS_PER_PAGE } from '../../constants'; // import { APPOINTMENTS_QUERY } from './AppointmentList'; import Datetime from 'react-datetime'; import "react-datetime/css/react-datetime.css"; const ONE_APPOINTMENT_QUERY = gql` query OneAppointmentQuery( $_id: ID! ){ oneAppointment(_id: $_id){ _id title description type start end } } `; const UPDATE_APPOINTMENT_MUTATION = gql` mutation UpdateAppointmentMutation( $_id: ID! $title: String! $description: String $type: String! $start: DateTime! $end: DateTime! ) { updateAppointment(title: $title, description: $description, start: $start, end: $end) { _id title description type start end } } `; const UpdateAppointment = ({ match: { params: { _id } } }) => { const history = useHistory(); const { data } = useQuery(ONE_APPOINTMENT_QUERY, { variables: { _id: _id } }); let [formState, setFormState] = useState({ // _id: '', // title: '', // description: '', // type: '', // start: '', // end: '' }); const [updateAppointment] = useMutation(UPDATE_APPOINTMENT_MUTATION, { variables: { _id: formState._id, title: formState.title, description: formState.description, type: formState.type, start: formState.start, end: formState.end }, onCompleted: () => history.push('/') }); if (data === undefined) { return