aboutsummaryrefslogtreecommitdiff
path: root/src/views/EditInvoice.vue
blob: 7a508f829104077ad590bc30444a1088c0c1a052 (plain)
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
48
49
50
<script setup lang="ts">
import { ref, toRaw, onMounted } from 'vue'
import { useRoute } from "vue-router"
import { useToast } from 'vue-toast-notification'
import axios from 'axios'

import Invoice from "./../classes/invoice"

import invoiceHeader from './../components/invoice_header.vue'
import itemSelector from './../components/item_selector.vue'
import invoiceItemsTable from './../components/invoice_items_table.vue'

const toast = useToast({
  position: 'top-right'
})

const route = useRoute()

const invoiceId = route.params.id
const invoice = ref(new Invoice())
const isLoading = ref(true)

const getInvoice = async () => {
  isLoading.value = true

  try {
    const r = await axios.get(`/invoice/${invoiceId}`)
    invoice.value = r.data.data
  } catch (err) {
    toast.error('An unhandled exception occoured. Please check logs')
    console.error(err)
  }

  isLoading.value = false
}

const refreshItems = () => {
   toast.success("Item was added but what happens after that hasn't been implemented yet!")
}

onMounted(() => {
  getInvoice()
})
</script>

<template>
  <invoiceHeader :invoice="invoice" />
  <itemSelector :invoiceId="invoiceId" @added="refreshItems()"/>
  <invoiceItemsTable :invoiceId="invoiceId" />
</template>