Ticket Data Model
Tickets are stored in MongoDB using theSupportTicket schema.
SupportTicket Schema
MongoDB ObjectId - unique ticket identifier
Reference to the user who created the ticket
Unique, human-readable ticket identifier (e.g., “TKT-ABC123”)
Initial description of the issue or request
Ticket category (e.g., “BUG”, “PAGOS”, “CUENTA”, “GENERAL”)
Current ticket status
Ticket priority level
Array of messages in the ticket conversation
prisma/schema.prisma:205-217
Ticket Status Workflow
Tickets progress through different statuses:Status Types
Newly created ticket, awaiting review
Administrator is actively working on the ticket
Issue has been solved, awaiting closure
Ticket is permanently closed
prisma/schema.prisma:81-86
Status Workflow
Ticket Priority Levels
Tickets can be prioritized for triage:Priority Types
Low priority - minor issues, feature requests
Medium priority (default) - standard support requests
High priority - significant issues affecting user experience
Urgent - critical issues requiring immediate attention
prisma/schema.prisma:88-93
Ticket Messages
Each ticket contains a threaded conversation using embeddedTicketMessage documents.
TicketMessage Type
Message text content
Who sent the message:
USER, ADMIN, or SUPPORT_BOTMessage timestamp
prisma/schema.prisma:103-107
Sender Roles
Message from the ticket creator
Message from platform administrator
Automated message (reserved for future AI support)
prisma/schema.prisma:95-99
Creating Support Tickets
Users can create tickets through the support form.Ticket Generation
Server Action:src/app/(main)/inicio/cda/actions.ts:10-66
Ticket Number Generation
Ticket numbers are generated using a custom function: Implementation:src/lib/utils.ts (referenced in actions)
The generateTicketId() function creates unique, human-readable identifiers.
Bot Protection
The form includes honeypot protection:The honeypot field should be hidden with CSS. Bots typically fill all form fields, triggering this check.
Viewing Tickets
Users can view their own tickets; admins can view all tickets.User Ticket List
Server Action:src/app/(main)/inicio/cda/actions.ts:69-94
Ticket Chat View
Server Action:src/app/(main)/inicio/cda/actions.ts:96-119
Ticket Messaging
Users and admins can exchange messages within tickets.Adding Messages
Server Action:src/app/(main)/inicio/cda/actions.ts:121-170
Message Display
Component:src/components/tickets/ChatView.tsx:44-75
Messages are displayed in a chat-like interface:
- User messages - Aligned right with user avatar
- Admin messages - Aligned left with support avatar
- Timestamps - Localized date and time
Chat Interface Features
Ticket Header
Displays:- Ticket number (e.g., “Ticket #TKT-ABC123”)
- Current status (translated to Spanish)
- Back navigation link
Message Thread
- Messages sorted chronologically
- Visual distinction between user and admin messages
- Avatar display for message attribution
- Timestamp formatting
Message Input
- Text input field
- Attachment button (placeholder for future implementation)
- Send button
- Form submission via server action
Admin Response Workflow
Recommended Admin Features
For full ticket management, implement:-
Admin Ticket Dashboard
- View all tickets across all users
- Filter by status, priority, category
- Sort by creation date, priority
-
Admin Response Interface
- Modify
addMessageToTicketto supportrole: "ADMIN" - Add status update controls (OPEN → IN_PROGRESS → RESOLVED)
- Priority management
- Modify
-
Ticket Assignment
- Assign tickets to specific admins
- Track admin response times
- Set SLA targets
Status Translation
Ticket statuses are translated for user display: Utility Function: Referenced insrc/lib/utils.ts
Database Queries
Indexing Recommendations
For optimal performance, add indexes:Common Queries
Find tickets by user:Related Resources
User Management
Understand user authentication and permissions
Database Schema
Full Prisma schema documentation