Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
80 lines
2.6 KiB
TypeScript
80 lines
2.6 KiB
TypeScript
import axiosInstance from '@/config/axios'
|
|
import { texts } from '@/texts'
|
|
import { parseRemittanceList, 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
|
|
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 listMySupportTickets(): Promise<SupportTicket[]> {
|
|
const response = await axiosInstance.get('support-tickets/me', { params: { pageSize: 100, sort: '-lastMessageAt' } })
|
|
|
|
return parseRemittanceList<SupportTicket>(response.data).items
|
|
}
|
|
|
|
export async function getMySupportTicket(id: string): Promise<SupportTicket> {
|
|
const response = await axiosInstance.get(`support-tickets/${id}`)
|
|
|
|
return unwrapTicket(response.data)
|
|
}
|
|
|
|
export async function createSupportTicket(payload: {
|
|
subject: string
|
|
category: string
|
|
priority: string
|
|
message: string
|
|
}): Promise<SupportTicket> {
|
|
const response = await axiosInstance.post('support-tickets', payload)
|
|
|
|
return unwrapTicket(response.data)
|
|
}
|
|
|
|
export async function replyToSupportTicket(id: string, message: string): Promise<SupportTicket> {
|
|
const response = await axiosInstance.post(`support-tickets/${id}/replies`, { message })
|
|
|
|
return unwrapTicket(response.data)
|
|
}
|
|
|
|
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)
|
|
}
|