Atualização para que possa mandar mesagens do Zap para grupos
This commit is contained in:
@@ -1,102 +1,172 @@
|
||||
<%= form_with model: [:admin, evento], url: (evento.persisted? ? admin_evento_path(evento) : admin_eventos_path),
|
||||
data: { turbo: false }, class: 'space-y-5' do |f| %>
|
||||
<%
|
||||
input = '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'
|
||||
menor = 'w-full px-3 py-2.5 bg-[#0a0a0a] border border-white/10 rounded-xl text-white text-sm
|
||||
focus:outline-none focus:border-[#f97316] focus:ring-1 focus:ring-[#f97316] transition-colors'
|
||||
rotulo = 'block text-sm font-medium text-gray-300 mb-1.5'
|
||||
secao = 'text-sm font-medium text-gray-300 mb-4'
|
||||
toggle = "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]"
|
||||
%>
|
||||
<%= form_with model: [:admin, evento],
|
||||
url: (evento.persisted? ? admin_evento_path(evento) : admin_eventos_path),
|
||||
data: { turbo: false },
|
||||
class: 'bg-[#1a1a1a] rounded-2xl border border-white/5 p-8 space-y-6' do |f| %>
|
||||
|
||||
<% if evento.errors.any? %>
|
||||
<div class="bg-red-500/10 border border-red-500/30 rounded-xl px-4 py-3 text-red-300 text-sm">
|
||||
<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(evento.errors.count, 'erro', 'erros') %> encontrado<%= evento.errors.count > 1 ? 's' : '' %>:
|
||||
</p>
|
||||
<ul class="list-disc list-inside space-y-1">
|
||||
<% evento.errors.full_messages.each do |msg| %><li><%= msg %></li><% end %>
|
||||
<% evento.errors.full_messages.each do |msg| %>
|
||||
<li class="text-red-300 text-sm"><%= 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, placeholder: 'Aviso de fechamento para a diretoria',
|
||||
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 class="grid grid-cols-1 sm:grid-cols-2 gap-6">
|
||||
<div class="sm:col-span-2">
|
||||
<%= f.label :nome, class: rotulo %>
|
||||
<%= f.text_field :nome, required: true,
|
||||
placeholder: 'Aviso de fechamento para a diretoria', class: input %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :gatilho, 'Gatilho (o que faz disparar)', class: rotulo %>
|
||||
<% if evento.sistema? %>
|
||||
<p class="w-full px-4 py-3 bg-[#0a0a0a] border border-white/10 rounded-xl text-white
|
||||
flex items-center gap-2">
|
||||
<%= icone :travado, cor: 'text-gray-500', tamanho: 'w-4 h-4', espaco: false %>
|
||||
<%= evento.gatilho_label %>
|
||||
</p>
|
||||
<p class="text-gray-500 text-xs mt-1.5">
|
||||
Evento de sistema: o gatilho e a chave são fixos porque o código dispara por eles.
|
||||
</p>
|
||||
<% else %>
|
||||
<%= f.select :gatilho,
|
||||
EventoNotificacao::GATILHOS.map { |g| [EventoNotificacao::GATILHO_LABEL[g], g] }, {},
|
||||
class: "#{input} cursor-pointer" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :descricao, 'Descrição', class: rotulo %>
|
||||
<%= f.text_field :descricao, placeholder: 'Opcional', class: input %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :gatilho, 'Gatilho (o que faz disparar)', class: 'block text-gray-400 text-sm mb-1' %>
|
||||
<% if evento.sistema? %>
|
||||
<p class="text-white text-sm bg-[#141414] border border-white/10 rounded-xl px-3 py-2.5"><%= evento.gatilho_label %></p>
|
||||
<p class="text-xs text-gray-500 mt-1">Evento de sistema: o gatilho e a chave são fixos porque o código dispara por eles.</p>
|
||||
<% else %>
|
||||
<%= f.select :gatilho, EventoNotificacao::GATILHOS.map { |g| [EventoNotificacao::GATILHO_LABEL[g], g] }, {},
|
||||
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' %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :descricao, 'Descrição', class: 'block text-gray-400 text-sm mb-1' %>
|
||||
<%= f.text_field :descricao,
|
||||
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>
|
||||
|
||||
<%# Só faz sentido no gatilho `agendado`; deixo sempre visível para não
|
||||
depender de JS, com a explicação de quando vale. %>
|
||||
<fieldset class="border border-white/10 rounded-xl p-4 space-y-3">
|
||||
<legend class="text-gray-400 text-sm px-2">Agendamento (só vale no gatilho "Agendado")</legend>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-3 gap-3">
|
||||
<%# Agendamento — só faz sentido no gatilho `agendado`; deixo sempre visível
|
||||
para não depender de JS, com a explicação de quando vale. %>
|
||||
<div class="border-t border-white/5 pt-6">
|
||||
<p class="<%= secao %>">
|
||||
Agendamento
|
||||
<span class="text-gray-500 font-normal">— só vale no gatilho "Agendado"</span>
|
||||
</p>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<%= f.label :frequencia, 'Frequência', class: 'block text-gray-500 text-xs mb-1' %>
|
||||
<%= f.select :frequencia, EventoNotificacao::FREQUENCIAS.map { |x| [x.capitalize, x] }, { include_blank: '—' },
|
||||
class: 'w-full bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5' %>
|
||||
<%= f.label :frequencia, 'Frequência', class: rotulo %>
|
||||
<%= f.select :frequencia, EventoNotificacao::FREQUENCIAS.map { |x| [x.capitalize, x] },
|
||||
{ include_blank: '—' }, class: "#{menor} cursor-pointer" %>
|
||||
</div>
|
||||
<div>
|
||||
<%= f.label :hora, 'Hora', class: 'block text-gray-500 text-xs mb-1' %>
|
||||
<%= f.number_field :hora, min: 0, max: 23,
|
||||
class: 'w-full bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5' %>
|
||||
<%= f.label :hora, 'Hora', class: rotulo %>
|
||||
<%= f.number_field :hora, min: 0, max: 23, class: menor %>
|
||||
</div>
|
||||
<div>
|
||||
<%= f.label :dia_semana, 'Dia (semanal)', class: 'block text-gray-500 text-xs mb-1' %>
|
||||
<%= f.select :dia_semana, Date::DAYNAMES.each_with_index.map { |nome, i| [nome, i] }, { include_blank: '—' },
|
||||
class: 'w-full bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5' %>
|
||||
<%= f.label :dia_semana, 'Dia (semanal)', class: rotulo %>
|
||||
<%= f.select :dia_semana, Date::DAYNAMES.each_with_index.map { |nome, i| [nome, i] },
|
||||
{ include_blank: '—' }, class: "#{menor} cursor-pointer" %>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<label class="flex items-start gap-2 text-sm text-gray-300">
|
||||
<%= f.check_box :notificar_envolvido, class: 'mt-1 rounded border-white/20 bg-[#1a1a1a] text-orange-500' %>
|
||||
<span>
|
||||
Avisar também a pessoa envolvida no fato
|
||||
<span class="block text-xs text-gray-500">Ex.: o motorista dono do pagamento, além dos grupos. Só se aplica aos gatilhos de consolidação/pagamento/valor.</span>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<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>
|
||||
|
||||
<%# Assinatura por grupo: TODOS os grupos ativos aparecem, marcados os que já
|
||||
assinam. Sem isso a tela só mostraria os já configurados e não haveria por
|
||||
onde adicionar. %>
|
||||
<fieldset class="border border-white/10 rounded-xl p-4 space-y-3">
|
||||
<legend class="text-gray-400 text-sm px-2">Quais grupos recebem</legend>
|
||||
<div class="border-t border-white/5 pt-6">
|
||||
<p class="<%= secao %>">Quais grupos recebem</p>
|
||||
|
||||
<% if @linhas_assinatura.blank? %>
|
||||
<p class="text-sm text-gray-500">
|
||||
Nenhum grupo cadastrado ainda —
|
||||
<%= link_to 'crie um grupo', new_admin_grupo_path, data: { turbo: false }, class: 'text-orange-400 underline' %>
|
||||
antes.
|
||||
</p>
|
||||
<% end %>
|
||||
<% Array(@linhas_assinatura).each do |linha| %>
|
||||
<% grupo = linha[:grupo]; assinatura = linha[:assinatura] %>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<label class="flex items-center gap-2 text-sm text-gray-300 min-w-[200px]">
|
||||
<%= check_box_tag "assinaturas[#{grupo.id}][ativo]", '1', assinatura&.ativo,
|
||||
class: 'rounded border-white/20 bg-[#1a1a1a] text-orange-500' %>
|
||||
<%= grupo.nome %>
|
||||
<span class="text-xs text-gray-500">(<%= grupo.contatos.size %>)</span>
|
||||
</label>
|
||||
<%= select_tag "assinaturas[#{grupo.id}][canal]",
|
||||
options_for_select(GrupoEventoAssinatura::CANAIS.map { |c| [GrupoEventoAssinatura::CANAL_LABEL[c], c] }, assinatura&.canal || 'ambos'),
|
||||
class: 'bg-[#141414] border border-white/10 rounded-xl text-white text-sm px-3 py-2' %>
|
||||
<div class="px-4 py-8 text-center bg-[#0a0a0a] border border-white/5 rounded-xl">
|
||||
<div class="mb-2"><%= icone :vazio, tamanho: 'w-8 h-8', cor: 'text-gray-600', espaco: false %></div>
|
||||
<p class="text-sm text-gray-500">
|
||||
Nenhum grupo cadastrado ainda —
|
||||
<%= link_to 'crie um grupo', new_admin_grupo_path, data: { turbo: false },
|
||||
class: 'text-[#f97316] hover:text-orange-400 underline' %>
|
||||
antes.
|
||||
</p>
|
||||
</div>
|
||||
<% else %>
|
||||
<div class="space-y-2">
|
||||
<% Array(@linhas_assinatura).each do |linha| %>
|
||||
<% grupo = linha[:grupo]; assinatura = linha[:assinatura] %>
|
||||
<div class="flex flex-wrap items-center gap-3 px-4 py-3 bg-[#0a0a0a] border border-white/5
|
||||
rounded-xl hover:border-white/10 transition-colors">
|
||||
<label class="flex items-center gap-3 text-sm text-gray-300 flex-1 min-w-[200px] cursor-pointer">
|
||||
<%= check_box_tag "assinaturas[#{grupo.id}][ativo]", '1', assinatura&.ativo,
|
||||
class: 'w-4 h-4 rounded border-white/20 bg-[#1a1a1a] text-[#f97316]
|
||||
focus:ring-[#f97316] focus:ring-offset-0 cursor-pointer' %>
|
||||
<span class="text-white font-medium"><%= grupo.nome %></span>
|
||||
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-xs
|
||||
bg-white/5 border border-white/10 text-gray-400">
|
||||
<%= grupo.contatos.size %> contato(s)
|
||||
</span>
|
||||
</label>
|
||||
<%= select_tag "assinaturas[#{grupo.id}][canal]",
|
||||
options_for_select(
|
||||
GrupoEventoAssinatura::CANAIS.map { |c| [GrupoEventoAssinatura::CANAL_LABEL[c], c] },
|
||||
assinatura&.canal || 'ambos'
|
||||
),
|
||||
class: 'px-3 py-2 bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm
|
||||
focus:outline-none focus:border-[#f97316] focus:ring-1 focus:ring-[#f97316]
|
||||
transition-colors cursor-pointer' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<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_eventos_path, data: { turbo: false }, class: 'text-gray-400 hover:text-white text-sm' %>
|
||||
<%# Opções %>
|
||||
<div class="border-t border-white/5 pt-6 space-y-5">
|
||||
<div class="flex items-start">
|
||||
<div class="flex-1">
|
||||
<%= f.label :notificar_envolvido, 'Avisar também a pessoa envolvida no fato',
|
||||
class: 'block text-sm font-medium text-gray-300' %>
|
||||
<p class="text-gray-500 text-xs mt-0.5 max-w-lg">
|
||||
Ex.: o motorista dono do pagamento, além dos grupos. Só se aplica aos gatilhos de
|
||||
consolidação/pagamento/valor.
|
||||
</p>
|
||||
</div>
|
||||
<label class="relative inline-flex items-center cursor-pointer ml-4 mt-0.5">
|
||||
<%= f.check_box :notificar_envolvido, class: 'sr-only peer' %>
|
||||
<div class="<%= toggle %>"></div>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center">
|
||||
<div class="flex-1">
|
||||
<%= f.label :ativo, 'Evento ativo', class: 'block text-sm font-medium text-gray-300' %>
|
||||
<p class="text-gray-500 text-xs mt-0.5">Evento inativo não dispara nada</p>
|
||||
</div>
|
||||
<label class="relative inline-flex items-center cursor-pointer ml-4">
|
||||
<%= f.check_box :ativo, class: 'sr-only peer' %>
|
||||
<div class="<%= toggle %>"></div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between pt-2 border-t border-white/5">
|
||||
<%= link_to 'Cancelar', admin_eventos_path, data: { turbo: false },
|
||||
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 evento.new_record? ? 'Criar Evento' : '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 %>
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
<div class="max-w-2xl space-y-6">
|
||||
<h1 class="text-2xl font-bold text-white">Editar evento</h1>
|
||||
<%= render "form", evento: @evento %>
|
||||
<div class="max-w-3xl mx-auto space-y-6">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-white">Editar: <%= @evento.nome %></h1>
|
||||
<p class="text-gray-400 text-sm mt-0.5">Atualize o gatilho, o agendamento e os grupos assinantes</p>
|
||||
</div>
|
||||
<%= render 'shared/flash' %>
|
||||
<%= render 'form', evento: @evento %>
|
||||
</div>
|
||||
|
||||
@@ -1,90 +1,157 @@
|
||||
<%
|
||||
input = '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-sm'
|
||||
pill = 'inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-bold'
|
||||
%>
|
||||
<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">Eventos de notificação</h1>
|
||||
<h1 class="text-2xl font-bold text-white flex items-center gap-2">
|
||||
<%= icone :diario, espaco: false %> Eventos de notificação
|
||||
</h1>
|
||||
<p class="text-gray-400 text-sm mt-0.5">
|
||||
O que dispara mensagem e para quais grupos. Você cria quantos eventos quiser —
|
||||
o <strong class="text-gray-300">gatilho</strong> sai de uma lista fixa, porque gatilho é código.
|
||||
</p>
|
||||
</div>
|
||||
<%= link_to 'Novo evento', new_admin_evento_path, data: { turbo: false },
|
||||
class: 'px-4 py-2.5 rounded-xl text-sm font-semibold bg-orange-500 text-black hover:bg-orange-400' %>
|
||||
<%= link_to new_admin_evento_path, data: { turbo: false },
|
||||
class: 'inline-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] whitespace-nowrap' do %>
|
||||
<%= icone :adicionar, cor: nil, tamanho: 'w-5 h-5', espaco: false %> Novo evento
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3">
|
||||
<%= render 'shared/flash' %>
|
||||
|
||||
<div class="space-y-4">
|
||||
<% @eventos.each do |evento| %>
|
||||
<div class="bg-[#1a1a1a] rounded-2xl border border-white/5 p-5">
|
||||
<div class="flex flex-wrap items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<p class="text-white font-bold flex items-center gap-2 flex-wrap">
|
||||
<%= evento.nome %>
|
||||
<span class="px-2 py-0.5 rounded-full bg-white/5 border border-white/10 text-xs text-gray-400"><%= evento.gatilho_label %></span>
|
||||
<%# Evento desativado fica esmaecido: a lista mistura ativo e inativo e sem
|
||||
isso os dois pesam igual na varredura visual. %>
|
||||
<div class="bg-[#1a1a1a] rounded-2xl border border-white/5 p-6 <%= 'opacity-60' unless evento.ativo? %>">
|
||||
<div class="flex flex-wrap items-start justify-between gap-4">
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-center gap-2 flex-wrap">
|
||||
<h2 class="text-white font-bold text-lg"><%= evento.nome %></h2>
|
||||
<span class="<%= pill %> bg-white/5 border border-white/10 text-gray-400">
|
||||
<%= evento.gatilho_label %>
|
||||
</span>
|
||||
<% if evento.sistema? %>
|
||||
<span class="px-2 py-0.5 rounded-full bg-blue-500/15 border border-blue-500/30 text-xs text-blue-300" title="Nasce com o sistema: pode desativar, não apagar">sistema</span>
|
||||
<span class="<%= pill %> bg-blue-500/15 border border-blue-500/30 text-blue-300"
|
||||
title="Nasce com o sistema: pode desativar, não apagar">sistema</span>
|
||||
<% end %>
|
||||
<% unless evento.ativo? %>
|
||||
<span class="px-2 py-0.5 rounded-full bg-white/5 border border-white/10 text-xs text-gray-500">desativado</span>
|
||||
<span class="<%= pill %> bg-gray-700 text-gray-300">desativado</span>
|
||||
<% end %>
|
||||
</p>
|
||||
<p class="text-sm text-gray-400 mt-1"><%= evento.descricao.presence || '—' %></p>
|
||||
<p class="text-xs text-gray-500 mt-2">
|
||||
</div>
|
||||
|
||||
<p class="text-sm text-gray-400 mt-1.5"><%= evento.descricao.presence || '—' %></p>
|
||||
|
||||
<div class="mt-3 space-y-1.5">
|
||||
<% assinantes = evento.assinaturas.select(&:ativo) %>
|
||||
<% if assinantes.any? %>
|
||||
Grupos: <%= assinantes.map { |a| "#{a.grupo_contato.nome} (#{a.canal_label})" }.join(' · ') %>
|
||||
<div class="flex items-start gap-2 flex-wrap text-xs">
|
||||
<span class="text-gray-500 uppercase tracking-wider font-semibold py-1">Grupos</span>
|
||||
<% assinantes.each do |a| %>
|
||||
<span class="inline-flex items-center px-2.5 py-1 rounded-full bg-white/5 border border-white/10 text-gray-300">
|
||||
<%= a.grupo_contato.nome %>
|
||||
<span class="text-gray-500 ml-1">· <%= a.canal_label %></span>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<% else %>
|
||||
<span class="text-amber-400">Nenhum grupo assina — este evento não manda nada.</span>
|
||||
<p class="flex items-center gap-1.5 text-xs text-amber-400">
|
||||
<%= icone :alerta, cor: nil, tamanho: 'w-3.5 h-3.5', espaco: false %>
|
||||
Nenhum grupo assina — este evento não manda nada.
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<% if evento.agendado? %>
|
||||
· <%= evento.frequencia == 'semanal' ? "toda #{Date::DAYNAMES[evento.dia_semana.to_i]}" : 'todo dia' %> às <%= format('%02d:00', evento.hora.to_i) %>
|
||||
<p class="flex items-center gap-1.5 text-xs text-gray-500">
|
||||
<%= icone :relogio, cor: 'text-gray-500', tamanho: 'w-3.5 h-3.5', espaco: false %>
|
||||
<%= evento.frequencia == 'semanal' ? "Toda #{Date::DAYNAMES[evento.dia_semana.to_i]}" : 'Todo dia' %>
|
||||
às <%= format('%02d:00', evento.hora.to_i) %>
|
||||
</p>
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-3 whitespace-nowrap">
|
||||
<%# Editor de blocos, um por canal. O ✓ diz se já existe mensagem
|
||||
montada — sem ela o evento usa o texto padrão do sistema. %>
|
||||
<% %w[whatsapp email].each do |canal| %>
|
||||
<% montado = evento.template_utilizavel(canal).present? %>
|
||||
<%= link_to "#{montado ? '✓ ' : ''}#{canal == 'email' ? 'E-mail' : 'WhatsApp'}",
|
||||
template_admin_evento_path(evento, canal: canal), data: { turbo: false },
|
||||
title: montado ? 'Mensagem montada no editor' : 'Sem mensagem — usa o texto padrão',
|
||||
class: "text-sm #{montado ? 'text-green-400 hover:text-green-300' : 'text-gray-400 hover:text-orange-400'}" %>
|
||||
<% end %>
|
||||
<span class="text-gray-700">|</span>
|
||||
<%= link_to 'Editar', edit_admin_evento_path(evento), data: { turbo: false },
|
||||
class: 'text-gray-300 hover:text-orange-400 text-sm' %>
|
||||
<% if evento.apagavel? %>
|
||||
<%= button_to 'Excluir', admin_evento_path(evento), method: :delete,
|
||||
form: { data: { turbo_confirm: "Excluir o evento #{evento.nome}?" } },
|
||||
class: 'text-red-400 hover:text-red-300 text-sm inline' %>
|
||||
<% end %>
|
||||
|
||||
<%# Ações: editor de mensagem por canal + editar/excluir %>
|
||||
<div class="flex flex-col items-end gap-2 whitespace-nowrap">
|
||||
<div class="flex items-center gap-2">
|
||||
<%# O ✓ diz se já existe mensagem montada — sem ela o evento usa o
|
||||
texto padrão do sistema. %>
|
||||
<% %w[whatsapp email].each do |canal| %>
|
||||
<% montado = evento.template_utilizavel(canal).present? %>
|
||||
<%= link_to template_admin_evento_path(evento, canal: canal), data: { turbo: false },
|
||||
title: montado ? 'Mensagem montada no editor' : 'Sem mensagem — usa o texto padrão',
|
||||
class: "inline-flex items-center gap-1.5 px-3 py-2 rounded-xl text-sm border transition-colors #{
|
||||
montado ? 'bg-green-500/10 border-green-500/30 text-green-300 hover:border-green-500'
|
||||
: 'bg-[#0a0a0a] border-white/10 text-gray-400 hover:border-[#f97316] hover:text-white'}" do %>
|
||||
<%= icone(montado ? :sucesso : (canal == 'email' ? :email : :telefone),
|
||||
cor: nil, tamanho: 'w-4 h-4', espaco: false) %>
|
||||
<%= canal == 'email' ? 'E-mail' : 'WhatsApp' %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2">
|
||||
<%= link_to edit_admin_evento_path(evento), data: { turbo: false },
|
||||
class: 'p-2 text-gray-400 hover:text-white hover:bg-white/10 rounded-lg transition-colors',
|
||||
title: 'Editar' do %>
|
||||
<%= icone :editar, cor: nil, tamanho: 'w-4 h-4', espaco: false %>
|
||||
<% end %>
|
||||
<% if evento.apagavel? %>
|
||||
<%= button_to admin_evento_path(evento), method: :delete,
|
||||
class: 'p-2 text-gray-600 hover:text-red-400 hover:bg-red-900/20 rounded-lg transition-colors',
|
||||
title: 'Excluir',
|
||||
form: { data: { turbo_confirm: "Excluir o evento #{evento.nome}?" } } do %>
|
||||
<%= icone :excluir, cor: nil, tamanho: 'w-4 h-4', espaco: false %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%# Disparo manual: manda mensagem DE VERDADE. O texto é digitado aqui
|
||||
porque o editor de blocos ainda não existe. %>
|
||||
<%# Disparo manual: manda mensagem DE VERDADE. %>
|
||||
<% if evento.manual? && evento.ativo? %>
|
||||
<details class="mt-4 border-t border-white/5 pt-4">
|
||||
<summary class="cursor-pointer text-sm text-orange-400 hover:text-orange-300 select-none">Disparar agora</summary>
|
||||
<details class="mt-5 border-t border-white/5 pt-4 group/disparo">
|
||||
<summary class="cursor-pointer select-none inline-flex items-center gap-1.5 text-sm
|
||||
text-[#f97316] hover:text-orange-400 transition-colors">
|
||||
<%= icone :expandir, cor: nil, tamanho: 'w-4 h-4', espaco: false %> Disparar agora
|
||||
</summary>
|
||||
<% com_template = %w[whatsapp email].any? { |c| evento.template_utilizavel(c) } %>
|
||||
<%= form_with url: disparar_admin_evento_path(evento), method: :post,
|
||||
data: { turbo: false }, class: 'mt-3 space-y-3' do |f| %>
|
||||
data: { turbo: false }, class: 'mt-4 space-y-3' do |f| %>
|
||||
<% if com_template %>
|
||||
<p class="text-xs text-green-400">
|
||||
Este evento tem mensagem montada no editor — ela será usada nos canais configurados.
|
||||
O texto abaixo só vale para o canal que ainda não tem mensagem própria.
|
||||
<p class="flex items-start gap-2 text-xs text-green-300 bg-green-500/10
|
||||
border border-green-500/30 rounded-xl px-3 py-2.5">
|
||||
<%= icone :sucesso, cor: nil, tamanho: 'w-4 h-4', espaco: false, classe: 'mt-0.5' %>
|
||||
<span>
|
||||
Este evento tem mensagem montada no editor — ela será usada nos canais configurados.
|
||||
O texto abaixo só vale para o canal que ainda não tem mensagem própria.
|
||||
</span>
|
||||
</p>
|
||||
<% end %>
|
||||
<%= f.text_field :assunto, placeholder: 'Assunto (só e-mail)', value: evento.nome,
|
||||
class: 'w-full bg-[#141414] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5 focus:outline-none focus:border-orange-500' %>
|
||||
<%= f.text_area :corpo, rows: 4, required: !com_template, placeholder: com_template ? 'Opcional — só para o canal sem mensagem montada' : 'Mensagem que será enviada…',
|
||||
class: 'w-full bg-[#141414] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5 focus:outline-none focus:border-orange-500' %>
|
||||
<%= f.text_field :assunto, placeholder: 'Assunto (só e-mail)', value: evento.nome, class: input %>
|
||||
<%= f.text_area :corpo, rows: 4, required: !com_template, class: input,
|
||||
placeholder: com_template ? 'Opcional — só para o canal sem mensagem montada' : 'Mensagem que será enviada…' %>
|
||||
<%= f.submit 'Enviar para os grupos assinantes',
|
||||
data: { turbo_confirm: 'Isso envia mensagem de verdade para todos os contatos dos grupos assinantes. Confirmar?' },
|
||||
class: 'px-4 py-2.5 rounded-xl text-sm font-semibold bg-orange-500 text-black hover:bg-orange-400 cursor-pointer' %>
|
||||
data: { turbo_confirm: 'Isso envia mensagem de verdade para todos os contatos dos grupos assinantes. Confirmar?' },
|
||||
class: 'px-6 py-3 bg-[#f97316] hover:bg-orange-500 text-white font-semibold
|
||||
rounded-xl transition-colors cursor-pointer min-h-[48px]' %>
|
||||
<% end %>
|
||||
</details>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @eventos.empty? %>
|
||||
<div class="bg-[#1a1a1a] rounded-2xl border border-white/5 px-6 py-16 text-center text-gray-500">
|
||||
<div class="mb-3"><%= icone :vazio, tamanho: 'w-10 h-10', cor: 'text-gray-600', espaco: false %></div>
|
||||
<p>Nenhum evento cadastrado.</p>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
<div class="max-w-2xl space-y-6">
|
||||
<h1 class="text-2xl font-bold text-white">Novo evento</h1>
|
||||
<%= render "form", evento: @evento %>
|
||||
<div class="max-w-3xl mx-auto space-y-6">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-white">Novo evento</h1>
|
||||
<p class="text-gray-400 text-sm mt-0.5">Defina o que dispara a mensagem e quem recebe</p>
|
||||
</div>
|
||||
<%= render 'shared/flash' %>
|
||||
<%= render 'form', evento: @evento %>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user