diff --git a/src/actions/show-pages-actions.js b/src/actions/show-pages-actions.js index 3ca10e72c..19befc106 100644 --- a/src/actions/show-pages-actions.js +++ b/src/actions/show-pages-actions.js @@ -71,9 +71,8 @@ export const getShowPages = page, per_page: perPage, access_token: accessToken, - fields: - "code,name,id,modules_count,sponsorship_types,is_archived,apply_to_all_types", - expand: "sponsorship_types" + fields: "code,name,id,modules_count,is_archived,apply_to_all_types", + expand: "sponsorship_types,modules" }; if (hideArchived) filter.push("is_archived==0"); @@ -114,7 +113,7 @@ export const getShowPage = (pageId) => async (dispatch, getState) => { const params = { access_token: accessToken, - expand: "modules" + expand: "modules,sponsorship_types" }; return getRequest( diff --git a/src/actions/sponsor-pages-actions.js b/src/actions/sponsor-pages-actions.js index 15cd232b4..ece734cd3 100644 --- a/src/actions/sponsor-pages-actions.js +++ b/src/actions/sponsor-pages-actions.js @@ -111,53 +111,53 @@ export const getSponsorManagedPages = orderDir = DEFAULT_ORDER_DIR, hideArchived = false ) => - async (dispatch, getState) => { - const { currentSummitState, currentSponsorState } = getState(); - const { currentSummit } = currentSummitState; - const { - entity: { id: sponsorId } - } = currentSponsorState; - const accessToken = await getAccessTokenSafely(); - const summitTZ = currentSummit.time_zone.name; - const filter = []; - - dispatch(startLoading()); - - if (term) { - const escapedTerm = escapeFilterValue(term); - filter.push(`name=@${escapedTerm},code=@${escapedTerm}`); - } - - const params = { - page, - fields: "id,code,name,kind,modules_count,allowed_add_ons,assigned_type", - per_page: perPage, - access_token: accessToken - }; - - if (hideArchived) filter.push("is_archived==0"); - - if (filter.length > 0) { - params["filter[]"] = filter; - } - - // order - if (order != null && orderDir != null) { - const orderDirSign = orderDir === 1 ? "" : "-"; - params.order = `${orderDirSign}${order}`; - } - - return getRequest( - createAction(REQUEST_SPONSOR_MANAGED_PAGES), - createAction(RECEIVE_SPONSOR_MANAGED_PAGES), - `${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/managed-pages`, - snackbarErrorHandler, - { order, orderDir, page, perPage, term, hideArchived, summitTZ } - )(params)(dispatch).finally(() => { - dispatch(stopLoading()); - }); + async (dispatch, getState) => { + const { currentSummitState, currentSponsorState } = getState(); + const { currentSummit } = currentSummitState; + const { + entity: { id: sponsorId } + } = currentSponsorState; + const accessToken = await getAccessTokenSafely(); + const summitTZ = currentSummit.time_zone.name; + const filter = []; + + dispatch(startLoading()); + + if (term) { + const escapedTerm = escapeFilterValue(term); + filter.push(`name=@${escapedTerm},code=@${escapedTerm}`); + } + + const params = { + page, + fields: "id,code,name,kind,modules_count,allowed_add_ons,assigned_type", + per_page: perPage, + access_token: accessToken }; + if (hideArchived) filter.push("is_archived==0"); + + if (filter.length > 0) { + params["filter[]"] = filter; + } + + // order + if (order != null && orderDir != null) { + const orderDirSign = orderDir === 1 ? "" : "-"; + params.order = `${orderDirSign}${order}`; + } + + return getRequest( + createAction(REQUEST_SPONSOR_MANAGED_PAGES), + createAction(RECEIVE_SPONSOR_MANAGED_PAGES), + `${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/managed-pages`, + snackbarErrorHandler, + { order, orderDir, page, perPage, term, hideArchived, summitTZ } + )(params)(dispatch).finally(() => { + dispatch(stopLoading()); + }); + }; + export const saveSponsorManagedPage = (entity) => async (dispatch, getState) => { const { currentSummitState, currentSponsorState } = getState(); @@ -256,55 +256,55 @@ export const getSponsorCustomizedPages = orderDir = DEFAULT_ORDER_DIR, hideArchived = false ) => - async (dispatch, getState) => { - const { currentSummitState, currentSponsorState } = getState(); - const { currentSummit } = currentSummitState; - const { - entity: { id: sponsorId } - } = currentSponsorState; - const accessToken = await getAccessTokenSafely(); - const summitTZ = currentSummit.time_zone.name; - const filter = []; - - dispatch(startLoading()); - - if (term) { - const escapedTerm = escapeFilterValue(term); - filter.push(`name=@${escapedTerm},code=@${escapedTerm}`); - } - - const params = { - page, - fields: - "id,code,name,allowed_add_ons,is_archived,modules,allowed_add_ons.type,allowed_add_ons.name,allowed_add_ons.id", - expand: "allowed_add_ons", - per_page: perPage, - access_token: accessToken - }; - - if (hideArchived) filter.push("is_archived==0"); - - if (filter.length > 0) { - params["filter[]"] = filter; - } - - // order - if (order != null && orderDir != null) { - const orderDirSign = orderDir === 1 ? "" : "-"; - params.order = `${orderDirSign}${order}`; - } - - return getRequest( - createAction(REQUEST_SPONSOR_CUSTOMIZED_PAGES), - createAction(RECEIVE_SPONSOR_CUSTOMIZED_PAGES), - `${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/sponsor-pages`, - snackbarErrorHandler, - { order, orderDir, page, perPage, term, hideArchived, summitTZ } - )(params)(dispatch).finally(() => { - dispatch(stopLoading()); - }); + async (dispatch, getState) => { + const { currentSummitState, currentSponsorState } = getState(); + const { currentSummit } = currentSummitState; + const { + entity: { id: sponsorId } + } = currentSponsorState; + const accessToken = await getAccessTokenSafely(); + const summitTZ = currentSummit.time_zone.name; + const filter = []; + + dispatch(startLoading()); + + if (term) { + const escapedTerm = escapeFilterValue(term); + filter.push(`name=@${escapedTerm},code=@${escapedTerm}`); + } + + const params = { + page, + fields: + "id,code,name,allowed_add_ons,is_archived,modules,allowed_add_ons.type,allowed_add_ons.name,allowed_add_ons.id", + expand: "allowed_add_ons,modules", + per_page: perPage, + access_token: accessToken }; + if (hideArchived) filter.push("is_archived==0"); + + if (filter.length > 0) { + params["filter[]"] = filter; + } + + // order + if (order != null && orderDir != null) { + const orderDirSign = orderDir === 1 ? "" : "-"; + params.order = `${orderDirSign}${order}`; + } + + return getRequest( + createAction(REQUEST_SPONSOR_CUSTOMIZED_PAGES), + createAction(RECEIVE_SPONSOR_CUSTOMIZED_PAGES), + `${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/sponsor-pages`, + snackbarErrorHandler, + { order, orderDir, page, perPage, term, hideArchived, summitTZ } + )(params)(dispatch).finally(() => { + dispatch(stopLoading()); + }); + }; + export const getSponsorCustomizedPage = (pageId) => async (dispatch, getState) => { const { currentSummitState, currentSponsorState } = getState(); @@ -319,7 +319,7 @@ export const getSponsorCustomizedPage = const params = { fields: "id,code,name,allowed_add_ons,is_archived,modules,allowed_add_ons.name,allowed_add_ons.id", - expand: "allowed_add_ons", + expand: "allowed_add_ons,modules", access_token: accessToken }; diff --git a/src/reducers/sponsors/show-pages-list-reducer.js b/src/reducers/sponsors/show-pages-list-reducer.js index 22a64e7b4..dc5e2f7f1 100644 --- a/src/reducers/sponsors/show-pages-list-reducer.js +++ b/src/reducers/sponsors/show-pages-list-reducer.js @@ -130,7 +130,7 @@ const showPagesListReducer = (state = DEFAULT_STATE, action) => { const sponsorshipTypeIds = pageData.apply_to_all_types ? ["all"] - : [...pageData.sponsorship_types]; + : pageData.sponsorship_types.map((st) => st.id); const currentShowPage = { ...pageData, @@ -148,7 +148,7 @@ const showPagesListReducer = (state = DEFAULT_STATE, action) => { sponsorship_types: sponsorshipTypeIds }; - return { ...state, currentShowPage }; + return { ...state, currentShowPage }; } case SHOW_PAGE_DELETED: { const { pageId } = payload; diff --git a/src/reducers/sponsors/sponsor-page-pages-list-reducer.js b/src/reducers/sponsors/sponsor-page-pages-list-reducer.js index 3ad921478..fa0b19cca 100644 --- a/src/reducers/sponsors/sponsor-page-pages-list-reducer.js +++ b/src/reducers/sponsors/sponsor-page-pages-list-reducer.js @@ -12,6 +12,7 @@ * */ 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, @@ -24,7 +25,10 @@ import { } from "../../actions/sponsor-pages-actions"; import { SET_CURRENT_SUMMIT } from "../../actions/summit-actions"; import { RECEIVE_GLOBAL_SPONSORSHIPS } from "../../actions/sponsor-forms-actions"; -import { PAGES_MODULE_KINDS } from "../../utils/constants"; +import { + PAGE_MODULES_DOWNLOAD, + PAGES_MODULE_KINDS +} from "../../utils/constants"; const DEFAULT_PAGE = { code: "", @@ -174,7 +178,38 @@ const sponsorPagePagesListReducer = (state = DEFAULT_STATE, action) => { } case RECEIVE_SPONSOR_CUSTOMIZED_PAGE: { const customizedPage = payload.response; - return { ...state, currentEditPage: customizedPage }; + + 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; + }); + + return { ...state, currentEditPage: { ...customizedPage, modules } }; } case SPONSOR_CUSTOMIZED_PAGE_ARCHIVED: { const { pageId } = payload;