Skip to content

Commit 48fcf7a

Browse files
committed
Move products components into a separate folder
1 parent 36a090f commit 48fcf7a

File tree

5 files changed

+56
-26
lines changed

5 files changed

+56
-26
lines changed

backend/src/axios.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
*/
44
import axios from "axios";
55
import store from "./store";
6-
import router from "./router";
6+
import {useRouter} from "vue-router";
7+
8+
const router = useRouter()
79

810
const axiosClient = axios.create({
911
baseURL: `${import.meta.env.VITE_API_BASE_URL}/api`
@@ -17,6 +19,7 @@ axiosClient.interceptors.request.use(config => {
1719
axiosClient.interceptors.response.use(response => {
1820
return response;
1921
}, error => {
22+
debugger;
2023
if (error.response.status === 401) {
2124
sessionStorage.removeItem('TOKEN')
2225
router.push({name: 'login'})

backend/src/router/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {createRouter, createWebHistory} from "vue-router";
22
import AppLayout from '../components/AppLayout.vue'
33
import Login from "../views/Login.vue";
44
import Dashboard from "../views/Dashboard.vue";
5-
import Products from "../views/Products.vue";
5+
import Products from "../views/Products/Products.vue";
66
import RequestPassword from "../views/RequestPassword.vue";
77
import ResetPassword from "../views/ResetPassword.vue";
88
import NotFound from "../views/NotFound.vue";

backend/src/views/ProductModal.vue renamed to backend/src/views/Products/ProductModal.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
leave-from="opacity-100 translate-y-0 sm:scale-100"
1616
leave-to="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95">
1717
<DialogPanel
18-
class="relative bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:max-w-lg sm:w-full">
18+
class="relative bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:max-w-[700px] sm:w-full">
1919
<Spinner v-if="loading"
2020
class="absolute left-0 top-0 bg-white right-0 bottom-0 flex items-center justify-center"/>
2121
<header class="py-3 px-4 flex justify-between items-center">
@@ -43,7 +43,7 @@
4343
</button>
4444
</header>
4545
<form @submit.prevent="onSubmit">
46-
<div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
46+
<div class="bg-white px-4 pt-5 pb-4">
4747
<CustomInput class="mb-2" v-model="product.title" label="Product Title"/>
4848
<CustomInput type="file" class="mb-2" label="Product Image" @change="file => product.image = file"/>
4949
<CustomInput type="textarea" class="mb-2" v-model="product.description" label="Description"/>
@@ -72,9 +72,9 @@
7272
import {computed, onUpdated, ref} from 'vue'
7373
import {Dialog, DialogPanel, DialogTitle, TransitionChild, TransitionRoot} from '@headlessui/vue'
7474
import {ExclamationIcon} from '@heroicons/vue/outline'
75-
import CustomInput from "../components/core/CustomInput.vue";
76-
import store from "../store/index.js";
77-
import Spinner from "../components/core/Spinner.vue";
75+
import CustomInput from "../../components/core/CustomInput.vue";
76+
import store from "../../store/index.js";
77+
import Spinner from "../../components/core/Spinner.vue";
7878

7979
const product = ref({
8080
id: props.product.id,
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<template>
2+
<div class="flex items-center justify-between mb-3">
3+
<h1 class="text-3xl font-semibold">Products</h1>
4+
<button type="button"
5+
@click="showAddNewModal()"
6+
class="py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
7+
>
8+
Add new Product
9+
</button>
10+
</div>
11+
<ProductsTable />
12+
<ProductModal v-model="showProductModal" :product="product"/>
13+
</template>
14+
15+
<script setup>
16+
import {computed, onMounted, ref} from "vue";
17+
import store from "../../store";
18+
import ProductModal from "./ProductModal.vue";
19+
import ProductsTable from "./ProductsTable.vue";
20+
21+
const products = computed(() => store.state.products);
22+
23+
const product = ref({})
24+
const showProductModal = ref(false);
25+
26+
function showAddNewModal() {
27+
showProductModal.value = true
28+
}
29+
</script>
30+
31+
<style scoped>
32+
33+
</style>

backend/src/views/Products.vue renamed to backend/src/views/Products/ProductsTable.vue

+13-19
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
<template>
2-
<div class="flex items-center justify-between mb-3">
3-
<h1 class="text-3xl font-semibold">Products</h1>
4-
<button type="button"
5-
@click="showAddNewModal()"
6-
class="py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
7-
>
8-
Add new Product
9-
</button>
10-
</div>
112
<div class="bg-white p-4 rounded-lg shadow">
123
<div class="flex justify-between border-b-2 pb-3">
134
<div class="flex items-center">
@@ -20,6 +11,7 @@
2011
<option value="50">50</option>
2112
<option value="100">100</option>
2213
</select>
14+
<span class="ml-3">Found {{products.total}} products</span>
2315
</div>
2416
<div>
2517
<input v-model="search" @change="getProducts(null)"
@@ -54,10 +46,13 @@
5446
</TableHeaderCell>
5547
</tr>
5648
</thead>
57-
<tbody v-if="products.loading">
49+
<tbody v-if="products.loading || !products.data.length">
5850
<tr>
5951
<td colspan="6">
60-
<Spinner/>
52+
<Spinner v-if="products.loading"/>
53+
<p v-else class="text-center py-8 text-gray-700">
54+
There are no products
55+
</p>
6156
</td>
6257
</tr>
6358
</tbody>
@@ -142,9 +137,9 @@
142137
</table>
143138

144139
<div v-if="!products.loading" class="flex justify-between items-center mt-5">
145-
<span>
146-
Showing from {{ products.from }} to {{ products.to }}
147-
</span>
140+
<div v-if="products.data.length">
141+
Showing from {{ products.from }} to {{ products.to }}
142+
</div>
148143
<nav
149144
v-if="products.total > products.limit"
150145
class="relative z-0 inline-flex justify-center rounded-md shadow-sm -space-x-px"
@@ -173,15 +168,14 @@
173168
</nav>
174169
</div>
175170
</div>
176-
<ProductModal v-model="showProductModal" :product="product"/>
177171
</template>
178172

179173
<script setup>
180174
import {computed, onMounted, ref} from "vue";
181-
import store from "../store";
182-
import Spinner from "../components/core/Spinner.vue";
183-
import {PRODUCTS_PER_PAGE} from "../constants";
184-
import TableHeaderCell from "../components/core/Table/TableHeaderCell.vue";
175+
import store from "../../store";
176+
import Spinner from "../../components/core/Spinner.vue";
177+
import {PRODUCTS_PER_PAGE} from "../../constants";
178+
import TableHeaderCell from "../../components/core/Table/TableHeaderCell.vue";
185179
import {Menu, MenuButton, MenuItem, MenuItems} from "@headlessui/vue";
186180
import {DotsVerticalIcon, PencilIcon, TrashIcon} from '@heroicons/vue/outline'
187181
import ProductModal from "./ProductModal.vue";

0 commit comments

Comments
 (0)