feat: add admin interface for viewing and managing contact messages, including a new service and sidebar navigation.
This commit is contained in:
41
src/services/contact.service.ts
Normal file
41
src/services/contact.service.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import api, { ApiResponse } from './api';
|
||||
|
||||
export interface ContactMessage {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
phone: string | null;
|
||||
message: string;
|
||||
isRead: boolean;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface ContactCounts {
|
||||
total: number;
|
||||
unread: number;
|
||||
}
|
||||
|
||||
class ContactService {
|
||||
async getAllMessages(isRead?: boolean): Promise<ContactMessage[]> {
|
||||
const params: Record<string, string> = {};
|
||||
if (isRead !== undefined) params.isRead = String(isRead);
|
||||
const response = await api.get<ApiResponse<ContactMessage[]>>('/contact/admin/all', { params });
|
||||
return response.data.data;
|
||||
}
|
||||
|
||||
async getCounts(): Promise<ContactCounts> {
|
||||
const response = await api.get<ApiResponse<ContactCounts>>('/contact/admin/counts');
|
||||
return response.data.data;
|
||||
}
|
||||
|
||||
async markAsRead(id: string): Promise<ContactMessage> {
|
||||
const response = await api.patch<ApiResponse<ContactMessage>>(`/contact/admin/${id}/read`);
|
||||
return response.data.data;
|
||||
}
|
||||
|
||||
async deleteMessage(id: string): Promise<void> {
|
||||
await api.delete(`/contact/admin/${id}`);
|
||||
}
|
||||
}
|
||||
|
||||
export const contactService = new ContactService();
|
||||
Reference in New Issue
Block a user