Skip to content

Commit 56ddf82

Browse files
[Bug Bash] Challenges bug bash - One more ticket (#185)
1 parent 3d14542 commit 56ddf82

File tree

9 files changed

+82
-55
lines changed

9 files changed

+82
-55
lines changed

src/components/challenge-detail/Header/ChallengeTags.jsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import { COMPETITION_TRACKS } from "utils/tc";
2626
import VerifiedTag from "components/challenge-listing/VerifiedTag";
2727
import MatchScore from "components/challenge-listing/ChallengeCard/MatchScore";
2828
import { calculateScore } from "../../../utils/challenge-listing/helper";
29+
import * as urlUtil from "utils/url";
30+
import * as constants from "constants";
2931
import "./style.module.scss";
3032

3133
export default function ChallengeTags(props) {
@@ -75,6 +77,19 @@ export default function ChallengeTags(props) {
7577

7678
const tags = technPlatforms.filter((tag) => !matchSkills.includes(tag));
7779

80+
const filterByChallengeType = urlUtil.buildQueryString({
81+
bucket: constants.FILTER_BUCKETS[1],
82+
tracks: _.values(constants.FILTER_CHALLENGE_TRACK_ABBREVIATIONS),
83+
page: 1,
84+
});
85+
86+
const filterByTag = urlUtil.buildQueryString({
87+
bucket: constants.FILTER_BUCKETS[1],
88+
tracks: _.values(constants.FILTER_CHALLENGE_TRACK_ABBREVIATIONS),
89+
page: 1,
90+
types: _.values(constants.FILTER_CHALLENGE_TYPE_ABBREVIATIONS),
91+
});
92+
7893
return (
7994
<div>
8095
{challengeType && (
@@ -84,7 +99,7 @@ export default function ChallengeTags(props) {
8499
setChallengeListingFilter({ types: [challengeType.name] })
85100
)
86101
}
87-
to={`${challengesUrl}?types[]=${encodeURIComponent(
102+
to={`${challengesUrl}${filterByChallengeType}&types[]=${encodeURIComponent(
88103
challengeType.abbreviation
89104
)}`}
90105
>
@@ -112,7 +127,7 @@ export default function ChallengeTags(props) {
112127
onClick={() =>
113128
setImmediate(() => setChallengeListingFilter({ tags: [tag] }))
114129
}
115-
to={`${challengesUrl}?tags[]=${encodeURIComponent(tag)}`}
130+
to={`${challengesUrl}${filterByTag}&tags[]=${encodeURIComponent(tag)}`}
116131
>
117132
{tag}
118133
</Tag>

src/constants/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ export const FILTER_CHALLENGE_TRACKS = [
2929
"Design",
3030
"Development",
3131
"Data Science",
32-
"QA",
32+
"Quality Assurance",
3333
];
3434

3535
export const FILTER_CHALLENGE_TRACK_ABBREVIATIONS = {
3636
Design: "DES",
3737
Development: "DEV",
3838
"Data Science": "DS",
39-
QA: "QA",
39+
"Quality Assurance": "QA",
4040
};
4141

4242
export const CHALLENGE_SORT_BY = {

src/containers/Challenges/Listing/ChallengeItem/index.jsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import * as utils from "../../../../utils";
1212
import ProgressTooltip from "../tooltips/ProgressTooltip";
1313
import PlacementsTooltip from "../tooltips/PlacementsTooltip";
1414
import TagsMoreTooltip from "../tooltips/TagsMoreTooltip";
15+
import { CHALLENGES_URL } from 'constants';
16+
import { Link } from '@reach/router';
1517

1618
import "./styles.scss";
1719

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

28-
let submissionLink = `/earn/find/challenges/${challenge.id}`;
30+
let submissionLink = `${CHALLENGES_URL}/${challenge.id}`;
2931
if (isLoggedIn && challenge.numOfSubmissions > 0) {
3032
submissionLink += "?tab=submissions";
3133
}
@@ -43,11 +45,11 @@ const ChallengeItem = ({ challenge, onClickTag, onClickTrack, isLoggedIn }) => {
4345
<div styleName="info">
4446
<div styleName="name-container">
4547
<h6 styleName="name">
46-
<a
47-
href={`/earn/find/challenges/${challenge.id}`} // eslint-disable-line no-undef
48+
<Link
49+
to={`${CHALLENGES_URL}/${challenge.id}`}
4850
>
4951
{challenge.name}
50-
</a>
52+
</Link>
5153
</h6>
5254
<PhaseEndDate
5355
challenge={challenge}
@@ -70,14 +72,14 @@ const ChallengeItem = ({ challenge, onClickTag, onClickTrack, isLoggedIn }) => {
7072
/>
7173
</div>
7274
<div styleName="nums">
73-
<a
74-
href={`${process.env.URL.BASE}/challenges/${challenge.id}?tab=registrants`} // eslint-disable-line no-undef
75+
<Link
76+
to={`${CHALLENGES_URL}/${challenge.id}?tab=registrants`}
7577
>
7678
<NumRegistrants numOfRegistrants={challenge.numOfRegistrants} />
77-
</a>
78-
<a href={submissionLink}>
79+
</Link>
80+
<Link to={submissionLink}>
7981
<NumSubmissions numOfSubmissions={challenge.numOfSubmissions} />
80-
</a>
82+
</Link>
8183
</div>
8284
</div>
8385
<div styleName="prize">

src/containers/Challenges/Listing/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const Listing = ({
129129
}}
130130
onClickTrack={(track) => {
131131
const filterChange = {
132-
tracks: [track.replace("Quality Assurance", "QA")],
132+
tracks: [track],
133133
page: 1,
134134
};
135135
updateFilter(filterChange);

src/containers/Filter/ChallengeFilter/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const ChallengeFilter = ({
121121
updateFilter(filterChange);
122122
}}
123123
/>
124-
<span>{track}</span>
124+
<span>{track.replace('Quality Assurance', 'QA')}</span>
125125
</span>
126126
))}
127127
</div>

src/containers/challenge-detail/index.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,7 @@ const mapDispatchToProps = (dispatch) => {
978978
}
979979
dispatch(updateFilter(change));
980980
dispatch(
981-
updateQuery({ ...stateProps.filter.challenge, ...change }),
982-
change
981+
updateQuery({ ...stateProps.filter.challenge, ...change })
983982
);
984983
},
985984
setSpecsTabState: (state) =>

src/reducers/challenges.js

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,9 @@ function onGetChallengesInit(state) {
1717
return { ...state, loadingChallenges: true, loadingChallengesError: null };
1818
}
1919

20-
function onGetChallengesDone(state, { payload }) {
21-
const error = payload;
22-
if (error.name === "AbortError") {
23-
return {
24-
...state,
25-
loadingChallenges: false,
26-
loadingChallengesError: null,
27-
};
20+
function onGetChallengesDone(state, { error, payload }) {
21+
if (error) {
22+
return onGetChallengesFailure(state, { payload });
2823
}
2924

3025
return {
@@ -39,32 +34,31 @@ function onGetChallengesDone(state, { payload }) {
3934
};
4035
}
4136

42-
// function onGetChallengesFailure(state, { payload }) {
43-
// const error = payload;
44-
// if (error.name === "AbortError") {
45-
// return {
46-
// ...state,
47-
// loadingChallenges: false,
48-
// loadingChallengesError: null,
49-
// };
50-
// }
37+
function onGetChallengesFailure(state, { payload }) {
38+
const error = payload;
39+
if (error.name === "AbortError") {
40+
return {
41+
...state,
42+
loadingChallenges: false,
43+
loadingChallengesError: null,
44+
};
45+
}
5146

52-
// return {
53-
// ...state,
54-
// loadingChallenges: false,
55-
// loadingChallengesError: payload,
56-
// challenges: [],
57-
// total: 0,
58-
// openForRegistrationCount: 0,
59-
// initialized: true,
60-
// };
61-
// }
47+
return {
48+
...state,
49+
loadingChallenges: false,
50+
loadingChallengesError: payload,
51+
challenges: [],
52+
total: 0,
53+
openForRegistrationCount: 0,
54+
initialized: true,
55+
};
56+
}
6257

6358
export default handleActions(
6459
{
6560
GET_CHALLENGE_INIT: onGetChallengesInit,
6661
GET_CHALLENGES_DONE: onGetChallengesDone,
67-
// GET_CHALLENGES_FAILURE: onGetChallengesFailure,
6862
},
6963
defaultState
7064
);

src/utils/challenge.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,49 @@ import Joi from "joi";
66
import { initialChallengeFilter } from "../reducers/filter";
77

88
Joi.optionalId = () => Joi.string().uuid();
9-
Joi.page = () => Joi.number().integer().min(1);
9+
10+
Joi.page = () =>
11+
Joi.alternatives()
12+
.try(
13+
Joi.number()
14+
.min(1),
15+
Joi.any().custom(() => 1)
16+
);
17+
1018
Joi.perPage = () =>
11-
Joi.number()
12-
.integer()
13-
.min(1)
14-
.max(100)
15-
.valid(...constants.PAGINATION_PER_PAGES);
19+
Joi.alternatives()
20+
.try(
21+
Joi.number()
22+
.integer()
23+
.min(1)
24+
.max(100)
25+
.valid(...constants.PAGINATION_PER_PAGES),
26+
Joi.any().custom(() => constants.PAGINATION_PER_PAGES[0])
27+
);
28+
1629
Joi.bucket = () =>
1730
Joi.string().custom((param) =>
1831
constants.FILTER_BUCKETS.find(
1932
(bucket) => param && param.toLowerCase() === bucket.toLowerCase()
20-
)
33+
) || null
2134
);
35+
2236
Joi.track = () =>
2337
Joi.string().custom((param) =>
2438
_.findKey(
2539
constants.FILTER_CHALLENGE_TRACK_ABBREVIATIONS,
2640
(trackAbbreviation) =>
2741
param && param.toLowerCase() === trackAbbreviation.toLowerCase()
28-
)
42+
) || null
2943
);
44+
3045
Joi.type = () =>
3146
Joi.string().custom((param) =>
3247
_.findKey(
3348
constants.FILTER_CHALLENGE_TYPE_ABBREVIATIONS,
3449
(typeAbbreviation) =>
3550
param && param.toLowerCase() === typeAbbreviation.toLowerCase()
36-
)
51+
) || null
3752
);
3853

3954
export function getCurrencySymbol(prizeSets) {
@@ -65,6 +80,7 @@ export function getCheckpointPrizes(prizeSets) {
6580
*/
6681
export function createChallengeFilter(params) {
6782
const schema = createChallengeFilter.schema;
83+
6884
const normalized = Joi.attempt(
6985
params,
7086
schema,

src/utils/lifeCycle.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import store from "../store";
22
import action from "../actions/initApp";
33
import * as utils from "../utils";
4+
import { CHALLENGES_URL } from '../constants';
45

56
export default function appInit() {
67
let initialQuery;
@@ -17,7 +18,7 @@ export default function appInit() {
1718
async function mount() {
1819
try {
1920
if (firstMounted) {
20-
if (initialQuery && urlPath === "/earn/find/challenges") {
21+
if (initialQuery && urlPath === CHALLENGES_URL) {
2122
const params = utils.url.parseUrlQuery(initialQuery);
2223
const filter = utils.challenge.createChallengeFilter(params);
2324
store.dispatch(action.initApp(filter));

0 commit comments

Comments
 (0)