import { apiGet, apiPost } from "@/app/lib/clientApi"; import type { CmsFormBody, CmsFormListItem, CmsFormSubmission, CmsFormView, SubmissionsPage } from "@/app/lib/cmsForms"; // Client calls for the Forms pages (add-cms-forms): only the portal's own /api/forms/** route // handlers, never solvway-mobile-api directly. export function listForms(): Promise { return apiGet("/api/forms"); } export function getForm(id: number | string): Promise { return apiGet(`/api/forms/${encodeURIComponent(id)}`); } export function saveForm(body: CmsFormBody): Promise { return apiPost("/api/forms", body); } export function deleteForm(id: number | string): Promise { return apiPost(`/api/forms/${encodeURIComponent(id)}/delete`); } export function listSubmissions( id: number | string, page: number, size: number, sort?: { sortBy?: string; sortDir?: "asc" | "desc" }, ): Promise { const qs = new URLSearchParams({ page: String(page), size: String(size) }); if (sort?.sortBy) { qs.set("sortBy", sort.sortBy); if (sort.sortDir) qs.set("sortDir", sort.sortDir); } return apiGet(`/api/forms/${encodeURIComponent(id)}/submissions?${qs.toString()}`); } export function getSubmission(sid: number | string): Promise { return apiGet(`/api/forms/submissions/${encodeURIComponent(sid)}`); } export function deleteSubmission(sid: number | string): Promise { return apiPost(`/api/forms/submissions/${encodeURIComponent(sid)}/delete`); }