@@ -2,10 +2,13 @@ import { Router, navigate } from "@reach/router";
2
2
import _ from "lodash" ;
3
3
import React , { useCallback , useState , useEffect , useMemo } from "react" ;
4
4
import { useDispatch , useSelector } from "react-redux" ;
5
+ import { getAuthUserTokens } from "@topcoder/micro-frontends-navbar-app" ;
6
+ import { decodeToken } from "tc-auth-lib" ;
5
7
import { SEARCH_STAGE_TIME } from "constants/" ;
6
8
import { useData } from "hooks/useData" ;
7
9
import { getSkills } from "services/skills" ;
8
- import { searchRoles } from "services/teams" ;
10
+ import { searchRoles , isExternalMemberRequest } from "services/teams" ;
11
+ import { getRoleById } from "services/roles" ;
9
12
import { isCustomRole , setCurrentStage } from "utils/helpers" ;
10
13
import {
11
14
clearMatchingRole ,
@@ -21,11 +24,44 @@ const SEARCHINGTIME = SEARCH_STAGE_TIME * 3 + 100;
21
24
22
25
function SearchAndSubmit ( props ) {
23
26
const { stages, setStages, searchObject, onClick, page } = props ;
24
-
25
27
const [ searchState , setSearchState ] = useState ( null ) ;
26
28
const [ isNewRole , setIsNewRole ] = useState ( false ) ;
29
+ const [ isExternalMember , setIsExternalMember ] = useState ( null ) ;
27
30
const [ skills ] = useData ( getSkills ) ;
28
31
const { matchingRole } = useSelector ( ( state ) => state . searchedRoles ) ;
32
+ const { userId } = useSelector ( ( state ) => state . authUser ) ;
33
+ useEffect ( ( ) => {
34
+ if ( stages . length === 3 ) {
35
+ getAuthUserTokens ( ) . then ( ( { tokenV3 } ) => {
36
+ if ( ! ! tokenV3 ) {
37
+ const tokenData = decodeToken ( tokenV3 ) ;
38
+ isExternalMemberRequest ( {
39
+ memberId : tokenData . userId ,
40
+ } ) . then ( ( res ) => {
41
+ const newStages = [ ...stages , { name : "Overview of the Results" } ] ;
42
+ setIsExternalMember ( res . data ) ;
43
+ setStages ( newStages ) ;
44
+ } ) ;
45
+ }
46
+ } ) ;
47
+ }
48
+ } , [ stages , setStages ] ) ;
49
+
50
+ useEffect ( ( ) => {
51
+ if ( isExternalMember === false ) {
52
+ if ( matchingRole && matchingRole . isExternalMember ) {
53
+ getRoleById ( matchingRole . id ) . then ( ( res ) => {
54
+ // update role info
55
+ const newRole = {
56
+ ...matchingRole ,
57
+ rates : res . data . rates ,
58
+ isExternalMember : false ,
59
+ } ;
60
+ dispatch ( saveMatchingRole ( newRole ) ) ;
61
+ } ) ;
62
+ }
63
+ }
64
+ } , [ isExternalMember , matchingRole , dispatch ] ) ;
29
65
30
66
const matchedSkills = useMemo ( ( ) => {
31
67
if ( skills && matchingRole && matchingRole . matchedSkills ) {
0 commit comments