Merge branch 'user-module'

This commit is contained in:
Saufi
2026-05-11 14:24:29 +08:00
23 changed files with 814 additions and 0 deletions

View File

@@ -15,6 +15,12 @@
<x-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
{{ __('Dashboard') }}
</x-nav-link>
<x-nav-link :href="route('users.index')" :active="request()->routeIs('users.*')">
{{ __('Users') }}
</x-nav-link>
<x-nav-link :href="route('roles.index')" :active="request()->routeIs('roles.*')">
{{ __('Roles') }}
</x-nav-link>
</div>
</div>
@@ -70,6 +76,12 @@
<x-responsive-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
{{ __('Dashboard') }}
</x-responsive-nav-link>
<x-responsive-nav-link :href="route('users.index')" :active="request()->routeIs('users.*')">
{{ __('Users') }}
</x-responsive-nav-link>
<x-responsive-nav-link :href="route('roles.index')" :active="request()->routeIs('roles.*')">
{{ __('Roles') }}
</x-responsive-nav-link>
</div>
<!-- Responsive Settings Options -->

View File

@@ -0,0 +1,34 @@
<table class="w-full text-sm text-left text-gray-900 dark:text-gray-100">
<thead class="text-xs text-gray-700 dark:text-gray-400 uppercase bg-gray-50 dark:bg-gray-700">
<tr>
<th class="px-6 py-3">#</th>
<th class="px-6 py-3">{{ __('Name') }}</th>
<th class="px-6 py-3">{{ __('Description') }}</th>
<th class="px-6 py-3">{{ __('Created') }}</th>
</tr>
</thead>
<tbody>
@foreach ($roles as $role)
<tr class="{{ $loop->even ? 'bg-gray-50 dark:bg-gray-700' : 'bg-white dark:bg-gray-800' }} border-b border-gray-200 dark:border-gray-600">
<td class="px-6 py-4">{{ $roles->firstItem() + $loop->index }}</td>
<td class="px-6 py-4 font-medium">{{ $role->name }}</td>
<td class="px-6 py-4">{{ $role->description ?? '—' }}</td>
<td class="px-6 py-4">{{ $role->created_at->format('d M Y') }}</td>
</tr>
@endforeach
@if ($roles->isEmpty())
<tr>
<td colspan="4" class="px-6 py-4 text-center text-gray-500 dark:text-gray-400">
{{ __('No roles found.') }}
</td>
</tr>
@endif
</tbody>
</table>
@if ($roles->hasPages())
<div class="mt-4">
{{ $roles->links() }}
</div>
@endif

View File

@@ -0,0 +1,56 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
{{ __('New Role') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="p-4 sm:p-8 bg-white dark:bg-gray-800 shadow sm:rounded-lg">
<div class="max-w-xl">
<section>
<header>
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
{{ __('Role Details') }}
</h2>
<p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
{{ __('Create a new role to assign to users in the system.') }}
</p>
</header>
<form method="post" action="{{ route('roles.store') }}" class="mt-6 space-y-6">
@csrf
<div>
<x-input-label for="name" :value="__('Name')" />
<x-text-input id="name" name="name" type="text" class="mt-1 block w-full" :value="old('name')" required autofocus autocomplete="off" />
<x-input-error class="mt-2" :messages="$errors->get('name')" />
</div>
<div>
<x-input-label for="description" :value="__('Description')" />
<textarea
id="description"
name="description"
rows="3"
class="mt-1 block w-full border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600 rounded-md shadow-sm"
>{{ old('description') }}</textarea>
<x-input-error class="mt-2" :messages="$errors->get('description')" />
</div>
<div class="flex items-center gap-4">
<x-primary-button>{{ __('Create Role') }}</x-primary-button>
<a href="{{ route('roles.index') }}" class="text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 underline">
{{ __('Cancel') }}
</a>
</div>
</form>
</section>
</div>
</div>
</div>
</div>
</x-app-layout>

View File

@@ -0,0 +1,59 @@
<x-app-layout>
<x-slot name="header">
<div class="flex items-center justify-between">
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
{{ __('Roles') }}
</h2>
<a href="{{ route('roles.create') }}">
<x-primary-button>{{ __('New Role') }}</x-primary-button>
</a>
</div>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
@if (session('status') === 'role-created')
<div
x-data="{ show: true }"
x-show="show"
x-transition
x-init="setTimeout(() => show = false, 3000)"
class="mb-4 p-4 bg-green-100 dark:bg-green-900 text-green-800 dark:text-green-200 text-sm rounded-lg"
>
{{ __('Role created successfully.') }}
</div>
@endif
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
<div
class="p-6"
x-data="{
loading: false,
async paginate(url) {
this.loading = true;
const response = await fetch(url, {
headers: { 'X-Requested-With': 'XMLHttpRequest' }
});
this.$refs.tableContainer.innerHTML = await response.text();
this.loading = false;
}
}"
@click.prevent="
const link = $event.target.closest('a[href]');
if (link && $refs.tableContainer.contains(link)) {
paginate(link.href);
}
"
>
<div x-show="loading" class="text-center py-4 text-gray-500 dark:text-gray-400">
{{ __('Loading...') }}
</div>
<div x-ref="tableContainer" x-show="!loading">
@include('roles._table')
</div>
</div>
</div>
</div>
</div>
</x-app-layout>

View File

@@ -0,0 +1,40 @@
<table class="w-full text-sm text-left text-gray-900 dark:text-gray-100">
<thead class="text-xs text-gray-700 dark:text-gray-400 uppercase bg-gray-50 dark:bg-gray-700">
<tr>
<th class="px-6 py-3">#</th>
<th class="px-6 py-3">{{ __('Name') }}</th>
<th class="px-6 py-3">{{ __('Email') }}</th>
<th class="px-6 py-3">{{ __('Joined') }}</th>
<th class="px-6 py-3"></th>
</tr>
</thead>
<tbody>
@foreach ($users as $user)
<tr class="{{ $loop->even ? 'bg-gray-50 dark:bg-gray-700' : 'bg-white dark:bg-gray-800' }} border-b border-gray-200 dark:border-gray-600">
<td class="px-6 py-4">{{ $users->firstItem() + $loop->index }}</td>
<td class="px-6 py-4 font-medium">{{ $user->name }}</td>
<td class="px-6 py-4">{{ $user->email }}</td>
<td class="px-6 py-4">{{ $user->created_at->format('d M Y') }}</td>
<td class="px-6 py-4 text-right">
<a href="{{ route('users.edit', $user) }}" class="text-indigo-600 dark:text-indigo-400 hover:underline text-sm font-medium">
{{ __('Edit') }}
</a>
</td>
</tr>
@endforeach
@if ($users->isEmpty())
<tr>
<td colspan="5" class="px-6 py-4 text-center text-gray-500 dark:text-gray-400">
{{ __('No users found.') }}
</td>
</tr>
@endif
</tbody>
</table>
@if ($users->hasPages())
<div class="mt-4">
{{ $users->links() }}
</div>
@endif

View File

@@ -0,0 +1,65 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
{{ __('Edit User') }}: {{ $user->name }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="p-4 sm:p-8 bg-white dark:bg-gray-800 shadow sm:rounded-lg">
<div class="max-w-xl">
<section>
<header>
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
{{ __('Assign Roles') }}
</h2>
<p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
{{ __('Select the roles to assign to this user.') }}
</p>
</header>
<form method="post" action="{{ route('users.update', $user) }}" class="mt-6 space-y-6">
@csrf
@method('put')
<div class="space-y-3">
@forelse ($roles as $role)
<label class="flex items-start gap-3 cursor-pointer">
<input
type="checkbox"
name="roles[]"
value="{{ $role->id }}"
{{ $user->roles->contains($role) ? 'checked' : '' }}
class="mt-0.5 rounded border-gray-300 dark:border-gray-700 text-indigo-600 shadow-sm focus:ring-indigo-500 dark:focus:ring-indigo-600 dark:bg-gray-900"
/>
<div>
<span class="text-sm font-medium text-gray-900 dark:text-gray-100">{{ $role->name }}</span>
@if ($role->description)
<p class="text-xs text-gray-500 dark:text-gray-400">{{ $role->description }}</p>
@endif
</div>
</label>
@empty
<p class="text-sm text-gray-500 dark:text-gray-400">{{ __('No roles available. Create one first.') }}</p>
@endforelse
</div>
<x-input-error class="mt-2" :messages="$errors->get('roles')" />
<x-input-error class="mt-2" :messages="$errors->get('roles.*')" />
<div class="flex items-center gap-4">
<x-primary-button>{{ __('Save Roles') }}</x-primary-button>
<a href="{{ route('users.index') }}" class="text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 underline">
{{ __('Cancel') }}
</a>
</div>
</form>
</section>
</div>
</div>
</div>
</div>
</x-app-layout>

View File

@@ -0,0 +1,43 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
{{ __('Users') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
<div
class="p-6"
x-data="{
loading: false,
async paginate(url) {
this.loading = true;
const response = await fetch(url, {
headers: { 'X-Requested-With': 'XMLHttpRequest' }
});
this.$refs.tableContainer.innerHTML = await response.text();
this.loading = false;
}
}"
@click="
const link = $event.target.closest('a[href]');
if (link && link.closest('nav[role=navigation]') && $refs.tableContainer.contains(link)) {
$event.preventDefault();
paginate(link.href);
}
"
>
<div x-show="loading" class="text-center py-4 text-gray-500 dark:text-gray-400">
{{ __('Loading...') }}
</div>
<div x-ref="tableContainer" x-show="!loading">
@include('users._table')
</div>
</div>
</div>
</div>
</div>
</x-app-layout>