import * as React from "react"; import { gql, graphql, QueryProps, DefaultChildProps, MutationFunc } from "react-apollo"; import { withRouter, RouteComponentProps } from "react-router-dom"; import * as UpdatePetMutationGql from "./UpdatePetMutation.graphql"; import { GetUpdatePetFormDataQuery, UpdatePetInput, UpdatePetMutation, PetData } from "../../types"; import PetEditForm from "../PetForm"; import withUpdatePetFormData from "./withUpdatePetFormData"; type UpdatePetPageOwnProps = RouteComponentProps<{}> & { formData: GetUpdatePetFormDataQuery; }; type UpdatePetPageProps = UpdatePetPageOwnProps & { mutate: MutationFunc; }; const UpdatePetPage = ({ mutate, history, formData }: UpdatePetPageProps) =>
{ const input: UpdatePetInput = { name: pet.name, petId: formData.pet.id, birthDate: pet.birthDate, typeId: pet.type }; return mutate({ variables: { input } }) .then(({ data }) => { history.push(`/owners/${formData.pet.owner.id}`); }) .catch(error => { console.log("there was an error sending the query", error); return Promise.reject(`Could not save owner: ${error}`); }); }} />
; export default withUpdatePetFormData(graphql(UpdatePetMutationGql)(UpdatePetPage));