app/resources/views/components/layouts/app.blade.php

225 lines
11 KiB
PHP
Raw Normal View History

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Dish Planner') }}</title>
<!-- Scripts -->
@vite(['resources/css/app.css', 'resources/js/app.js'])
@livewireStyles
</head>
2026-01-04 02:50:42 +01:00
<body class="font-sans antialiased bg-gray-600 text-gray-100" x-data="{ mobileMenuOpen: false }">
<div class="min-h-screen">
<!-- Navigation -->
<nav class="border-b-2 border-secondary shadow-sm z-50 mb-8 bg-gray-700">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between h-16">
<div class="flex items-center">
<!-- Logo -->
<div class="flex-shrink-0 flex items-center">
2026-01-04 03:58:47 +01:00
<a href="{{ route('dashboard') }}" class="flex items-center">
<img src="{{ asset('images/logo-without-text.png') }}" alt="Dish Planner" class="h-8 mr-2">
<span class="text-2xl font-syncopate text-primary relative top-[3px]">DISH PLANNER</span>
</a>
</div>
<!-- Navigation Links -->
@auth
<div class="hidden space-x-8 sm:ml-10 sm:flex">
2026-01-04 02:46:13 +01:00
<a href="{{ route('dashboard') }}"
class="inline-flex items-center px-3 py-2 text-sm font-medium {{ request()->routeIs('dashboard') ? 'text-accent-blue' : 'text-gray-100 hover:text-accent-blue' }} transition">
Dashboard
</a>
2026-01-04 02:46:13 +01:00
<a href="{{ route('users.index') }}"
class="inline-flex items-center px-3 py-2 text-sm font-medium {{ request()->routeIs('users.*') ? 'text-accent-blue' : 'text-gray-100 hover:text-accent-blue' }} transition">
Users
</a>
<a href="{{ route('dishes.index') }}"
class="inline-flex items-center px-3 py-2 text-sm font-medium {{ request()->routeIs('dishes.*') ? 'text-accent-blue' : 'text-gray-100 hover:text-accent-blue' }} transition">
Dishes
</a>
2026-01-04 02:46:13 +01:00
<a href="{{ route('schedule.index') }}"
class="inline-flex items-center px-3 py-2 text-sm font-medium {{ request()->routeIs('schedule.*') ? 'text-accent-blue' : 'text-gray-100 hover:text-accent-blue' }} transition">
Schedule
</a>
</div>
@endauth
</div>
<!-- Right Side Of Navbar -->
<div class="hidden sm:flex sm:items-center">
@auth
<div class="ml-3 relative" x-data="{ open: false }">
<button @click="open = !open" class="flex items-center text-sm font-medium text-gray-100 hover:text-accent-blue focus:outline-none transition">
{{ Auth::user()->name }}
<svg class="ml-1 h-4 w-4" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
</svg>
</button>
2026-01-04 03:58:47 +01:00
<div x-show="open"
@click.away="open = false"
x-cloak
x-transition
class="origin-top-right absolute right-0 mt-2 w-48 rounded-md shadow-lg bg-gray-700 ring-1 ring-secondary">
<div class="py-1">
<form method="POST" action="{{ route('logout') }}">
@csrf
<button type="submit" class="block w-full text-left px-4 py-2 text-sm text-gray-100 hover:bg-gray-600 hover:text-accent-blue">
Logout
</button>
</form>
</div>
</div>
</div>
@else
<a href="{{ route('login') }}" class="text-sm text-accent-blue hover:underline">Login</a>
@if (Route::has('register'))
<a href="{{ route('register') }}" class="ml-4 text-sm text-accent-blue hover:underline">Register</a>
@endif
@endauth
</div>
<!-- Mobile menu button -->
2026-01-04 02:50:42 +01:00
<div class="-mr-2 flex items-center sm:hidden">
<button @click="mobileMenuOpen = !mobileMenuOpen" class="inline-flex items-center justify-center p-2 rounded-md text-gray-100 hover:text-accent-blue hover:bg-gray-700 focus:outline-none focus:bg-gray-700 focus:text-accent-blue transition">
<svg class="h-6 w-6" stroke="currentColor" fill="none" viewBox="0 0 24 24">
2026-01-04 02:50:42 +01:00
<path :class="{'hidden': mobileMenuOpen, 'inline-flex': !mobileMenuOpen }" class="inline-flex" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
<path :class="{'hidden': !mobileMenuOpen, 'inline-flex': mobileMenuOpen }" class="hidden" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
</div>
</div>
2026-01-04 02:50:42 +01:00
</nav>
2026-01-04 02:50:42 +01:00
<!-- Mobile menu (full screen overlay) -->
<div x-show="mobileMenuOpen"
x-cloak
x-transition:enter="transition ease-out duration-200"
x-transition:enter-start="opacity-0"
x-transition:enter-end="opacity-100"
x-transition:leave="transition ease-in duration-150"
x-transition:leave-start="opacity-100"
x-transition:leave-end="opacity-0"
class="sm:hidden fixed inset-0 z-50 bg-gray-700">
<!-- Close button -->
<div class="flex justify-end p-4">
<button @click="mobileMenuOpen = false" class="p-2 text-gray-100 hover:text-accent-blue">
<svg class="h-8 w-8" stroke="currentColor" fill="none" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<!-- Menu content -->
<div class="flex flex-col items-center justify-center h-full -mt-16">
@auth
<div class="space-y-6 text-center">
<a href="{{ route('dashboard') }}"
class="block text-2xl font-medium {{ request()->routeIs('dashboard') ? 'text-accent-blue' : 'text-gray-100' }}">
Dashboard
</a>
<a href="{{ route('users.index') }}"
class="block text-2xl font-medium {{ request()->routeIs('users.*') ? 'text-accent-blue' : 'text-gray-100' }}">
Users
</a>
<a href="{{ route('dishes.index') }}"
class="block text-2xl font-medium {{ request()->routeIs('dishes.*') ? 'text-accent-blue' : 'text-gray-100' }}">
Dishes
</a>
<a href="{{ route('schedule.index') }}"
class="block text-2xl font-medium {{ request()->routeIs('schedule.*') ? 'text-accent-blue' : 'text-gray-100' }}">
Schedule
</a>
</div>
<div class="mt-12 pt-6 border-t border-secondary text-center">
<div class="text-gray-300 mb-4">{{ Auth::user()->name }}</div>
<form method="POST" action="{{ route('logout') }}">
@csrf
<button type="submit" class="text-xl text-danger">
Logout
</button>
</form>
</div>
@else
<div class="space-y-6 text-center">
<a href="{{ route('login') }}" class="block text-2xl font-medium text-accent-blue">Login</a>
@if (Route::has('register'))
<a href="{{ route('register') }}" class="block text-2xl font-medium text-accent-blue">Register</a>
@endif
</div>
@endauth
</div>
</div>
<!-- Page Content -->
<main>
{{ $slot }}
</main>
</div>
@livewireScripts
2026-01-04 03:58:47 +01:00
{{-- CSRF Token Auto-Refresh for Livewire --}}
<script>
// Handle CSRF token expiration gracefully
Livewire.hook("request", ({ fail }) => {
fail(async ({ status, preventDefault, retry }) => {
if (status === 419) {
// Prevent the default error handling
preventDefault();
2026-01-04 03:58:47 +01:00
try {
// Fetch a new CSRF token
const response = await fetch("/refresh-csrf", {
method: "GET",
headers: {
"Accept": "application/json",
"X-Requested-With": "XMLHttpRequest"
},
credentials: "same-origin",
});
2026-01-04 03:58:47 +01:00
if (response.ok) {
const data = await response.json();
const newToken = data.token;
2026-01-04 03:58:47 +01:00
// Update the CSRF token in the meta tag
const csrfMeta = document.querySelector("meta[name='csrf-token']");
if (csrfMeta) {
csrfMeta.setAttribute("content", newToken);
}
2026-01-04 03:58:47 +01:00
// Update Livewire's CSRF token
if (window.Livewire && Livewire.csrfToken) {
Livewire.csrfToken = newToken;
}
2026-01-04 03:58:47 +01:00
// Retry the original request with the new token
retry();
} else {
// If we can't refresh the token, redirect to login
window.location.href = '/login';
}
} catch (error) {
console.error('Failed to refresh CSRF token:', error);
// Fallback: redirect to login
window.location.href = '/login';
}
}
});
});
</script>
2026-01-04 03:58:47 +01:00
<style>
[x-cloak] { display: none !important; }
</style>
</body>
2026-01-04 03:58:47 +01:00
</html>