Skip to content

Commit aa05717

Browse files
committed
feat: add custom 404 page and global toast notification system
1 parent 3f0af38 commit aa05717

6 files changed

Lines changed: 320 additions & 3 deletions

File tree

‎app/Http/Middleware/HandleInertiaRequests.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public function share(Request $request): array
4141
'auth' => [
4242
'user' => $request->user(),
4343
],
44+
'flash' => [
45+
'success' => fn() => $request->session()->get('success'),
46+
'error' => fn() => $request->session()->get('error'),
47+
],
4448
];
4549
}
4650
}

‎bootstrap/app.php‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,28 @@
3131
$exceptions->shouldRenderJsonWhen(
3232
fn(Request $request) => $request->is('api/*'),
3333
);
34+
$exceptions->render(function (\Illuminate\Http\Request $request) {
35+
36+
$request->session()->flash('error', 'Access Denied: You do not have permission to access that section.');
37+
38+
$previousUrl = url()->previous();
39+
$currentUrl = $request->fullUrl();
40+
41+
// If the previous URL is empty or matches the current URL, fallback to home page
42+
if (!$previousUrl || $previousUrl === $currentUrl) {
43+
return redirect()->to('/');
44+
}
45+
46+
return redirect()->back();
47+
});
48+
49+
$exceptions->respond(function (\Symfony\Component\HttpFoundation\Response $response, \Throwable $exception, \Illuminate\Http\Request $request) {
50+
if ($response->getStatusCode() === 404) {
51+
return \Inertia\Inertia::render('Error')
52+
->toResponse($request)
53+
->setStatusCode(404);
54+
}
55+
56+
return $response;
57+
});
3458
})->create();
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<script setup lang="ts">
2+
import { usePage } from '@inertiajs/vue3';
3+
import { CheckCircle2, AlertTriangle, X } from 'lucide-vue-next';
4+
import { ref, watch } from 'vue';
5+
6+
interface Toast {
7+
id: number;
8+
message: string;
9+
type: 'success' | 'error';
10+
}
11+
12+
const page = usePage();
13+
const toasts = ref<Toast[]>([]);
14+
let toastId = 0;
15+
16+
const addToast = (message: string, type: 'success' | 'error') => {
17+
const id = toastId++;
18+
toasts.value.push({ id, message, type });
19+
setTimeout(() => {
20+
removeToast(id);
21+
}, 5000);
22+
};
23+
24+
const removeToast = (id: number) => {
25+
toasts.value = toasts.value.filter((t) => t.id !== id);
26+
};
27+
28+
// Watch Inertia page flash props for new messages
29+
watch(
30+
() => page.props.flash,
31+
(flash: any) => {
32+
if (flash?.success) {
33+
addToast(flash.success, 'success');
34+
}
35+
36+
if (flash?.error) {
37+
addToast(flash.error, 'error');
38+
}
39+
},
40+
{ deep: true, immediate: true },
41+
);
42+
</script>
43+
44+
<template>
45+
<div
46+
class="pointer-events-none fixed top-4 right-4 z-[9999] flex w-full max-w-sm flex-col gap-3 px-4 sm:px-0"
47+
>
48+
<TransitionGroup name="toast" tag="div" class="flex flex-col gap-2.5">
49+
<div
50+
v-for="toast in toasts"
51+
:key="toast.id"
52+
class="pointer-events-auto flex w-full items-start gap-3 rounded-2xl border p-4 shadow-xl backdrop-blur-md transition-all duration-300 hover:scale-[1.01]"
53+
:class="
54+
toast.type === 'success'
55+
? 'border-emerald-500/25 bg-emerald-50/95 text-emerald-950 shadow-emerald-100/30'
56+
: 'border-rose-500/25 bg-rose-50/95 text-rose-950 shadow-rose-100/30'
57+
"
58+
>
59+
<!-- Icon -->
60+
<component
61+
:is="
62+
toast.type === 'success' ? CheckCircle2 : AlertTriangle
63+
"
64+
class="h-5 w-5 shrink-0"
65+
:class="
66+
toast.type === 'success'
67+
? 'text-emerald-600'
68+
: 'text-rose-600'
69+
"
70+
/>
71+
72+
<!-- Message -->
73+
<p class="flex-1 text-sm leading-relaxed font-semibold">
74+
{{ toast.message }}
75+
</p>
76+
77+
<!-- Close Button -->
78+
<button
79+
@click="removeToast(toast.id)"
80+
class="cursor-pointer rounded-lg p-0.5 text-slate-400 transition-colors hover:bg-black/5 hover:text-slate-700"
81+
>
82+
<X class="h-4 w-4" />
83+
</button>
84+
</div>
85+
</TransitionGroup>
86+
</div>
87+
</template>
88+
89+
<style scoped>
90+
.toast-enter-active,
91+
.toast-leave-active {
92+
transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
93+
}
94+
.toast-enter-from {
95+
opacity: 0;
96+
transform: translateX(40px) scale(0.9);
97+
}
98+
.toast-leave-to {
99+
opacity: 0;
100+
transform: translateX(40px) scale(0.9);
101+
}
102+
</style>

‎resources/js/layouts/AdminLayout.vue‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ref } from 'vue';
88
import DesktopSidebar from '@/components/admin/DesktopSidebar.vue';
99
import MobileSideBar from '@/components/admin/MobileSideBar.vue';
1010
import NavBar from '@/components/NavBar.vue';
11-
11+
import ToastNotification from '@/components/ToastNotification.vue';
1212
1313
const isMobileSidebarOpen = ref(false);
1414
@@ -25,8 +25,6 @@ const openMobileSidebar = () => {
2525
const closeMobileSidebar = () => {
2626
isMobileSidebarOpen.value = false;
2727
};
28-
29-
3028
</script>
3129

3230
<template>
@@ -63,5 +61,6 @@ const closeMobileSidebar = () => {
6361
</main>
6462
</div>
6563
</div>
64+
<ToastNotification />
6665
</div>
6766
</template>

‎resources/js/layouts/AppLayout.vue‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import Footer from '@/components/Footer.vue';
33
import NavBar from '@/components/NavBar.vue';
4+
import ToastNotification from '@/components/ToastNotification.vue';
45
56
// const searchQuery = ref('');
67
</script>
@@ -32,5 +33,6 @@ import NavBar from '@/components/NavBar.vue';
3233

3334
<Footer />
3435
</div>
36+
<ToastNotification />
3537
</div>
3638
</template>

‎resources/js/pages/Error.vue‎

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
<script setup lang="ts">
2+
import { Link } from '@inertiajs/vue3';
3+
import {
4+
HelpCircle,
5+
ArrowLeft,
6+
Home,
7+
BookOpen,
8+
Users,
9+
Info,
10+
ChevronRight,
11+
} from 'lucide-vue-next';
12+
13+
const goBack = () => {
14+
if (window.history.length > 1) {
15+
window.history.back();
16+
}
17+
};
18+
</script>
19+
20+
<template>
21+
<div
22+
class="relative flex min-h-[calc(100vh-10rem)] items-center justify-center px-4 py-16 sm:px-6 sm:py-24"
23+
>
24+
<!-- Glowing aura behind the card -->
25+
<div
26+
class="animate-pulse-glow absolute top-1/2 left-1/2 -z-10 h-72 w-72 -translate-x-1/2 -translate-y-1/2 rounded-full bg-indigo-400 opacity-15 blur-[100px] transition-all duration-700"
27+
></div>
28+
29+
<!-- Glass card content -->
30+
<div
31+
class="relative z-10 w-full max-w-lg overflow-hidden rounded-2xl border border-slate-200/50 bg-white/70 p-8 text-center shadow-xl backdrop-blur-md transition-all duration-300 hover:border-slate-300/40 hover:shadow-2xl sm:p-10"
32+
>
33+
<!-- Animated decorative icon wrapper -->
34+
<div
35+
class="relative mx-auto mb-6 flex h-24 w-24 items-center justify-center rounded-2xl bg-slate-50 text-slate-800 shadow-inner"
36+
>
37+
<div
38+
class="absolute inset-0 animate-ping rounded-2xl bg-slate-100 opacity-60"
39+
></div>
40+
<div
41+
class="animate-float flex items-center justify-center text-slate-700"
42+
>
43+
<HelpCircle
44+
class="h-12 w-12 stroke-[1.5] text-indigo-600"
45+
/>
46+
</div>
47+
</div>
48+
49+
<!-- Big Gradient Error Code -->
50+
<h1
51+
class="bg-gradient-to-r from-indigo-600 via-violet-600 to-pink-500 bg-clip-text text-8xl font-black tracking-tight text-transparent select-none sm:text-9xl"
52+
>
53+
404
54+
</h1>
55+
56+
<h2 class="mt-4 text-2xl font-bold tracking-tight text-slate-900">
57+
Page Lost in Space
58+
</h2>
59+
60+
<p
61+
class="mx-auto mt-3 max-w-sm text-sm leading-relaxed text-slate-500"
62+
>
63+
We couldn't find the page you were looking for. It might have
64+
been moved, deleted, or never existed in the first place.
65+
</p>
66+
67+
<!-- Navigation Buttons -->
68+
<div
69+
class="mt-8 flex flex-col items-center justify-center gap-3 sm:flex-row"
70+
>
71+
<button
72+
@click="goBack"
73+
class="inline-flex w-full cursor-pointer items-center justify-center gap-2 rounded-xl bg-slate-100 px-5 py-2.5 text-sm font-semibold text-slate-700 transition-all duration-150 hover:bg-slate-200 active:scale-95 sm:w-auto"
74+
>
75+
<ArrowLeft class="h-4 w-4" />
76+
Go Back
77+
</button>
78+
79+
<Link
80+
href="/"
81+
class="inline-flex w-full cursor-pointer items-center justify-center gap-2 rounded-xl bg-gradient-to-r from-indigo-600 to-violet-600 px-5 py-2.5 text-sm font-semibold text-white shadow-md shadow-indigo-100 transition-all duration-150 hover:scale-[1.02] hover:shadow-lg hover:shadow-indigo-200/60 active:scale-[0.98] sm:w-auto"
82+
>
83+
<Home class="h-4 w-4" />
84+
Go Home
85+
</Link>
86+
</div>
87+
88+
<!-- Divider -->
89+
<div class="my-8 h-px bg-slate-200/60"></div>
90+
91+
<!-- Directory / Helpful Links -->
92+
<div class="text-left">
93+
<h3
94+
class="text-xs font-bold tracking-wider text-slate-400 uppercase"
95+
>
96+
Quick Links
97+
</h3>
98+
99+
<div class="mt-3 grid grid-cols-1 gap-2.5">
100+
<Link
101+
href="/"
102+
class="group flex items-center justify-between rounded-xl border border-slate-100 bg-white/40 p-3 text-sm font-medium text-slate-700 transition-all duration-150 hover:border-slate-200 hover:bg-white/80 hover:shadow-sm"
103+
>
104+
<div class="flex items-center gap-3">
105+
<div
106+
class="flex h-8 w-8 items-center justify-center rounded-lg bg-indigo-50 text-indigo-600 transition-colors group-hover:bg-indigo-100"
107+
>
108+
<BookOpen class="h-4 w-4" />
109+
</div>
110+
<span>Academic Resources</span>
111+
</div>
112+
<ChevronRight
113+
class="h-4 w-4 text-slate-400 transition-transform duration-200 group-hover:translate-x-0.5"
114+
/>
115+
</Link>
116+
117+
<Link
118+
href="/join"
119+
class="group flex items-center justify-between rounded-xl border border-slate-100 bg-white/40 p-3 text-sm font-medium text-slate-700 transition-all duration-150 hover:border-slate-200 hover:bg-white/80 hover:shadow-sm"
120+
>
121+
<div class="flex items-center gap-3">
122+
<div
123+
class="flex h-8 w-8 items-center justify-center rounded-lg bg-emerald-50 text-emerald-600 transition-colors group-hover:bg-emerald-100"
124+
>
125+
<Users class="h-4 w-4" />
126+
</div>
127+
<span>Join Our Team</span>
128+
</div>
129+
<ChevronRight
130+
class="h-4 w-4 text-slate-400 transition-transform duration-200 group-hover:translate-x-0.5"
131+
/>
132+
</Link>
133+
134+
<Link
135+
href="/about-us"
136+
class="group flex items-center justify-between rounded-xl border border-slate-100 bg-white/40 p-3 text-sm font-medium text-slate-700 transition-all duration-150 hover:border-slate-200 hover:bg-white/80 hover:shadow-sm"
137+
>
138+
<div class="flex items-center gap-3">
139+
<div
140+
class="flex h-8 w-8 items-center justify-center rounded-lg bg-sky-50 text-sky-600 transition-colors group-hover:bg-sky-100"
141+
>
142+
<Info class="h-4 w-4" />
143+
</div>
144+
<span>About Us</span>
145+
</div>
146+
<ChevronRight
147+
class="h-4 w-4 text-slate-400 transition-transform duration-200 group-hover:translate-x-0.5"
148+
/>
149+
</Link>
150+
</div>
151+
</div>
152+
</div>
153+
</div>
154+
</template>
155+
156+
<style scoped>
157+
@keyframes float {
158+
0%,
159+
100% {
160+
transform: translateY(0px);
161+
}
162+
50% {
163+
transform: translateY(-8px);
164+
}
165+
}
166+
167+
@keyframes pulseGlow {
168+
0%,
169+
100% {
170+
opacity: 0.15;
171+
transform: translate(-50%, -50%) scale(1);
172+
}
173+
50% {
174+
opacity: 0.25;
175+
transform: translate(-50%, -50%) scale(1.08);
176+
}
177+
}
178+
179+
.animate-float {
180+
animation: float 4s ease-in-out infinite;
181+
}
182+
183+
.animate-pulse-glow {
184+
animation: pulseGlow 6s ease-in-out infinite;
185+
}
186+
</style>

0 commit comments

Comments
 (0)