aboutsummaryrefslogtreecommitdiff
path: root/src/views/AllBrands.vue
blob: ad456cd6e13a0047b022fa8dbe9abb32e96d787a (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
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useToast } from 'vue-toast-notification'
import axios from 'axios'

import brandsTable from './../components/brands_table.vue'
import newBrand from './../components/new_brand.vue'

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

const isLoading = ref(false)
const allBrands = ref([])

const getAllBrands = async () => {
  allBrands.value = []
  isLoading.value = true

  try {
    const res = await axios.get('/brand')
    if (res.status === 200) {
      allBrands.value = res.data.data
    } else if (res.status === 204) {
      toast.warning('No records found')
    }
  } catch (err) {
    toast.error('An unhandled exception occoured. Please check logs')
    console.error(err)
  }

  isLoading.value = false
}

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

<template>
  <newBrand @added="getAllBrands()" />
  <brandsTable :brands="allBrands" @refresh="getAllBrands()" />
</template>