Skip to content

Commit 9e5df33

Browse files
committed
feat: sponsor media upload grids
1 parent 491a5b1 commit 9e5df33

5 files changed

Lines changed: 79 additions & 43 deletions

File tree

src/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,7 @@
24872487
"alert_info": "Here you can see the status of this Sponsor's Media Uploads. If an additional file upload is required, it must be requested from the specific page where it is needed.",
24882488
"media_upload": "media upload",
24892489
"sponsor_request": "Sponsor Specific Request",
2490+
"general_request": "General Media Request",
24902491
"add_on": "Add-on",
24912492
"max_size": "Max Size",
24922493
"format": "Format",

src/pages/sponsors/sponsor-media-upload-tab/index.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import { Box, Chip, IconButton } from "@mui/material";
1818
import ArrowUpwardIcon from "@mui/icons-material/ArrowUpward";
1919
import DownloadIcon from "@mui/icons-material/Download";
2020
import DeleteIcon from "@mui/icons-material/Delete";
21-
import EditIcon from "@mui/icons-material/Edit";
21+
import VisibilityIcon from "@mui/icons-material/Visibility";
2222
import {
23-
getSponsorMURequests,
24-
getGeneralMURequests
23+
getGeneralMURequests,
24+
getSponsorMURequests
2525
} from "../../../actions/sponsor-mu-actions";
2626
import CustomAlert from "../../../components/mui/custom-alert";
2727
import MuiTable from "../../../components/mui/table/mui-table";
@@ -102,6 +102,19 @@ const SponsorMediaUploadTab = ({
102102
const onDelete = isSponsor ? handleSponsorDelete : handleGeneralDelete;
103103
const onUpload = isSponsor ? handleSponsorUpload : handleGeneralUpload;
104104

105+
const getChipColor = (status) => {
106+
switch (status) {
107+
case SPONSOR_MEDIA_UPLOAD_STATUS.DEADLINE_ALERT:
108+
return "warning";
109+
case SPONSOR_MEDIA_UPLOAD_STATUS.DEADLINE_MISSED:
110+
return "error";
111+
case SPONSOR_MEDIA_UPLOAD_STATUS.COMPLETE:
112+
return "success";
113+
default:
114+
return "default";
115+
}
116+
};
117+
105118
return [
106119
{
107120
columnKey: "name",
@@ -131,11 +144,8 @@ const SponsorMediaUploadTab = ({
131144
sortable: true,
132145
render: (row) => (
133146
<Chip
134-
color={
135-
row.status === SPONSOR_MEDIA_UPLOAD_STATUS.PENDING
136-
? "warning"
137-
: "success"
138-
}
147+
variant="outlined"
148+
color={getChipColor(row.status)}
139149
label={row.status}
140150
/>
141151
)
@@ -148,10 +158,10 @@ const SponsorMediaUploadTab = ({
148158
render: (row) => (
149159
<IconButton
150160
size="large"
151-
disabled={!!row.file}
161+
disabled={!row.media_upload}
152162
onClick={() => onView(row)}
153163
>
154-
<EditIcon fontSize="large" />
164+
<VisibilityIcon fontSize="large" />
155165
</IconButton>
156166
)
157167
},
@@ -163,7 +173,7 @@ const SponsorMediaUploadTab = ({
163173
render: (row) => (
164174
<IconButton
165175
size="large"
166-
disabled={!!row.file}
176+
disabled={!row.media_upload}
167177
onClick={() => onDownload(row)}
168178
>
169179
<DownloadIcon fontSize="large" />
@@ -176,7 +186,7 @@ const SponsorMediaUploadTab = ({
176186
width: 80,
177187
align: "center",
178188
render: (row) => {
179-
if (row.file) {
189+
if (row.media_upload) {
180190
return (
181191
<IconButton size="large" onClick={() => onDelete(row.id)}>
182192
<DeleteIcon fontSize="large" />

src/reducers/sponsors/sponsor-page-mu-list-reducer.js

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* limitations under the License.
1212
* */
1313

14+
import moment from "moment-timezone";
1415
import { LOGOUT_USER } from "openstack-uicore-foundation/lib/security/actions";
1516
import { epochToMomentTimeZone } from "openstack-uicore-foundation/lib/utils/methods";
1617
import { SET_CURRENT_SUMMIT } from "../../actions/summit-actions";
@@ -20,6 +21,11 @@ import {
2021
REQUEST_GENERAL_MEDIA_UPLOADS,
2122
REQUEST_SPONSOR_MEDIA_UPLOADS
2223
} from "../../actions/sponsor-mu-actions";
24+
import { bytesToMb } from "../../utils/methods";
25+
import {
26+
DEADLINE_ALERT_DAYS,
27+
SPONSOR_MEDIA_UPLOAD_STATUS
28+
} from "../../utils/constants";
2329

2430
const DEFAULT_STATE = {
2531
sponsorRequests: {
@@ -43,6 +49,39 @@ const DEFAULT_STATE = {
4349
summitTZ: ""
4450
};
4551

52+
const mapMediaObject = (mediaObject, summitTZ) => {
53+
const deadline = mediaObject.upload_deadline
54+
? epochToMomentTimeZone(mediaObject.upload_deadline, summitTZ)?.format(
55+
"YYYY/MM/DD"
56+
)
57+
: "N/A";
58+
59+
let status = SPONSOR_MEDIA_UPLOAD_STATUS.COMPLETE;
60+
if (!mediaObject.media_upload) {
61+
if (mediaObject.upload_deadline < moment().unix()) {
62+
status = SPONSOR_MEDIA_UPLOAD_STATUS.DEADLINE_MISSED;
63+
} else if (
64+
mediaObject.upload_deadline <
65+
moment().add(DEADLINE_ALERT_DAYS, "days").unix()
66+
) {
67+
status = SPONSOR_MEDIA_UPLOAD_STATUS.DEADLINE_ALERT;
68+
} else {
69+
status = SPONSOR_MEDIA_UPLOAD_STATUS.PENDING;
70+
}
71+
}
72+
73+
return {
74+
id: mediaObject.id,
75+
name: mediaObject.name,
76+
add_on: mediaObject.add_ons.map((a) => a.name).join(", "),
77+
max_size: `${bytesToMb(mediaObject.max_file_size)} MB`,
78+
format: mediaObject.file_type?.allowed_extensions || "N/A",
79+
media_upload: mediaObject.media_upload,
80+
deadline,
81+
status
82+
};
83+
};
84+
4685
const sponsorPageMUListReducer = (state = DEFAULT_STATE, action) => {
4786
const { type, payload } = action;
4887

@@ -73,21 +112,9 @@ const sponsorPageMUListReducer = (state = DEFAULT_STATE, action) => {
73112
last_page: lastPage
74113
} = payload.response;
75114

76-
const requests = payload.response.data.map((a) => {
77-
const expiresAt = a.expires_at
78-
? epochToMomentTimeZone(a.expires_at, state.summitTZ)?.format(
79-
"YYYY/MM/DD"
80-
)
81-
: "N/A";
82-
83-
return {
84-
id: a.id,
85-
code: a.code,
86-
name: a.name,
87-
items_count: a.items_count,
88-
expires_at: expiresAt
89-
};
90-
});
115+
const requests = payload.response.data.map((a) =>
116+
mapMediaObject(a, state.summitTZ)
117+
);
91118

92119
return {
93120
...state,
@@ -122,21 +149,9 @@ const sponsorPageMUListReducer = (state = DEFAULT_STATE, action) => {
122149
last_page: lastPage
123150
} = payload.response;
124151

125-
const requests = payload.response.data.map((a) => {
126-
const expiresAt = a.expires_at
127-
? epochToMomentTimeZone(a.expires_at, state.summitTZ)?.format(
128-
"YYYY/MM/DD"
129-
)
130-
: "N/A";
131-
132-
return {
133-
id: a.id,
134-
code: a.code,
135-
name: a.name,
136-
items_count: a.items_count,
137-
expires_at: expiresAt
138-
};
139-
});
152+
const requests = payload.response.data.map((a) =>
153+
mapMediaObject(a, state.summitTZ)
154+
);
140155

141156
return {
142157
...state,

src/utils/constants.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ export const SPONSOR_USER_ASSIGNMENT_TYPE = {
265265

266266
export const SPONSOR_MEDIA_UPLOAD_STATUS = {
267267
PENDING: "PENDING",
268-
DEADLINE: "DEADLINE ALERT",
268+
DEADLINE_ALERT: "DEADLINE ALERT",
269+
DEADLINE_MISSED: "DEADLINE MISSED",
269270
COMPLETE: "COMPLETE"
270271
};
272+
273+
// eslint-disable-next-line no-magic-numbers
274+
export const BYTES_IN_MEGABYTE = 1024 * 1024;
275+
276+
export const DEADLINE_ALERT_DAYS = 3;

src/utils/methods.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import * as Sentry from "@sentry/react";
2222
import T from "i18n-react/dist/i18n-react";
2323
import {
2424
BADGE_QR_MINIMUM_EXPECTED_FIELDS,
25+
BYTES_IN_MEGABYTE,
2526
ERROR_CODE_401,
2627
ERROR_CODE_403,
2728
ERROR_CODE_412,
@@ -530,3 +531,6 @@ export const formatBadgeQR = (code, summit) => {
530531

531532
return null;
532533
};
534+
535+
// eslint-disable-next-line no-magic-numbers
536+
export const bytesToMb = (bytes) => (bytes / BYTES_IN_MEGABYTE).toFixed(2);

0 commit comments

Comments
 (0)