-
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
base: master
Are you sure you want to change the base?
Changes from all commits
1ae7562
aef8fbf
491a5b1
9e5df33
fe15898
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| /** | ||
| * 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 { | ||
| 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).then(() => { | ||
| dispatch(stopLoading()); | ||
| }); | ||
|
Comment on lines
53
to
77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure loading stops on errors (use finally). If the request rejects, ✅ Suggested fix (try/finally)- 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).then(() => {
- dispatch(stopLoading());
- });
+ try {
+ return await 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());
+ }🤖 Prompt for AI Agents |
||
| }; | ||
|
|
||
| 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).then(() => { | ||
| dispatch(stopLoading()); | ||
| }); | ||
| }; | ||
|
|
||
| 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(); | ||
|
|
||
| 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()); | ||
| }); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| 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}> | ||
| <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 | ||
| }) => { | ||
| 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 = () => { | ||
| 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; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,7 @@ import SponsorCartTab from "./sponsor-cart-tab"; | |
| import SponsorFormsManageItems from "./sponsor-forms-tab/components/manage-items/sponsor-forms-manage-items"; | ||
| import { SPONSOR_TABS } from "../../utils/constants"; | ||
| import SponsorPurchasesTab from "./sponsor-purchases-tab"; | ||
| import SponsorMediaUploadTab from "./sponsor-media-upload-tab"; | ||
|
|
||
| export const tabsToFragmentMap = [ | ||
| "general", | ||
|
|
@@ -246,8 +247,14 @@ const EditSponsorPage = (props) => { | |
| /> | ||
| </CustomTabPanel> | ||
| <CustomTabPanel value={selectedTab} index={1}> | ||
| USERS | ||
| </CustomTabPanel> | ||
| <CustomTabPanel value={selectedTab} index={2}> | ||
| <SponsorUsersListPerSponsorPage sponsor={entity} /> | ||
| </CustomTabPanel> | ||
| <CustomTabPanel value={selectedTab} index={3}> | ||
| <SponsorMediaUploadTab sponsor={entity} summitId={currentSummit.id} /> | ||
| </CustomTabPanel> | ||
|
Comment on lines
249
to
+257
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the tab-panel index mismatch (Users and Pages are swapped). The Users tab now renders a placeholder string while the Pages tab renders the users list, which is a user-visible functional mismatch. Ensure the Users tab renders 🤖 Prompt for AI Agents |
||
| <CustomTabPanel value={selectedTab} index={4}> | ||
| {isNestedFormItemRoute ? ( | ||
| <SponsorFormsManageItems match={match} /> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.