fix: sync employee photo to user profile avatar, topbar, and dashboard
This commit is contained in:
@@ -210,9 +210,13 @@
|
||||
<tr class="hover:bg-slate-50/70 transition">
|
||||
<td class="py-3 px-4">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-8 h-8 rounded-full bg-indigo-50 border border-indigo-100 text-indigo-700 font-black flex items-center justify-center text-xs flex-shrink-0">
|
||||
{{ strtoupper(substr($user->name, 0, 1)) }}
|
||||
</div>
|
||||
@if($user->photo_url)
|
||||
<img src="{{ $user->photo_url }}" alt="{{ $user->name }}" class="w-8 h-8 rounded-full object-cover border border-slate-200 shadow-2xs flex-shrink-0">
|
||||
@else
|
||||
<div class="w-8 h-8 rounded-full bg-indigo-50 border border-indigo-100 text-indigo-700 font-black flex items-center justify-center text-xs flex-shrink-0">
|
||||
{{ strtoupper(substr($user->name, 0, 1)) }}
|
||||
</div>
|
||||
@endif
|
||||
<div>
|
||||
<p class="font-bold text-slate-900 text-xs">{{ $user->name }}</p>
|
||||
<p class="text-[11px] text-slate-400 font-mono">@<span>{{ $user->username }}</span></p>
|
||||
@@ -303,7 +307,7 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form action="{{ route('admin.users.store') }}" method="POST" class="p-6 space-y-4">
|
||||
<form action="{{ route('admin.users.store') }}" method="POST" enctype="multipart/form-data" class="p-6 space-y-4">
|
||||
@csrf
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-700 mb-1">Nama Lengkap *</label>
|
||||
@@ -326,6 +330,26 @@
|
||||
<input type="password" name="password" required minlength="6" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white" placeholder="Minimal 6 karakter">
|
||||
</div>
|
||||
|
||||
<!-- Upload Foto Profil (Opsional) -->
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-700 mb-1">Foto Profil Pengguna (Opsional)</label>
|
||||
<div class="flex items-center space-x-3">
|
||||
<div id="addUserPhotoPreviewContainer" class="w-12 h-12 rounded-full border-2 border-dashed border-slate-300 bg-slate-50 flex items-center justify-center overflow-hidden flex-shrink-0 shadow-2xs">
|
||||
<img id="addUserPhotoPreview" src="" alt="Pratinjau" class="w-full h-full object-cover hidden">
|
||||
<i id="addUserPhotoPlaceholder" class="fa-solid fa-camera text-slate-400 text-sm"></i>
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<input type="file"
|
||||
name="photo"
|
||||
id="addUserPhotoInput"
|
||||
accept="image/jpeg,image/png,image/jpg,image/webp"
|
||||
onchange="previewUserImage(this, 'addUserPhotoPreview', 'addUserPhotoPlaceholder')"
|
||||
class="block w-full text-xs text-slate-500 file:mr-2.5 file:py-1.5 file:px-3 file:rounded-lg file:border-0 file:text-[11px] file:font-bold file:bg-indigo-50 file:text-indigo-700 hover:file:bg-indigo-100 cursor-pointer">
|
||||
<p class="text-[10px] text-slate-400 mt-0.5">Otomatis dikompresi hemat storage (Maks. 10MB).</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-700 mb-1">Role RBAC *</label>
|
||||
@@ -374,7 +398,7 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form id="editUserForm" method="POST" class="p-6 space-y-4">
|
||||
<form id="editUserForm" method="POST" enctype="multipart/form-data" class="p-6 space-y-4">
|
||||
@csrf
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-700 mb-1">Nama Lengkap *</label>
|
||||
@@ -399,6 +423,26 @@
|
||||
<input type="password" name="password" minlength="6" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white" placeholder="Masukkan password baru">
|
||||
</div>
|
||||
|
||||
<!-- Upload / Ganti Foto Profil -->
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-700 mb-1">Foto Profil Pengguna</label>
|
||||
<div class="flex items-center space-x-3">
|
||||
<div id="editUserPhotoPreviewContainer" class="w-12 h-12 rounded-full border border-slate-200 bg-slate-50 flex items-center justify-center overflow-hidden flex-shrink-0 shadow-2xs">
|
||||
<img id="editUserPhotoPreview" src="" alt="Foto" class="w-full h-full object-cover hidden">
|
||||
<i id="editUserPhotoPlaceholder" class="fa-solid fa-user text-slate-400 text-sm"></i>
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<input type="file"
|
||||
name="photo"
|
||||
id="editUserPhotoInput"
|
||||
accept="image/jpeg,image/png,image/jpg,image/webp"
|
||||
onchange="previewUserImage(this, 'editUserPhotoPreview', 'editUserPhotoPlaceholder')"
|
||||
class="block w-full text-xs text-slate-500 file:mr-2.5 file:py-1.5 file:px-3 file:rounded-lg file:border-0 file:text-[11px] file:font-bold file:bg-indigo-50 file:text-indigo-700 hover:file:bg-indigo-100 cursor-pointer">
|
||||
<p class="text-[10px] text-slate-400 mt-0.5">Pilih file baru jika ingin mengganti foto profil.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-700 mb-1">Role RBAC *</label>
|
||||
@@ -519,6 +563,24 @@
|
||||
const rolePermissionsMap = @json($rolePermissionsMap ?? []);
|
||||
let currentUserDirectPerms = [];
|
||||
|
||||
function previewUserImage(input, previewId, placeholderId) {
|
||||
const preview = document.getElementById(previewId);
|
||||
const placeholder = document.getElementById(placeholderId);
|
||||
if (input.files && input.files[0]) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
if (preview) {
|
||||
preview.src = e.target.result;
|
||||
preview.classList.remove('hidden');
|
||||
}
|
||||
if (placeholder) {
|
||||
placeholder.classList.add('hidden');
|
||||
}
|
||||
};
|
||||
reader.readAsDataURL(input.files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
function openCreateUserModal() {
|
||||
document.getElementById('createUserModal').classList.remove('hidden');
|
||||
document.documentElement.classList.add('modal-open');
|
||||
@@ -527,6 +589,17 @@
|
||||
function closeCreateUserModal() {
|
||||
document.getElementById('createUserModal').classList.add('hidden');
|
||||
document.documentElement.classList.remove('modal-open');
|
||||
const input = document.getElementById('addUserPhotoInput');
|
||||
const preview = document.getElementById('addUserPhotoPreview');
|
||||
const placeholder = document.getElementById('addUserPhotoPlaceholder');
|
||||
if (input) input.value = '';
|
||||
if (preview) {
|
||||
preview.src = '';
|
||||
preview.classList.add('hidden');
|
||||
}
|
||||
if (placeholder) {
|
||||
placeholder.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
function toggleDirectPermsAccordion() {
|
||||
@@ -633,6 +706,24 @@
|
||||
document.getElementById('edit_role').value = primaryRole;
|
||||
document.getElementById('edit_gate_id').value = user.gate_id || '';
|
||||
|
||||
const editPhotoPreview = document.getElementById('editUserPhotoPreview');
|
||||
const editPhotoPlaceholder = document.getElementById('editUserPhotoPlaceholder');
|
||||
const editPhotoInput = document.getElementById('editUserPhotoInput');
|
||||
if (editPhotoInput) editPhotoInput.value = '';
|
||||
if (user.photo_url) {
|
||||
if (editPhotoPreview) {
|
||||
editPhotoPreview.src = user.photo_url;
|
||||
editPhotoPreview.classList.remove('hidden');
|
||||
}
|
||||
if (editPhotoPlaceholder) editPhotoPlaceholder.classList.add('hidden');
|
||||
} else {
|
||||
if (editPhotoPreview) {
|
||||
editPhotoPreview.src = '';
|
||||
editPhotoPreview.classList.add('hidden');
|
||||
}
|
||||
if (editPhotoPlaceholder) editPhotoPlaceholder.classList.remove('hidden');
|
||||
}
|
||||
|
||||
currentUserDirectPerms = Array.isArray(userDirectPerms) ? [...userDirectPerms] : [];
|
||||
updatePermissionCheckboxes();
|
||||
|
||||
@@ -643,6 +734,15 @@
|
||||
function closeEditUserModal() {
|
||||
document.getElementById('editUserModal').classList.add('hidden');
|
||||
document.documentElement.classList.remove('modal-open');
|
||||
const editPhotoInput = document.getElementById('editUserPhotoInput');
|
||||
const editPhotoPreview = document.getElementById('editUserPhotoPreview');
|
||||
const editPhotoPlaceholder = document.getElementById('editUserPhotoPlaceholder');
|
||||
if (editPhotoInput) editPhotoInput.value = '';
|
||||
if (editPhotoPreview) {
|
||||
editPhotoPreview.src = '';
|
||||
editPhotoPreview.classList.add('hidden');
|
||||
}
|
||||
if (editPhotoPlaceholder) editPhotoPlaceholder.classList.remove('hidden');
|
||||
}
|
||||
|
||||
function openDeleteUserModal(userId, userName) {
|
||||
|
||||
@@ -6,36 +6,52 @@
|
||||
<div class="w-full space-y-6">
|
||||
|
||||
<!-- Header Halaman Simple Kayak Satpam (Seamless, Tanpa Card Wrapper) -->
|
||||
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 pb-3 border-b border-slate-200/80">
|
||||
<div class="min-w-0">
|
||||
<div class="flex items-center flex-wrap gap-2.5">
|
||||
<h1 class="text-lg sm:text-xl font-black text-slate-900 tracking-tight">
|
||||
Dashboard Karyawan
|
||||
</h1>
|
||||
@if($employee && $employee->hasValidSimper())
|
||||
<span class="px-2.5 py-1 rounded-lg text-xs font-black bg-emerald-50 text-emerald-700 border border-emerald-200">
|
||||
SIMPER Aktif
|
||||
</span>
|
||||
@elseif($employee)
|
||||
<span class="px-2.5 py-1 rounded-lg text-xs font-black bg-rose-50 text-rose-700 border border-rose-200">
|
||||
SIMPER Exp
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
<div class="text-sm sm:text-base text-slate-600 font-medium truncate mt-1 flex items-center flex-wrap gap-1.5">
|
||||
<span>Karyawan: <strong class="text-slate-900 font-bold">{{ $employee ? $employee->name : auth()->user()->name }}</strong></span>
|
||||
@if($employee && $employee->nik)
|
||||
<span class="text-slate-500 font-mono text-xs sm:text-sm font-semibold">({{ $employee->nik }})</span>
|
||||
@endif
|
||||
@if($employee && $employee->division)
|
||||
<span class="text-slate-400">•</span>
|
||||
<span class="text-slate-500 text-xs sm:text-sm">{{ $employee->division }}</span>
|
||||
@endif
|
||||
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-4 pb-4 border-b border-slate-200/80">
|
||||
<div class="flex items-center space-x-3.5 min-w-0">
|
||||
@php
|
||||
$empPhoto = $employee?->photo_url ?: auth()->user()->photo_url;
|
||||
$empName = $employee ? $employee->name : auth()->user()->name;
|
||||
@endphp
|
||||
@if($empPhoto)
|
||||
<img src="{{ $empPhoto }}" alt="{{ $empName }}" class="w-12 h-12 rounded-2xl object-cover ring-2 ring-emerald-500/20 shadow-sm flex-shrink-0">
|
||||
@else
|
||||
<div class="w-12 h-12 rounded-2xl bg-gradient-to-br from-emerald-700 to-[#1b5e20] text-white font-black text-lg flex items-center justify-center ring-2 ring-emerald-500/20 shadow-sm flex-shrink-0">
|
||||
{{ strtoupper(substr($empName, 0, 1)) }}
|
||||
</div>
|
||||
@endif
|
||||
<div class="min-w-0">
|
||||
<div class="flex items-center flex-wrap gap-2.5">
|
||||
<h1 class="text-lg sm:text-xl font-black text-slate-900 tracking-tight">
|
||||
{{ $empName }}
|
||||
</h1>
|
||||
@if($employee && $employee->hasValidSimper())
|
||||
<span class="px-2.5 py-0.5 rounded-lg text-xs font-black bg-emerald-50 text-emerald-700 border border-emerald-200">
|
||||
SIMPER Aktif
|
||||
</span>
|
||||
@elseif($employee)
|
||||
<span class="px-2.5 py-0.5 rounded-lg text-xs font-black bg-rose-50 text-rose-700 border border-rose-200">
|
||||
SIMPER Exp
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
<div class="text-xs sm:text-sm text-slate-500 font-medium truncate mt-0.5 flex items-center flex-wrap gap-1.5">
|
||||
@if($employee && $employee->nik)
|
||||
<span class="text-slate-700 font-mono font-semibold">NIK: {{ $employee->nik }}</span>
|
||||
@endif
|
||||
@if($employee && $employee->division)
|
||||
<span class="text-slate-300">•</span>
|
||||
<span class="text-slate-600">{{ $employee->division }}</span>
|
||||
@endif
|
||||
@if($employee && $employee->position)
|
||||
<span class="text-slate-300">•</span>
|
||||
<span class="text-slate-600 font-semibold">{{ $employee->position }}</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if($employee && $employee->simper_expired_at)
|
||||
<div class="text-xs text-slate-500 font-medium self-start sm:self-center">
|
||||
<div class="text-xs text-slate-500 font-medium self-start sm:self-center bg-slate-50 px-3 py-1.5 rounded-xl border border-slate-200/60">
|
||||
Masa Berlaku SIMPER: <span class="font-bold text-slate-800">{{ $employee->simper_expired_at->format('d/m/Y') }}</span>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@@ -449,9 +449,13 @@
|
||||
<!-- Footer Bawah Sidebar: Profil Pengguna & Tombol Logout (Persis Gambar IT All Role) -->
|
||||
<div class="p-4 border-t border-slate-100 flex items-center justify-between bg-slate-50/50">
|
||||
<a href="{{ route('profile.index') }}" class="flex items-center space-x-2.5 min-w-0 hover:opacity-80 transition group" title="Buka Profil Saya">
|
||||
<div class="w-8 h-8 rounded-full bg-[#1b5e20] text-white font-black text-xs flex items-center justify-center flex-shrink-0 shadow-sm group-hover:ring-2 ring-emerald-500/30">
|
||||
{{ strtoupper(substr(auth()->user()->name, 0, 1)) }}
|
||||
</div>
|
||||
@if(auth()->user()->photo_url)
|
||||
<img src="{{ auth()->user()->photo_url }}" alt="{{ auth()->user()->name }}" class="w-8 h-8 rounded-full object-cover flex-shrink-0 shadow-sm group-hover:ring-2 ring-emerald-500/30">
|
||||
@else
|
||||
<div class="w-8 h-8 rounded-full bg-[#1b5e20] text-white font-black text-xs flex items-center justify-center flex-shrink-0 shadow-sm group-hover:ring-2 ring-emerald-500/30">
|
||||
{{ strtoupper(substr(auth()->user()->name, 0, 1)) }}
|
||||
</div>
|
||||
@endif
|
||||
<div class="truncate">
|
||||
<p class="text-xs font-bold text-slate-800 truncate leading-tight group-hover:text-[#1b5e20]">{{ auth()->user()->name }}</p>
|
||||
<p class="text-[10px] text-slate-400 capitalize truncate">{{ str_replace('_', ' ', auth()->user()->role) }}</p>
|
||||
@@ -740,9 +744,13 @@
|
||||
|
||||
<div class="p-4 border-t border-slate-100 flex items-center justify-between bg-slate-50/50">
|
||||
<a href="{{ route('profile.index') }}" class="flex items-center space-x-2.5 min-w-0 hover:opacity-80 transition group" title="Buka Profil Saya">
|
||||
<div class="w-8 h-8 rounded-full bg-[#1b5e20] text-white font-black text-xs flex items-center justify-center flex-shrink-0 shadow-sm group-hover:ring-2 ring-emerald-500/30">
|
||||
{{ strtoupper(substr(auth()->user()->name, 0, 1)) }}
|
||||
</div>
|
||||
@if(auth()->user()->photo_url)
|
||||
<img src="{{ auth()->user()->photo_url }}" alt="{{ auth()->user()->name }}" class="w-8 h-8 rounded-full object-cover flex-shrink-0 shadow-sm group-hover:ring-2 ring-emerald-500/30">
|
||||
@else
|
||||
<div class="w-8 h-8 rounded-full bg-[#1b5e20] text-white font-black text-xs flex items-center justify-center flex-shrink-0 shadow-sm group-hover:ring-2 ring-emerald-500/30">
|
||||
{{ strtoupper(substr(auth()->user()->name, 0, 1)) }}
|
||||
</div>
|
||||
@endif
|
||||
<div class="truncate">
|
||||
<p class="text-xs font-bold text-slate-800 truncate leading-tight group-hover:text-[#1b5e20]">{{ auth()->user()->name }}</p>
|
||||
<p class="text-[10px] text-slate-400 capitalize truncate">{{ str_replace('_', ' ', auth()->user()->role) }}</p>
|
||||
@@ -824,9 +832,13 @@
|
||||
class="flex items-center space-x-2.5 p-1 sm:px-2.5 sm:py-1.5 rounded-xl hover:bg-slate-50 transition group focus:outline-none cursor-pointer"
|
||||
aria-expanded="false"
|
||||
aria-haspopup="true">
|
||||
<div class="w-9 h-9 rounded-full bg-[#1b5e20] text-white font-bold text-sm flex items-center justify-center shadow-sm group-hover:ring-2 ring-emerald-500/30 flex-shrink-0">
|
||||
{{ strtoupper(substr(auth()->user()->name, 0, 1)) }}
|
||||
</div>
|
||||
@if(auth()->user()->photo_url)
|
||||
<img src="{{ auth()->user()->photo_url }}" alt="{{ auth()->user()->name }}" class="w-9 h-9 rounded-full object-cover shadow-sm group-hover:ring-2 ring-emerald-500/30 flex-shrink-0">
|
||||
@else
|
||||
<div class="w-9 h-9 rounded-full bg-[#1b5e20] text-white font-bold text-sm flex items-center justify-center shadow-sm group-hover:ring-2 ring-emerald-500/30 flex-shrink-0">
|
||||
{{ strtoupper(substr(auth()->user()->name, 0, 1)) }}
|
||||
</div>
|
||||
@endif
|
||||
<div class="text-left hidden sm:block">
|
||||
<p class="text-xs font-bold text-slate-800 leading-tight group-hover:text-[#1b5e20]">{{ auth()->user()->name }}</p>
|
||||
<p class="text-[10px] font-semibold text-slate-400 uppercase tracking-wider mt-0.5">
|
||||
|
||||
@@ -35,9 +35,13 @@
|
||||
<!-- Kolom Kiri: Kartu Ringkasan Pengguna -->
|
||||
<div class="bg-white rounded-2xl border border-slate-200 p-6 shadow-sm flex flex-col items-center text-center">
|
||||
<!-- Avatar Besar -->
|
||||
<div class="w-24 h-24 rounded-full bg-[#1b5e20] text-white text-3xl font-black flex items-center justify-center shadow-lg mb-4 ring-4 ring-emerald-50">
|
||||
{{ strtoupper(substr($user->name, 0, 1)) }}
|
||||
</div>
|
||||
@if($user->photo_url)
|
||||
<img src="{{ $user->photo_url }}" alt="{{ $user->name }}" class="w-24 h-24 rounded-full object-cover shadow-lg mb-4 ring-4 ring-emerald-50">
|
||||
@else
|
||||
<div class="w-24 h-24 rounded-full bg-[#1b5e20] text-white text-3xl font-black flex items-center justify-center shadow-lg mb-4 ring-4 ring-emerald-50">
|
||||
{{ strtoupper(substr($user->name, 0, 1)) }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<h3 class="text-lg font-bold text-slate-900">{{ $user->name }}</h3>
|
||||
<p class="text-xs font-mono text-slate-500 mt-0.5">NIK / Username: {{ $user->username ?? '-' }}</p>
|
||||
@@ -62,6 +66,35 @@
|
||||
<span class="text-slate-500">Unit Operasional</span>
|
||||
<span class="font-semibold text-slate-800">PLTA Merangin 350 MW</span>
|
||||
</div>
|
||||
@if($user->employee || ($user->isEmployee() && $user->getOrCreateEmployee()))
|
||||
@php $emp = $user->employee ?: $user->getOrCreateEmployee(); @endphp
|
||||
@if($emp && $emp->division)
|
||||
<div class="flex justify-between items-center py-1">
|
||||
<span class="text-slate-500">Divisi</span>
|
||||
<span class="font-semibold text-slate-800">{{ $emp->division }}</span>
|
||||
</div>
|
||||
@endif
|
||||
@if($emp && $emp->position)
|
||||
<div class="flex justify-between items-center py-1">
|
||||
<span class="text-slate-500">Jabatan</span>
|
||||
<span class="font-semibold text-slate-800">{{ $emp->position }}</span>
|
||||
</div>
|
||||
@endif
|
||||
@if($emp && $emp->is_operator)
|
||||
<div class="flex justify-between items-center py-1">
|
||||
<span class="text-slate-500">Status SIMPER</span>
|
||||
@if($emp->hasValidSimper())
|
||||
<span class="inline-flex items-center px-2 py-0.5 rounded text-[11px] font-bold bg-emerald-100 text-emerald-800">
|
||||
Aktif (s/d {{ $emp->simper_expired_at?->format('d/m/Y') }})
|
||||
</span>
|
||||
@else
|
||||
<span class="inline-flex items-center px-2 py-0.5 rounded text-[11px] font-bold bg-rose-100 text-rose-800">
|
||||
Kedaluwarsa
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
@endif
|
||||
<div class="flex justify-between items-center py-1">
|
||||
<span class="text-slate-500">Terdaftar Sejak</span>
|
||||
<span class="font-semibold text-slate-800">{{ $user->created_at ? $user->created_at->format('d M Y') : '12 Okt 2026' }}</span>
|
||||
|
||||
Reference in New Issue
Block a user