|
49 | 49 | @click="sortProducts('updated_at')">
|
50 | 50 | Last Updated At
|
51 | 51 | </TableHeaderCell>
|
| 52 | + <TableHeaderCell field="actions"> |
| 53 | + Actions |
| 54 | + </TableHeaderCell> |
52 | 55 | </tr>
|
53 | 56 | </thead>
|
54 | 57 | <tbody v-if="products.loading">
|
55 | 58 | <tr>
|
56 |
| - <td colspan="5"> |
| 59 | + <td colspan="6"> |
57 | 60 | <Spinner/>
|
58 | 61 | </td>
|
59 | 62 | </tr>
|
|
64 | 67 | <td class="border-b p-2 ">
|
65 | 68 | <img class="w-16 h-16 object-cover" :src="product.image_url" :alt="product.title">
|
66 | 69 | </td>
|
67 |
| - <td class="border-b p-2 max-w-[200px] whitespace-nowrap overflow-hidden text-ellipsis">{{ |
68 |
| - product.title |
69 |
| - }} |
| 70 | + <td class="border-b p-2 max-w-[200px] whitespace-nowrap overflow-hidden text-ellipsis"> |
| 71 | + {{ product.title }} |
70 | 72 | </td>
|
71 | 73 | <td class="border-b p-2">
|
72 | 74 | {{ product.price }}
|
73 | 75 | </td>
|
74 | 76 | <td class="border-b p-2 ">
|
75 | 77 | {{ product.updated_at }}
|
76 | 78 | </td>
|
| 79 | + <td class="border-b p-2 "> |
| 80 | + <Menu as="div" class="relative inline-block text-left"> |
| 81 | + <div> |
| 82 | + <MenuButton |
| 83 | + class="inline-flex items-center justify-center w-full justify-center rounded-full w-10 h-10 bg-black bg-opacity-0 text-sm font-medium text-white hover:bg-opacity-5 focus:bg-opacity-5 focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75" |
| 84 | + > |
| 85 | + <DotsVerticalIcon |
| 86 | + class="h-5 w-5 text-indigo-500" |
| 87 | + aria-hidden="true"/> |
| 88 | + </MenuButton> |
| 89 | + </div> |
| 90 | + |
| 91 | + <transition |
| 92 | + enter-active-class="transition duration-100 ease-out" |
| 93 | + enter-from-class="transform scale-95 opacity-0" |
| 94 | + enter-to-class="transform scale-100 opacity-100" |
| 95 | + leave-active-class="transition duration-75 ease-in" |
| 96 | + leave-from-class="transform scale-100 opacity-100" |
| 97 | + leave-to-class="transform scale-95 opacity-0" |
| 98 | + > |
| 99 | + <MenuItems |
| 100 | + class="absolute z-10 right-0 mt-2 w-32 origin-top-right divide-y divide-gray-100 rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none" |
| 101 | + > |
| 102 | + <div class="px-1 py-1"> |
| 103 | + <MenuItem v-slot="{ active }"> |
| 104 | + <button |
| 105 | + :class="[ |
| 106 | + active ? 'bg-indigo-600 text-white' : 'text-gray-900', |
| 107 | + 'group flex w-full items-center rounded-md px-2 py-2 text-sm', |
| 108 | + ]" |
| 109 | + > |
| 110 | + <PencilIcon |
| 111 | + :active="active" |
| 112 | + class="mr-2 h-5 w-5 text-indigo-400" |
| 113 | + aria-hidden="true" |
| 114 | + /> |
| 115 | + Edit |
| 116 | + </button> |
| 117 | + </MenuItem> |
| 118 | + <MenuItem v-slot="{ active }"> |
| 119 | + <button |
| 120 | + :class="[ |
| 121 | + active ? 'bg-indigo-600 text-white' : 'text-gray-900', |
| 122 | + 'group flex w-full items-center rounded-md px-2 py-2 text-sm', |
| 123 | + ]" |
| 124 | + @click="deleteProduct(product)" |
| 125 | + > |
| 126 | + <TrashIcon |
| 127 | + :active="active" |
| 128 | + class="mr-2 h-5 w-5 text-indigo-400" |
| 129 | + aria-hidden="true" |
| 130 | + /> |
| 131 | + Delete |
| 132 | + </button> |
| 133 | + </MenuItem> |
| 134 | + </div> |
| 135 | + </MenuItems> |
| 136 | + </transition> |
| 137 | + </Menu> |
| 138 | + </td> |
77 | 139 | </tr>
|
78 | 140 | </tbody>
|
79 | 141 | </table>
|
@@ -120,6 +182,8 @@ import Spinner from "../components/core/Spinner.vue";
|
120 | 182 | import {PRODUCTS_PER_PAGE} from "../constants";
|
121 | 183 | import TableHeaderCell from "../components/core/Table/TableHeaderCell.vue";
|
122 | 184 | import AddNewProduct from "./AddNewProduct.vue";
|
| 185 | +import {Menu, MenuButton, MenuItem, MenuItems} from "@headlessui/vue"; |
| 186 | +import {DotsVerticalIcon, PencilIcon, TrashIcon} from '@heroicons/vue/outline' |
123 | 187 |
|
124 | 188 | const perPage = ref(PRODUCTS_PER_PAGE);
|
125 | 189 | const search = ref('');
|
@@ -170,6 +234,17 @@ function sortProducts(field) {
|
170 | 234 | function showAddNewModal() {
|
171 | 235 | showProductModal.value = true
|
172 | 236 | }
|
| 237 | +
|
| 238 | +function deleteProduct(product) { |
| 239 | + if (!confirm(`Are you sure you want to delete the product?`)) { |
| 240 | + return |
| 241 | + } |
| 242 | + store.dispatch('deleteProduct', product.id) |
| 243 | + .then(res => { |
| 244 | + // TODO Show notification |
| 245 | + store.dispatch('getProducts') |
| 246 | + }) |
| 247 | +} |
173 | 248 | </script>
|
174 | 249 |
|
175 | 250 | <style scoped>
|
|
0 commit comments