Implantação da geração de mensagem de forma livre e mudança na engine de mensagem
This commit is contained in:
102
app/views/admin/eventos_notificacao/_form.html.erb
Normal file
102
app/views/admin/eventos_notificacao/_form.html.erb
Normal file
@@ -0,0 +1,102 @@
|
||||
<%= form_with model: [:admin, evento], url: (evento.persisted? ? admin_evento_path(evento) : admin_eventos_path),
|
||||
data: { turbo: false }, class: 'space-y-5' 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">
|
||||
<ul class="list-disc list-inside space-y-1">
|
||||
<% evento.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, 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>
|
||||
|
||||
<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">
|
||||
<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' %>
|
||||
</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' %>
|
||||
</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' %>
|
||||
</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>
|
||||
|
||||
<%# 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>
|
||||
<% 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>
|
||||
<% end %>
|
||||
</fieldset>
|
||||
|
||||
<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' %>
|
||||
</div>
|
||||
<% end %>
|
||||
Reference in New Issue
Block a user