package components import ( "context" "fmt" ) type Role struct { ID uint Name string Description string Permissions []string } type RolesData struct { Roles []Role Error string } templ AdminRoles(ctx context.Context, data RolesData) { @LayoutWithContext("Role Management", ctx) {

Role Management

New Role
if len(data.Roles) == 0 { } else { for _, role := range data.Roles { @RoleDialog( fmt.Sprintf("delete-role-dialog-%d", role.ID), "Delete Role", fmt.Sprintf("Are you sure you want to delete role \"%s\"? This action cannot be undone.", role.Name), "bg-red-600 hover:bg-red-700 dark:bg-red-600 dark:hover:bg-red-700", "Delete Role", "delete", role.ID, role.Name, ) } }
Role Name Description Permissions Actions
No roles found. Create your first role to get started.
{ role.Name } { role.Description }
for _, perm := range role.Permissions { { perm } }
if data.Error != "" { } } } // RoleDialog for confirmation actions templ RoleDialog(id string, title string, message string, confirmClass string, confirmText string, action string, roleID uint, roleName string) { } script hideRoleDialog(id string) { document.getElementById(id).classList.add("hidden"); document.getElementById(id).classList.remove("flex"); } script showRoleDialog(id string) { document.getElementById(id).classList.remove("hidden"); document.getElementById(id).classList.add("flex"); } script triggerRoleDelete(dialogId string, roleID uint, roleName string) { // Hide the dialog document.getElementById(dialogId).classList.add("hidden"); document.getElementById(dialogId).classList.remove("flex"); // Store data in a way that's accessible to event handlers window.lastDeletedRole = { id: roleID, name: roleName }; // Add custom marker to track this deletion window.isRoleDeletingRequest = true; }