-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathUpdatePetPage.tsx
More file actions
47 lines (43 loc) · 1.69 KB
/
UpdatePetPage.tsx
File metadata and controls
47 lines (43 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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<UpdatePetMutation>;
};
const UpdatePetPage = ({ mutate, history, formData }: UpdatePetPageProps) =>
<div>
<PetEditForm
formTitle={`Update Pet ${formData.pet.name} from ${formData.pet.owner.firstName} ${formData.pet.owner.lastName}`}
initialPet={{
...formData.pet,
type: formData.pet.type.id
}}
pettypes={formData.pettypes}
onFormSubmit={(pet: PetData) => {
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}`);
});
}}
/>
</div>;
export default withUpdatePetFormData(graphql<UpdatePetMutation, UpdatePetPageOwnProps>(UpdatePetMutationGql)(UpdatePetPage));