Files
MatchLiveTv/backend/app/views/public/teams/_streaming_staff.html.erb
eminuxandCursor db8b14ba4e Snellisci l'invito a trasmettere e invia l'email automatica.
Il form invito è sulla pagina squadra, genera il link e manda la mail; in caso di errore SMTP resta la copia manuale.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-15 20:02:25 +02:00

154 lines
7.3 KiB
ERB

<% team = local_assigns[:team] %>
<% can_manage = local_assigns[:can_manage] %>
<% owner_membership = local_assigns[:owner_membership] %>
<% staff_memberships = local_assigns[:staff_memberships] %>
<% pending_invitations = local_assigns[:pending_invitations] %>
<% recordings = local_assigns[:recordings] %>
<% entitlements = local_assigns[:entitlements] %>
<section class="team-streaming-staff" id="responsabili-trasmissione">
<% if can_manage %>
<% if owner_membership&.staff_kind.blank? %>
<div class="card team-streaming-staff__self">
<h2><%= t("team.streaming_staff.self_account_heading", email: current_user.email) %></h2>
<p class="muted">
<%= raw t("team.streaming_staff.self_account_hint") %>
</p>
<div class="team-details-actions">
<%= button_to t("team.streaming_staff.self_assign_submit"), public_team_assign_self_staff_path(team), method: :post, params: { staff_kind: "transmission" }, class: "btn btn-primary" %>
</div>
</div>
<% end %>
<% end %>
<h2><%= t("team.streaming_staff.staff_heading") %></h2>
<div class="card">
<% if staff_memberships.any? %>
<table class="data">
<thead><tr><th><%= t("team.streaming_staff.col_name") %></th><th><%= t("team.streaming_staff.col_email") %></th><th><%= t("team.streaming_staff.col_role") %></th><% if can_manage %><th></th><% end %></tr></thead>
<tbody>
<% staff_memberships.each do |ut| %>
<tr>
<td>
<%= ut.user.name %>
<% if ut.user_id == current_user.id %><span class="muted"> <%= t("team.streaming_staff.you_suffix") %></span><% end %>
</td>
<td><%= ut.user.email %></td>
<td><%= t("team.streaming_staff.role_transmission") %></td>
<% if can_manage %>
<td>
<% if ut.user_id == current_user.id && team.club.owned_by?(current_user) %>
<%= button_to t("team.streaming_staff.clear_self_staff"), public_team_clear_self_staff_path(team), method: :delete, class: "btn btn-secondary", style: "padding:4px 10px;font-size:0.8rem", form: { data: { turbo_confirm: t("team.streaming_staff.clear_self_staff_confirm"), confirm_kind: "delete" } } %>
<% elsif ut.role == "member" %>
<%= button_to t("team.streaming_staff.revoke"), public_team_remove_member_path(team, ut.user), method: :delete, class: "btn btn-secondary", style: "padding:4px 10px;font-size:0.8rem", form: { data: { turbo_confirm: t("team.streaming_staff.revoke_confirm", name: ut.user.name), confirm_kind: "delete" } } %>
<% end %>
</td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<p class="muted">
<%= t("team.streaming_staff.no_staff") %>
<% if can_manage %><%= link_to t("team.streaming_staff.invite_someone"), "#invita-trasmissione" %>.<% end %>
</p>
<% end %>
</div>
<% if can_manage %>
<div class="card team-invite-form" id="invita-trasmissione">
<h2><%= t("team.streaming_staff.invite_form_heading") %></h2>
<p class="muted team-invite-form__hint"><%= t("team.streaming_staff.invite_form_hint") %></p>
<%= form_with url: public_team_invite_path(team), method: :post, class: "team-invite-form__fields" do %>
<%= hidden_field_tag :staff_kind, "transmission" %>
<%= label_tag :email, t("team.invite.email_label") %>
<%= email_field_tag :email, params[:email], required: true, autocomplete: "email", placeholder: "nome@email.it" %>
<%= submit_tag t("team.invite.submit"), class: "btn btn-primary" %>
<% end %>
<% if flash[:invite_url].present? %>
<div class="team-invite-link" id="invito-generato">
<p class="team-invite-link__title"><%= t("team.invite.share_hint") %></p>
<code class="team-invite-link__url" id="team-invite-url"><%= flash[:invite_url] %></code>
<button type="button" class="btn btn-secondary team-invite-link__copy" data-copy-target="team-invite-url">
<%= t("regia.copy_link") %>
</button>
<p class="muted team-invite-link__note"><%= t("team.streaming_staff.invite_once_note") %></p>
</div>
<% end %>
</div>
<h2><%= t("team.streaming_staff.pending_invitations_heading") %></h2>
<div class="card">
<% if pending_invitations.any? %>
<table class="data">
<thead><tr><th><%= t("team.streaming_staff.col_email_short") %></th><th><%= t("team.streaming_staff.col_expires") %></th><th></th></tr></thead>
<tbody>
<% pending_invitations.each do |inv| %>
<tr>
<td><%= inv.email %></td>
<td><%= l inv.expires_at, format: :short %></td>
<td>
<%= button_to t("team.streaming_staff.cancel_invitation"), public_team_destroy_invitation_path(team, inv), method: :delete, class: "btn btn-secondary", style: "padding:4px 10px;font-size:0.8rem", form: { data: { confirm_kind: "delete" } } %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<p class="muted"><%= t("team.streaming_staff.no_pending") %></p>
<% end %>
</div>
<% end %>
<% if entitlements.can_access_recordings? %>
<h2><%= t("team.streaming_staff.archive_heading") %></h2>
<div class="card">
<% if recordings.any? %>
<table class="data">
<thead><tr><th><%= t("team.streaming_staff.col_match") %></th><th><%= t("team.streaming_staff.col_date") %></th><th><%= t("team.streaming_staff.col_duration") %></th><th><%= t("team.streaming_staff.col_expiry") %></th><th><%= t("team.streaming_staff.col_status") %></th><th></th></tr></thead>
<tbody>
<% recordings.each do |rec| %>
<tr>
<td><%= rec.title_or_default %></td>
<td><%= l_local(rec.recorded_at_or_fallback) %></td>
<td><%= rec.duration_label %></td>
<td><%= rec.expires_at ? l_local(rec.expires_at) : "—" %></td>
<td><%= rec.status_label %></td>
<td>
<% if rec.replay_url %>
<%= link_to t("team.streaming_staff.watch"), rec.replay_url, target: "_blank", rel: "noopener" %>
<% else %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<p style="margin-top:12px">
<%= link_to t("team.streaming_staff.manage_all_replays"), public_club_recordings_path(team.club) %>
</p>
<% else %>
<p class="muted"><%= t("team.streaming_staff.no_recordings") %></p>
<% end %>
</div>
<% end %>
</section>
<script>
document.querySelectorAll("[data-copy-target]").forEach(function (btn) {
btn.addEventListener("click", async function () {
var el = document.getElementById(btn.getAttribute("data-copy-target"));
if (!el) return;
try {
await navigator.clipboard.writeText(el.textContent.trim());
btn.textContent = <%= raw t("team.streaming_staff.copied").to_json %>;
} catch (e) {
window.getSelection().selectAllChildren(el);
}
});
});
</script>