admin/services/contactMessages.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

63 lines
1.5 KiB
TypeScript

import axiosInstance from '@/config/axios'
import { texts } from '@/texts'
import { API_ROUTES } from '@/services/config'
import {
createServiceError,
errorResult,
handleServiceError,
type ServiceCallOptions,
type ServiceResult,
shouldBubbleErrorToParent,
successResult,
} from '@/services/errorHandler'
import { unwrapApiData, type ApiResponse } from '@/services/apiResponse'
export interface ContactMessage {
id: string
fullName: string
mobile: string
subject: string
message: string
readAt: string | null
readBy: string | null
createdAt: string
}
export interface CreateContactMessagePayload {
fullName: string
mobile: string
subject: string
message: string
arcaptchaToken: string
}
export const CREATE_CONTACT_MESSAGE = async (
payload: CreateContactMessagePayload,
options?: ServiceCallOptions
): Promise<ServiceResult<ContactMessage>> => {
try {
const res = await axiosInstance.post<ApiResponse<ContactMessage>>(API_ROUTES.CONTACT_MESSAGES.CREATE, payload)
const body = res.data
if (!body.success) {
throw createServiceError(body.message || texts.chats.sendFailed)
}
const data = unwrapApiData(body)
if (!data?.id) {
throw createServiceError(texts.common.invalidServerResponse)
}
return successResult(data)
} catch (error) {
const normalizedError = handleServiceError(error, options)
if (shouldBubbleErrorToParent(options)) {
throw normalizedError
}
return errorResult(normalizedError)
}
}