aboutsummaryrefslogtreecommitdiff
path: root/src/components/brands_table.vue
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/brands_table.vue')
-rw-r--r--src/components/brands_table.vue114
1 files changed, 114 insertions, 0 deletions
diff --git a/src/components/brands_table.vue b/src/components/brands_table.vue
new file mode 100644
index 0000000..a0f95ad
--- /dev/null
+++ b/src/components/brands_table.vue
@@ -0,0 +1,114 @@
+<script setup lang="ts">
+import { ref, onMounted } from 'vue'
+import axios from 'axios'
+import { useToast } from 'vue-toast-notification'
+
+const toast = useToast({
+ position: 'top-right'
+})
+
+const allBrands = ref([])
+const isLoading = ref(false)
+
+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
+}
+
+const handleDelete = async (id) => {
+ try {
+ const res = await axios.delete(`/brand/${id}`)
+ if (res.status === 200) {
+ toast.success('Successfully deleted brand')
+ }
+
+ getAllBrands()
+ } catch (err) {
+ toast.error('An unhandled exception occoured. Please check logs')
+ console.error(err)
+ }
+}
+
+onMounted(() => {
+ getAllBrands()
+})
+</script>
+
+<template>
+ <div v-if="isLoading" class="w-100 d-flex justify-content-center">
+ <div class="spinner-border" role="status">
+ <span class="sr-only"></span>
+ </div>
+ </div>
+
+ <table v-else class="table table-light table-striped table-hover">
+ <thead>
+ <tr>
+ <th scope="col">#</th>
+ <th scope="col">Brand Name</th>
+ <th scope="col" class="table-action-column">
+ <button class="btn btn-dark" v-on:click="getAllBrands">
+ <i class="bi bi-arrow-clockwise"></i>
+ </button>
+ </th>
+ </tr>
+ </thead>
+
+ <tbody>
+ <tr v-for="(brand, index) in allBrands">
+ <td scope="row">{{ index + 1 }}</td>
+ <td>{{ brand.Name }}</td>
+ <td class="table-action-column">
+ <button class="btn" data-bs-toggle="dropdown" aria-expanded="false">
+ <i class="bi bi-caret-down-fill"></i>
+ </button>
+
+ <div class="dropdown">
+ <ul class="dropdown-menu">
+ <li>
+ <button class="dropdown-item" v-on:click="console.log('Edit: ', brand.ID)">
+ Edit Item
+ </button>
+ </li>
+ <li>
+ <button class="dropdown-item" v-on:click="handleDelete(brand.ID)">
+ Delete Item
+ </button>
+ </li>
+ </ul>
+ </div>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+</template>
+
+<style>
+.table-action-column {
+ width: 2rem;
+}
+
+tbody .table-action-column .btn {
+ opacity: 0;
+ transition: opacity 300ms;
+}
+
+tbody tr:hover .table-action-column .btn {
+ opacity: 1;
+ transition: opacity 300ms;
+}
+</style>