Skip to content

Commit 461b038

Browse files
authored
Merge pull request #265 from connorabbas/develop
Error Page, Menu updates
2 parents ddfb28a + 44e6ea0 commit 461b038

File tree

11 files changed

+108
-24
lines changed

11 files changed

+108
-24
lines changed

bootstrap/app.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
<?php
22

3+
use App\Http\Middleware\HandleInertiaRequests;
34
use Illuminate\Foundation\Application;
45
use Illuminate\Foundation\Configuration\Exceptions;
56
use Illuminate\Foundation\Configuration\Middleware;
7+
use Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets;
8+
use Illuminate\Http\Request;
9+
use Inertia\Inertia;
10+
use Symfony\Component\HttpFoundation\Response;
611

712
return Application::configure(basePath: dirname(__DIR__))
813
->withRouting(
@@ -12,12 +17,28 @@
1217
)
1318
->withMiddleware(function (Middleware $middleware) {
1419
$middleware->web(append: [
15-
App\Http\Middleware\HandleInertiaRequests::class,
16-
Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class,
20+
HandleInertiaRequests::class,
21+
AddLinkHeadersForPreloadedAssets::class,
1722
]);
18-
19-
//
2023
})
2124
->withExceptions(function (Exceptions $exceptions) {
22-
//
25+
$exceptions->respond(function (Response $response, Throwable $exception, Request $request) {
26+
if (
27+
!app()->environment(['local', 'testing'])
28+
&& in_array($response->getStatusCode(), [500, 503, 404, 403])
29+
) {
30+
return Inertia::render('Error', [
31+
'homepageRoute' => route('welcome'),
32+
'status' => $response->getStatusCode()
33+
])
34+
->toResponse($request)
35+
->setStatusCode($response->getStatusCode());
36+
} elseif ($response->getStatusCode() === 419) {
37+
return back()->with([
38+
'message' => 'The page expired, please try again.',
39+
]);
40+
}
41+
42+
return $response;
43+
});
2344
})->create();

resources/js/components/primevue/menu/Breadcrumb.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import { ref, useTemplateRef } from 'vue';
33
import Breadcrumb, { type BreadcrumbPassThroughOptions, type BreadcrumbProps } from 'primevue/breadcrumb';
44
import { ChevronRight } from 'lucide-vue-next';
5-
import type { ExtendedMenuItem } from '@/types';
5+
import type { MenuItem } from '@/types';
66
import { ptViewMerge } from '@/utils';
77
88
interface ExtendedBreadcrumbProps extends Omit<BreadcrumbProps, 'model'> {
9-
model: ExtendedMenuItem[];
9+
model: MenuItem[];
1010
}
1111
const componentProps = defineProps<ExtendedBreadcrumbProps>();
1212

resources/js/components/primevue/menu/ContextMenu.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import { useTemplateRef } from 'vue';
33
import ContextMenu, { type ContextMenuProps } from 'primevue/contextmenu';
44
import { ChevronRight } from 'lucide-vue-next';
5-
import type { ExtendedMenuItem } from '@/types';
5+
import type { MenuItem } from '@/types';
66
import { ptViewMerge } from '@/utils';
77
88
interface ExtendedContextMenuProps extends Omit<ContextMenuProps, 'model'> {
9-
model: ExtendedMenuItem[];
9+
model: MenuItem[];
1010
}
1111
const componentProps = defineProps<ExtendedContextMenuProps>();
1212

resources/js/components/primevue/menu/Menu.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script setup lang="ts">
22
import { useTemplateRef } from 'vue';
33
import Menu, { type MenuProps } from 'primevue/menu';
4-
import type { ExtendedMenuItem } from '@/types';
4+
import type { MenuItem } from '@/types';
55
import { ptViewMerge } from '@/utils';
66
77
interface ExtendedMenuProps extends Omit<MenuProps, 'model'> {
8-
model: ExtendedMenuItem[];
8+
model: MenuItem[];
99
}
1010
const componentProps = defineProps<ExtendedMenuProps>();
1111

resources/js/components/primevue/menu/Menubar.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import { useTemplateRef } from 'vue';
33
import Menubar, { type MenubarProps } from 'primevue/menubar';
44
import { ChevronDown, ChevronRight } from 'lucide-vue-next';
5-
import type { ExtendedMenuItem } from '@/types';
5+
import type { MenuItem } from '@/types';
66
import { ptViewMerge } from '@/utils';
77
88
interface ExtendedMenubarProps extends Omit<MenubarProps, 'model'> {
9-
model: ExtendedMenuItem[];
9+
model: MenuItem[];
1010
}
1111
const componentProps = withDefaults(
1212
defineProps<ExtendedMenubarProps>(),

resources/js/components/primevue/menu/PanelMenu.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import { useTemplateRef } from 'vue';
33
import PanelMenu, { type PanelMenuPassThroughOptions, type PanelMenuProps } from 'primevue/panelmenu';
44
import { ChevronDown, ChevronRight } from 'lucide-vue-next';
5-
import type { ExtendedMenuItem } from '@/types';
5+
import type { MenuItem } from '@/types';
66
import { ptViewMerge } from '@/utils';
77
88
interface ExtendedPanelMenuProps extends Omit<PanelMenuProps, 'model'> {
9-
model: ExtendedMenuItem[];
9+
model: MenuItem[];
1010
}
1111
const componentProps = defineProps<ExtendedPanelMenuProps>();
1212

resources/js/components/primevue/menu/TabMenu.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { route } from 'ziggy-js';
55
import Tabs from 'primevue/tabs';
66
import TabList, { type TabListProps } from 'primevue/tablist';
77
import Tab from 'primevue/tab';
8-
import type { ExtendedMenuItem } from '@/types';
8+
import type { MenuItem } from '@/types';
99
import { ptViewMerge } from '@/utils';
1010
1111
interface ExtendedTabListProps extends Omit<TabListProps, 'items'> {
12-
items: ExtendedMenuItem[];
12+
items: MenuItem[];
1313
}
1414
const componentProps = defineProps<ExtendedTabListProps>();
1515

resources/js/components/primevue/menu/TieredMenu.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import { useTemplateRef } from 'vue';
33
import TieredMenu, { type TieredMenuProps } from 'primevue/tieredmenu';
44
import { ChevronRight } from 'lucide-vue-next';
5-
import type { ExtendedMenuItem } from '@/types';
5+
import type { MenuItem } from '@/types';
66
import { ptViewMerge } from '@/utils';
77
88
interface ExtendedTieredMenuProps extends Omit<TieredMenuProps, 'model'> {
9-
model: ExtendedMenuItem[];
9+
model: MenuItem[];
1010
}
1111
const componentProps = defineProps<ExtendedTieredMenuProps>();
1212

resources/js/composables/useAppLayout.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ref, computed, onMounted, onUnmounted, watchEffect } from 'vue';
22
import { usePage, useForm } from '@inertiajs/vue3';
33
import { route } from 'ziggy-js';
44
import { LayoutGrid, House, Info, Github, Code, Settings, LogOut, BookOpen } from 'lucide-vue-next';
5-
import { ExtendedMenuItem } from '@/types';
5+
import { MenuItem } from '@/types';
66

77
export function useAppLayout() {
88
const page = usePage();
@@ -15,7 +15,7 @@ export function useAppLayout() {
1515
});
1616

1717
// Menu items
18-
const menuItems = computed<ExtendedMenuItem[]>(() => [
18+
const menuItems = computed<MenuItem[]>(() => [
1919
{
2020
label: 'Home',
2121
lucideIcon: House,
@@ -56,7 +56,7 @@ export function useAppLayout() {
5656
const logout = () => {
5757
logoutForm.post(route('logout'));
5858
};
59-
const userMenuItems: ExtendedMenuItem[] = [
59+
const userMenuItems: MenuItem[] = [
6060
{
6161
label: 'Settings',
6262
route: route('profile.edit'),

resources/js/pages/Error.vue

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<script setup>
2+
import { computed } from 'vue';
3+
import { ArrowLeft } from 'lucide-vue-next';
4+
5+
const props = defineProps({
6+
homepageRoute: String,
7+
status: Number
8+
});
9+
10+
const title = computed(() => {
11+
return {
12+
503: 'Service Unavailable',
13+
500: 'Server Error',
14+
404: 'Page Not Found',
15+
403: 'Forbidden',
16+
}[props.status];
17+
});
18+
19+
const description = computed(() => {
20+
return {
21+
503: 'Sorry, we are doing some maintenance. Please check back soon.',
22+
500: 'Whoops, something went wrong on our servers.',
23+
404: 'Sorry, the page you are looking for could not be found.',
24+
403: 'Sorry, you are forbidden from accessing this page.',
25+
}[props.status];
26+
});
27+
</script>
28+
29+
<template>
30+
<InertiaHead title="Error" />
31+
<Container fluid>
32+
<main>
33+
<div class="h-screen flex items-center justify-center">
34+
<Card class="p-4 py-6 sm:p-12">
35+
<template #content>
36+
<div class="flex flex-col gap-8 items-center justify-center text-center">
37+
<h1 class="font-extrabold text-5xl md:text-8xl text-primary">
38+
{{ props.status }}
39+
</h1>
40+
<h2 class="font-extrabold text-4xl md:text-6xl">
41+
{{ title }}
42+
</h2>
43+
<p class="text-xl font-semibold md:text-3xl text-muted-color">
44+
{{ description }}
45+
</p>
46+
<InertiaLink :href="props.homepageRoute">
47+
<Button
48+
label="Back to homepage"
49+
raised
50+
>
51+
<template #icon>
52+
<ArrowLeft />
53+
</template>
54+
</Button>
55+
</InertiaLink>
56+
</div>
57+
</template>
58+
</Card>
59+
</div>
60+
</main>
61+
</Container>
62+
</template>

resources/js/types/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { DataTableFilterMetaData } from 'primevue';
22
import type { Page, PageProps, Errors } from '@inertiajs/core';
3-
import type { MenuItem } from 'primevue/menuitem';
3+
import type { MenuItem as PrimeVueMenuItem } from 'primevue/menuitem';
44
import type { LucideIcon } from 'lucide-vue-next';
55

66
export interface User {
@@ -18,9 +18,10 @@ export type PrimeVueDataFilters = {
1818
[key: string]: DataTableFilterMetaData;
1919
};
2020

21-
export interface ExtendedMenuItem extends MenuItem {
21+
export interface MenuItem extends PrimeVueMenuItem {
2222
route?: string;
2323
lucideIcon?: LucideIcon;
24+
active?: boolean;
2425
}
2526

2627
export interface InertiaRouterFetchCallbacks {

0 commit comments

Comments
 (0)