Skip to content

Commit 479a7ad

Browse files
committed
Reflect selected tab in URL for Position Details page when navigating without URL param.
Issue topcoder-archive#391
1 parent 27c890e commit 479a7ad

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/routes/PositionDetails/index.jsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import React, { useCallback, useEffect, useState } from "react";
77
import PT from "prop-types";
88
import { navigate } from "@reach/router";
9+
import _ from "lodash";
910
import Page from "components/Page";
1011
import LoadingIndicator from "components/LoadingIndicator";
1112
import PageHeader from "components/PageHeader";
@@ -26,7 +27,7 @@ const inReviewStatusFilter = _.find(CANDIDATE_STATUS_FILTERS, {
2627
const getKeyFromParam = (urlParam) => {
2728
const filter = _.find(CANDIDATE_STATUS_FILTERS, { urlParam });
2829
return filter?.key || undefined;
29-
}
30+
};
3031

3132
const PositionDetails = ({ teamId, positionId, candidateStatus }) => {
3233
// by default show "interested" tab
@@ -40,25 +41,31 @@ const PositionDetails = ({ teamId, positionId, candidateStatus }) => {
4041

4142
const onCandidateStatusChange = useCallback(
4243
(statusFilter) => {
43-
navigate(`/taas/myteams/${teamId}/positions/${positionId}/candidates/${statusFilter.urlParam}`);
44+
navigate(
45+
`/taas/myteams/${teamId}/positions/${positionId}/candidates/${statusFilter.urlParam}`,
46+
{ replace: true }
47+
);
4448
},
4549
[teamId, positionId]
4650
);
4751

4852
// if there are some candidates to review, then show "To Review" tab by default
4953
useEffect(() => {
54+
const key = getKeyFromParam(candidateStatus);
5055
if (position) {
51-
const key = getKeyFromParam(candidateStatus);
5256
if (key) {
5357
setCandidateStatusFilterKey(key);
54-
} else if (_.filter(position.candidates, (candidate) =>
55-
inReviewStatusFilter.statuses.includes(candidate.status)
58+
} else if (
59+
_.filter(position.candidates, (candidate) =>
60+
inReviewStatusFilter.statuses.includes(candidate.status)
5661
).length > 0
5762
) {
58-
setCandidateStatusFilterKey(CANDIDATE_STATUS_FILTER_KEY.TO_REVIEW);
63+
onCandidateStatusChange({ urlParam: "to-review" });
64+
} else {
65+
onCandidateStatusChange({ urlParam: "interviews" });
5966
}
6067
}
61-
}, [position, candidateStatus]);
68+
}, [position, candidateStatus, onCandidateStatusChange]);
6269

6370
return (
6471
<Page title="Job Details">

0 commit comments

Comments
 (0)