Implantação da geração de mensagem de forma livre e mudança na engine de mensagem
This commit is contained in:
52
app/views/admin/contatos/_form.html.erb
Normal file
52
app/views/admin/contatos/_form.html.erb
Normal file
@@ -0,0 +1,52 @@
|
||||
<%= form_with model: [:admin, contato], data: { turbo: false }, class: 'space-y-5' do |f| %>
|
||||
<% if contato.errors.any? %>
|
||||
<div class="bg-red-500/10 border border-red-500/30 rounded-xl px-4 py-3 text-red-300 text-sm">
|
||||
<ul class="list-disc list-inside space-y-1">
|
||||
<% contato.errors.full_messages.each do |msg| %><li><%= msg %></li><% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div>
|
||||
<%= f.label :nome, class: 'block text-gray-400 text-sm mb-1' %>
|
||||
<%= f.text_field :nome, required: true,
|
||||
class: 'w-full bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5 focus:outline-none focus:border-orange-500' %>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<%= f.label :telefone, 'WhatsApp', class: 'block text-gray-400 text-sm mb-1' %>
|
||||
<%= f.text_field :telefone, placeholder: '(11) 92005-1157',
|
||||
class: 'w-full bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5 focus:outline-none focus:border-orange-500' %>
|
||||
<p class="text-xs text-gray-500 mt-1">Pode digitar com máscara — é normalizado ao salvar.</p>
|
||||
</div>
|
||||
<div>
|
||||
<%= f.label :email, 'E-mail', class: 'block text-gray-400 text-sm mb-1' %>
|
||||
<%= f.email_field :email,
|
||||
class: 'w-full bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5 focus:outline-none focus:border-orange-500' %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :grupo_contato_id, 'Grupo', class: 'block text-gray-400 text-sm mb-1' %>
|
||||
<%= f.collection_select :grupo_contato_id, @grupos, :id, :nome, { include_blank: 'Sem grupo (não recebe nada)' },
|
||||
class: 'w-full bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5 focus:outline-none focus:border-orange-500' %>
|
||||
<p class="text-xs text-gray-500 mt-1">É o grupo que define quais eventos este contato recebe.</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :observacao, 'Observação', class: 'block text-gray-400 text-sm mb-1' %>
|
||||
<%= f.text_field :observacao,
|
||||
class: 'w-full bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5 focus:outline-none focus:border-orange-500' %>
|
||||
</div>
|
||||
|
||||
<label class="flex items-center gap-2 text-sm text-gray-300">
|
||||
<%= f.check_box :ativo, class: 'rounded border-white/20 bg-[#1a1a1a] text-orange-500' %>
|
||||
Ativo
|
||||
</label>
|
||||
|
||||
<div class="flex items-center gap-3">
|
||||
<%= f.submit 'Salvar', class: 'px-4 py-2.5 rounded-xl text-sm font-semibold bg-orange-500 text-black hover:bg-orange-400 cursor-pointer' %>
|
||||
<%= link_to 'Cancelar', admin_contatos_path, data: { turbo: false }, class: 'text-gray-400 hover:text-white text-sm' %>
|
||||
</div>
|
||||
<% end %>
|
||||
4
app/views/admin/contatos/edit.html.erb
Normal file
4
app/views/admin/contatos/edit.html.erb
Normal file
@@ -0,0 +1,4 @@
|
||||
<div class="max-w-xl space-y-6">
|
||||
<h1 class="text-2xl font-bold text-white">Editar contato</h1>
|
||||
<%= render "form", contato: @contato %>
|
||||
</div>
|
||||
74
app/views/admin/contatos/index.html.erb
Normal file
74
app/views/admin/contatos/index.html.erb
Normal file
@@ -0,0 +1,74 @@
|
||||
<div class="space-y-6">
|
||||
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-white">Contatos</h1>
|
||||
<p class="text-gray-400 text-sm mt-0.5">
|
||||
Quem recebe as mensagens. Quem tem só número recebe só WhatsApp; quem tem só
|
||||
e-mail recebe só e-mail.
|
||||
</p>
|
||||
</div>
|
||||
<%= link_to 'Novo contato', new_admin_contato_path(grupo_id: params[:grupo_id]), data: { turbo: false },
|
||||
class: 'px-4 py-2.5 rounded-xl text-sm font-semibold bg-orange-500 text-black hover:bg-orange-400' %>
|
||||
</div>
|
||||
|
||||
<form method="get" action="<%= admin_contatos_path %>" data-turbo="false" class="flex flex-wrap items-center gap-2">
|
||||
<input type="text" name="q" value="<%= params[:q] %>" placeholder="Buscar por nome, número ou e-mail"
|
||||
class="bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5 focus:outline-none focus:border-orange-500 min-w-[260px]">
|
||||
<select name="grupo_id" class="bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5 focus:outline-none focus:border-orange-500">
|
||||
<option value="">Todos os grupos</option>
|
||||
<% @grupos.each do |grupo| %>
|
||||
<option value="<%= grupo.id %>" <%= 'selected' if params[:grupo_id].to_s == grupo.id.to_s %>><%= grupo.nome %></option>
|
||||
<% end %>
|
||||
</select>
|
||||
<button type="submit" class="px-4 py-2.5 rounded-xl text-sm bg-[#1a1a1a] text-gray-300 border border-white/10 hover:border-orange-500">Filtrar</button>
|
||||
</form>
|
||||
|
||||
<div class="bg-[#1a1a1a] rounded-2xl border border-white/5 overflow-hidden">
|
||||
<% if @contatos.empty? %>
|
||||
<p class="px-6 py-10 text-center text-gray-500 text-sm">Nenhum contato encontrado.</p>
|
||||
<% else %>
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full text-sm">
|
||||
<thead class="bg-white/5 text-gray-400 text-xs uppercase tracking-wider">
|
||||
<tr>
|
||||
<th class="text-left px-6 py-3 font-medium">Nome</th>
|
||||
<th class="text-left px-4 py-3 font-medium">WhatsApp</th>
|
||||
<th class="text-left px-4 py-3 font-medium">E-mail</th>
|
||||
<th class="text-left px-4 py-3 font-medium">Grupo</th>
|
||||
<th class="text-left px-4 py-3 font-medium">Situação</th>
|
||||
<th class="px-4 py-3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-white/5">
|
||||
<% @contatos.each do |contato| %>
|
||||
<tr class="hover:bg-white/5">
|
||||
<td class="px-6 py-2.5 text-white"><%= contato.nome %></td>
|
||||
<td class="px-4 py-2.5 text-gray-300 font-mono"><%= contato.telefone.presence || '—' %></td>
|
||||
<td class="px-4 py-2.5 text-gray-300"><%= contato.email.presence || '—' %></td>
|
||||
<td class="px-4 py-2.5">
|
||||
<% if contato.grupo_contato %>
|
||||
<span class="text-gray-300"><%= contato.grupo_contato.nome %></span>
|
||||
<% else %>
|
||||
<span class="text-amber-400" title="Sem grupo não recebe nada">sem grupo</span>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="px-4 py-2.5">
|
||||
<span class="<%= contato.ativo? ? 'text-green-400' : 'text-gray-500' %>">
|
||||
<%= contato.ativo? ? 'Ativo' : 'Inativo' %>
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-4 py-2.5 text-right whitespace-nowrap">
|
||||
<%= link_to 'Editar', edit_admin_contato_path(contato), data: { turbo: false },
|
||||
class: 'text-gray-300 hover:text-orange-400 mr-3' %>
|
||||
<%= button_to 'Excluir', admin_contato_path(contato), method: :delete,
|
||||
form: { data: { turbo_confirm: "Excluir #{contato.nome}?" } },
|
||||
class: 'text-red-400 hover:text-red-300 inline' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
4
app/views/admin/contatos/new.html.erb
Normal file
4
app/views/admin/contatos/new.html.erb
Normal file
@@ -0,0 +1,4 @@
|
||||
<div class="max-w-xl space-y-6">
|
||||
<h1 class="text-2xl font-bold text-white">Novo contato</h1>
|
||||
<%= render "form", contato: @contato %>
|
||||
</div>
|
||||
Reference in New Issue
Block a user