diff --git a/app/routes/support.py b/app/routes/support.py index 994e4e0..23e4ddd 100644 --- a/app/routes/support.py +++ b/app/routes/support.py @@ -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/') +@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, diff --git a/app/templates/base.html b/app/templates/base.html index 0763836..abeafb1 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -177,11 +177,23 @@ {% endif %} {% if current_user.role == 'customer' %} - {% endif %} {% if current_user.role == 'admin' %} diff --git a/app/templates/support/my_ticket_detail.html b/app/templates/support/my_ticket_detail.html new file mode 100644 index 0000000..837453c --- /dev/null +++ b/app/templates/support/my_ticket_detail.html @@ -0,0 +1,88 @@ +{% extends "base.html" %} +{% block title %}Support Request #{{ ticket.id }}{% endblock %} + +{% block extra_css %} + +{% endblock %} + +{% block content %} +
+ + All My Requests + +
+ +
+
+ + {# Original request #} +
+
+ Request #{{ ticket.id }}: {{ ticket.subject }} + {% set status_class = {'open': 'warning', 'answered': 'success', 'closed': 'secondary'} %} + {% set status_label = {'open': 'Awaiting reply', 'answered': 'Answered', 'closed': 'Closed'} %} + + {{ status_label.get(ticket.status, ticket.status | capitalize) }} + +
+
+
+ {% if ticket.facility %} + {{ ticket.facility.name }} ·  + {% endif %} + {{ ticket.created_at.strftime('%b %d, %Y %I:%M %p') }} +
+

{{ ticket.body }}

+
+
+ + {# Staff replies #} + {% if replies %} +
+
+ Replies from Support Team +
+
+
+ {% for reply in replies %} +
+
+
+ {{ reply.author.display_name if reply.author else 'Support Team' }} +  · {{ reply.created_at.strftime('%b %d, %Y %I:%M %p') }} +
+ {{ reply.body }} +
+
+ {% endfor %} +
+
+
+ {% else %} +
+ + Your request has been received. Our team will reply shortly. +
+ {% endif %} + + + +
+
+{% endblock %} diff --git a/app/templates/support/my_tickets.html b/app/templates/support/my_tickets.html new file mode 100644 index 0000000..75b0e67 --- /dev/null +++ b/app/templates/support/my_tickets.html @@ -0,0 +1,64 @@ +{% extends "base.html" %} +{% block title %}My Support Requests{% endblock %} + +{% block content %} +
+
+

My Support Requests

+ {{ tickets | length }} request{{ 's' if tickets | length != 1 }} +
+ + New Chat / Ask a Question + +
+ +{% if tickets %} +
+
+ + + + + + + + + + + + + {% set status_class = {'open': 'warning', 'answered': 'success', 'closed': 'secondary'} %} + {% set status_label = {'open': 'Awaiting reply', 'answered': 'Answered', 'closed': 'Closed'} %} + {% for ticket in tickets %} + + + + + + + + + {% endfor %} + +
#SubjectFacilityStatusSubmitted
{{ ticket.id }}{{ ticket.subject }}{{ ticket.facility.name if ticket.facility else '—' }} + + {{ status_label.get(ticket.status, ticket.status | capitalize) }} + + + {{ ticket.created_at.strftime('%b %d, %Y') }} + + + View + +
+
+
+{% else %} +
+ + You haven't submitted any support requests yet.
+ Start a support chat +
+{% endif %} +{% endblock %}