Files
gobeyhan/views/admin/user/list.templ
Beyhan Oğur f34e54c5a5 first commit
2026-04-26 21:43:40 +03:00

72 lines
3.3 KiB
Plaintext

package user
import (
"gobeyhan/database/models"
"gobeyhan/views/admin"
"fmt"
)
templ List(users []models.User) {
@admin.Layout("User Management") {
<div class="px-4 py-6 sm:px-0">
<div class="flex justify-between items-center mb-6">
<h1 class="text-2xl font-semibold text-gray-900">Users</h1>
<a href="/admin/users/new" class="bg-indigo-600 text-white px-4 py-2 rounded-md hover:bg-indigo-700">Add User</a>
</div>
<div class="bg-white shadow overflow-hidden sm:rounded-lg">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Email</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Role</th>
<th scope="col" class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
for _, user := range users {
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{ fmt.Sprintf("%d", user.ID) }</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{ user.UserName }</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{ user.Email }</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
if len(user.Roles) > 0 {
{ user.Roles[0].Name }
} else {
<span class="text-gray-400">-</span>
}
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<a href={ templ.SafeURL(fmt.Sprintf("/admin/users/%d/edit", user.ID)) } class="text-indigo-600 hover:text-indigo-900 mr-4">Edit</a>
<form id={ fmt.Sprintf("delete-form-%d", user.ID) } action={ templ.SafeURL(fmt.Sprintf("/admin/users/%d/delete", user.ID)) } method="POST" class="inline">
<button type="button" class="text-red-600 hover:text-red-900" onclick={ templ.ComponentScript{ Call: fmt.Sprintf("confirmDelete(%d)", user.ID) } }>Delete</button>
</form>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
<script>
function confirmDelete(id) {
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.isConfirmed) {
document.getElementById('delete-form-' + id).submit();
}
})
}
</script>
}
}