forked from OpenStackweb/summit-admin
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: sponsor media upload tab #783
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
santipalenque
wants to merge
7
commits into
master
Choose a base branch
from
feature/sponsor-media-upload-tab
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.
+917
−5
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
27125bd
feat: sponsor media upload tab - WIP
santipalenque dbbeb0c
feat: build grid - WIP
santipalenque d0b0994
feat: managed requests - WIP
santipalenque 8180d4a
feat: sponsor media upload grids
santipalenque 11afe75
feat: upload media upload file
santipalenque 0897cc3
fix: pr feedback
santipalenque 6feff0e
fix: update headers
santipalenque 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,176 @@ | ||
| /** | ||
| * Copyright 2026 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 { | ||
| createAction, | ||
| getRequest, | ||
| putRequest, | ||
| deleteRequest, | ||
| startLoading, | ||
| stopLoading | ||
| } from "openstack-uicore-foundation/lib/utils/actions"; | ||
| import { getAccessTokenSafely } from "../utils/methods"; | ||
| import { | ||
| DEFAULT_CURRENT_PAGE, | ||
| DEFAULT_ORDER_DIR, | ||
| DEFAULT_PER_PAGE | ||
| } from "../utils/constants"; | ||
| import { snackbarErrorHandler } from "./base-actions"; | ||
|
|
||
| export const REQUEST_SPONSOR_MEDIA_UPLOADS = "REQUEST_SPONSOR_MEDIA_UPLOADS"; | ||
| export const RECEIVE_SPONSOR_MEDIA_UPLOADS = "RECEIVE_SPONSOR_MEDIA_UPLOADS"; | ||
| export const REQUEST_GENERAL_MEDIA_UPLOADS = "REQUEST_GENERAL_MEDIA_UPLOADS"; | ||
| export const RECEIVE_GENERAL_MEDIA_UPLOADS = "RECEIVE_GENERAL_MEDIA_UPLOADS"; | ||
| export const SPONSOR_MEDIA_UPLOAD_FILE_UPLOADED = | ||
| "SPONSOR_MEDIA_UPLOAD_FILE_UPLOADED"; | ||
| export const SPONSOR_MEDIA_UPLOAD_FILE_DELETED = | ||
| "SPONSOR_MEDIA_UPLOAD_FILE_DELETED"; | ||
|
|
||
| export const getSponsorMURequests = | ||
| ( | ||
| currentPage = DEFAULT_CURRENT_PAGE, | ||
| perPage = DEFAULT_PER_PAGE, | ||
| order = "id", | ||
| orderDir = DEFAULT_ORDER_DIR | ||
| ) => | ||
| async (dispatch, getState) => { | ||
| const { currentSummitState, currentSponsorState } = getState(); | ||
| const { currentSummit } = currentSummitState; | ||
| const summitTZ = currentSummit.time_zone.name; | ||
| const { entity: sponsor } = currentSponsorState; | ||
| const accessToken = await getAccessTokenSafely(); | ||
|
|
||
| dispatch(startLoading()); | ||
|
|
||
| const params = { | ||
| page: currentPage, | ||
| // fields: "id,name,max_file_size,media_upload,file_type", | ||
| // relations: "media_upload,file_type", | ||
| per_page: perPage, | ||
| access_token: accessToken | ||
| }; | ||
|
|
||
| // order | ||
| if (order != null && orderDir != null) { | ||
| const orderDirSign = orderDir === 1 ? "" : "-"; | ||
| params.order = `${orderDirSign}${order}`; | ||
| } | ||
|
|
||
| return getRequest( | ||
| createAction(REQUEST_SPONSOR_MEDIA_UPLOADS), | ||
| createAction(RECEIVE_SPONSOR_MEDIA_UPLOADS), | ||
| `${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsor.id}/custom-media-request-modules`, | ||
| snackbarErrorHandler, | ||
| { order, orderDir, currentPage, perPage, summitTZ } | ||
| )(params)(dispatch).finally(() => { | ||
| dispatch(stopLoading()); | ||
| }); | ||
| }; | ||
|
|
||
| export const getGeneralMURequests = | ||
| ( | ||
| currentPage = DEFAULT_CURRENT_PAGE, | ||
| perPage = DEFAULT_PER_PAGE, | ||
| order = "id", | ||
| orderDir = DEFAULT_ORDER_DIR | ||
| ) => | ||
| async (dispatch, getState) => { | ||
| const { currentSummitState, currentSponsorState } = getState(); | ||
| const { currentSummit } = currentSummitState; | ||
| const summitTZ = currentSummit.time_zone.name; | ||
| const { entity: sponsor } = currentSponsorState; | ||
| const accessToken = await getAccessTokenSafely(); | ||
|
|
||
| dispatch(startLoading()); | ||
|
|
||
| const params = { | ||
| page: currentPage, | ||
| // fields: "id,name,max_file_size,media_upload,file_type", | ||
| expand: "media_upload,file_type", | ||
| per_page: perPage, | ||
| access_token: accessToken | ||
| }; | ||
|
|
||
| // order | ||
| if (order != null && orderDir != null) { | ||
| const orderDirSign = orderDir === 1 ? "" : "-"; | ||
| params.order = `${orderDirSign}${order}`; | ||
| } | ||
|
|
||
| return getRequest( | ||
| createAction(REQUEST_GENERAL_MEDIA_UPLOADS), | ||
| createAction(RECEIVE_GENERAL_MEDIA_UPLOADS), | ||
| `${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsor.id}/managed-media-request-modules`, | ||
| snackbarErrorHandler, | ||
| { order, orderDir, currentPage, perPage, summitTZ } | ||
| )(params)(dispatch).finally(() => { | ||
| dispatch(stopLoading()); | ||
santipalenque marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| }; | ||
|
|
||
| export const uploadFileForSponsorMU = | ||
| (pageId, moduleId, fileObj) => async (dispatch, getState) => { | ||
| const { currentSummitState, currentSponsorState } = getState(); | ||
| const { currentSummit } = currentSummitState; | ||
| const { entity: sponsor } = currentSponsorState; | ||
| const accessToken = await getAccessTokenSafely(); | ||
|
|
||
| dispatch(startLoading()); | ||
|
|
||
| const params = { | ||
| access_token: accessToken | ||
| }; | ||
|
|
||
| return putRequest( | ||
| null, | ||
| createAction("DUMMY_ACTION"), | ||
| `${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsor.id}/available-pages/${pageId}/modules/${moduleId}/file`, | ||
| fileObj, | ||
| snackbarErrorHandler | ||
| )(params)(dispatch) | ||
| .then(({ response }) => { | ||
| dispatch( | ||
| createAction(SPONSOR_MEDIA_UPLOAD_FILE_UPLOADED)({ | ||
| ...response, | ||
| moduleId | ||
| }) | ||
| ); | ||
| }) | ||
| .finally(() => { | ||
| dispatch(stopLoading()); | ||
| }); | ||
| }; | ||
|
|
||
| export const removeFileForSponsorMU = | ||
| (pageId, moduleId) => async (dispatch, getState) => { | ||
| const { currentSummitState, currentSponsorState } = getState(); | ||
| const { currentSummit } = currentSummitState; | ||
| const { entity: sponsor } = currentSponsorState; | ||
| const accessToken = await getAccessTokenSafely(); | ||
|
|
||
| dispatch(startLoading()); | ||
|
|
||
| const params = { | ||
| access_token: accessToken | ||
| }; | ||
|
|
||
| return deleteRequest( | ||
| null, | ||
| createAction(SPONSOR_MEDIA_UPLOAD_FILE_DELETED)({ moduleId }), | ||
| `${window.SPONSOR_PAGES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsor.id}/available-pages/${pageId}/modules/${moduleId}/file`, | ||
| null, | ||
| snackbarErrorHandler | ||
| )(params)(dispatch).finally(() => { | ||
| dispatch(stopLoading()); | ||
santipalenque marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| }; | ||
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,180 @@ | ||
| /** | ||
| * Copyright 2026 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 React, { useState } from "react"; | ||
| import { | ||
| Box, | ||
| Button, | ||
| Dialog, | ||
| DialogContent, | ||
| DialogTitle, | ||
| Divider, | ||
| IconButton, | ||
| Typography | ||
| } from "@mui/material"; | ||
| import PropTypes from "prop-types"; | ||
| import UploadInputV2 from "openstack-uicore-foundation/lib/components/inputs/upload-input-v2"; | ||
| import T from "i18n-react/dist/i18n-react"; | ||
| import CloseIcon from "@mui/icons-material/Close"; | ||
| import NoteAddIcon from "@mui/icons-material/NoteAdd"; | ||
| import DeleteIcon from "@mui/icons-material/Delete"; | ||
| import CheckCircleIcon from "@mui/icons-material/CheckCircle"; | ||
| import DialogActions from "@mui/material/DialogActions"; | ||
|
|
||
| const MAX_PAGE_MODULE_UPLOAD_QTY = 1; | ||
|
|
||
| const CurrentFile = ({ file, onRemove }) => ( | ||
| <Box sx={{ display: "flex", flexDirection: "row" }}> | ||
| <Box | ||
| sx={{ | ||
| display: "flex", | ||
| alignItems: "center", | ||
| justifyContent: "center", | ||
| width: 40 | ||
| }} | ||
| > | ||
| <NoteAddIcon sx={{ mr: 1 }} color="primary" /> | ||
| </Box> | ||
| <Box sx={{ flexGrow: 1 }}> | ||
| <Typography variant="body2" sx={{ mb: 1 }}> | ||
| {file.filename} | ||
| </Typography> | ||
| <Typography variant="body2" sx={{ color: "text.secondary" }}> | ||
| {file.size} {T.translate("upload_input.complete")} | ||
| </Typography> | ||
| </Box> | ||
| <IconButton aria-label="delete" onClick={onRemove}> | ||
santipalenque marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <DeleteIcon /> | ||
| </IconButton> | ||
| <Box | ||
| sx={{ | ||
| display: "flex", | ||
| alignItems: "center", | ||
| justifyContent: "center", | ||
| width: 40 | ||
| }} | ||
| > | ||
| <CheckCircleIcon color="success" sx={{ ml: 1 }} /> | ||
| </Box> | ||
| </Box> | ||
| ); | ||
|
|
||
| const UploadDialog = ({ | ||
| name, | ||
| value, | ||
| open, | ||
| fileMeta, | ||
| maxFiles = MAX_PAGE_MODULE_UPLOAD_QTY, | ||
| onClose, | ||
| onUpload, | ||
| onRemove | ||
santipalenque marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) => { | ||
| const [uploadedFile, setUploadedFile] = useState(null); | ||
|
|
||
| const mediaType = { | ||
| id: name, | ||
| max_size: fileMeta.max_file_size, | ||
| max_uploads_qty: maxFiles, | ||
| type: { | ||
| allowed_extensions: fileMeta?.allowed_extensions?.split(",") || [] | ||
| } | ||
| }; | ||
|
|
||
| const handleUpload = () => { | ||
| onUpload(uploadedFile); | ||
| }; | ||
|
|
||
| const handleRemove = () => { | ||
| if (onRemove) { | ||
| onRemove(); | ||
| } | ||
| }; | ||
|
|
||
| const canAddMore = () => (value?.length || 0) < maxFiles; | ||
|
|
||
| const getInputValue = () => | ||
| value?.length > 0 | ||
| ? value.map((file) => ({ | ||
| ...file, | ||
| filename: | ||
| file.file_name ?? file.filename ?? file.file_path ?? file.file_url | ||
| })) | ||
| : []; | ||
|
|
||
| return ( | ||
| <Dialog open={open} onClose={onClose} maxWidth="sm" fullWidth> | ||
| <DialogTitle> | ||
| {T.translate("edit_sponsor.mu_tab.upload_input.upload_file")} | ||
| </DialogTitle> | ||
| <IconButton | ||
| aria-label="close" | ||
| onClick={onClose} | ||
| sx={(theme) => ({ | ||
| position: "absolute", | ||
| right: 8, | ||
| top: 8, | ||
| color: theme.palette.grey[500] | ||
| })} | ||
| > | ||
| <CloseIcon /> | ||
| </IconButton> | ||
| <Divider /> | ||
| <DialogContent> | ||
| <Typography variant="body1" sx={{ mb: 2 }}> | ||
| {fileMeta.name} | ||
| </Typography> | ||
| <Typography variant="body2" sx={{ mb: 2, color: "text.secondary" }}> | ||
| {fileMeta.description} | ||
| </Typography> | ||
| {value ? ( | ||
| <> | ||
| <Divider sx={{ marginLeft: -2, marginRight: -2, mb: 2 }} /> | ||
| <CurrentFile file={value} onRemove={handleRemove} /> | ||
| </> | ||
| ) : ( | ||
| <UploadInputV2 | ||
| id={`media_upload_${name}`} | ||
| name={name} | ||
| onUploadComplete={setUploadedFile} | ||
| value={getInputValue()} | ||
| mediaType={mediaType} | ||
| onRemove={() => setUploadedFile(null)} | ||
| postUrl={`${window.FILE_UPLOAD_API_BASE_URL}/api/v1/files/upload`} | ||
| djsConfig={{ withCredentials: true }} | ||
| maxFiles={maxFiles} | ||
| canAdd={canAddMore()} | ||
| parallelChunkUploads | ||
| /> | ||
| )} | ||
| </DialogContent> | ||
| <DialogActions> | ||
| <Button | ||
| onClick={handleUpload} | ||
| fullWidth | ||
| disabled={!uploadedFile} | ||
| variant="contained" | ||
| > | ||
| {T.translate("edit_sponsor.mu_tab.upload_input.upload_file")} | ||
| </Button> | ||
| </DialogActions> | ||
| </Dialog> | ||
| ); | ||
| }; | ||
|
|
||
| UploadDialog.propTypes = { | ||
| open: PropTypes.bool.isRequired, | ||
| name: PropTypes.string.isRequired, | ||
| onClose: PropTypes.func.isRequired | ||
| }; | ||
|
|
||
| export default UploadDialog; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.