From 1d2d1739845f25346351a76b3f8e9920fdf3b04d Mon Sep 17 00:00:00 2001 From: yoution Date: Tue, 12 Oct 2021 13:34:22 +0800 Subject: [PATCH 1/2] fix: issue #44 --- src/App.jsx | 2 +- src/constants/index.js | 10 ++++++++++ .../SubmissionManagement/MySubmissions/index.jsx | 6 +++--- src/containers/SubmissionManagement/index.jsx | 2 +- src/services/submission.js | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 639097f..40ef5ea 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -13,7 +13,7 @@ const App = () => { - + ); }; diff --git a/src/constants/index.js b/src/constants/index.js index 896cd85..f679d1d 100644 --- a/src/constants/index.js +++ b/src/constants/index.js @@ -1,6 +1,16 @@ export const PAGINATION_PER_PAGES = [10, 20, 50]; export const PAGINATION_MAX_PAGE_DISPLAY = 3; +/* + * Challenge Status + */ +export const CHALLENGE_STATUS = { + ACTIVE: "Active", + CANCELLED: "Cancelled", + COMPLETED: "Completed", + DRAFT: "Draft", +}; + export const FILTER_BUCKETS = [ "All Active Challenges", "Open for Registration", diff --git a/src/containers/SubmissionManagement/MySubmissions/index.jsx b/src/containers/SubmissionManagement/MySubmissions/index.jsx index 807c678..7b21c7f 100644 --- a/src/containers/SubmissionManagement/MySubmissions/index.jsx +++ b/src/containers/SubmissionManagement/MySubmissions/index.jsx @@ -5,7 +5,7 @@ import { PrimaryButton } from "components/Buttons"; import SubmissionTable from "./SubmissionTable"; import LoadingIndicator from "components/LoadingIndicator"; import * as util from "../../../utils/challenge"; -import { CHALLENGES_URL, COMMUNITY_CHALLENGES_URL } from "../../../constants"; +import config from "../../../../config"; import styles from "./styles.scss"; @@ -53,7 +53,7 @@ const MySubmissions = ({

{challengeName}

< Back @@ -125,7 +125,7 @@ const MySubmissions = ({ theme={{ button: styles["add-sub-btn"], }} - to={`${CHALLENGES_URL}/${challengeId}/submit`} + to={`${config.URL.PLATFORM_WEBSITE}/earn/find/challenges/${challengeId}/submit`} > {!isDevelop || !submissions || submissions.length === 0 ? "Add Submission" diff --git a/src/containers/SubmissionManagement/index.jsx b/src/containers/SubmissionManagement/index.jsx index 6eedcf7..a582958 100644 --- a/src/containers/SubmissionManagement/index.jsx +++ b/src/containers/SubmissionManagement/index.jsx @@ -197,7 +197,7 @@ SubmissionManagement.propTypes = { }; const mapStateToProps = (state, ownProps) => { - const challenge = state.challenge.challenge; + const challenge = (state.challenge && state.challenge.challenge) || {}; const allPhases = challenge.phases || []; const submissionPhase = allPhases.find( diff --git a/src/services/submission.js b/src/services/submission.js index 539f92e..ffad5d2 100644 --- a/src/services/submission.js +++ b/src/services/submission.js @@ -44,7 +44,7 @@ function getSubmissions(filter) { return api .get(`/submissions?${qs.stringify(filter, { encode: false })}`) .then(util.tryThrowError) - .then((res) => res.json()); + .then((res) => res); } export default { From e65daf25179fa11f7434f8df8d63ee53d8d7c898 Mon Sep 17 00:00:00 2001 From: yoution Date: Tue, 12 Oct 2021 20:56:11 +0800 Subject: [PATCH 2/2] fix: issue #44 --- src/services/api.js | 11 +++++++++++ src/services/submission.js | 6 ++++-- src/utils/index.js | 10 ++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/services/api.js b/src/services/api.js index 78216bb..dc85cbd 100644 --- a/src/services/api.js +++ b/src/services/api.js @@ -25,6 +25,16 @@ async function doFetch(endpoint, options = {}, v3, baseUrl) { }); } +async function download(endpoint, baseUrl, cancellationSignal) { + const options = { + headers: { ["Content-Type"]: "application/json" }, + signal: cancellationSignal, + }; + const response = await doFetch(endpoint, options, undefined, baseUrl); + + return response; +} + async function get(endpoint, baseUrl, cancellationSignal) { const options = { headers: { ["Content-Type"]: "application/json" }, @@ -108,4 +118,5 @@ export default { put, patch, upload, + download, }; diff --git a/src/services/submission.js b/src/services/submission.js index ffad5d2..a67dd64 100644 --- a/src/services/submission.js +++ b/src/services/submission.js @@ -35,9 +35,11 @@ function deleteSubmission(submissionId) { function downloadSubmission(track, submissionId) { return api - .get(`/submissions/${submissionId}/download`) + .download(`/submissions/${submissionId}/download`) .then(util.tryThrowError) - .then((res) => res.blob()); + .then((res) => { + return res.blob(); + }); } function getSubmissions(filter) { diff --git a/src/utils/index.js b/src/utils/index.js index f8cbb73..b3fc4e1 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -169,3 +169,13 @@ export function parseTotalPrizes(s) { } if (valid) return n; } + +export function triggerDownload(fileName,blob) { + const url = window.URL.createObjectURL(new Blob([blob])); + const link = document.createElement('a'); + link.href = url; + link.setAttribute('download', fileName); + document.body.appendChild(link); + link.click(); + link.parentNode.removeChild(link); +}