From 5aa44f9bc3c2725c6588759fca20619461e98324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Fri, 15 May 2026 09:56:15 -0300 Subject: [PATCH] fix: use denormalize function for modules for sponsor managed pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomás Castillo --- src/actions/sponsor-pages-actions.js | 27 +------- .../sponsor-page-pages-list-reducer.js | 61 ++++--------------- 2 files changed, 14 insertions(+), 74 deletions(-) diff --git a/src/actions/sponsor-pages-actions.js b/src/actions/sponsor-pages-actions.js index 7ce4ec5ba..b4778ae66 100644 --- a/src/actions/sponsor-pages-actions.js +++ b/src/actions/sponsor-pages-actions.js @@ -22,7 +22,6 @@ import { escapeFilterValue } from "openstack-uicore-foundation/lib/utils/actions"; import T from "i18n-react/dist/i18n-react"; -import moment from "moment-timezone"; import { getAccessTokenSafely, normalizeSelectAllField @@ -31,8 +30,7 @@ import { snackbarErrorHandler, snackbarSuccessHandler } from "./base-actions"; import { DEFAULT_CURRENT_PAGE, DEFAULT_ORDER_DIR, - DEFAULT_PER_PAGE, - PAGES_MODULE_KINDS + DEFAULT_PER_PAGE } from "../utils/constants"; import { normalizePageTemplateModules } from "../utils/page-template"; @@ -309,28 +307,7 @@ const normalizeSponsorManagedPageToCustomize = (entity) => { ) }; - normalizedEntity.modules = entity.modules.map((module) => { - const normalizedModule = { ...module }; - - if (module.kind === PAGES_MODULE_KINDS.MEDIA && module.upload_deadline) { - normalizedModule.upload_deadline = moment - .utc(module.upload_deadline) - .unix(); - } - - if (module.kind === PAGES_MODULE_KINDS.MEDIA && module.file_type_id) { - normalizedModule.file_type_id = - module.file_type_id?.value || module.file_type_id; - } - - if (module.kind === PAGES_MODULE_KINDS.DOCUMENT && module.file) { - normalizedModule.file = module.file[0] || null; - } - - delete normalizedModule._tempId; - - return normalizedModule; - }); + normalizedEntity.modules = normalizePageTemplateModules(entity.modules); delete normalizedEntity.page_ptr_id; delete normalizedEntity.sponsorship_types; diff --git a/src/reducers/sponsors/sponsor-page-pages-list-reducer.js b/src/reducers/sponsors/sponsor-page-pages-list-reducer.js index edc6ae08e..4efbfc29f 100644 --- a/src/reducers/sponsors/sponsor-page-pages-list-reducer.js +++ b/src/reducers/sponsors/sponsor-page-pages-list-reducer.js @@ -12,7 +12,6 @@ * */ import { LOGOUT_USER } from "openstack-uicore-foundation/lib/security/actions"; -import { epochToMomentTimeZone } from "openstack-uicore-foundation/lib/utils/methods"; import { REQUEST_SPONSOR_MANAGED_PAGES, RECEIVE_SPONSOR_MANAGED_PAGES, @@ -26,10 +25,8 @@ import { } from "../../actions/sponsor-pages-actions"; import { SET_CURRENT_SUMMIT } from "../../actions/summit-actions"; import { RECEIVE_GLOBAL_SPONSORSHIPS } from "../../actions/sponsor-forms-actions"; -import { - PAGE_MODULES_DOWNLOAD, - PAGES_MODULE_KINDS -} from "../../utils/constants"; +import { PAGES_MODULE_KINDS } from "../../utils/constants"; +import { denormalizePageModules } from "../../utils/page-template"; const DEFAULT_PAGE = { code: "", @@ -180,54 +177,20 @@ const sponsorPagePagesListReducer = (state = DEFAULT_STATE, action) => { case RECEIVE_SPONSOR_MANAGED_PAGE: { const editPage = payload.response; - const currentEditPage = { - ...editPage, - modules: editPage.modules.map((m) => ({ - ...m, - ...(m.upload_deadline - ? { - upload_deadline: epochToMomentTimeZone( - m.upload_deadline, - state.summitTZ || "UTC" - ) - } - : {}) - })) - }; - return { ...state, currentEditPage }; + const modules = denormalizePageModules( + editPage.modules, + state.summitTZ || "UTC" + ); + + return { ...state, currentEditPage: { ...editPage, modules } }; } case RECEIVE_SPONSOR_CUSTOMIZED_PAGE: { const customizedPage = payload.response; - const modules = customizedPage.modules.map((module) => { - const tmpModule = { - ...module, - ...(module.upload_deadline - ? { - upload_deadline: epochToMomentTimeZone( - module.upload_deadline, - state.summitTZ || "UTC" - ) - } - : {}) - }; - - if (module.kind === PAGES_MODULE_KINDS.DOCUMENT) { - if (module.file) { - tmpModule.file = [ - { - ...module.file, - file_path: module.file.storage_key, - public_url: module.file.file_url - } - ]; - tmpModule.type = PAGE_MODULES_DOWNLOAD.FILE; - } else { - tmpModule.type = PAGE_MODULES_DOWNLOAD.URL; - } - } - return tmpModule; - }); + const modules = denormalizePageModules( + customizedPage.modules, + state.summitTZ || "UTC" + ); return { ...state, currentEditPage: { ...customizedPage, modules } }; }