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

113 lines
5.7 KiB
PHP

<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@yield('title', 'INUFA Production')</title>
<script src="https://cdn.tailwindcss.com"></script>
@stack('styles')
</head>
<body class="bg-white">
<div class="flex h-screen">
<!-- Sidebar -->
@include('layouts.sidebar')
<!-- Main Content -->
<div class="flex-1 flex flex-col">
<!-- Header -->
<header class="bg-[#1e3a8a] text-white py-4 px-6 flex justify-between items-center">
<div class="flex space-x-8">
<h1 class="text-xl font-bold">@yield('header', 'Dashboard')</h1>
</div>
<div class="flex items-center space-x-4">
<a href="{{ route('profile.index') }}" class="font-semibold flex items-center space-x-2">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z" clip-rule="evenodd" />
</svg>
<span>Profile</span>
</a>
<form action="{{ route('logout') }}" method="POST" class="inline">
@csrf
<button type="submit" class="font-semibold flex items-center space-x-2 hover:text-gray-200">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M3 3a1 1 0 00-1 1v12a1 1 0 102 0V4a1 1 0 00-1-1zm10.293 9.293a1 1 0 001.414 1.414l3-3a1 1 0 000-1.414l-3-3a1 1 0 10-1.414 1.414L14.586 9H7a1 1 0 100 2h7.586l-1.293 1.293z" clip-rule="evenodd" />
</svg>
<span>Logout</span>
</button>
</form>
<!-- Profile dropdown -->
<div class="ml-3 relative flex items-center space-x-4">
<!-- Chat Button -->
@auth
<a href="{{ route('chat.index') }}"
class="relative inline-flex items-center p-2 text-white hover:text-gray-200 focus:outline-none">
<svg class="h-7 w-7" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z" />
</svg>
<span id="unread-count" class="absolute -top-2 -right-2 inline-flex items-center justify-center px-2 py-1 text-xs font-bold leading-none text-white transform translate-x-1/2 -translate-y-1/2 bg-red-600 rounded-full shadow-lg hidden">0</span>
</a>
@endauth
<div class="relative">
<button type="button" class="flex text-sm rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500" id="user-menu-button" aria-expanded="false" aria-haspopup="true">
<span class="sr-only">Open user menu</span>
<img class="h-8 w-8 rounded-full" src="https://ui-avatars.com/api/?name={{ urlencode(auth()->user()->nama ?? 'User') }}&background=random" alt="{{ auth()->user()->nama ?? 'User' }}">
</button>
</div>
</div>
</div>
</header>
<!-- Content -->
<main class="flex-1 p-6 bg-[#1e3a8a] overflow-auto">
@if(session('success'))
<div class="bg-green-100 border-l-4 border-green-500 text-green-700 p-4 mb-4 rounded" role="alert">
<p>{{ session('success') }}</p>
</div>
@endif
@if(session('warning'))
<div class="bg-yellow-100 border-l-4 border-yellow-500 text-yellow-700 p-4 mb-4 rounded" role="alert">
<p>{{ session('warning') }}</p>
</div>
@endif
@if(session('error'))
<div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 mb-4 rounded" role="alert">
<p>{{ session('error') }}</p>
</div>
@endif
@yield('content')
</main>
</div>
</div>
@stack('scripts')
@push('scripts')
<script>
// Fungsi untuk mengambil jumlah pesan yang belum dibaca
function getUnreadCount() {
fetch('{{ route("chat.unreadCount") }}')
.then(response => response.json())
.then(data => {
const unreadCount = document.getElementById('unread-count');
if (data.count > 0) {
unreadCount.textContent = data.count;
unreadCount.classList.remove('hidden');
} else {
unreadCount.classList.add('hidden');
}
})
.catch(error => console.error('Error:', error));
}
// Panggil fungsi setiap 30 detik
setInterval(getUnreadCount, 30000);
// Panggil fungsi saat halaman dimuat
document.addEventListener('DOMContentLoaded', getUnreadCount);
</script>
@endpush
</body>
</html>