{"componentChunkName":"component---src-templates-post-js","path":"/execute-booking-mutation","result":{"data":{"markdownRemark":{"html":"<p>In this part we will finilize the mutation.</p>\n<p>So we will use the Apollo Mutation component to execute the mutation. Go back into your <code class=\"language-text\">BookingIndex.vue</code> and make sure it looks like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"vue\"><pre class=\"language-vue\"><code class=\"language-vue\">&lt;template&gt;\n  &lt;div&gt;\n    &lt;!-- mutation ---&gt;\n    &lt;ApolloMutation\n      :mutation=&quot;require(&#39;../../graphql/makeABooking.gql&#39;)&quot;\n      :variables=&quot;{\n        size: parseInt(number),\n        customerEmail: email,\n        bookingDate: date,\n        listingId: this.$route.params.id,\n        customers: customers,\n      }&quot;\n      @done=&quot;onDone&quot;\n    &gt;\n      &lt;template v-slot=&quot;{ mutate, loading, error }&quot;&gt;\n        &lt;!-- TAB ONE ---&gt;\n\n        &lt;a-tabs v-model=&quot;activeKey&quot;&gt;\n          &lt;a-tab-pane tab=&quot;Tab 1&quot; key=&quot;1&quot; class=&quot;flex justify-center&quot;&gt;\n            &lt;div class=&quot;flex flex-col p-20 &quot;&gt;\n              &lt;HeadingOne&gt;\n                Booking for Listing Name\n              &lt;/HeadingOne&gt;\n              &lt;div class=&quot;mt-5&quot;&gt;\n                &lt;BodyOne&gt;\n                  Booking date\n                &lt;/BodyOne&gt;\n                &lt;DateInput placeholder=&quot;date&quot; type=&quot;date&quot; v-model=&quot;date&quot; /&gt;\n              &lt;/div&gt;\n\n              &lt;div class=&quot;mt-5&quot;&gt;\n                &lt;BodyOne&gt;\n                  Number of people\n                &lt;/BodyOne&gt;\n                &lt;Input placeholder=&quot;3&quot; type=&quot;number&quot; v-model=&quot;number&quot; /&gt;\n              &lt;/div&gt;\n\n              &lt;div class=&quot;mt-5&quot;&gt;\n                &lt;BodyOne&gt; Email address &lt;/BodyOne&gt;\n                &lt;Input\n                  placeholder=&quot;doku@corrisant.io&quot;\n                  type=&quot;email&quot;\n                  v-model=&quot;email&quot;\n                /&gt;\n              &lt;/div&gt;\n              &lt;div class=&quot;flex lg:flex-row mt-5 s:flex-col&quot;&gt;\n                &lt;RedBlockButton\n                  @click=&quot;next(2)&quot;\n                  text=&quot;Proceed&quot;\n                  class=&quot;mr-5 s:mb-5 lg:mb-0&quot;\n                /&gt;\n                &lt;RedOutlineButton @click=&quot;$router.push(&#39;/&#39;)&quot; text=&quot;Cancel&quot; /&gt;\n              &lt;/div&gt;\n            &lt;/div&gt;\n          &lt;/a-tab-pane&gt;\n\n          &lt;!-- TAB ONE  END---&gt;\n\n          &lt;!-- TAB TWO ---&gt;\n\n          &lt;a-tab-pane tab=&quot;Tab 2&quot; key=&quot;2&quot; class=&quot;flex justify-center&quot;&gt;\n            &lt;div class=&quot;flex flex-col p-20 &quot;&gt;\n              &lt;HeadingOne&gt;\n                Who are you travelling with?Who are you travelling with?\n              &lt;/HeadingOne&gt;\n              &lt;div\n                class=&quot;flex lg:flex-row s:flex-col mt-10&quot;\n                v-for=&quot;(customer, i) in customers&quot;\n                :key=&quot;i&quot;\n              &gt;\n                &lt;hr /&gt;\n                &lt;div class=&quot;flex flex-col mr-5&quot;&gt;\n                  &lt;BodyOne&gt; customer name &lt;/BodyOne&gt;\n\n                  &lt;Input\n                    placeholder=&quot;doku@corrisant.io&quot;\n                    type=&quot;email&quot;\n                    v-model=&quot;customer.name&quot;\n                  /&gt;\n\n                  &lt;BodyOne&gt; customer country &lt;/BodyOne&gt;\n\n                  &lt;Input\n                    placeholder=&quot;doku@corrisant.io&quot;\n                    type=&quot;email&quot;\n                    v-model=&quot;customer.country&quot;\n                  /&gt;\n\n                  &lt;BodyOne&gt; Physio score &lt;/BodyOne&gt;\n\n                  &lt;Input\n                    placeholder=&quot;doku@corrisant.io&quot;\n                    type=&quot;email&quot;\n                    v-model=&quot;customer.physioScore&quot;\n                  /&gt;\n                &lt;/div&gt;\n\n                &lt;div class=&quot;flex flex-col&quot;&gt;\n                  &lt;BodyOne&gt; Customer surname &lt;/BodyOne&gt;\n\n                  &lt;Input\n                    placeholder=&quot;doku@corrisant.io&quot;\n                    type=&quot;email&quot;\n                    v-model=&quot;customer.Surname&quot;\n                  /&gt;\n                  &lt;label&gt; &lt;/label&gt;\n                  &lt;input /&gt;\n\n                  &lt;BodyOne&gt; Passport number &lt;/BodyOne&gt;\n\n                  &lt;Input\n                    placeholder=&quot;doku@corrisant.io&quot;\n                    type=&quot;email&quot;\n                    v-model=&quot;customer.passportNumber&quot;\n                  /&gt;\n                  &lt;RemoveButton @click=&quot;removeCustomer(i)&quot; /&gt;\n                &lt;/div&gt;\n              &lt;/div&gt;\n              &lt;div class=&quot;mt-5 &quot;&gt;\n                &lt;BlueBlockButton text=&quot;Add a customer&quot; @click=&quot;addCustomer&quot; /&gt;\n              &lt;/div&gt;\n              &lt;div class=&quot;flex lg:flex-row mt-5 s:flex-col&quot;&gt;\n                &lt;RedBlockButton\n                  @click=&quot;next(3)&quot;\n                  text=&quot;Proceed&quot;\n                  class=&quot;mr-5 s:mb-5  lg:mb-0&quot;\n                /&gt;\n                &lt;RedOutlineButton @click=&quot;next(1)&quot; text=&quot;Back&quot; /&gt;\n              &lt;/div&gt;\n            &lt;/div&gt;\n          &lt;/a-tab-pane&gt;\n          &lt;!-- TAB TWO  END---&gt;\n          &lt;!-- TAB THREE ---&gt;\n\n          &lt;a-tab-pane\n            tab=&quot;Tab 3&quot;\n            key=&quot;3&quot;\n            class=&quot;text-black flex justify-center&quot;\n          &gt;\n            &lt;div class=&quot;flex flex-col p-20 &quot;&gt;\n              &lt;HeadingOne&gt;\n                Your trip total\n              &lt;/HeadingOne&gt;\n\n              &lt;BodyOne&gt;\n                Test using this credit card: 4242 4242 4242 4242, and enter any\n                5 digits for the zip code&lt;/BodyOne\n              &gt;\n\n              &lt;card\n                class=&quot;stripe-card mt-20 w-full&quot;\n                id=&quot;card&quot;\n                :class=&quot;{ complete }&quot;\n                stripe=&quot;pk_test_5ThYi0UvX3xwoNdgxxxTxxrG&quot;\n                :options=&quot;stripeOptions&quot;\n              /&gt;\n\n              &lt;BodyOne v-if=&quot;error&quot;&gt; {{ error }}&lt;/BodyOne&gt;\n\n              &lt;BodyOne v-if=&quot;loading&quot;&gt; Busy booking your trip&lt;/BodyOne&gt;\n\n              &lt;div class=&quot;flex flex-row mt-20&quot;&gt;\n                &lt;RedBlockButton\n                  @click=&quot;\n                    pay()\n                    mutate()\n                  &quot;\n                  text=&quot;Pay&quot;\n                  class=&quot;mr-5&quot;\n                /&gt;\n                &lt;RedOutlineButton @click=&quot;next(2)&quot; text=&quot;Back&quot; /&gt;\n              &lt;/div&gt;\n            &lt;/div&gt;\n          &lt;/a-tab-pane&gt;\n          &lt;!-- TAB THREE END---&gt;\n          &lt;!-- TAB FOUR ---&gt;\n\n          &lt;a-tab-pane\n            tab=&quot;Tab 4&quot;\n            key=&quot;4&quot;\n            class=&quot;text-black flex justify-center&quot;\n          &gt;\n            &lt;div class=&quot;flex flex-col p-20 &quot;&gt;\n              &lt;HeadingOne&gt;\n                Thanks for booking with us\n              &lt;/HeadingOne&gt;\n              &lt;img src=&quot;../../assets/Vector.svg&quot; class=&quot;mt-5&quot; /&gt;\n              &lt;BodyOne class=&quot;mt-5&quot;\n                &gt;Your link to your ticket is in the mail. Keep it safe and we\n                will see you soon&lt;/BodyOne\n              &gt;\n\n              &lt;div class=&quot;flex flex-row ml-32 mt-20&quot;&gt;\n                &lt;RedBlockButton\n                  @click=&quot;$router.push(&#39;/&#39;)&quot;\n                  text=&quot;Book more&quot;\n                  class=&quot;mr-5&quot;\n                /&gt;\n              &lt;/div&gt;\n            &lt;/div&gt;\n          &lt;/a-tab-pane&gt;\n          &lt;!-- TAB FOUR END---&gt;\n        &lt;/a-tabs&gt;\n      &lt;/template&gt;\n    &lt;/ApolloMutation&gt;\n  &lt;/div&gt;\n&lt;/template&gt;\n\n&lt;script&gt;\nimport HeadingOne from &quot;../../components/typography/HeadingOne&quot;\nimport BodyOne from &quot;../../components/typography/BodyOne&quot;\nimport DateInput from &quot;../../components/inputs/DateInput&quot;\nimport Input from &quot;../../components/inputs/Input&quot;\nimport RedBlockButton from &quot;../../components/buttons/RedBlockButton&quot;\nimport RedOutlineButton from &quot;../../components/buttons/RedOutlineButton&quot;\nimport RemoveButton from &quot;../../components/buttons/RemoveButton&quot;\nimport BlueBlockButton from &quot;../../components/buttons/BlueBlockButton&quot;\nimport { Card, createToken } from &quot;vue-stripe-elements-plus&quot;\n\nexport default {\n  name: &quot;Index&quot;,\n  components: {\n    HeadingOne,\n    BodyOne,\n    DateInput,\n    Input,\n    RedBlockButton,\n    RedOutlineButton,\n    RemoveButton,\n    BlueBlockButton,\n    Card,\n  },\n  data() {\n    return {\n      activeKey: &quot;1&quot;,\n      email: &quot;&quot;,\n      number: &quot;&quot;,\n      date: &quot;&quot;,\n      customers: [],\n    }\n  },\n  methods: {\n    onDone() {\n      this.activeKey = &quot;4&quot;\n    },\n    next(k) {\n      this.activeKey = k.toString()\n    },\n    addCustomer() {\n      // const o = [...this.customers];\n      this.customers.push({\n        name: null,\n        Surname: null,\n      })\n\n      // this.customers.push({ o });\n      // console.log(this.customers);\n      //Failed to persist entry: TypeError: Cannot read property &#39;expires_at&#39; of null\n    },\n\n    removeCustomer(i) {\n      this.customers.splice(i, 1)\n    },\n    submitForm() {\n      console.log(this.date)\n      alert(\n        `${this.customers[0].customerName}, ${this.email}, ${this.number}, ${this.date}`\n      )\n    },\n    pay() {\n      createToken().then(data =&gt; console.log(data.token))\n    },\n  },\n}\n&lt;/script&gt;\n&lt;style&gt;\n.ant-tabs-bar.ant-tabs-top-bar {\n  display: none;\n}\n\n.stripe-card {\n  margin-top: 10px;\n  border: 1px solid #ccc;\n  padding: 5px 10px;\n  box-shadow: 0px 1px 3px rgba(230, 235, 241, 0.25);\n  border-radius: 4px;\n}\n.stripe-card.complete {\n  border-color: green;\n}\n&lt;/style&gt;</code></pre></div>\n<p>♻️ We pass in the schema document and the variables necessasry for the mutation. As well as execute an <code class=\"language-text\">OnDone</code> function which will allow the user to go to the next tab post mutation.</p>\n<p>♻️ We have a slot that as the variables that are similar to the query ones.</p>\n<p>♻️ In the third tab we have error states and loading states.</p>\n<p>♻️ In the red button the pay and mutate functions will hit stripe and execute the mutation.</p>\n<p>Thats it! You have a working GraphQL FULLSTACK APP. You should be able to make bookings for different listings now.</p>","frontmatter":{"date":"May 25, 2020","path":"/execute-booking-mutation","title":"Execute Booking Mutation","postnumber":35}}},"pageContext":{"previous":{"node":{"frontmatter":{"path":"/create-nav-and-header-react","postnumber":36}}},"next":{"node":{"frontmatter":{"path":"/create-react-input","postnumber":35}}}}},"staticQueryHashes":["3207677222","3649515864","63159454"]}