Files
co-lite/solvway-admin-portal/app/lib/services/adminPages.ts
T
ngqileandClaude Opus 5.5 bb2c5c5db7 feat(portal): landing pages list, editor, preview and public page
Pages list and Tiptap editor (ported from babyboo) with image upload on
save, the FORM event picker, field errors at their fields, delete
confirmation, unsaved-edits guard and a draft preview. The public page
/p/<company>/<slug> renders on the server with metadata, sanitize-html,
the company's logo and accent, and the sign-up form with UTM tags.
Companies get branding; the event lead detail shows the web page and
campaign. Labels in English and Chinese.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
2026-12-02 16:30:54 +08:00

32 lines
1.4 KiB
TypeScript

import { apiDelete, apiGet, apiPost, apiPut } from "@/app/lib/clientApi";
import type { CmsPage, pageBody } from "@/app/lib/cmsPages";
export interface PageListParams {
q?: string;
page: number;
pageSize: number;
companyId?: number;
}
export async function listPages(params: PageListParams): Promise<{ items: CmsPage[]; total: number }> {
const qs = new URLSearchParams();
if (params.q) qs.set("q", params.q);
if (params.companyId) qs.set("companyId", String(params.companyId));
qs.set("page", String(Math.max(0, params.page - 1)));
qs.set("size", String(params.pageSize));
const raw = await apiGet<{ content?: CmsPage[]; totalElements?: number }>(`/api/pages?${qs.toString()}`);
const items = Array.isArray(raw?.content) ? raw.content : [];
return { items, total: typeof raw?.totalElements === "number" ? raw.totalElements : items.length };
}
export const getPage = (id: number) => apiGet<CmsPage>(`/api/pages/${id}`);
export const savePage = (id: number | undefined, body: ReturnType<typeof pageBody>) =>
id == null ? apiPost<CmsPage>("/api/pages", body) : apiPut<CmsPage>(`/api/pages/${id}`, body);
export const deletePage = (id: number) => apiDelete<unknown>(`/api/pages/${id}`);
/** Base64 without the data-URL prefix; the counter checks type (PNG, JPEG, WebP) and size (2 MB). */
export const uploadPageImage = (companyId: number | undefined, data: string) =>
apiPost<{ id: number }>("/api/pages/images", { companyId, data });