Add read-tracking and soft-delete to contact messages

Admin can now open a message via a per-row "View" page (which stamps
read_at the first time it's opened), see a sortable Read column on the
list instead of the raw message text, and soft-delete messages via a
Delete button on both the list and detail view. Deleted messages are
excluded from the default list so it doesn't pile up over time.
This commit is contained in:
Frank
2026-08-29 11:19:54 +02:00
parent 6fb3ed597b
commit e470a9848d
7 changed files with 206 additions and 4 deletions
+18 -3
View File
@@ -15,7 +15,8 @@
<th style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Received</th>
<th style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Name</th>
<th style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Email</th>
<th style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Message</th>
<th data-type="boolean" style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Read</th>
<th data-sortable="false" style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Actions</th>
</tr>
</thead>
<tbody>
@@ -26,11 +27,25 @@
<td style="padding: 0.75rem 1rem; color: #475569;">
<a href="mailto:{{ entry.email }}" style="color: #3b82f6; text-decoration: none;">{{ entry.email }}</a>
</td>
<td style="padding: 0.75rem 1rem; color: #475569; max-width: 480px; white-space: pre-wrap;">{{ entry.message }}</td>
<td style="padding: 0.75rem 1rem; color: #16a34a; font-weight: 600;">{{ entry.read ? '✓' : '' }}</td>
<td style="padding: 0.75rem 1rem;">
<a href="{{ path('game_admin_contact_show', {id: entry.id}) }}" style="color: #3b82f6; text-decoration: none; font-size: 0.85rem; margin-right: 0.75rem;">View</a>
<form method="post" action="{{ path('game_admin_contact_delete', {id: entry.id}) }}" style="display: inline;" onsubmit="return confirm('Delete message from {{ entry.name }}?')">
<input type="hidden" name="_token" value="{{ csrf_token('delete_contact_' ~ entry.id) }}">
<button type="submit" style="
background: none;
border: none;
color: #ef4444;
cursor: pointer;
font-size: 0.85rem;
padding: 0;
">Delete</button>
</form>
</td>
</tr>
{% else %}
<tr>
<td colspan="4" style="padding: 2rem; text-align: center; color: #94a3b8;">No messages yet.</td>
<td colspan="5" style="padding: 2rem; text-align: center; color: #94a3b8;">No messages yet.</td>
</tr>
{% endfor %}
</tbody>
@@ -0,0 +1,53 @@
{% extends 'game/admin/base.html.twig' %}
{% block title %}Message from {{ message.name }} — Admin{% endblock %}
{% block admin_body %}
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem;">
<h1 style="margin: 0; font-size: 1.5rem; color: #0f172a;">Message from {{ message.name }}</h1>
<a href="{{ path('game_admin_contact') }}" style="color: #3b82f6; text-decoration: none; font-size: 0.85rem;">&larr; Back to Contact Messages</a>
</div>
<div style="background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.07); padding: 1.5rem; max-width: 720px;">
<dl style="display: grid; grid-template-columns: 140px 1fr; row-gap: 0.75rem; margin: 0 0 1.5rem;">
<dt style="color: #64748b; font-weight: 600;">Name</dt>
<dd style="margin: 0; color: #0f172a;">{{ message.name }}</dd>
<dt style="color: #64748b; font-weight: 600;">Email</dt>
<dd style="margin: 0;">
<a href="mailto:{{ message.email }}" style="color: #3b82f6; text-decoration: none;">{{ message.email }}</a>
</dd>
<dt style="color: #64748b; font-weight: 600;">Received</dt>
<dd style="margin: 0; color: #0f172a;">{{ message.createdAt|date('Y-m-d H:i:s') }}</dd>
<dt style="color: #64748b; font-weight: 600;">Read at</dt>
<dd style="margin: 0; color: #0f172a;">
{% if message.readAt %}
{{ message.readAt|date('Y-m-d H:i:s') }}
{% else %}
<span style="color: #94a3b8;">Just now</span>
{% endif %}
</dd>
</dl>
<hr style="border-color: #f1f5f9; margin-bottom: 1.5rem;">
<div style="white-space: pre-wrap; color: #0f172a; line-height: 1.6; margin-bottom: 1.5rem;">{{ message.message }}</div>
<hr style="border-color: #f1f5f9; margin-bottom: 1.5rem;">
<form method="post" action="{{ path('game_admin_contact_delete', {id: message.id}) }}" onsubmit="return confirm('Delete message from {{ message.name }}?')">
<input type="hidden" name="_token" value="{{ csrf_token('delete_contact_' ~ message.id) }}">
<button type="submit" style="
background: none;
border: 1px solid #fca5a5;
color: #ef4444;
cursor: pointer;
font-size: 0.85rem;
padding: 0.4rem 0.9rem;
border-radius: 6px;
">Delete Message</button>
</form>
</div>
{% endblock %}