- Replaced `LIST_PUBLIC_CATEGORIES` with `LIST_ADMIN_CATEGORIES_FLAT` in `ArticleFormModal.tsx`. - Removed the "Add Event" button from the dashboard page. - Simplified the `EventsPage` by removing the button and adjusting the layout. - Cleaned up the `AdminEventEditPage` by removing unnecessary props. - Deleted unused layout and page files related to event creation. - Updated `AdminAuthContent` to use `useAdminCitiesQuery` instead of `useDiscoveryCitiesQuery`. - Refactored `EventGuestListAccessPanel` to remove the `accessMode` prop and adjust API calls accordingly. - Removed several unused components and tests related to event creation, enhancing project maintainability.
161 lines
4.6 KiB
TypeScript
161 lines
4.6 KiB
TypeScript
import type { CreateEventCategoryDto, EventCategoryResponseDto, EventCategorySummaryResponseDto } from '@/api/generated/models'
|
|
import {
|
|
createServiceError,
|
|
errorResult,
|
|
handleServiceError,
|
|
type ServiceCallOptions,
|
|
type ServiceResult,
|
|
shouldBubbleErrorToParent,
|
|
successResult,
|
|
} from '@/services/errorHandler'
|
|
import { unwrapApiData } from '@/services/apiResponse'
|
|
import { getAdminEventCategories } from '@/api/generated/admin-event-categories/admin-event-categories'
|
|
import { texts } from '@/texts'
|
|
|
|
export type EventCategory = EventCategoryResponseDto
|
|
export type EventCategorySummary = EventCategorySummaryResponseDto
|
|
export type EventCategoryPayload = CreateEventCategoryDto
|
|
|
|
const adminEventCategoriesApi = getAdminEventCategories()
|
|
|
|
/** Flat admin category list for filters/selects (id + name). */
|
|
export const LIST_ADMIN_CATEGORIES_FLAT = async (
|
|
options?: ServiceCallOptions
|
|
): Promise<ServiceResult<{ items: EventCategorySummary[] }>> => {
|
|
try {
|
|
const res = await adminEventCategoriesApi.adminEventCategoriesControllerListFlat()
|
|
const payload = res.data
|
|
|
|
if (!payload.success) {
|
|
throw createServiceError(payload.message || texts.events.categoriesListFailed)
|
|
}
|
|
|
|
const items = unwrapApiData(payload)
|
|
|
|
return successResult({ items: items ?? [] })
|
|
} catch (error) {
|
|
const normalizedError = handleServiceError(error, options)
|
|
|
|
if (shouldBubbleErrorToParent(options)) {
|
|
throw normalizedError
|
|
}
|
|
|
|
return errorResult(normalizedError)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* One "level" of the category tree: every direct child of `parentId`
|
|
* (or every root category, when `parentId` is null).
|
|
*/
|
|
export const GET_CATEGORY_CHILDREN = async (
|
|
parentId: number | null,
|
|
options?: ServiceCallOptions
|
|
): Promise<ServiceResult<EventCategory[]>> => {
|
|
try {
|
|
const res = await adminEventCategoriesApi.adminEventCategoriesControllerList({
|
|
pageSize: 100,
|
|
filters: { parentId: parentId === null ? 'null' : String(parentId) },
|
|
})
|
|
const payload = res.data
|
|
|
|
if (!payload.success) {
|
|
throw createServiceError(payload.message || texts.events.categoriesListFailed)
|
|
}
|
|
|
|
const list = unwrapApiData(payload)
|
|
|
|
return successResult(list?.items ?? [])
|
|
} catch (error) {
|
|
const normalizedError = handleServiceError(error, options)
|
|
|
|
if (shouldBubbleErrorToParent(options)) {
|
|
throw normalizedError
|
|
}
|
|
|
|
return errorResult(normalizedError)
|
|
}
|
|
}
|
|
|
|
export const CREATE_CATEGORY = async (
|
|
payload: EventCategoryPayload,
|
|
options?: ServiceCallOptions
|
|
): Promise<ServiceResult<EventCategory>> => {
|
|
try {
|
|
const res = await adminEventCategoriesApi.adminEventCategoriesControllerCreate(payload)
|
|
const body = res.data
|
|
|
|
if (!body.success) {
|
|
throw createServiceError(body.message || texts.events.categoryCreateFailed)
|
|
}
|
|
|
|
const category = unwrapApiData(body)
|
|
|
|
if (!category?.id) {
|
|
throw createServiceError(texts.common.invalidServerResponse)
|
|
}
|
|
|
|
return successResult(category)
|
|
} catch (error) {
|
|
const normalizedError = handleServiceError(error, options)
|
|
|
|
if (shouldBubbleErrorToParent(options)) {
|
|
throw normalizedError
|
|
}
|
|
|
|
return errorResult(normalizedError)
|
|
}
|
|
}
|
|
|
|
export const UPDATE_CATEGORY = async (
|
|
id: number,
|
|
payload: Omit<EventCategoryPayload, 'parentId'>,
|
|
options?: ServiceCallOptions
|
|
): Promise<ServiceResult<EventCategory>> => {
|
|
try {
|
|
const res = await adminEventCategoriesApi.adminEventCategoriesControllerUpdate(id, payload)
|
|
const body = res.data
|
|
|
|
if (!body.success) {
|
|
throw createServiceError(body.message || texts.events.categoryUpdateFailed)
|
|
}
|
|
|
|
const category = unwrapApiData(body)
|
|
|
|
if (!category?.id) {
|
|
throw createServiceError(texts.common.invalidServerResponse)
|
|
}
|
|
|
|
return successResult(category)
|
|
} catch (error) {
|
|
const normalizedError = handleServiceError(error, options)
|
|
|
|
if (shouldBubbleErrorToParent(options)) {
|
|
throw normalizedError
|
|
}
|
|
|
|
return errorResult(normalizedError)
|
|
}
|
|
}
|
|
|
|
export const DELETE_CATEGORY = async (id: number, options?: ServiceCallOptions): Promise<ServiceResult<{ success: boolean }>> => {
|
|
try {
|
|
const res = await adminEventCategoriesApi.adminEventCategoriesControllerRemove(id)
|
|
const body = res.data
|
|
|
|
if (!body.success) {
|
|
throw createServiceError(body.message || texts.events.categoryDeleteFailed)
|
|
}
|
|
|
|
return successResult(unwrapApiData(body) ?? { success: true })
|
|
} catch (error) {
|
|
const normalizedError = handleServiceError(error, options)
|
|
|
|
if (shouldBubbleErrorToParent(options)) {
|
|
throw normalizedError
|
|
}
|
|
|
|
return errorResult(normalizedError)
|
|
}
|
|
}
|