Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import type { EventManagementBootstrap } from '@/services/eventManagement'
|
|
|
|
type ApiEnvelope<T> = { success: true; data: T } | { success: false; message: string }
|
|
|
|
const resolveApiBaseUrl = () => {
|
|
const raw = process.env.NEXT_PUBLIC_API_URL
|
|
|
|
if (!raw) throw new Error('NEXT_PUBLIC_API_URL is not configured')
|
|
const trimmed = raw.replace(/\/+$/, '')
|
|
|
|
return trimmed.endsWith('/api/v1') ? trimmed : `${trimmed}/api/v1`
|
|
}
|
|
|
|
/** Private owner data: never enters the public Next.js or persistent browser cache. */
|
|
export async function fetchEventManagementBootstrapForOwner(
|
|
eventId: string,
|
|
accessToken: string
|
|
): Promise<EventManagementBootstrap | null> {
|
|
const response = await fetch(`${resolveApiBaseUrl()}/events/${encodeURIComponent(eventId)}/management-bootstrap`, {
|
|
cache: 'no-store',
|
|
headers: { Authorization: `Bearer ${accessToken}` },
|
|
})
|
|
|
|
if (response.status === 401 || response.status === 403 || response.status === 404) return null
|
|
if (!response.ok) throw new Error(`Management bootstrap failed: ${response.status}`)
|
|
|
|
const body = (await response.json()) as ApiEnvelope<EventManagementBootstrap>
|
|
|
|
return body.success ? body.data : null
|
|
}
|