@@ -2,10 +2,13 @@ import { Router, navigate } from "@reach/router";
22import _ from "lodash" ;
33import React , { useCallback , useState , useEffect , useMemo } from "react" ;
44import { useDispatch , useSelector } from "react-redux" ;
5+ import { getAuthUserTokens } from "@topcoder/micro-frontends-navbar-app" ;
6+ import { decodeToken } from "tc-auth-lib" ;
57import { SEARCH_STAGE_TIME } from "constants/" ;
68import { useData } from "hooks/useData" ;
79import { getSkills } from "services/skills" ;
8- import { searchRoles } from "services/teams" ;
10+ import { searchRoles , isExternalMemberRequest } from "services/teams" ;
11+ import { getRoleById } from "services/roles" ;
912import { isCustomRole , setCurrentStage } from "utils/helpers" ;
1013import {
1114 clearMatchingRole ,
@@ -21,11 +24,44 @@ const SEARCHINGTIME = SEARCH_STAGE_TIME * 3 + 100;
2124
2225function SearchAndSubmit ( props ) {
2326 const { stages, setStages, searchObject, onClick, page } = props ;
24-
2527 const [ searchState , setSearchState ] = useState ( null ) ;
2628 const [ isNewRole , setIsNewRole ] = useState ( false ) ;
29+ const [ isExternalMember , setIsExternalMember ] = useState ( null ) ;
2730 const [ skills ] = useData ( getSkills ) ;
2831 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 ] ) ;
2965
3066 const matchedSkills = useMemo ( ( ) => {
3167 if ( skills && matchingRole && matchingRole . matchedSkills ) {
0 commit comments