06/09 Add customer request view
This commit is contained in:
+34
-2
@@ -162,7 +162,39 @@ def submit_ticket():
|
||||
_notify_admins_new_ticket(ticket)
|
||||
|
||||
flash('Your message has been submitted. Our team will get back to you soon.', 'success')
|
||||
return redirect(url_for('support.chat'))
|
||||
return redirect(url_for('support.my_tickets'))
|
||||
|
||||
|
||||
# ── Customer: my tickets list ─────────────────────────────────────────────────
|
||||
|
||||
@bp.route('/my-tickets')
|
||||
@login_required
|
||||
def my_tickets():
|
||||
if current_user.role != 'customer':
|
||||
abort(403)
|
||||
|
||||
tickets = (SupportTicket.query
|
||||
.filter_by(customer_id=current_user.id)
|
||||
.order_by(SupportTicket.created_at.desc())
|
||||
.all())
|
||||
return render_template('support/my_tickets.html', tickets=tickets)
|
||||
|
||||
|
||||
# ── Customer: ticket detail ───────────────────────────────────────────────────
|
||||
|
||||
@bp.route('/my-tickets/<int:ticket_id>')
|
||||
@login_required
|
||||
def my_ticket_detail(ticket_id):
|
||||
if current_user.role != 'customer':
|
||||
abort(403)
|
||||
|
||||
ticket = db.session.get(SupportTicket, ticket_id)
|
||||
if ticket is None or ticket.customer_id != current_user.id:
|
||||
abort(404)
|
||||
|
||||
replies = ticket.replies.order_by(SupportTicketReply.created_at.asc()).all()
|
||||
return render_template('support/my_ticket_detail.html',
|
||||
ticket=ticket, replies=replies)
|
||||
|
||||
|
||||
def _notify_admins_new_ticket(ticket):
|
||||
@@ -274,7 +306,7 @@ def _notify_customer_reply(ticket, reply):
|
||||
title = f'Reply to your support request #{ticket.id}'
|
||||
body = (f'{admin_name} replied to your ticket "{ticket.subject}":\n\n'
|
||||
f'{reply.body[:400]}{"…" if len(reply.body) > 400 else ""}')
|
||||
link = url_for('support.chat')
|
||||
link = url_for('support.my_ticket_detail', ticket_id=ticket.id)
|
||||
|
||||
notify(
|
||||
recipient = ticket.customer,
|
||||
|
||||
+15
-3
@@ -177,11 +177,23 @@
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if current_user.role == 'customer' %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {{ 'active' if request.endpoint and request.endpoint.startswith('support.') }}"
|
||||
href="{{ url_for('support.chat') }}">
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle {{ 'active' if request.endpoint and request.endpoint.startswith('support.') }}"
|
||||
href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="bi bi-chat-dots me-1"></i>Support
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for('support.chat') }}">
|
||||
<i class="bi bi-chat-dots me-2"></i>Ask a Question
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for('support.my_tickets') }}">
|
||||
<i class="bi bi-inbox me-2"></i>My Requests
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if current_user.role == 'admin' %}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Support Request #{{ ticket.id }}{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<style>
|
||||
.reply-bubble {
|
||||
max-width: 85%;
|
||||
padding: .65rem 1rem;
|
||||
border-radius: 1rem;
|
||||
font-size: .9rem;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.reply-staff { background:#d1ecf1; border-bottom-right-radius:.25rem; align-self:flex-end; }
|
||||
#reply-thread { display:flex; flex-direction:column; gap:.75rem; }
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="mb-3">
|
||||
<a href="{{ url_for('support.my_tickets') }}" class="btn btn-sm btn-outline-secondary">
|
||||
<i class="bi bi-arrow-left me-1"></i>All My Requests
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-8">
|
||||
|
||||
{# Original request #}
|
||||
<div class="card shadow-sm mb-3">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<strong>Request #{{ ticket.id }}: {{ ticket.subject }}</strong>
|
||||
{% set status_class = {'open': 'warning', 'answered': 'success', 'closed': 'secondary'} %}
|
||||
{% set status_label = {'open': 'Awaiting reply', 'answered': 'Answered', 'closed': 'Closed'} %}
|
||||
<span class="badge bg-{{ status_class.get(ticket.status, 'secondary') }}">
|
||||
{{ status_label.get(ticket.status, ticket.status | capitalize) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="text-muted small mb-2">
|
||||
{% if ticket.facility %}
|
||||
<i class="bi bi-building me-1"></i>{{ ticket.facility.name }} ·
|
||||
{% endif %}
|
||||
<i class="bi bi-clock me-1"></i>{{ ticket.created_at.strftime('%b %d, %Y %I:%M %p') }}
|
||||
</div>
|
||||
<p class="mb-0" style="white-space:pre-wrap;">{{ ticket.body }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Staff replies #}
|
||||
{% if replies %}
|
||||
<div class="card shadow-sm mb-3">
|
||||
<div class="card-header">
|
||||
<i class="bi bi-chat-left-text me-2"></i>Replies from Support Team
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div id="reply-thread">
|
||||
{% for reply in replies %}
|
||||
<div class="d-flex flex-column">
|
||||
<div class="reply-bubble reply-staff ms-auto">
|
||||
<div class="text-muted small mb-1">
|
||||
<strong>{{ reply.author.display_name if reply.author else 'Support Team' }}</strong>
|
||||
· {{ reply.created_at.strftime('%b %d, %Y %I:%M %p') }}
|
||||
</div>
|
||||
{{ reply.body }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="alert alert-info">
|
||||
<i class="bi bi-hourglass-split me-2"></i>
|
||||
Your request has been received. Our team will reply shortly.
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="text-center mt-2">
|
||||
<a href="{{ url_for('support.chat') }}" class="btn btn-outline-primary btn-sm">
|
||||
<i class="bi bi-chat-dots me-1"></i>Ask another question
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,64 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}My Support Requests{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<div>
|
||||
<h4 class="mb-0"><i class="bi bi-inbox me-2 text-primary"></i>My Support Requests</h4>
|
||||
<small class="text-muted">{{ tickets | length }} request{{ 's' if tickets | length != 1 }}</small>
|
||||
</div>
|
||||
<a href="{{ url_for('support.chat') }}" class="btn btn-outline-primary btn-sm">
|
||||
<i class="bi bi-chat-dots me-1"></i>New Chat / Ask a Question
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% if tickets %}
|
||||
<div class="card shadow-sm">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover mb-0 align-middle">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th style="width:60px">#</th>
|
||||
<th>Subject</th>
|
||||
<th>Facility</th>
|
||||
<th>Status</th>
|
||||
<th>Submitted</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% set status_class = {'open': 'warning', 'answered': 'success', 'closed': 'secondary'} %}
|
||||
{% set status_label = {'open': 'Awaiting reply', 'answered': 'Answered', 'closed': 'Closed'} %}
|
||||
{% for ticket in tickets %}
|
||||
<tr>
|
||||
<td class="text-muted small">{{ ticket.id }}</td>
|
||||
<td>{{ ticket.subject }}</td>
|
||||
<td>{{ ticket.facility.name if ticket.facility else '—' }}</td>
|
||||
<td>
|
||||
<span class="badge bg-{{ status_class.get(ticket.status, 'secondary') }}">
|
||||
{{ status_label.get(ticket.status, ticket.status | capitalize) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="text-muted small text-nowrap">
|
||||
{{ ticket.created_at.strftime('%b %d, %Y') }}
|
||||
</td>
|
||||
<td>
|
||||
<a href="{{ url_for('support.my_ticket_detail', ticket_id=ticket.id) }}"
|
||||
class="btn btn-sm btn-outline-primary">
|
||||
<i class="bi bi-eye me-1"></i>View
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="text-center text-muted py-5">
|
||||
<i class="bi bi-inbox fs-1 d-block mb-2"></i>
|
||||
You haven't submitted any support requests yet.<br>
|
||||
<a href="{{ url_for('support.chat') }}" class="mt-2 d-inline-block">Start a support chat</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user