aboutsummaryrefslogtreecommitdiff
path: root/src/views/AllBrands.vue
blob: be1e1222ddface6c56ccb0481b729f0fdeb91d39 (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
<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
    }
  } 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 :isLoading="isLoading" :brands="allBrands" @refresh="getAllBrands()" />
</template>