Skip to content

Commit d3a29b2

Browse files
committed
Flash notifications
1 parent e2089fe commit d3a29b2

File tree

30 files changed

+80
-9
lines changed

30 files changed

+80
-9
lines changed

app/Http/Controllers/PuppyController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class PuppyController extends Controller
1919
public function index(Request $request)
2020
{
2121
$search = $request->search;
22-
2322
return Inertia::render('puppies/index', [
2423
'puppies' => PuppyResource::collection(
2524
Puppy::query()

app/Http/Middleware/HandleInertiaRequests.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,16 @@ public function share(Request $request): array
4646
'auth' => [
4747
'user' => $request->user(),
4848
],
49-
'ziggy' => fn (): array => [
49+
'ziggy' => fn(): array => [
5050
...(new Ziggy)->toArray(),
5151
'location' => $request->url(),
5252
],
5353
'sidebarOpen' => ! $request->hasCookie('sidebar_state') || $request->cookie('sidebar_state') === 'true',
54+
'flash' => [
55+
'success' => $request->session()->get('success'),
56+
'warning' => $request->session()->get('warning'),
57+
'info' => $request->session()->get('info'),
58+
]
5459
];
5560
}
5661
}

database/seeders/PuppySeeder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function run(): void
143143
foreach ($puppies as $puppy) {
144144

145145
// Optimize the image
146-
$input = storage_path('app/public/puppies/' . $puppy['image']);
146+
$input = base_path('seed-images/' . $puppy['image']);
147147
$optimized = $optimizer->handle($input);
148148

149149
// Grab the path of the image

package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@
5050
"laravel-vite-plugin": "^1.0",
5151
"lodash-es": "^4.17.21",
5252
"lucide-react": "^0.475.0",
53+
"next-themes": "^0.4.6",
5354
"react": "^19.0.0",
5455
"react-dom": "^19.0.0",
5556
"react-error-boundary": "^6.0.0",
57+
"sonner": "^2.0.7",
5658
"tailwind-merge": "^3.0.1",
5759
"tailwindcss": "^4.0.0",
5860
"tailwindcss-animate": "^1.0.7",
Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1-
export function PageWrapper({ children }) {
2-
return (
3-
<div className="min-h-dvh bg-gradient-to-b from-cyan-200 to-white to-[60vh]">
4-
{children}
5-
</div>
6-
);
1+
import { Toaster } from '@/components/ui/sonner';
2+
import { SharedData } from '@/types';
3+
import { usePage } from '@inertiajs/react';
4+
import { toast } from 'sonner';
5+
6+
export function PageWrapper({ children }: { children: React.ReactNode }) {
7+
const { flash, errors } = usePage<SharedData>().props;
8+
if (flash.success) toast.success(flash.success);
9+
if (flash.warning) toast.warning(flash.warning);
10+
if (flash.info) toast.info(flash.info);
11+
if (errors) {
12+
Object.values(errors).forEach((error) => {
13+
toast.error(error);
14+
});
15+
}
16+
return (
17+
<>
18+
<div className="min-h-dvh bg-gradient-to-b from-cyan-200 to-white to-[60vh]">{children}</div>
19+
<Toaster position="top-center" richColors />
20+
</>
21+
);
722
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useTheme } from "next-themes"
2+
import { Toaster as Sonner, ToasterProps } from "sonner"
3+
4+
const Toaster = ({ ...props }: ToasterProps) => {
5+
const { theme = "system" } = useTheme()
6+
7+
return (
8+
<Sonner
9+
theme={theme as ToasterProps["theme"]}
10+
className="toaster group"
11+
style={
12+
{
13+
"--normal-bg": "var(--popover)",
14+
"--normal-text": "var(--popover-foreground)",
15+
"--normal-border": "var(--border)",
16+
} as React.CSSProperties
17+
}
18+
{...props}
19+
/>
20+
)
21+
}
22+
23+
export { Toaster }

resources/js/types/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export interface SharedData {
2828
auth: Auth;
2929
ziggy: Config & { location: string };
3030
sidebarOpen: boolean;
31+
flash: {
32+
success?: string;
33+
warning?: string;
34+
info?: string;
35+
};
3136
[key: string]: unknown;
3237
}
3338

seed-images/1.jpg

1.71 MB
Loading

seed-images/10.jpg

87.5 KB
Loading

0 commit comments

Comments
 (0)