Files
cms.techvanguard.vn/utils/contentEditors/policiesConfig.js
T
Tống Thành Đạt a39c336dd4 feat(cms): enhance content editors with dynamic UI configs and validation
Implement a more flexible, configuration-driven approach for CMS editors across accreditation, admissions, and partnerships modules.
- Move UI labels, help texts, and field limits from hardcoded views to `editorUi` configurations in config files.
- Add server-side and client-side validation to prevent duplicate category tabs in accreditation and partnerships editors.
- Refactor partnership and admission views to dynamically render tabs and fields based on the provided configuration.
- Update field length constraints and default values across multiple content editors to better align with frontend requirements.
- Improve the admissions calculator editor with dynamic field configurations and default value fallbacks.
2026-04-22 18:06:03 +07:00

113 lines
3.1 KiB
JavaScript

const {
ICON_OPTIONS,
text,
date,
textarea,
icon,
url,
combobox,
object,
objectList,
stringList,
variantList,
} = require("./sharedFields");
const baseConfig = {
key: "policies",
title: "Policies Management",
subtitle: "Manage policy metadata and block-based content for the policies page",
routeBase: "/admin/policies",
apiPath: "/api/policies",
previewPath: "/policies",
dataFile: "policies",
imageType: "policies",
tabs: [
{
key: "hero",
label: "Hero",
icon: "fas fa-scale-balanced",
schema: object("hero", "Hero", [
text("badge", "Eyebrow label", { maxLength: 40 }),
icon("icon", "Hero icon", {
helpText: "Policies uses icon-only controls and does not require image upload.",
}),
text("titlePrefix", "Headline prefix", { maxLength: 50 }),
text("titleHighlight", "Headline highlight", { maxLength: 40 }),
textarea("description", "Supporting text", {
maxLength: 220,
rows: 4,
}),
]),
},
{
key: "sidebar",
label: "Sidebar",
icon: "fas fa-bars",
schema: object("sidebar", "Sidebar", [
text("heading", "Sidebar heading", { maxLength: 30 }),
text("helperText", "Helper text", { maxLength: 60 }),
text("contactLabel", "Contact link label", { maxLength: 25 }),
url("contactHref", "Contact URL", { maxLength: 255 }),
]),
},
{
key: "policies",
label: "Policies",
icon: "fas fa-file-lines",
schema: objectList(
"policies",
"Policies",
[
text("navLabel", "Sidebar label", { maxLength: 40 }),
text("title", "Policy title", { maxLength: 70 }),
date("effectiveDate", "Effective date", {
helpText: "Pick a calendar date. It will be saved in the standard policy display format.",
}),
textarea("intro", "Intro text", { maxLength: 260, rows: 4 }),
],
{
itemLabel: "Policy",
sortable: true,
itemTitleKey: "title",
itemSubtitleKey: "effectiveDate",
emptyText: "No policies yet.",
itemActions: [
{
label: "Edit Content",
icon: "fas fa-pen-to-square",
hrefTemplate: "/admin/policies/{id}/section",
className: "btn btn-outline-primary btn-sm",
},
],
},
),
},
],
};
function createPoliciesSectionEditorConfig(policy, allPolicies = []) {
const policyOptions = allPolicies
.filter((item) => item.id && item.id !== policy.id)
.map((item) => ({
value: item.id,
label: item.title || item.navLabel || item.id,
}));
return {
key: "policyContent",
title: `Policy Content: ${policy.title || policy.id}`,
subtitle: "Edit block-based policy content with realtime preview",
routeBase: `/admin/policies/${policy.id}/section`,
previewPath: "/policies",
imageType: "policies",
policyId: policy.id,
policyOptions,
iconOptions: ICON_OPTIONS,
};
}
module.exports = {
baseConfig,
createPoliciesSectionEditorConfig,
};