forked from OpenStackweb/summit-admin
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add edit popup on sponsor pages list #770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tomrndom
wants to merge
6
commits into
master
Choose a base branch
from
fix/sponsor-pages-edit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+450
−248
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
921501b
feat: add edit popup on sponsor pages list
tomrndom c9d47a7
fix: adjust initial value for file types on media modules at edit
tomrndom f13f305
fix: reset form on close for sponsor page popup
tomrndom 218d880
fix: add missing expand for page modules
tomrndom 157b2a7
fix: renaming and adjust structure to show pages
tomrndom 273e2dd
fix: update select page template test resources
tomrndom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,271 @@ | ||
| /** | ||
| * Copyright 2018 OpenStack Foundation | ||
| * 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"; | ||
|
|
||
| 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 } | ||
| )(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()); | ||
| }); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard against missing summit time zone before dereferencing.
currentSummitortime_zonecan be null during initial load; this would throw and break the list fetch. Add a safe fallback.🛠️ Suggested fix
Also applies to: 98-98
🤖 Prompt for AI Agents