@@ -10,7 +10,8 @@ import CardHeader from "components/CardHeader";
10
10
import "./styles.module.scss" ;
11
11
import Select from "components/Select" ;
12
12
import {
13
- CANDIDATE_STATUS_TO_TITLE_TEXT ,
13
+ CANDIDATE_STATUS_FILTERS ,
14
+ CANDIDATE_STATUS_FILTER_KEY ,
14
15
CANDIDATES_SORT_OPTIONS ,
15
16
CANDIDATES_SORT_BY ,
16
17
CANDIDATE_STATUS ,
@@ -57,24 +58,21 @@ const populateSkillsMatched = (position, candidate) => ({
57
58
skillsMatched : _ . intersectionBy ( position . skills , candidate . skills , "id" ) ,
58
59
} ) ;
59
60
60
- const PositionCandidates = ( { position, candidateStatus , updateCandidate } ) => {
61
+ const PositionCandidates = ( { position, statusFilterKey , updateCandidate } ) => {
61
62
const { candidates } = position ;
62
63
const [ sortBy , setSortBy ] = useState ( CANDIDATES_SORT_BY . SKILL_MATCHED ) ;
63
-
64
- useEffect ( ( ) => {
65
- setPage ( 1 ) ;
66
- } , [ candidateStatus ] ) ;
64
+ const statusFilter = useMemo ( ( ) =>
65
+ _ . find ( CANDIDATE_STATUS_FILTERS , { key : statusFilterKey } )
66
+ , [ statusFilterKey ] ) ;
67
67
68
68
const filteredCandidates = useMemo (
69
69
( ) =>
70
70
_ . chain ( candidates )
71
71
. map ( ( candidate ) => populateSkillsMatched ( position , candidate ) )
72
- . filter ( {
73
- status : candidateStatus ,
74
- } )
72
+ . filter ( ( candidate ) => statusFilter . statuses . includes ( candidate . status ) )
75
73
. value ( )
76
74
. sort ( createSortCandidatesMethod ( sortBy ) ) ,
77
- [ candidates , candidateStatus , sortBy , position ]
75
+ [ candidates , statusFilter , sortBy , position ]
78
76
) ;
79
77
80
78
const onSortByChange = useCallback (
@@ -94,6 +92,10 @@ const PositionCandidates = ({ position, candidateStatus, updateCandidate }) => {
94
92
setPage ( newPage ) ;
95
93
} , [ perPage , setPerPage , page , setPage ] ) ;
96
94
95
+ useEffect ( ( ) => {
96
+ setPage ( 1 ) ;
97
+ } , [ statusFilterKey ] ) ;
98
+
97
99
const pagesTotal = Math . ceil ( filteredCandidates . length / perPage ) ;
98
100
99
101
const pageCandidates = useMemo (
@@ -147,7 +149,7 @@ const PositionCandidates = ({ position, candidateStatus, updateCandidate }) => {
147
149
return (
148
150
< div styleName = "position-candidates" >
149
151
< CardHeader
150
- title = { `${ CANDIDATE_STATUS_TO_TITLE_TEXT [ candidateStatus ] } (${ filteredCandidates . length } )` }
152
+ title = { `${ statusFilter . title } (${ filteredCandidates . length } )` }
151
153
aside = {
152
154
< Select
153
155
options = { CANDIDATES_SORT_OPTIONS }
@@ -160,7 +162,7 @@ const PositionCandidates = ({ position, candidateStatus, updateCandidate }) => {
160
162
161
163
{ filteredCandidates . length === 0 && (
162
164
< div styleName = "no-candidates" >
163
- No { CANDIDATE_STATUS_TO_TITLE_TEXT [ candidateStatus ] }
165
+ No { statusFilter . title }
164
166
</ div >
165
167
) }
166
168
{ filteredCandidates . length > 0 && (
@@ -194,7 +196,7 @@ const PositionCandidates = ({ position, candidateStatus, updateCandidate }) => {
194
196
) }
195
197
</ div >
196
198
< div styleName = "table-cell cell-action" >
197
- { candidateStatus === CANDIDATE_STATUS . OPEN && hasPermission ( PERMISSIONS . UPDATE_JOB_CANDIDATE ) && (
199
+ { statusFilterKey === CANDIDATE_STATUS_FILTER_KEY . TO_REVIEW && hasPermission ( PERMISSIONS . UPDATE_JOB_CANDIDATE ) && (
198
200
< >
199
201
Interested in this candidate?
200
202
< div styleName = "actions" >
@@ -247,7 +249,7 @@ const PositionCandidates = ({ position, candidateStatus, updateCandidate }) => {
247
249
248
250
PositionCandidates . propType = {
249
251
position : PT . object ,
250
- candidateStatus : PT . oneOf ( Object . values ( CANDIDATE_STATUS ) ) ,
252
+ statusFilterKey : PT . oneOf ( Object . values ( CANDIDATE_STATUS_FILTER_KEY ) ) ,
251
253
} ;
252
254
253
255
export default PositionCandidates ;
0 commit comments