Files
Reem-Notas/app/views/admin/eventos_notificacao/_form.html.erb

173 lines
8.0 KiB
Plaintext

<%
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="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 class="text-red-300 text-sm"><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<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>
<%# 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: rotulo %>
<%= f.select :frequencia, EventoNotificacao::FREQUENCIAS.map { |x| [x.capitalize, x] },
{ include_blank: '—' }, class: "#{menor} cursor-pointer" %>
</div>
<div>
<%= 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: rotulo %>
<%= f.select :dia_semana, Date::DAYNAMES.each_with_index.map { |nome, i| [nome, i] },
{ include_blank: '—' }, class: "#{menor} cursor-pointer" %>
</div>
</div>
</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. %>
<div class="border-t border-white/5 pt-6">
<p class="<%= secao %>">Quais grupos recebem</p>
<% if @linhas_assinatura.blank? %>
<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 %>
</div>
<%# 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 %>