admin/services/supportTickets.ts
alisaza 9254a8b487 feat(support-tickets): add close action and turn-based reply guidance
Let admins close tickets with confirmation and surface closedBy so consumer reopen rules stay clear.
2026-09-11 21:31:16 +03:30

52 lines
1.7 KiB
TypeScript

import axiosInstance from '@/config/axios'
import { texts } from '@/texts'
import { unwrapApiDataUnknown } from '@/helpers/listResponse'
export interface SupportTicketMessage {
id: string
senderId: string
body: string
isAdmin: boolean
createdAt: string
}
export interface SupportTicket {
id: string
userId: string
subject: string
category: string
priority: string
status: string
lastMessageAt: string
closedAt: string | null
closedBy?: 'user' | 'admin' | null
createdAt: string
user: { mobile: string; displayName: string | null }
messages: SupportTicketMessage[]
}
export const SUPPORT_CATEGORY_LABELS: Record<string, string> = { ...texts.support.categories }
export const SUPPORT_PRIORITY_LABELS: Record<string, string> = { ...texts.support.priorities }
export const SUPPORT_STATUS_LABELS: Record<string, string> = { ...texts.support.status }
export const SUPPORT_ADMIN_STATUS_LABELS: Record<string, string> = { ...texts.support.adminStatus }
const unwrapTicket = (raw: unknown): SupportTicket => unwrapApiDataUnknown(raw) as SupportTicket
export async function getAdminSupportTicket(id: string): Promise<SupportTicket> {
const response = await axiosInstance.get(`admin/support-tickets/${id}`)
return unwrapTicket(response.data)
}
export async function adminReplyToSupportTicket(id: string, message: string): Promise<SupportTicket> {
const response = await axiosInstance.post(`admin/support-tickets/${id}/replies`, { message })
return unwrapTicket(response.data)
}
export async function updateSupportTicketStatus(id: string, status: string): Promise<SupportTicket> {
const response = await axiosInstance.patch(`admin/support-tickets/${id}/status`, { status })
return unwrapTicket(response.data)
}