Skip to content

fixed some issues #184

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
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
4 changes: 2 additions & 2 deletions src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ export const FILTER_CHALLENGE_TRACKS = [
"Design",
"Development",
"Data Science",
"QA",
"Quality Assurance",
];

export const FILTER_CHALLENGE_TRACK_ABBREVIATIONS = {
Design: "DES",
Development: "DEV",
"Data Science": "DS",
QA: "QA",
"Quality Assurance": "QA",
};

export const CHALLENGE_SORT_BY = {
Expand Down
20 changes: 11 additions & 9 deletions src/containers/Challenges/Listing/ChallengeItem/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import * as utils from "../../../../utils";
import ProgressTooltip from "../tooltips/ProgressTooltip";
import PlacementsTooltip from "../tooltips/PlacementsTooltip";
import TagsMoreTooltip from "../tooltips/TagsMoreTooltip";
import { CHALLENGES_URL } from 'constants';
import { Link } from '@reach/router';

import "./styles.scss";

Expand All @@ -25,7 +27,7 @@ const ChallengeItem = ({ challenge, onClickTag, onClickTrack, isLoggedIn }) => {
challenge.prizeSets
);

let submissionLink = `/earn/find/challenges/${challenge.id}`;
let submissionLink = `${CHALLENGES_URL}/${challenge.id}`;
if (isLoggedIn && challenge.numOfSubmissions > 0) {
submissionLink += "?tab=submissions";
}
Expand All @@ -43,11 +45,11 @@ const ChallengeItem = ({ challenge, onClickTag, onClickTrack, isLoggedIn }) => {
<div styleName="info">
<div styleName="name-container">
<h6 styleName="name">
<a
href={`/earn/find/challenges/${challenge.id}`} // eslint-disable-line no-undef
<Link
to={`${CHALLENGES_URL}/${challenge.id}`}
>
{challenge.name}
</a>
</Link>
</h6>
<PhaseEndDate
challenge={challenge}
Expand All @@ -70,14 +72,14 @@ const ChallengeItem = ({ challenge, onClickTag, onClickTrack, isLoggedIn }) => {
/>
</div>
<div styleName="nums">
<a
href={`${process.env.URL.BASE}/challenges/${challenge.id}?tab=registrants`} // eslint-disable-line no-undef
<Link
to={`${CHALLENGES_URL}/${challenge.id}?tab=registrants`}
>
<NumRegistrants numOfRegistrants={challenge.numOfRegistrants} />
</a>
<a href={submissionLink}>
</Link>
<Link to={submissionLink}>
<NumSubmissions numOfSubmissions={challenge.numOfSubmissions} />
</a>
</Link>
</div>
</div>
<div styleName="prize">
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Challenges/Listing/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const Listing = ({
}}
onClickTrack={(track) => {
const filterChange = {
tracks: [track.replace("Quality Assurance", "QA")],
tracks: [track],
page: 1,
};
updateFilter(filterChange);
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Filter/ChallengeFilter/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const ChallengeFilter = ({
updateFilter(filterChange);
}}
/>
<span>{track}</span>
<span>{track.replace('Quality Assurance', 'QA')}</span>
</span>
))}
</div>
Expand Down
50 changes: 22 additions & 28 deletions src/reducers/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@ function onGetChallengesInit(state) {
return { ...state, loadingChallenges: true, loadingChallengesError: null };
}

function onGetChallengesDone(state, { payload }) {
const error = payload;
if (error.name === "AbortError") {
return {
...state,
loadingChallenges: false,
loadingChallengesError: null,
};
function onGetChallengesDone(state, { error, payload }) {
if (error) {
return onGetChallengesFailure(state, { payload });
}

return {
Expand All @@ -39,32 +34,31 @@ function onGetChallengesDone(state, { payload }) {
};
}

// function onGetChallengesFailure(state, { payload }) {
// const error = payload;
// if (error.name === "AbortError") {
// return {
// ...state,
// loadingChallenges: false,
// loadingChallengesError: null,
// };
// }
function onGetChallengesFailure(state, { payload }) {
const error = payload;
if (error.name === "AbortError") {
return {
...state,
loadingChallenges: false,
loadingChallengesError: null,
};
}

// return {
// ...state,
// loadingChallenges: false,
// loadingChallengesError: payload,
// challenges: [],
// total: 0,
// openForRegistrationCount: 0,
// initialized: true,
// };
// }
return {
...state,
loadingChallenges: false,
loadingChallengesError: payload,
challenges: [],
total: 0,
openForRegistrationCount: 0,
initialized: true,
};
}

export default handleActions(
{
GET_CHALLENGE_INIT: onGetChallengesInit,
GET_CHALLENGES_DONE: onGetChallengesDone,
// GET_CHALLENGES_FAILURE: onGetChallengesFailure,
},
defaultState
);
34 changes: 25 additions & 9 deletions src/utils/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,49 @@ import Joi from "joi";
import { initialChallengeFilter } from "../reducers/filter";

Joi.optionalId = () => Joi.string().uuid();
Joi.page = () => Joi.number().integer().min(1);

Joi.page = () =>
Joi.alternatives()
.try(
Joi.number()
.min(1),
Joi.any().custom(() => 1)
);

Joi.perPage = () =>
Joi.number()
.integer()
.min(1)
.max(100)
.valid(...constants.PAGINATION_PER_PAGES);
Joi.alternatives()
.try(
Joi.number()
.integer()
.min(1)
.max(100)
.valid(...constants.PAGINATION_PER_PAGES),
Joi.any().custom(() => constants.PAGINATION_PER_PAGES[0])
);

Joi.bucket = () =>
Joi.string().custom((param) =>
constants.FILTER_BUCKETS.find(
(bucket) => param && param.toLowerCase() === bucket.toLowerCase()
)
) || null
);

Joi.track = () =>
Joi.string().custom((param) =>
_.findKey(
constants.FILTER_CHALLENGE_TRACK_ABBREVIATIONS,
(trackAbbreviation) =>
param && param.toLowerCase() === trackAbbreviation.toLowerCase()
)
) || null
);

Joi.type = () =>
Joi.string().custom((param) =>
_.findKey(
constants.FILTER_CHALLENGE_TYPE_ABBREVIATIONS,
(typeAbbreviation) =>
param && param.toLowerCase() === typeAbbreviation.toLowerCase()
)
) || null
);

export function getCurrencySymbol(prizeSets) {
Expand Down Expand Up @@ -65,6 +80,7 @@ export function getCheckpointPrizes(prizeSets) {
*/
export function createChallengeFilter(params) {
const schema = createChallengeFilter.schema;

const normalized = Joi.attempt(
params,
schema,
Expand Down
3 changes: 2 additions & 1 deletion src/utils/lifeCycle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import store from "../store";
import action from "../actions/initApp";
import * as utils from "../utils";
import { CHALLENGES_URL } from '../constants';

export default function appInit() {
let initialQuery;
Expand All @@ -17,7 +18,7 @@ export default function appInit() {
async function mount() {
try {
if (firstMounted) {
if (initialQuery && urlPath === "/earn/find/challenges") {
if (initialQuery && urlPath === CHALLENGES_URL) {
const params = utils.url.parseUrlQuery(initialQuery);
const filter = utils.challenge.createChallengeFilter(params);
store.dispatch(action.initApp(filter));
Expand Down