6
6
import React , { useCallback , useEffect , useState } from "react" ;
7
7
import PT from "prop-types" ;
8
8
import { navigate } from "@reach/router" ;
9
+ import _ from "lodash" ;
9
10
import Page from "components/Page" ;
10
11
import LoadingIndicator from "components/LoadingIndicator" ;
11
12
import PageHeader from "components/PageHeader" ;
@@ -26,7 +27,7 @@ const inReviewStatusFilter = _.find(CANDIDATE_STATUS_FILTERS, {
26
27
const getKeyFromParam = ( urlParam ) => {
27
28
const filter = _ . find ( CANDIDATE_STATUS_FILTERS , { urlParam } ) ;
28
29
return filter ?. key || undefined ;
29
- }
30
+ } ;
30
31
31
32
const PositionDetails = ( { teamId, positionId, candidateStatus } ) => {
32
33
// by default show "interested" tab
@@ -40,25 +41,31 @@ const PositionDetails = ({ teamId, positionId, candidateStatus }) => {
40
41
41
42
const onCandidateStatusChange = useCallback (
42
43
( 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
+ ) ;
44
48
} ,
45
49
[ teamId , positionId ]
46
50
) ;
47
51
48
52
// if there are some candidates to review, then show "To Review" tab by default
49
53
useEffect ( ( ) => {
54
+ const key = getKeyFromParam ( candidateStatus ) ;
50
55
if ( position ) {
51
- const key = getKeyFromParam ( candidateStatus ) ;
52
56
if ( key ) {
53
57
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 )
56
61
) . length > 0
57
62
) {
58
- setCandidateStatusFilterKey ( CANDIDATE_STATUS_FILTER_KEY . TO_REVIEW ) ;
63
+ onCandidateStatusChange ( { urlParam : "to-review" } ) ;
64
+ } else {
65
+ onCandidateStatusChange ( { urlParam : "interviews" } ) ;
59
66
}
60
67
}
61
- } , [ position , candidateStatus ] ) ;
68
+ } , [ position , candidateStatus , onCandidateStatusChange ] ) ;
62
69
63
70
return (
64
71
< Page title = "Job Details" >
0 commit comments