content: import React, { Component } from 'react';
  import gql from 'graphql-tag';
  import { graphql } from 'react-apollo';
  import { Link, hashHistory } from 'react-router';
  //queries
  import fetchVisits from '../../queries/fetchVisits';
  import query from '../../queries/fetchVisit';
  
  class updateVisit extends Component {
      constructor(props){
          super(props);
          this.state={
              visitDate: "",
              status: "",
              result: ""
          }
      };
      Submit(event){
          event.preventDefault();
         /*  let variable= {
              id: this.props.params.id,
              status: "",
              result: "",
              visitDate: ""
          };
          if(this.state.status===null){
              variable.status=this.props.params.sttus;
          } else {
  
          } */
  
  
          this.props.mutate({
              variables:{
                  id: this.props.params.id,
                  status: this.state.status,
                  result: this.state.result,
                  visitDate: this.state.visitDate
              },
              refetchQueries: [{ query: fetchVisits }]
          })
              .then(()=> hashHistory.push('/admin'))
              .catch(err=>{alert(err)});
  
      };
      UpdateState(event){
          event.preventDefault();
          this.setState({ [event.target.name] :event.target.value });
      };
      render(){
          if(this.props.data.loading){
              return(
                  <div>
                      loading
                  </div>
              )
          }
          else return(
              <div>
                  <h3>Modify the visit</h3>
                  <form onSubmit={this.Submit.bind(this)}>
                      <h5>firstName: {this.props.data.visit.user.firstName}</h5>
                      <label>Visit Date
                          <input type="text" className="datepicker" 
                              name="visitDate"
                              onChange={this.UpdateState.bind(this)}
                              value={this.state.visitDate}
                              placeholder={this.props.data.visit.visitDate}/>
                      </label>
                      <label>Status
                          <input 
                              name="status"
                              onChange={this.UpdateState.bind(this)}
                              value={this.state.status}
                              placeholder={this.props.data.visit.status}/>
                      </label>
                      <label>Results (from doctor notes)
                          <input
                              name="result"
                              onChange={this.UpdateState.bind(this)}
                              value={this.state.result}
                              placeholder={this.props.data.visit.result}/>
                      </label>
                      <button type="submit">Save changes</button>
                      <button><Link to={'/'}>Cancel</Link></button>
                  </form>
              </div>
          )
      }
  };
  
  
  
  const mutation = gql`
  mutation updateVisit(
      $id: ID!
      $status: String
      $result: String
      $visitDate: String
      ){
          updateVisit(
              id:$id
              status: $status
              result: $result
              visitDate: $visitDate
          ){
              id
          }
      }
  `;
  
  export default graphql(mutation)(
      graphql(query.fetchVisit,{
          options: (props)=>{
              return {variables: {visitID: props.params.id}}
          }
      })(updateVisit)
  )
  
  