feat: enhance role selection in Employee edit page; add conditional rendering based on view permissions and update role filtering in EmployeeService
This commit is contained in:
parent
ab217a8d79
commit
8aa4e83cd8
@ -36,7 +36,9 @@ public function create(): Response
|
||||
|
||||
return Inertia::render('admin/hr/employee/create', [
|
||||
'roles' => $this->service->canViewAll()
|
||||
? Role::where('name', '!=', 'Developer')->get(['id', 'name'])
|
||||
? Role::where('name', '!=', 'Developer')
|
||||
->when($this->service->shouldHideAdminBahanBaku(), fn ($q) => $q->where('name', '!=', 'admin-bahan-baku'))
|
||||
->get(['id', 'name'])
|
||||
: Role::where('name', '=', $user->roles->first()?->name)->get(['id', 'name']),
|
||||
'canViewAll' => $this->service->canViewAll(),
|
||||
]);
|
||||
@ -57,7 +59,10 @@ public function edit(User $user): Response
|
||||
|
||||
return Inertia::render('admin/hr/employee/edit', [
|
||||
'employee' => $user,
|
||||
'roles' => Role::where('name', '!=', 'Developer')->get(['id', 'name']),
|
||||
'roles' => Role::where('name', '!=', 'Developer')
|
||||
->when($this->service->shouldHideAdminBahanBaku(), fn ($q) => $q->where('name', '!=', 'admin-bahan-baku'))
|
||||
->get(['id', 'name']),
|
||||
'canViewAll' => $this->service->canViewAll(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@ -57,6 +57,7 @@ public function paginated(int $perPage = 25, string $search = '', string $sort =
|
||||
$userRoles = auth()->user()->roles->pluck('name');
|
||||
$q->whereHas('roles', fn ($rq) => $rq->whereIn('name', $userRoles));
|
||||
})
|
||||
->when($this->shouldHideAdminBahanBaku(), fn ($q) => $q->whereDoesntHave('roles', fn ($rq) => $rq->where('name', 'admin-bahan-baku')))
|
||||
->when($search, fn ($q) => $q->whereHas('userProfile', fn ($uq) => $uq->where('full_name', 'like', "%{$search}%")))
|
||||
->when($filters['employment_status'] ?? null, fn ($q, $status) => $q->whereHas('employee', fn ($eq) => $eq->where('employment_status', $status)))
|
||||
->when(isset($filters['is_active']) && $filters['is_active'] !== '', fn ($q) => $q->where('is_active', filter_var($filters['is_active'], FILTER_VALIDATE_BOOLEAN)))
|
||||
|
||||
@ -161,35 +161,41 @@ export default function EmployeeEdit({ employee, roles, canViewAll }: Props) {
|
||||
*
|
||||
</span>
|
||||
</Label>
|
||||
<Combobox
|
||||
items={roles}
|
||||
itemToStringLabel={(r) => r.name}
|
||||
value={selectedRole}
|
||||
onValueChange={(value) =>
|
||||
setSelectedRole(value)
|
||||
}
|
||||
>
|
||||
<ComboboxInput
|
||||
placeholder="Cari role..."
|
||||
className="w-full"
|
||||
/>
|
||||
<ComboboxContent>
|
||||
<ComboboxEmpty>
|
||||
Tidak ada role
|
||||
ditemukan.
|
||||
</ComboboxEmpty>
|
||||
<ComboboxList>
|
||||
{(role) => (
|
||||
<ComboboxItem
|
||||
key={role.id}
|
||||
value={role}
|
||||
>
|
||||
{role.name}
|
||||
</ComboboxItem>
|
||||
)}
|
||||
</ComboboxList>
|
||||
</ComboboxContent>
|
||||
</Combobox>
|
||||
{canViewAll ? (
|
||||
<Combobox
|
||||
items={roles}
|
||||
itemToStringLabel={(r) => r.name}
|
||||
value={selectedRole}
|
||||
onValueChange={(value) =>
|
||||
setSelectedRole(value)
|
||||
}
|
||||
>
|
||||
<ComboboxInput
|
||||
placeholder="Cari role..."
|
||||
className="w-full"
|
||||
/>
|
||||
<ComboboxContent>
|
||||
<ComboboxEmpty>
|
||||
Tidak ada role
|
||||
ditemukan.
|
||||
</ComboboxEmpty>
|
||||
<ComboboxList>
|
||||
{(role) => (
|
||||
<ComboboxItem
|
||||
key={role.id}
|
||||
value={role}
|
||||
>
|
||||
{role.name}
|
||||
</ComboboxItem>
|
||||
)}
|
||||
</ComboboxList>
|
||||
</ComboboxContent>
|
||||
</Combobox>
|
||||
) : (
|
||||
<div className="flex h-10 w-full items-center rounded-md border border-input bg-muted px-3 py-2 text-sm">
|
||||
{selectedRole?.name ?? '-'}
|
||||
</div>
|
||||
)}
|
||||
<InputError
|
||||
message={errors.role}
|
||||
/>
|
||||
|
||||
@ -101,8 +101,8 @@
|
||||
Route::post('employees/{user}/reset-password', [EmployeeController::class, 'resetPassword'])->name('employees.reset-password')->middleware('permission:employees.reset_password');
|
||||
|
||||
Route::get('attendances', [AttendanceController::class, 'index'])->name('attendances.index')->middleware('permission:attendances.view');
|
||||
Route::post('attendances', [AttendanceController::class, 'store'])->name('attendances.store')->middleware('permission:attendances.manage');
|
||||
Route::put('attendances/{attendance}', [AttendanceController::class, 'update'])->name('attendances.update')->middleware('permission:attendances.manage');
|
||||
Route::post('attendances', [AttendanceController::class, 'store'])->name('attendances.store')->middleware('permission:attendances.create');
|
||||
Route::put('attendances/{attendance}', [AttendanceController::class, 'update'])->name('attendances.update')->middleware('permission:attendances.create');
|
||||
Route::get('attendances/by-date', [AttendanceController::class, 'byDate'])->name('attendances.by-date')->middleware('permission:attendances.view');
|
||||
|
||||
Route::resource('leave-requests', LeaveRequestController::class)->except(['show', 'create', 'edit'])->middleware('permission:leave_requests.view|leave_requests.create|leave_requests.update|leave_requests.delete');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user