Correções de integração Fases 2/3 ↔ 4-8 + Auditoria UI + README final
This commit is contained in:
153
app/views/admin/usuarios/_form.html.erb
Normal file
153
app/views/admin/usuarios/_form.html.erb
Normal file
@@ -0,0 +1,153 @@
|
||||
<%# app/views/usuarios/_form.html.erb %>
|
||||
<div class="max-w-2xl mx-auto space-y-6">
|
||||
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-white">
|
||||
<%= usuario.new_record? ? 'Novo Usuário' : "Editar: #{usuario.nome}" %>
|
||||
</h1>
|
||||
<p class="text-gray-400 text-sm mt-0.5">
|
||||
<%= usuario.new_record? ? 'Preencha os dados para criar um novo acesso' : 'Atualize as informações do usuário' %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<%= render 'shared/flash' %>
|
||||
|
||||
<%= form_with(model: usuario, url: usuario.new_record? ? admin_usuarios_path : admin_usuario_path(usuario),
|
||||
method: usuario.new_record? ? :post : :patch,
|
||||
class: 'bg-[#1a1a1a] rounded-2xl border border-white/5 p-8 space-y-6') do |f| %>
|
||||
|
||||
<% if usuario.errors.any? %>
|
||||
<div class="p-4 bg-red-900/30 border border-red-500/40 rounded-xl">
|
||||
<p class="text-red-400 text-sm font-medium mb-2">
|
||||
<%= pluralize(usuario.errors.count, 'erro', 'erros') %> encontrado<%= usuario.errors.count > 1 ? 's' : '' %>:
|
||||
</p>
|
||||
<ul class="list-disc list-inside space-y-1">
|
||||
<% usuario.errors.full_messages.each do |msg| %>
|
||||
<li class="text-red-300 text-sm"><%= msg %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-6">
|
||||
<%# Nome %>
|
||||
<div class="sm:col-span-2">
|
||||
<%= f.label :nome, 'Nome completo', class: 'block text-sm font-medium text-gray-300 mb-1.5' %>
|
||||
<%= f.text_field :nome,
|
||||
class: 'w-full px-4 py-3 bg-[#0a0a0a] border border-white/10 rounded-xl text-white
|
||||
placeholder-gray-600 focus:outline-none focus:border-[#f97316] focus:ring-1
|
||||
focus:ring-[#f97316] transition-colors',
|
||||
placeholder: 'João da Silva' %>
|
||||
</div>
|
||||
|
||||
<%# Perfil %>
|
||||
<div>
|
||||
<%= f.label :role, 'Perfil de acesso', class: 'block text-sm font-medium text-gray-300 mb-1.5' %>
|
||||
<%= f.select :role,
|
||||
options_for_select(role_options_for_select, usuario.role),
|
||||
{},
|
||||
class: 'w-full px-4 py-3 bg-[#0a0a0a] border border-white/10 rounded-xl text-white
|
||||
focus:outline-none focus:border-[#f97316] focus:ring-1 focus:ring-[#f97316]
|
||||
transition-colors cursor-pointer' %>
|
||||
</div>
|
||||
|
||||
<%# Ativo toggle %>
|
||||
<div class="flex items-center">
|
||||
<div class="flex-1">
|
||||
<%= f.label :ativo, 'Usuário ativo', class: 'block text-sm font-medium text-gray-300' %>
|
||||
<p class="text-gray-500 text-xs mt-0.5">Usuários inativos não conseguem fazer login</p>
|
||||
</div>
|
||||
<label class="relative inline-flex items-center cursor-pointer ml-4">
|
||||
<%= f.check_box :ativo, class: 'sr-only peer' %>
|
||||
<div class="w-11 h-6 bg-gray-700 peer-focus:outline-none rounded-full peer
|
||||
peer-checked:after:translate-x-full peer-checked:after:border-white
|
||||
after:content-[''] after:absolute after:top-[2px] after:left-[2px]
|
||||
after:bg-white after:border-gray-300 after:border after:rounded-full
|
||||
after:h-5 after:w-5 after:transition-all peer-checked:bg-[#f97316]"></div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%# E-mail e senha (não motorista) %>
|
||||
<div id="fields-email" class="space-y-6">
|
||||
<div class="border-t border-white/5 pt-6">
|
||||
<p class="text-sm font-medium text-gray-300 mb-4">Credenciais de acesso</p>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-6">
|
||||
<div class="sm:col-span-2">
|
||||
<%= f.label :email, 'E-mail', class: 'block text-sm font-medium text-gray-300 mb-1.5' %>
|
||||
<%= f.email_field :email,
|
||||
class: 'w-full px-4 py-3 bg-[#0a0a0a] border border-white/10 rounded-xl text-white
|
||||
placeholder-gray-600 focus:outline-none focus:border-[#f97316] focus:ring-1
|
||||
focus:ring-[#f97316] transition-colors',
|
||||
placeholder: 'usuario@gade.com' %>
|
||||
</div>
|
||||
<div>
|
||||
<%= f.label :password,
|
||||
usuario.new_record? ? 'Senha' : 'Nova senha (deixe em branco para manter)',
|
||||
class: 'block text-sm font-medium text-gray-300 mb-1.5' %>
|
||||
<%= f.password_field :password,
|
||||
class: 'w-full px-4 py-3 bg-[#0a0a0a] border border-white/10 rounded-xl text-white
|
||||
placeholder-gray-600 focus:outline-none focus:border-[#f97316] focus:ring-1
|
||||
focus:ring-[#f97316] transition-colors',
|
||||
placeholder: '••••••••' %>
|
||||
</div>
|
||||
<div>
|
||||
<%= f.label :password_confirmation, 'Confirmar senha',
|
||||
class: 'block text-sm font-medium text-gray-300 mb-1.5' %>
|
||||
<%= f.password_field :password_confirmation,
|
||||
class: 'w-full px-4 py-3 bg-[#0a0a0a] border border-white/10 rounded-xl text-white
|
||||
placeholder-gray-600 focus:outline-none focus:border-[#f97316] focus:ring-1
|
||||
focus:ring-[#f97316] transition-colors',
|
||||
placeholder: '••••••••' %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%# PIN (motorista) %>
|
||||
<div id="fields-pin" class="hidden border-t border-white/5 pt-6">
|
||||
<p class="text-sm font-medium text-gray-300 mb-4">PIN de acesso</p>
|
||||
<div class="max-w-xs">
|
||||
<%= f.label :pin_code, 'PIN (4 dígitos)', class: 'block text-sm font-medium text-gray-300 mb-1.5' %>
|
||||
<%= f.text_field :pin_code,
|
||||
maxlength: 4,
|
||||
pattern: '\d{4}',
|
||||
inputmode: 'numeric',
|
||||
class: 'w-full px-4 py-3 bg-[#0a0a0a] border border-white/10 rounded-xl text-white
|
||||
placeholder-gray-600 focus:outline-none focus:border-[#f97316] focus:ring-1
|
||||
focus:ring-[#f97316] transition-colors text-center text-2xl tracking-[0.5em] font-bold',
|
||||
placeholder: '0000' %>
|
||||
<p class="text-gray-500 text-xs mt-1.5">Deve ser único entre todos os motoristas</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%# Botões %>
|
||||
<div class="flex items-center justify-between pt-2 border-t border-white/5">
|
||||
<%= link_to 'Cancelar', admin_usuarios_path,
|
||||
class: 'px-6 py-3 text-gray-400 hover:text-white border border-white/10
|
||||
hover:border-white/20 rounded-xl transition-colors' %>
|
||||
<%= f.submit usuario.new_record? ? 'Criar Usuário' : 'Salvar Alterações',
|
||||
class: 'px-8 py-3 bg-[#f97316] hover:bg-orange-500 text-white font-semibold
|
||||
rounded-xl transition-colors cursor-pointer min-h-[48px]' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const roleSelect = document.querySelector('select[name="user[role]"]');
|
||||
const fieldsEmail = document.getElementById('fields-email');
|
||||
const fieldsPin = document.getElementById('fields-pin');
|
||||
|
||||
function toggleFields() {
|
||||
if (roleSelect.value === 'motorista') {
|
||||
fieldsEmail.classList.add('hidden');
|
||||
fieldsPin.classList.remove('hidden');
|
||||
} else {
|
||||
fieldsEmail.classList.remove('hidden');
|
||||
fieldsPin.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
roleSelect.addEventListener('change', toggleFields);
|
||||
toggleFields(); // run on load
|
||||
</script>
|
||||
2
app/views/admin/usuarios/edit.html.erb
Normal file
2
app/views/admin/usuarios/edit.html.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
<%# app/views/usuarios/edit.html.erb %>
|
||||
<%= render 'form', usuario: @usuario %>
|
||||
120
app/views/admin/usuarios/index.html.erb
Normal file
120
app/views/admin/usuarios/index.html.erb
Normal file
@@ -0,0 +1,120 @@
|
||||
<%# app/views/usuarios/index.html.erb %>
|
||||
<div class="space-y-6">
|
||||
|
||||
<%# Header %>
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-white">Usuários</h1>
|
||||
<p class="text-gray-400 text-sm mt-0.5">Gerencie o acesso ao sistema</p>
|
||||
</div>
|
||||
<% if policy(User).create? %>
|
||||
<%= link_to new_admin_usuario_path,
|
||||
class: 'flex items-center gap-2 px-5 py-3 bg-[#f97316] hover:bg-orange-500
|
||||
text-white font-semibold rounded-xl transition-colors min-h-[48px]' do %>
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
|
||||
</svg>
|
||||
Novo Usuário
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%# Flash %>
|
||||
<%= render 'shared/flash' %>
|
||||
|
||||
<%# Tabela %>
|
||||
<div class="bg-[#1a1a1a] rounded-2xl border border-white/5 overflow-hidden">
|
||||
<table class="w-full">
|
||||
<thead>
|
||||
<tr class="border-b border-white/10">
|
||||
<th class="px-6 py-4 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider">Nome</th>
|
||||
<th class="px-6 py-4 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider">E-mail / PIN</th>
|
||||
<th class="px-6 py-4 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider">Perfil</th>
|
||||
<th class="px-6 py-4 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider">Status</th>
|
||||
<th class="px-6 py-4 text-right text-xs font-semibold text-gray-400 uppercase tracking-wider">Ações</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-white/5">
|
||||
<% @usuarios.each do |usuario| %>
|
||||
<tr class="hover:bg-white/5 transition-colors group">
|
||||
<td class="px-6 py-4">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-9 h-9 rounded-full bg-[#f97316]/20 border border-[#f97316]/30
|
||||
flex items-center justify-center text-[#f97316] font-bold text-sm flex-shrink-0">
|
||||
<%= usuario.nome.to_s[0].upcase %>
|
||||
</div>
|
||||
<span class="text-white font-medium"><%= usuario.nome %></span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<% if usuario.motorista? && usuario.pin_code.present? %>
|
||||
<div class="text-gray-300 text-sm">PIN: ••••</div>
|
||||
<% else %>
|
||||
<div class="text-gray-300 text-sm"><%= usuario.email %></div>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<%= badge_role(usuario.role) %>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<%= badge_status_usuario(usuario.ativo?) %>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<div class="flex items-center justify-end gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<% if policy(usuario).edit? %>
|
||||
<%= link_to edit_admin_usuario_path(usuario),
|
||||
class: 'p-2 text-gray-400 hover:text-white hover:bg-white/10 rounded-lg transition-colors',
|
||||
title: 'Editar' do %>
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/>
|
||||
</svg>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if policy(usuario).toggle_ativo? %>
|
||||
<%= button_to toggle_ativo_usuario_path(usuario), method: :post,
|
||||
class: "p-2 rounded-lg transition-colors #{usuario.ativo? ? 'text-green-400 hover:bg-green-900/30' : 'text-red-400 hover:bg-red-900/30'}",
|
||||
title: usuario.ativo? ? 'Desativar' : 'Ativar',
|
||||
data: { confirm: "#{usuario.ativo? ? 'Desativar' : 'Ativar'} #{usuario.nome}?" } do %>
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"/>
|
||||
</svg>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if policy(usuario).destroy? %>
|
||||
<%= button_to admin_usuario_path(usuario), method: :delete,
|
||||
class: 'p-2 text-gray-600 hover:text-red-400 hover:bg-red-900/20 rounded-lg transition-colors',
|
||||
title: 'Excluir',
|
||||
data: { confirm: "Excluir #{usuario.nome} permanentemente?" } do %>
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
|
||||
</svg>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
<% if @usuarios.empty? %>
|
||||
<tr>
|
||||
<td colspan="5" class="px-6 py-16 text-center text-gray-500">
|
||||
<div class="text-4xl mb-3">👥</div>
|
||||
<p>Nenhum usuário encontrado.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<% if @usuarios.respond_to?(:total_pages) && @usuarios.total_pages > 1 %>
|
||||
<div class="px-6 py-4 border-t border-white/10">
|
||||
<%= paginate @usuarios %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
2
app/views/admin/usuarios/new.html.erb
Normal file
2
app/views/admin/usuarios/new.html.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
<%# app/views/usuarios/new.html.erb %>
|
||||
<%= render 'form', usuario: @usuario %>
|
||||
Reference in New Issue
Block a user