Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/actions/page-template-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ export const getPageTemplates =
orderDir = DEFAULT_ORDER_DIR,
hideArchived = false
) =>
async (dispatch) => {
async (dispatch, getState) => {
const { currentSummitState } = getState();
const { currentSummit } = currentSummitState;
const summitTZ = currentSummit.time_zone.name;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could break is currentSummit.time_zone is not loaded

const accessToken = await getAccessTokenSafely();
const filter = [];

Expand Down Expand Up @@ -93,7 +96,7 @@ export const getPageTemplates =
createAction(RECEIVE_PAGE_TEMPLATES),
`${window.SPONSOR_PAGES_API_URL}/api/v1/page-templates`,
authErrorHandler,
{ order, orderDir, page, perPage, term, hideArchived }
{ order, orderDir, page, perPage, term, hideArchived, summitTZ }
)(params)(dispatch).then(() => {
dispatch(stopLoading());
});
Expand Down
271 changes: 271 additions & 0 deletions src/actions/show-pages-actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
/**
* Copyright 2018 OpenStack Foundation
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomrndom header should be 2026.

* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* */

import {
authErrorHandler,
createAction,
getRequest,
postRequest,
putRequest,
deleteRequest,
startLoading,
stopLoading
} from "openstack-uicore-foundation/lib/utils/actions";
import T from "i18n-react/dist/i18n-react";
import moment from "moment-timezone";
import { escapeFilterValue, getAccessTokenSafely } from "../utils/methods";
import {
DEFAULT_CURRENT_PAGE,
DEFAULT_ORDER_DIR,
DEFAULT_PER_PAGE,
PAGES_MODULE_KINDS
} from "../utils/constants";
import { snackbarErrorHandler, snackbarSuccessHandler } from "./base-actions";

export const REQUEST_SHOW_PAGES = "REQUEST_SHOW_PAGES";
export const RECEIVE_SHOW_PAGES = "RECEIVE_SHOW_PAGES";

export const RECEIVE_SHOW_PAGE = "RECEIVE_SHOW_PAGE";
export const SHOW_PAGE_UPDATED = "SHOW_PAGE_UPDATED";
export const SHOW_PAGE_ADDED = "SHOW_PAGE_ADDED";
export const SHOW_PAGE_ARCHIVED = "SHOW_PAGE_ARCHIVED";
export const SHOW_PAGE_UNARCHIVED = "SHOW_PAGE_UNARCHIVED";
export const RESET_SHOW_PAGE_FORM = "RESET_SHOW_PAGE_FORM";

export const GLOBAL_PAGE_CLONED = "GLOBAL_PAGE_CLONED";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomrndom this seems a dupe constant


export const getShowPages =
(
term = "",
page = DEFAULT_CURRENT_PAGE,
perPage = DEFAULT_PER_PAGE,
order = "id",
orderDir = DEFAULT_ORDER_DIR,
hideArchived = false,
sponsorshipTypesId = []
) =>
async (dispatch, getState) => {
const { currentSummitState } = getState();
const { currentSummit } = currentSummitState;
const accessToken = await getAccessTokenSafely();
const filter = [];

dispatch(startLoading());

if (term) {
const escapedTerm = escapeFilterValue(term);
filter.push(`name=@${escapedTerm},code=@${escapedTerm}`);
}

const params = {
page,
per_page: perPage,
access_token: accessToken,
expand: "sponsorship_types"
};

if (hideArchived) filter.push("is_archived==0");

if (sponsorshipTypesId?.length > 0) {
const formattedSponsorships = sponsorshipTypesId.join("&&");
filter.push("applies_to_all_tiers==0");
filter.push(`sponsorship_type_id_not_in==${formattedSponsorships}`);
}

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_SHOW_PAGES),
createAction(RECEIVE_SHOW_PAGES),
`${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/show-pages`,
authErrorHandler,
{ order, orderDir, page, term, hideArchived }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomrndom
the reducer's REQUEST_SHOW_PAGES case destructures summitTZ from the payload ( see https://github.com/fntechgit/summit-admin/pull/770/changes#diff-30f965cccdeb18fdaffc13c197ef73cb744f1ea7334a51aab58a10fccd338ff4R55) , but getShowPages never includes summitTZ in its extra data object:

  // show-pages-actions.js line ~131
  { order, orderDir, page, term, hideArchived }  // <-- no summitTZ

So state.summitTZ will always remain null. This needs to be passed through the action and forwarded to the popup.

)(params)(dispatch).then(() => {
dispatch(stopLoading());
});
};

export const getShowPage = (pageId) => async (dispatch, getState) => {
const { currentSummitState } = getState();
const { currentSummit } = currentSummitState;
const accessToken = await getAccessTokenSafely();

dispatch(startLoading());

const params = {
access_token: accessToken,
expand: "modules,modules.file_type"
};

return getRequest(
null,
createAction(RECEIVE_SHOW_PAGE),
`${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/show-pages/${pageId}`,
authErrorHandler
)(params)(dispatch).then(() => {
dispatch(stopLoading());
});
};

const normalizeShowPage = (entity) => {
const normalizedEntity = { ...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;
});

return normalizedEntity;
};

export const saveShowPage = (entity) => async (dispatch, getState) => {
const { currentSummitState } = getState();
const { currentSummit } = currentSummitState;
const accessToken = await getAccessTokenSafely();

dispatch(startLoading());

const params = {
access_token: accessToken
};

const normalizedShowPage = normalizeShowPage(entity);

if (entity.id) {
return putRequest(
null,
createAction(SHOW_PAGE_UPDATED),
`${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/show-pages/${entity.id}`,
normalizedShowPage,
snackbarErrorHandler,
entity
)(params)(dispatch)
.then(() => {
dispatch(
snackbarSuccessHandler({
title: T.translate("general.success"),
html: T.translate("show_pages.page_saved")
})
);
})
.finally(() => {
dispatch(stopLoading());
});
}

return postRequest(
null,
createAction(SHOW_PAGE_ADDED),
`${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/show-pages`,
normalizedShowPage,
snackbarErrorHandler,
entity
)(params)(dispatch)
.then(() => {
dispatch(
snackbarSuccessHandler({
title: T.translate("general.success"),
html: T.translate("show_pages.page_created")
})
);
})
.finally(() => {
dispatch(stopLoading());
});
};

export const resetShowPageForm = () => (dispatch) => {
dispatch(createAction(RESET_SHOW_PAGE_FORM)({}));
};

export const archiveShowPage = (pageId) => async (dispatch, getState) => {
const { currentSummitState } = getState();
const { currentSummit } = currentSummitState;
const accessToken = await getAccessTokenSafely();
const params = { access_token: accessToken };

dispatch(startLoading());

return putRequest(
null,
createAction(SHOW_PAGE_ARCHIVED)({ pageId }),
`${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/show-pages/${pageId}/archive`,
null,
snackbarErrorHandler
)(params)(dispatch)
.then(() => {
dispatch(
snackbarSuccessHandler({
title: T.translate("general.success"),
html: T.translate("show_pages.archived")
})
);
})
.finally(() => {
dispatch(stopLoading());
});
};

export const unarchiveShowPage = (pageId) => async (dispatch, getState) => {
const { currentSummitState } = getState();
const { currentSummit } = currentSummitState;
const accessToken = await getAccessTokenSafely();
const params = { access_token: accessToken };

dispatch(startLoading());

return deleteRequest(
null,
createAction(SHOW_PAGE_UNARCHIVED)({ pageId }),
`${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/show-pages/${pageId}/archive`,
null,
snackbarErrorHandler
)(params)(dispatch)
.then(() => {
dispatch(
snackbarSuccessHandler({
title: T.translate("general.success"),
html: T.translate("show_pages.unarchived")
})
);
})
.finally(() => {
dispatch(stopLoading());
});
};
Loading