diff --git a/src/layouts/headers/headerauth.vue b/src/layouts/headers/headerauth.vue index 62fa3e1..d5111c3 100755 --- a/src/layouts/headers/headerauth.vue +++ b/src/layouts/headers/headerauth.vue @@ -102,7 +102,9 @@ export default defineComponent({ created() { this.userStatus(); }, - + mounted() { + this.updatestatus(); + }, methods: { userStatus() { let path = import.meta.env.VITE_BASE_URL + '/auth/whoami'; @@ -122,9 +124,18 @@ export default defineComponent({ this.$router.push('/login'); } }) - }, - + updatestatus() { + let path = import.meta.env.VITE_BASE_URL + '/delivery/updatestatus'; + axios({ + method: 'get', + url: path, + headers: authHeader(), + }).then((response: any) => { + if (response.data.update) + console.log("Updated Status of Deliveries") + }) + }, logout() { console.log("Logging out..."); // Clear auth data diff --git a/src/pages/Index.vue b/src/pages/Index.vue index de57f11..97814e7 100755 --- a/src/pages/Index.vue +++ b/src/pages/Index.vue @@ -55,7 +55,7 @@ - +

Service Price

@@ -67,14 +67,13 @@ Price / Emergency: $200
-
-
+
diff --git a/src/pages/delivery/home.vue b/src/pages/delivery/home.vue index f6aa38a..fe60f08 100755 --- a/src/pages/delivery/home.vue +++ b/src/pages/delivery/home.vue @@ -63,10 +63,10 @@ 'badge-error': [3, 5].includes(oil.delivery_status), }"> Waiting - Delivered - Out for Delivery - Cancelled - Partial Delivery + Cancelled + Today + Tomorrow_Delivery + Partial_Delivery Issue Finalized @@ -124,8 +124,8 @@ }"> Waiting Delivered - Out for Delivery - Cancelled + Today_Delivery + Tommorrow_Delivery Partial Delivery Issue Finalized diff --git a/src/pages/delivery/update_tickets/finalize_ticket.vue b/src/pages/delivery/update_tickets/finalize_ticket.vue index 5b9d354..6b43a16 100755 --- a/src/pages/delivery/update_tickets/finalize_ticket.vue +++ b/src/pages/delivery/update_tickets/finalize_ticket.vue @@ -85,8 +85,8 @@
waiting
delivered
-
Out for Delivery
-
Cancelled
+
Today
+
Tommorrow
Partial Delivery
misdelivery
unknown
diff --git a/src/pages/delivery/update_tickets/missing_data_home.vue b/src/pages/delivery/update_tickets/missing_data_home.vue index 24cdfd0..1d69aa0 100755 --- a/src/pages/delivery/update_tickets/missing_data_home.vue +++ b/src/pages/delivery/update_tickets/missing_data_home.vue @@ -40,7 +40,7 @@
Waiting
delivered
-
Out for Delivery
+
Out_for_Delivery
Cancelled
Partial Delivery
Issue
diff --git a/src/pages/delivery/view.vue b/src/pages/delivery/view.vue index 47a2d08..aa50e66 100755 --- a/src/pages/delivery/view.vue +++ b/src/pages/delivery/view.vue @@ -74,7 +74,7 @@ }"> Waiting Delivered - Out for Delivery + Out_for_Delivery Tomorrow Partial Delivery Misdelivery diff --git a/src/pages/delivery/viewstatus/pending.vue b/src/pages/delivery/viewstatus/pending.vue index 95540b8..12c0abb 100644 --- a/src/pages/delivery/viewstatus/pending.vue +++ b/src/pages/delivery/viewstatus/pending.vue @@ -50,7 +50,7 @@ }"> Waiting Cancelled - Out for Delivery + Out_for_Delivery Finalized N/A @@ -107,7 +107,7 @@ }"> Waiting Cancelled - Out for Delivery + Out_for_Delivery Finalized N/A
diff --git a/src/pages/delivery/viewstatus/todaysdeliveries.vue b/src/pages/delivery/viewstatus/todaysdeliveries.vue index af4939b..bb5cb98 100755 --- a/src/pages/delivery/viewstatus/todaysdeliveries.vue +++ b/src/pages/delivery/viewstatus/todaysdeliveries.vue @@ -56,7 +56,7 @@ }"> Waiting Cancelled - Out for Delivery + Out_for_Delivery Tomorrow Partial Issue @@ -115,7 +115,7 @@ }"> Waiting Cancelled - Out for Delivery + Out_for_Delivery Tomorrow Partial Issue diff --git a/src/pages/delivery/viewstatus/tommorrow.vue b/src/pages/delivery/viewstatus/tommorrow.vue index 39ba01a..9f17744 100644 --- a/src/pages/delivery/viewstatus/tommorrow.vue +++ b/src/pages/delivery/viewstatus/tommorrow.vue @@ -49,7 +49,7 @@ }"> Waiting Cancelled - Out for Delivery + Out_for_Delivery Tomorrow Partial Issue @@ -100,7 +100,7 @@ }"> Waiting Cancelled - Out for Delivery + Out_for_Delivery Tomorrow Partial Issue diff --git a/src/pages/pay/pay_oil.vue b/src/pages/pay/pay_oil.vue index 77e91ea..9da98db 100755 --- a/src/pages/pay/pay_oil.vue +++ b/src/pages/pay/pay_oil.vue @@ -53,7 +53,7 @@
Waiting Delivered - Out for Delivery + Out_for_Delivery Cancelled Partial Delivery Issue @@ -298,10 +298,22 @@ export default defineComponent({ this.getOilOrder(this.$route.params.id) this.sumdelivery(this.$route.params.id); this.getOilPricing() + this.updatestatus(); }, methods: { + updatestatus() { + let path = import.meta.env.VITE_BASE_URL + '/delivery/updatestatus'; + axios({ + method: 'get', + url: path, + headers: authHeader(), + }).then((response: any) => { + if (response.data.update) + console.log("Updated Status of Deliveries") + }) + }, sumdelivery(delivery_id: any) { let path = import.meta.env.VITE_BASE_URL + "/delivery/total/" + delivery_id; axios({ diff --git a/src/router/index.ts b/src/router/index.ts index 786906a..24bd889 100755 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,6 +1,5 @@ import { createRouter, createWebHistory } from "vue-router"; - // Import your route modules import authRoutes from '../pages/auth/routes.ts'; import oilRoutes from '../pages/delivery/routes.ts'; @@ -18,9 +17,11 @@ import serviceRoutes from "../pages/service/routes.ts"; import Home from '../pages/Index.vue'; import Error404 from '../pages/error/Error404.vue'; -// Import the Pinia Auth Store +// Import the Pinia Stores import { useAuthStore } from '../stores/auth.ts'; +import { useCountsStore } from '../stores/counts.ts'; +// Your protectRoutes function and routes array remain the same... const protectRoutes = (routes: any[]) => { return routes.map(route => { route.meta = { ...route.meta, requiresAuth: true }; @@ -32,7 +33,7 @@ const protectRoutes = (routes: any[]) => { }; const routes = [ - // Auth routes are public and don't get protected + // ... routes are unchanged ...authRoutes, ...protectRoutes(moneyRoutes), ...protectRoutes(cardRoutes), @@ -45,17 +46,6 @@ const routes = [ ...protectRoutes(tickerRoutes), ...protectRoutes(serviceRoutes), - - // ...(moneyRoutes), - // ...(cardRoutes), - // ...(payRoutes), - // ...(employeeRoutes), - // ...(customerRoutes), - // ...(oilRoutes), - // ...(autoRoutes), - // ...(adminRoutes), - // ...(tickerRoutes), - // ...(serviceRoutes), { path: '/', name: 'home', @@ -68,18 +58,18 @@ const routes = [ component: Error404, meta: { requiresAuth: false } }, -] +]; const router = createRouter({ history: createWebHistory(), routes, }) -// --- THE NAVIGATION GUARD --- +// Your beforeEach guard remains the same... // @ts-ignore -router.beforeEach(async (to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext) => { +router.beforeEach(async (to, from, next) => { const authStore = useAuthStore(); - const isAuthenticated = await authStore.checkAuthStatus(); + const isAuthenticated = await authStore.checkAuthStatus(); const requiresAuth = to.meta.requiresAuth; if (requiresAuth && !isAuthenticated) { @@ -91,4 +81,17 @@ router.beforeEach(async (to: RouteLocationNormalized, from: RouteLocationNormali } }); +// --- DATA FETCHING GUARD (runs AFTER navigation is confirmed) --- +// THIS IS THE CORRECTED BLOCK +router.afterEach((_to: any, _from: any) => { + // We add types and prefix with `_` to signal they are unused. + const countsStore = useCountsStore(); + const authStore = useAuthStore(); + + if (authStore.isAuthenticated) { + console.log('Navigation complete, fetching sidebar counts...'); + countsStore.fetchSidebarCounts(); + } +}); + export default router;