Skip to content

fix: issue #44 #50

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

Merged
merged 2 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const App = () => {
<Router>
<ChallengeList path="/earn/find/challenges" />
<ChallengeDetail path={`/earn/find/challenges/:challengeId`} />
<Submission path={`/earn/find/challenges/:challengeId/submit`} />
<Submission path={`/earn/find/challenges/:challengeId/:page`} />
</Router>
);
};
Expand Down
10 changes: 10 additions & 0 deletions src/constants/index.js
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/containers/SubmissionManagement/MySubmissions/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -53,7 +53,7 @@ const MySubmissions = ({
<div styleName="left-col">
<h4 styleName="name">{challengeName}</h4>
<a
href={`${COMMUNITY_CHALLENGES_URL}/${challengeId}`}
href={`${config.URL.PLATFORM_WEBSITE}/earn/find/challenges/${challengeId}`}
styleName="back-btn"
>
&lt; Back
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/containers/SubmissionManagement/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down Expand Up @@ -108,4 +118,5 @@ export default {
put,
patch,
upload,
download,
};
8 changes: 5 additions & 3 deletions src/services/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ 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) {
return api
.get(`/submissions?${qs.stringify(filter, { encode: false })}`)
.then(util.tryThrowError)
.then((res) => res.json());
.then((res) => res);
}

export default {
Expand Down
10 changes: 10 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}