Aggiunge fascia oraria, prova manuale obbligatoria e cruscotto invii email.
CI / lint (push) Failing after 16m2s
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled

Le campagne rispettano orario e giorni lavorativi, richiedono una mail di test con dati inseriti a mano prima dell'invio massivo e offrono una dashboard per monitorare l'avanzamento.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-18 00:04:33 +02:00
co-authored by Cursor
parent 4ddf534a0c
commit 98dcdbbf82
33 changed files with 882 additions and 56 deletions
+2 -2
View File
@@ -42,7 +42,7 @@
<%= nav_link "Contatti", contacts_path %>
<%= nav_link "Pipeline", pipeline_path %>
<%= nav_link "Task", tasks_path %>
<%= nav_link "Email", mailings_path %>
<%= nav_link "Email", dashboard_mailings_path %>
<%= nav_link "Report", reports_path %>
<%= nav_link "Impostazioni", settings_path %>
<% if current_user.admin? %>
@@ -91,7 +91,7 @@
<%= link_to "Org", organizations_path, class: "whitespace-nowrap rounded px-2 py-1 text-xs font-medium text-zinc-700 dark:text-zinc-300" %>
<%= link_to "Pipeline", pipeline_path, class: "whitespace-nowrap rounded px-2 py-1 text-xs font-medium text-zinc-700 dark:text-zinc-300" %>
<%= link_to "Task", tasks_path, class: "whitespace-nowrap rounded px-2 py-1 text-xs font-medium text-zinc-700 dark:text-zinc-300" %>
<%= link_to "Email", mailings_path, class: "whitespace-nowrap rounded px-2 py-1 text-xs font-medium text-zinc-700 dark:text-zinc-300" %>
<%= link_to "Email", dashboard_mailings_path, class: "whitespace-nowrap rounded px-2 py-1 text-xs font-medium text-zinc-700 dark:text-zinc-300" %>
<% if current_user.admin? %>
<%= link_to "Utenti", users_path, class: "whitespace-nowrap rounded px-2 py-1 text-xs font-medium text-zinc-700 dark:text-zinc-300" %>
<% end %>
+1 -1
View File
@@ -3,7 +3,7 @@
<div>
<h1 class="text-2xl font-semibold tracking-tight">Template email</h1>
<p class="mt-1 text-sm text-zinc-500">
<%= link_to "Invii", mailings_path, class: "hover:underline" %>
<%= link_to "Invii", dashboard_mailings_path, class: "hover:underline" %>
· HTML riutilizzabile con variabili della scheda cliente.
</p>
</div>
+21 -1
View File
@@ -32,6 +32,26 @@
</div>
</div>
<div class="rounded-lg border border-zinc-200 p-4 dark:border-zinc-700" data-controller="send-window">
<label class="flex items-start gap-2 text-sm">
<%= f.check_box :send_window_enabled, { data: { send_window_target: "checkbox", action: "send-window#toggle" } } %>
<span>
<span class="font-medium">Invia solo in fascia oraria</span>
<span class="mt-1 block text-xs text-zinc-500">Le email partono solo nei giorni lavorativi (lunven, esclusi i festivi italiani). Se la fascia finisce, linvio riprende dal giorno lavorativo successivo.</span>
</span>
</label>
<div class="mt-4 grid gap-4 md:grid-cols-2 <%= "hidden" unless mailing.send_window_enabled? %>" data-send-window-target="panel">
<div>
<label class="mb-1 block text-sm font-medium">Dalle</label>
<%= f.time_field :send_window_start_tod, include_seconds: false, step: 60, class: input_class %>
</div>
<div>
<label class="mb-1 block text-sm font-medium">Alle</label>
<%= f.time_field :send_window_end_tod, include_seconds: false, step: 60, class: input_class %>
</div>
</div>
</div>
<div class="rounded-lg border border-zinc-200 p-4 dark:border-zinc-700">
<label class="flex items-start gap-2 text-sm">
<%= f.check_box :ab_test, { data: { ab_test_target: "checkbox", action: "ab-test#toggle" } } %>
@@ -101,7 +121,7 @@
<div class="flex flex-wrap items-center gap-2 border-t border-zinc-100 pt-4 dark:border-zinc-800">
<%= f.submit mailing.new_record? ? "Crea bozza" : "Salva", class: btn_primary %>
<%= link_to "Annulla", mailing.new_record? ? mailings_path : mailing_path(mailing), class: btn_secondary %>
<%= link_to "Annulla", mailing.new_record? ? dashboard_mailings_path : mailing_path(mailing), class: btn_secondary %>
</div>
</div>
@@ -0,0 +1,33 @@
<div class="<%= card_class %> p-4">
<div class="flex items-start justify-between gap-3">
<div>
<%= link_to mailing.name, mailing, class: "font-semibold hover:underline" %>
<p class="mt-1 text-xs text-zinc-500">
<%= mailing.mail_identity.from_email %>
<% if mailing.send_window_enabled? %>
· fascia <%= mailing.send_window_label %>
<% end %>
<% if mailing.interval_seconds.positive? %>
· pausa <%= mailing.interval_seconds %>s
<% end %>
</p>
</div>
<%= mailing_status_badge(mailing.status) %>
</div>
<div class="mt-4"><%= progress_bar(mailing.progress_percentage, color: mailing.failed_count.positive? ? "bg-amber-500" : "bg-emerald-500") %></div>
<div class="mt-2 flex flex-wrap gap-3 text-sm text-zinc-600 dark:text-zinc-300">
<span><strong class="tabular-nums"><%= mailing.sent_count %></strong> inviate</span>
<span><strong class="tabular-nums"><%= mailing.pending_count %></strong> in coda</span>
<span><strong class="tabular-nums"><%= mailing.skipped_count %></strong> escluse</span>
<% if mailing.failed_count.positive? %>
<span class="text-rose-700"><strong class="tabular-nums"><%= mailing.failed_count %></strong> errori</span>
<% end %>
</div>
<% if mailing.next_send_at.present? && mailing.next_send_at > Time.current %>
<p class="mt-3 rounded-lg bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:bg-amber-950 dark:text-amber-100">
In pausa fino a <%= l(mailing.next_send_at, format: :long) %>
</p>
<% elsif mailing.pending_count.positive? %>
<p class="mt-3 text-xs text-zinc-500">Prossima email in lavorazione.</p>
<% end %>
</div>
@@ -0,0 +1,7 @@
<div class="space-y-2">
<p class="text-sm font-medium"><%= @test_preview_subject.presence || "(oggetto vuoto)" %></p>
<div class="max-h-64 overflow-auto rounded-lg border border-zinc-100 bg-white p-3 text-sm text-zinc-800 dark:border-zinc-800 dark:bg-zinc-950 dark:text-zinc-100">
<%= sanitize_email_html(@test_preview_html) %>
</div>
<p class="text-xs text-zinc-500">Anteprima con i dati inseriti. Lemail di prova parte subito, senza fascia oraria.</p>
</div>
@@ -0,0 +1,50 @@
<% used = mailing.used_merge_tokens %>
<% extra = MailMerge.catalog.keys - used %>
<%= form_with url: test_send_mailing_path(mailing), method: :post, class: "space-y-3",
data: {
controller: "test-mail",
test_mail_preview_url_value: test_preview_mailing_path(mailing),
action: "input->test-mail#preview change->test-mail#preview"
} do %>
<div>
<label class="mb-1 block text-sm font-medium">Invia la prova a</label>
<%= email_field_tag :to, @test_to, required: true, class: input_class %>
</div>
<% if mailing.ab_test? %>
<div>
<label class="mb-1 block text-sm font-medium">Variante</label>
<%= select_tag :variant, options_for_select(%w[A B], @test_variant), class: input_class %>
</div>
<% end %>
<div class="grid gap-3 sm:grid-cols-2">
<% used.each do |token| %>
<div>
<label class="mb-1 block text-xs font-medium text-zinc-600 dark:text-zinc-300"><%= MailMerge.catalog[token] || token %> <code class="text-zinc-400">{{<%= token %>}}</code></label>
<%= text_field_tag "vars[#{token}]", @test_vars[token], class: input_class %>
</div>
<% end %>
</div>
<% if extra.any? %>
<details class="rounded-lg border border-zinc-200 p-3 dark:border-zinc-700">
<summary class="cursor-pointer text-sm font-medium">Altri campi di test</summary>
<div class="mt-3 grid gap-3 sm:grid-cols-2">
<% extra.each do |token| %>
<div>
<label class="mb-1 block text-xs font-medium text-zinc-600 dark:text-zinc-300"><%= MailMerge.catalog[token] %> <code class="text-zinc-400">{{<%= token %>}}</code></label>
<%= text_field_tag "vars[#{token}]", @test_vars[token], class: input_class %>
</div>
<% end %>
</div>
</details>
<% end %>
<%= turbo_frame_tag "mailing_test_preview", data: { test_mail_target: "frame" } do %>
<%= render "mailings/test_preview" %>
<% end %>
<%= submit_tag "Invia prova ora", class: btn_primary %>
<% end %>
+113
View File
@@ -0,0 +1,113 @@
<% refresh = @active_mailings.any? %>
<%= tag.div class: "space-y-6", data: (refresh ? { controller: "auto-reload", auto_reload_interval_value: 10_000 } : {}) do %>
<div class="flex flex-wrap items-end justify-between gap-3">
<div>
<h1 class="text-2xl font-semibold tracking-tight">Invii email</h1>
<p class="mt-1 text-sm text-zinc-500">Stato delle campagne, prove e invii di massa scaglionati.</p>
</div>
<div class="flex flex-wrap gap-2">
<%= link_to "Template", mail_templates_path, class: btn_secondary %>
<% if current_user.admin? %>
<%= link_to "Account SMTP", mail_identities_path, class: btn_secondary %>
<% end %>
<%= link_to "Nuovo invio", new_mailing_path, class: btn_primary %>
</div>
</div>
<% if @mail_identities_count.zero? %>
<div class="rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-100">
Manca un account mittente SMTP.
<% if current_user.admin? %>
<%= link_to "Configuralo qui", mail_identities_path, class: "font-medium underline" %>.
<% else %>
Chiedi a un amministratore di censirlo.
<% end %>
</div>
<% end %>
<div class="grid gap-4 sm:grid-cols-2 xl:grid-cols-4">
<div class="<%= card_class %> p-4">
<div class="text-xs uppercase tracking-wide text-zinc-500">In corso</div>
<div class="mt-1 text-2xl font-semibold tabular-nums"><%= @active_mailings.size %></div>
</div>
<div class="<%= card_class %> p-4">
<div class="text-xs uppercase tracking-wide text-zinc-500">In pausa (fascia)</div>
<div class="mt-1 text-2xl font-semibold tabular-nums"><%= @paused_mailings.size %></div>
</div>
<div class="<%= card_class %> p-4">
<div class="text-xs uppercase tracking-wide text-zinc-500">Completati oggi</div>
<div class="mt-1 text-2xl font-semibold tabular-nums"><%= @completed_today %></div>
</div>
<div class="<%= card_class %> p-4">
<div class="text-xs uppercase tracking-wide text-zinc-500">Errori aperti</div>
<div class="mt-1 text-2xl font-semibold tabular-nums"><%= @failed_open %></div>
</div>
</div>
<% if @active_mailings.any? %>
<section class="space-y-3">
<h2 class="text-lg font-semibold">Campagne in corso</h2>
<div class="grid gap-4 lg:grid-cols-2">
<% @active_mailings.each do |mailing| %>
<%= render "mailings/progress_card", mailing: mailing %>
<% end %>
</div>
<p class="text-xs text-zinc-500">Questa pagina si aggiorna da sola ogni 10 secondi mentre c’è un invio attivo.</p>
</section>
<% end %>
<div class="overflow-hidden <%= card_class %>">
<% if @mailings.empty? %>
<p class="p-6 text-sm text-zinc-500">Nessun invio. Crea una bozza, fai una prova con dati manuali e poi autorizza linvio di massa.</p>
<% else %>
<table class="<%= table_class %>">
<thead class="border-b border-zinc-100 bg-zinc-50 text-left text-xs font-medium uppercase tracking-wide text-zinc-500 dark:border-zinc-800 dark:bg-zinc-800 dark:text-zinc-400">
<tr>
<th class="px-4 py-3">Invio</th>
<th class="px-4 py-3">Avanzamento</th>
<th class="px-4 py-3">Stato</th>
<th class="px-4 py-3">Prossimo / creato</th>
</tr>
</thead>
<tbody class="divide-y divide-zinc-100 dark:divide-zinc-800">
<% @mailings.each do |mailing| %>
<tr class="hover:bg-zinc-50 dark:hover:bg-zinc-800/80">
<td class="px-4 py-3">
<%= link_to mailing.name, mailing, class: "font-medium hover:underline" %>
<div class="text-xs text-zinc-500"><%= mailing.mail_identity.from_email %></div>
<% if mailing.ab_test? %>
<span class="mt-1 inline-flex gap-1"><%= ab_variant_badge("A") %><%= ab_variant_badge("B") %></span>
<% end %>
</td>
<td class="px-4 py-3 min-w-48">
<%= progress_bar(mailing.progress_percentage) %>
<div class="mt-1 text-xs text-zinc-500">
<%= mailing.sent_count %> inviate
· <%= mailing.pending_count %> in coda
<% if mailing.failed_count.positive? %>
· <span class="text-rose-700"><%= mailing.failed_count %> errori</span>
<% end %>
</div>
</td>
<td class="px-4 py-3">
<%= mailing_status_badge(mailing.status) %>
<% if mailing.draft? && mailing.tested? %>
<div class="mt-1 text-xs text-emerald-700 dark:text-emerald-300">Prova ok</div>
<% elsif mailing.draft? %>
<div class="mt-1 text-xs text-zinc-500">Manca prova</div>
<% end %>
</td>
<td class="px-4 py-3 text-sm text-zinc-500">
<% if mailing.sending? && mailing.next_send_at.present? %>
<%= mailing.next_send_at > Time.current ? "Riparte #{l(mailing.next_send_at, format: :short)}" : "In invio" %>
<% else %>
<%= format_dt(mailing.created_at) %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>
<% end %>
+41 -15
View File
@@ -1,4 +1,4 @@
<div class="space-y-6">
<%= tag.div class: "space-y-6", data: (@mailing.sending? ? { controller: "auto-reload", auto_reload_interval_value: 10_000 } : {}) do %>
<div class="flex flex-wrap items-start justify-between gap-3">
<div>
<h1 class="text-2xl font-semibold tracking-tight"><%= @mailing.name %></h1>
@@ -12,10 +12,21 @@
<% if @mailing.interval_seconds.positive? %>
· pausa <%= @mailing.interval_seconds %>s
<% end %>
<% if @mailing.send_window_enabled? %>
· fascia <%= @mailing.send_window_label %>
<% end %>
</p>
<% if @mailing.sending? && @mailing.next_send_at.present? && @mailing.next_send_at > Time.current %>
<p class="mt-2 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-100">
In pausa fino a <%= l(@mailing.next_send_at, format: :long) %>
<% if @mailing.send_window_enabled? %>
(fuori fascia o giorno non lavorativo).
<% end %>
</p>
<% end %>
</div>
<div class="flex flex-wrap gap-2">
<%= link_to "Tutti gli invii", mailings_path, class: btn_secondary %>
<%= link_to "Cruscotto invii", dashboard_mailings_path, class: btn_secondary %>
<% if @mailing.editable? %>
<%= link_to "Modifica contenuto", edit_mailing_path(@mailing), class: btn_secondary %>
<%= button_to "Aggiorna lista", refresh_recipients_mailing_path(@mailing), method: :post, class: btn_secondary %>
@@ -23,6 +34,10 @@
</div>
</div>
<% if @mailing.sending? || @mailing.sent? %>
<%= render "mailings/progress_card", mailing: @mailing %>
<% end %>
<div class="grid gap-4 sm:grid-cols-4">
<div class="<%= card_class %> p-4">
<div class="text-xs uppercase tracking-wide text-zinc-500">Da inviare</div>
@@ -158,9 +173,22 @@
</section>
<section class="space-y-4">
<% if @mailing.draft? %>
<div class="<%= card_class %> space-y-3 p-4">
<h2 class="font-semibold">1. Prova con dati manuali</h2>
<p class="text-sm text-zinc-500">Compila i campi, controlla lanteprima e manda <strong>una sola email subito</strong> a un indirizzo tuo. Non parte linvio di massa.</p>
<% if @mailing.tested? %>
<p class="rounded-lg border border-emerald-200 bg-emerald-50 px-3 py-2 text-sm text-emerald-900 dark:border-emerald-900 dark:bg-emerald-950 dark:text-emerald-100">
Ultima prova inviata a <%= @mailing.test_sent_to %> il <%= l(@mailing.test_sent_at, format: :short) %>.
</p>
<% end %>
<%= render "mailings/test_send_form", mailing: @mailing %>
</div>
<% end %>
<div class="<%= card_class %> p-4">
<div class="flex items-center justify-between gap-2">
<h2 class="font-semibold">Anteprima<%= " #{@preview_variant}" if @mailing.ab_test? %></h2>
<h2 class="font-semibold">Anteprima da lista<%= " #{@preview_variant}" if @mailing.ab_test? %></h2>
<% if @preview_recipient %>
<span class="text-xs text-zinc-500"><%= @preview_recipient.organization.name %></span>
<% end %>
@@ -179,20 +207,18 @@
</div>
</div>
<% if @mailing.draft? || @mailing.sending? %>
<% if @mailing.draft? %>
<div class="<%= card_class %> space-y-3 p-4">
<% if @mailing.ab_test? %>
<%= button_to "Invia prova A a me", test_send_mailing_path(@mailing, recipient_id: @preview_recipient&.id, variant: "A"), method: :post, class: btn_secondary %>
<%= button_to "Invia prova B a me", test_send_mailing_path(@mailing, recipient_id: @preview_recipient&.id, variant: "B"), method: :post, class: btn_secondary %>
<% else %>
<%= button_to "Invia prova a me (#{current_user.email})", test_send_mailing_path(@mailing), method: :post, class: btn_secondary %>
<% end %>
<% if @mailing.pending_count.positive? %>
<%= button_to "Invia a #{@mailing.pending_count} destinatari", queue_mailing_path(@mailing), method: :post,
<h2 class="font-semibold">2. Autorizza linvio di massa</h2>
<% if @mailing.tested? && @mailing.pending_count.positive? %>
<p class="text-sm text-zinc-500">Se loutput della prova è corretto, autorizza il job. Partirà rispettando pausa e fascia oraria.</p>
<%= button_to "Autorizza invio a #{@mailing.pending_count} destinatari", queue_mailing_path(@mailing), method: :post,
class: btn_primary,
form: { data: { turbo_confirm: "Inviare #{@mailing.pending_count} email da #{@mailing.mail_identity.from_email}?" } } %>
<% else %>
form: { data: { turbo_confirm: @mailing.send_window_enabled? ? "Autorizzare l'invio di #{@mailing.pending_count} email da #{@mailing.mail_identity.from_email} nella fascia #{@mailing.send_window_label}?" : "Autorizzare l'invio di #{@mailing.pending_count} email da #{@mailing.mail_identity.from_email}?" } } %>
<% elsif @mailing.pending_count.zero? %>
<p class="text-sm text-zinc-500">Nessun destinatario da inviare. Spunta almeno un contatto con email valida.</p>
<% else %>
<p class="text-sm text-zinc-500">Linvio di massa resta bloccato finché non mandi una prova.</p>
<% end %>
</div>
<% end %>
@@ -204,4 +230,4 @@
<% end %>
</section>
</div>
</div>
<% end %>
+3
View File
@@ -0,0 +1,3 @@
<%= turbo_frame_tag "mailing_test_preview" do %>
<%= render "mailings/test_preview" %>
<% end %>
+1 -1
View File
@@ -64,7 +64,7 @@
<li><%= link_to "Gestione utenti", users_path, class: "hover:underline" %></li>
<li><%= link_to "Account email / SMTP", mail_identities_path, class: "hover:underline" %></li>
<% end %>
<li><%= link_to "Email e campagne", mailings_path, class: "hover:underline" %></li>
<li><%= link_to "Email e campagne", dashboard_mailings_path, class: "hover:underline" %></li>
<li><%= link_to "Import CSV organizzazioni", new_import_path, class: "hover:underline" %></li>
<li><%= link_to "Cambio password", edit_password_path, class: "hover:underline" %></li>
</ul>