4
4
* Requires authentication to complete submission process
5
5
* and contains a series of popups to lead user through the flow.
6
6
*/
7
- import React , { useCallback , useEffect , useState } from "react" ;
7
+ import React , {
8
+ useCallback ,
9
+ useEffect ,
10
+ useLayoutEffect ,
11
+ useState ,
12
+ } from "react" ;
8
13
import PT from "prop-types" ;
9
- import { useDispatch , useSelector } from "react-redux" ;
14
+ import { useDispatch } from "react-redux" ;
10
15
import _ from "lodash" ;
11
16
import { toastr } from "react-redux-toastr" ;
12
17
import { navigate } from "@reach/router" ;
@@ -19,46 +24,19 @@ import ConfirmationModal from "../ConfirmationModal";
19
24
import withAuthentication from "../../../../hoc/withAuthentication" ;
20
25
import "./styles.module.scss" ;
21
26
import { setCurrentStage } from "utils/helpers" ;
22
- import { clearSearchedRoles , replaceSearchedRoles } from "../../actions" ;
27
+ import { clearSearchedRoles } from "../../actions" ;
23
28
import { postTeamRequest } from "services/teams" ;
24
29
import SuccessCard from "../SuccessCard" ;
25
30
26
- const retrieveRoles = ( ) => {
27
- const searchIdString = sessionStorage . getItem ( "searchIds" ) ;
28
- const nameString = sessionStorage . getItem ( "roleNames" ) ;
29
-
30
- if ( ! searchIdString || ! nameString ) return [ ] ;
31
- const searchIds = searchIdString . split ( "," ) ;
32
- const names = nameString . split ( "," ) ;
33
- if ( searchIds . length !== names . length ) return [ ] ;
34
-
35
- const roles = [ ] ;
36
- for ( let i = 0 ; i < searchIds . length ; i ++ ) {
37
- roles . push ( {
38
- searchId : searchIds [ i ] ,
39
- name : names [ i ] ,
40
- } ) ;
41
- }
42
-
43
- return roles ;
44
- } ;
45
-
46
- const clearSessionKeys = ( ) => {
47
- sessionStorage . removeItem ( "searchIds" ) ;
48
- sessionStorage . removeItem ( "roleNames" ) ;
49
- } ;
50
-
51
31
function SubmitContainer ( {
52
32
stages,
53
33
setStages,
54
34
completenessStyle,
55
- reloadRolesPage,
56
35
location,
36
+ addedRoles,
57
37
} ) {
58
38
const matchingRole = location ?. state ?. matchingRole ;
59
39
60
- const { addedRoles } = useSelector ( ( state ) => state . searchedRoles ) ;
61
-
62
40
const [ addAnotherOpen , setAddAnotherOpen ] = useState ( true ) ;
63
41
const [ teamDetailsOpen , setTeamDetailsOpen ] = useState ( false ) ;
64
42
const [ teamObject , setTeamObject ] = useState ( null ) ;
@@ -68,11 +46,17 @@ function SubmitContainer({
68
46
69
47
useEffect ( ( ) => {
70
48
setCurrentStage ( 2 , stages , setStages ) ;
71
- const storedRoles = retrieveRoles ( ) ;
72
- if ( storedRoles ) {
73
- if ( ! addedRoles || storedRoles . length > addedRoles . length ) {
74
- dispatch ( replaceSearchedRoles ( storedRoles ) ) ;
75
- }
49
+ if ( ! addedRoles || addedRoles . length === 0 ) {
50
+ navigate ( "/taas/myteams/createnewteam" ) ;
51
+ }
52
+ // eslint-disable-next-line react-hooks/exhaustive-deps
53
+ } , [ ] ) ;
54
+
55
+ // redirects user if they enter the page URL directly
56
+ // without adding any roles.
57
+ useLayoutEffect ( ( ) => {
58
+ if ( ! addedRoles || addedRoles . length === 0 ) {
59
+ navigate ( "/taas/myteams/createnewteam" ) ;
76
60
}
77
61
// eslint-disable-next-line react-hooks/exhaustive-deps
78
62
} , [ ] ) ;
@@ -83,11 +67,7 @@ function SubmitContainer({
83
67
} ;
84
68
85
69
const addAnother = ( ) => {
86
- if ( reloadRolesPage ) {
87
- setCurrentStage ( 0 , stages , setStages ) ;
88
- reloadRolesPage ( ) ;
89
- }
90
- navigate ( "/taas/myteams/createnewteam/role" ) ;
70
+ navigate ( "/taas/myteams/createnewteam" ) ;
91
71
} ;
92
72
93
73
const assembleTeam = ( formData ) => {
@@ -121,7 +101,6 @@ function SubmitContainer({
121
101
postTeamRequest ( teamObject )
122
102
. then ( ( res ) => {
123
103
const projectId = _ . get ( res , [ "data" , "projectId" ] ) ;
124
- clearSessionKeys ( ) ;
125
104
dispatch ( clearSearchedRoles ( ) ) ;
126
105
navigate ( `/taas/myteams/${ projectId } ` ) ;
127
106
} )
@@ -171,8 +150,8 @@ SubmitContainer.propTypes = {
171
150
stages : PT . array ,
172
151
setStages : PT . func ,
173
152
completenessStyle : PT . string ,
174
- reloadRolesPage : PT . bool ,
175
153
location : PT . object ,
154
+ addedRoles : PT . array ,
176
155
} ;
177
156
178
157
export default withAuthentication ( SubmitContainer ) ;
0 commit comments