1
- import { Router } from "@reach/router" ;
1
+ import { Router , navigate } from "@reach/router" ;
2
2
import _ from "lodash" ;
3
- import React , { useCallback , useState } from "react" ;
3
+ import React , { useCallback , useState , useEffect } from "react" ;
4
4
import { useDispatch , useSelector } from "react-redux" ;
5
5
import { searchRoles } from "services/teams" ;
6
6
import { isCustomRole , setCurrentStage } from "utils/helpers" ;
7
- import { addRoleSearchId , addSearchedRole } from "../../actions" ;
7
+ import { clearMatchingRole , saveMatchingRole , addRoleSearchId , addSearchedRole } from "../../actions" ;
8
+ import InputContainer from "../InputContainer" ;
8
9
import SearchContainer from "../SearchContainer" ;
9
10
import SubmitContainer from "../SubmitContainer" ;
10
11
11
12
function SearchAndSubmit ( props ) {
12
- const { stages, setStages, searchObject, onClick } = props ;
13
+ const { stages, setStages, searchObject, onClick, page } = props ;
13
14
14
15
const [ searchState , setSearchState ] = useState ( null ) ;
15
- const [ matchingRole , setMatchingRole ] = useState ( null ) ;
16
16
17
- const { addedRoles , previousSearchId } = useSelector (
17
+ const { matchingRole } = useSelector (
18
18
( state ) => state . searchedRoles
19
19
) ;
20
20
21
+ useEffect ( ( ) => {
22
+ const isFromInputPage = searchObject . role || searchObject . skills && searchObject . skills . length
23
+ || searchObject . jobDescription
24
+ // refresh in search page directly
25
+ if ( matchingRole && ! isFromInputPage ) {
26
+ setCurrentStage ( 2 , stages , setStages ) ;
27
+ setSearchState ( "done" ) ;
28
+ }
29
+ } , [ ] )
30
+
21
31
const dispatch = useDispatch ( ) ;
22
32
33
+ const { addedRoles, previousSearchId } = useSelector (
34
+ ( state ) => state . searchedRoles
35
+ ) ;
36
+
23
37
const search = useCallback ( ( ) => {
38
+ navigate ( `${ page } /search` ) ;
24
39
setCurrentStage ( 1 , stages , setStages ) ;
25
40
setSearchState ( "searching" ) ;
26
- setMatchingRole ( null ) ;
41
+ dispatch ( clearMatchingRole ( ) ) ;
27
42
const searchObjectCopy = { ...searchObject } ;
28
43
if ( previousSearchId ) {
29
44
searchObjectCopy . previousRoleSearchRequestId = previousSearchId ;
@@ -37,7 +52,9 @@ function SearchAndSubmit(props) {
37
52
} else if ( searchId ) {
38
53
dispatch ( addRoleSearchId ( searchId ) ) ;
39
54
}
40
- setMatchingRole ( res . data ) ;
55
+ // setMatchingRole(res.data);
56
+
57
+ dispatch ( saveMatchingRole ( res . data ) ) ;
41
58
} )
42
59
. catch ( ( err ) => {
43
60
console . error ( err ) ;
@@ -51,11 +68,18 @@ function SearchAndSubmit(props) {
51
68
52
69
return (
53
70
< Router >
54
- < SearchContainer
71
+ < InputContainer
55
72
path = "/"
56
73
addedRoles = { addedRoles }
57
74
previousSearchId = { previousSearchId }
58
75
search = { search }
76
+ { ...props }
77
+ />
78
+ < SearchContainer
79
+ path = "search"
80
+ addedRoles = { addedRoles }
81
+ previousSearchId = { previousSearchId }
82
+ search = { search }
59
83
searchState = { searchState }
60
84
matchingRole = { matchingRole }
61
85
{ ...props }
0 commit comments