Files
co-lite/solvway-admin-portal/app/lib/services/adminEventLeads.ts
T
ngqileandClaude Opus 5.5 5f4f2705e8 feat(admin-portal): xlsx export buttons on both lead listings
A binary mobile-api call with the same error shape, export proxy routes
that pass Content-Type and Content-Disposition through, and an Export
button under BO_LEADS_EXPORT that downloads with the current search or
filters and shows EXPORT_TOO_LARGE on the page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-27 17:09:23 +08:00

52 lines
2.4 KiB
TypeScript

import { apiDownload, apiGet, apiPost, apiPut } from "@/app/lib/clientApi";
import type {
EventLeadCapturePayload,
EventLeadEvent,
EventLeadRow,
EventLeadUpdatePayload,
InterestOption,
LeadMatchResult,
SalespersonOption,
} from "@/app/lib/types";
const BASE = "/api/event-leads";
const FILTERS = ["salespersonId", "temperature", "status", "interestId", "leadType"] as const;
export type EventLeadFilters = Partial<Record<(typeof FILTERS)[number], string>>;
export interface EventLeadListParams extends EventLeadFilters {
/** 1-based. */
page: number;
pageSize: number;
}
export const listEventLeadEvents = () => apiGet<EventLeadEvent[]>(`${BASE}/events`);
export const listEventLeadInterests = () => apiGet<InterestOption[]>(`${BASE}/interest-options`);
export const listEventSalespeople = (eventUuid: string) =>
apiGet<SalespersonOption[]>(`${BASE}/${eventUuid}/salesperson-options`);
export async function listEventLeads(eventUuid: string, params: EventLeadListParams): Promise<{ items: EventLeadRow[]; total: number }> {
const qs = new URLSearchParams();
for (const key of FILTERS) if (params[key]) qs.set(key, params[key]);
qs.set("page", String(Math.max(0, params.page - 1)));
qs.set("size", String(params.pageSize));
const raw = await apiGet<{ content?: EventLeadRow[]; totalElements?: number } | null>(`${BASE}/${eventUuid}/leads?${qs}`);
const items = Array.isArray(raw?.content) ? raw.content : [];
return { items, total: typeof raw?.totalElements === "number" ? raw.totalElements : items.length };
}
export const matchLead = (eventUuid: string, contact: { mobile: string | null; email: string | null }) =>
apiPost<LeadMatchResult>(`${BASE}/${eventUuid}/match`, contact);
export const captureEventLead = (eventUuid: string, payload: EventLeadCapturePayload) =>
apiPost<EventLeadRow>(`${BASE}/${eventUuid}`, payload);
export const getEventLead = (eventUuid: string, eventLeadUuid: string) =>
apiGet<EventLeadRow>(`${BASE}/${eventUuid}/leads/${eventLeadUuid}`);
export const updateEventLead = (eventUuid: string, eventLeadUuid: string, payload: EventLeadUpdatePayload) =>
apiPut<EventLeadRow>(`${BASE}/${eventUuid}/leads/${eventLeadUuid}`, payload);
export function exportEventLeads(eventUuid: string, filters: EventLeadFilters) {
const qs = new URLSearchParams();
for (const key of FILTERS) if (filters[key]) qs.set(key, filters[key]);
return apiDownload(`${BASE}/${eventUuid}/export${qs.size ? `?${qs}` : ""}`, "event-leads.xlsx");
}