Wrap components with NotFoundFallBackPageWrapper for validation.

Added NotFoundFallBackPageWrapper across various department-related components to handle scenarios where the department ID is missing or inaccessible. Also updated getDepartmentIdFromUrl to ensure valid department IDs are returned.
This commit is contained in:
Jepp9350
2025-03-04 11:52:54 +01:00
parent a1cafbcd2f
commit af61ead3b1
6 changed files with 64 additions and 48 deletions
+1 -1
View File
@@ -271,7 +271,7 @@ export const SessionUser = {
getDepartmentIdFromUrl: () => {
// Check if the department id is in the route
const router = useRouter();
return parseInt(router.currentRoute.value.params.departmentId);
return parseInt(router.currentRoute.value.params.departmentId) > 0 ? parseInt(router.currentRoute.value.params.departmentId) : undefined;
},
/** Redirect to */
redirectTo: {
@@ -8,6 +8,7 @@ import RestrictedPageWrapper from "@/components/page/wrappers/RestrictedPageWrap
import { SessionUser } from "@/components/session/token/SessionUser.vue";
import DepartmentDashboardPageWrapper from "@/views/dashboards/departmentDashboard/DepartmentDashboardPageWrapper.vue";
import PageTitle from "@/components/global/PageTitle.vue";
import NotFoundFallBackPageWrapper from "@/components/page/wrappers/NotFoundFallBackPageWrapper.vue";
</script>
<template>
@@ -17,9 +18,11 @@ import PageTitle from "@/components/global/PageTitle.vue";
>
<template #default>
<RestrictedPageWrapper :hasPermission="SessionUser.canAccessAdmin()">
<NotFoundFallBackPageWrapper :exists="SessionUser.functions.getDepartmentIdFromUrl() && SessionUser.canAccessDepartment(SessionUser.functions.getDepartmentIdFromUrl())" error="Please select a department, that you have access to. If you believe this is an error, please contact support.">
<!-- <DepartmentDashboardHero /> -->
<!-- <DepartmentPosNavigation /> -->
<PosDepartmentMVP />
</NotFoundFallBackPageWrapper>
</RestrictedPageWrapper>
</template>
</DepartmentDashboardPageWrapper>
@@ -148,7 +148,7 @@ const isBookedWithEconomic = () => {
title="Kassesystem"
subtitle="Transaktion"
>
<notFoundFallBackPageWrapper :exists="(customer_name || isLoading)" error="Denne handel findes ikke, eller du har ikke adgang til at se den.">
<notFoundFallBackPageWrapper :exists="(customer_name || isLoading) && (SessionUser.functions.getDepartmentIdFromUrl() > 1 && SessionUser.canAccessDepartment(SessionUser.functions.getDepartmentIdFromUrl()))" error="Denne handel findes ikke, eller du har ikke adgang til at se den.">
<div class="columns">
<div class="column is-8-desktop" v-if="AddOrderItemsVisible">
<SelectProductsFormPOS class="mt-3" category="products" />
@@ -6,16 +6,19 @@ import OrdersPagination from "@/components/displays/pagination/models/Department
import RestrictedPageWrapper from "@/components/page/wrappers/RestrictedPageWrapper.vue";
import { SessionUser } from "@/components/session/token/SessionUser.vue";
import DepartmentDashboardPageWrapper from "@/views/dashboards/departmentDashboard/DepartmentDashboardPageWrapper.vue";
import NotFoundFallBackPageWrapper from "@/components/page/wrappers/NotFoundFallBackPageWrapper.vue";
</script>
<template>
<RestrictedPageWrapper :hasPermission="SessionUser.canAccessAdmin()">
<DepartmentDashboardPageWrapper title="Kassesystem" subtitle="Point of Sale">
<NotFoundFallBackPageWrapper :exists="SessionUser.functions.getDepartmentIdFromUrl() && SessionUser.canAccessDepartment(SessionUser.functions.getDepartmentIdFromUrl())" error="Please select a department, that you have access to. If you believe this is an error, please contact support.">
<template #default>
<DepartmentDashboardHero />
<OrdersPagination />
</template>
</NotFoundFallBackPageWrapper>
</DepartmentDashboardPageWrapper>
</RestrictedPageWrapper>
</template>
@@ -7,6 +7,7 @@ import RestrictedPageWrapper from "@/components/page/wrappers/RestrictedPageWrap
import { SessionUser } from "@/components/session/token/SessionUser.vue";
import BookingsPagination from "@/components/displays/pagination/models/UserDashboard/BookingsPagination.vue";
import DepartmentDashboardPageWrapper from "@/views/dashboards/departmentDashboard/DepartmentDashboardPageWrapper.vue";
import NotFoundFallBackPageWrapper from "@/components/page/wrappers/NotFoundFallBackPageWrapper.vue";
</script>
<template>
@@ -15,7 +16,9 @@ import DepartmentDashboardPageWrapper from "@/views/dashboards/departmentDashboa
title="Bookinger"
subtitle="Oversigt over bookinger"
>
<NotFoundFallBackPageWrapper :exists="SessionUser.functions.getDepartmentIdFromUrl() && SessionUser.canAccessDepartment(SessionUser.functions.getDepartmentIdFromUrl())" error="Please select a department, that you have access to. If you believe this is an error, please contact support.">
<BookingsPagination />
</NotFoundFallBackPageWrapper>
</DepartmentDashboardPageWrapper>
</RestrictedPageWrapper>
</template>
@@ -15,6 +15,7 @@ import DepartmentDashboardDailyReportProductSales
import DepartmentDashboardDailyReportTodayForm
from "@/views/dashboards/departmentDashboard/modules/daily-report/displays/DepartmentDashboardDailyReportTodayForm.vue";
import { Colors } from "@/ThemeConfig.vue";
import NotFoundFallBackPageWrapper from "@/components/page/wrappers/NotFoundFallBackPageWrapper.vue";
/**
* Get the current date
@@ -39,6 +40,10 @@ const products_sold = ref(null);
// Get the transactions for the current day
const getTransactions = async () => {
// If the department ID is not set, return
if (!department_id.value) {
return;
}
await SessionUser.objects.department_daily_reports.functions.getTransactionCount(department_id.value, getDate())
.then(response => {
transactions.value = response.data.data.quantity;
@@ -100,6 +105,7 @@ const product_ids = ref([
title="Dagsopgørelse"
subtitle="Få et overblik over dagens omsætning, forbrug og bookinger"
>
<NotFoundFallBackPageWrapper :exists="SessionUser.functions.getDepartmentIdFromUrl() && SessionUser.canAccessDepartment(SessionUser.functions.getDepartmentIdFromUrl())" error="Please select a department, that you have access to. If you believe this is an error, please contact support.">
<!-- Create daily report button -->
<div class="columns is-flex-wrap-wrap">
<div class="column is-12 has-text-right">
@@ -140,6 +146,7 @@ const product_ids = ref([
:department_id="department_id"
:date="getDate()"
/>
</NotFoundFallBackPageWrapper>
</DepartmentDashboardPageWrapper>
</RestrictedPageWrapper>
</template>