forked from UKSOURCE/cms.lams
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.
This commit is contained in:
@@ -9,6 +9,34 @@ const controller = createPageContentController({
|
||||
modelName: "AccreditationPage",
|
||||
auditAction: AUDIT_ACTIONS.UPDATE_ACCREDITATION,
|
||||
editorConfig: accreditationConfig,
|
||||
preparePayload(rawPayload) {
|
||||
const payload = JSON.parse(JSON.stringify(rawPayload || {}));
|
||||
const tabs = Array.isArray(payload?.grid?.tabs) ? payload.grid.tabs : [];
|
||||
const seenTabs = new Set();
|
||||
const duplicateTabs = [];
|
||||
|
||||
tabs.forEach((tab) => {
|
||||
const normalizedTab = String(tab || "").trim().toLowerCase();
|
||||
if (!normalizedTab) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (seenTabs.has(normalizedTab)) {
|
||||
duplicateTabs.push(String(tab || "").trim());
|
||||
return;
|
||||
}
|
||||
|
||||
seenTabs.add(normalizedTab);
|
||||
});
|
||||
|
||||
if (duplicateTabs.length > 0) {
|
||||
throw new Error(
|
||||
`Category tab already exists: ${duplicateTabs[0]}. Please use unique tab names.`,
|
||||
);
|
||||
}
|
||||
|
||||
return payload;
|
||||
},
|
||||
});
|
||||
|
||||
controller.index = async function index(req, res) {
|
||||
|
||||
Reference in New Issue
Block a user