7
7
import React , {
8
8
useCallback ,
9
9
useEffect ,
10
+ useMemo ,
10
11
useLayoutEffect ,
11
12
useState ,
12
13
} from "react" ;
@@ -24,7 +25,7 @@ import ConfirmationModal from "../ConfirmationModal";
24
25
import { withBusinessAuthentication } from "../../../../hoc/withAuthentication" ;
25
26
import "./styles.module.scss" ;
26
27
import { isCustomRole , isUuid , setCurrentStage } from "utils/helpers" ;
27
- import { clearSearchedRoles } from "../../actions" ;
28
+ import { clearSearchedRoles , editRoleAction } from "../../actions" ;
28
29
import { postTeamRequest } from "services/teams" ;
29
30
import NoMatchingProfilesResultCard from "../NoMatchingProfilesResultCard" ;
30
31
@@ -33,15 +34,30 @@ function SubmitContainer({
33
34
setStages,
34
35
progressStyle,
35
36
matchingRole,
37
+ previousSearchId,
36
38
addedRoles,
37
39
} ) {
38
40
const [ addAnotherOpen , setAddAnotherOpen ] = useState ( false ) ;
39
41
const [ teamDetailsOpen , setTeamDetailsOpen ] = useState ( true ) ;
40
42
const [ teamObject , setTeamObject ] = useState ( null ) ;
41
43
const [ requestLoading , setRequestLoading ] = useState ( false ) ;
44
+ const [ buttonClickable , setButtonClickable ] = useState ( true ) ;
42
45
43
46
const dispatch = useDispatch ( ) ;
44
47
48
+ const currentRole = useMemo ( ( ) => {
49
+ return _ . find ( addedRoles , { searchId : previousSearchId } ) ;
50
+ } , [ addedRoles , previousSearchId ] ) ;
51
+
52
+ const onSaveEditRole = useCallback (
53
+ ( isValid , role ) => {
54
+ setButtonClickable ( isValid ) ;
55
+ if ( isValid ) {
56
+ dispatch ( editRoleAction ( { ...role , searchId : previousSearchId } ) ) ;
57
+ }
58
+ } ,
59
+ [ dispatch , previousSearchId ]
60
+ ) ;
45
61
useEffect ( ( ) => {
46
62
setCurrentStage ( 2 , stages , setStages ) ;
47
63
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -114,7 +130,11 @@ function SubmitContainer({
114
130
return (
115
131
< div styleName = "page" >
116
132
{ ! isCustomRole ( matchingRole ) ? (
117
- < ResultCard role = { matchingRole } />
133
+ < ResultCard
134
+ role = { matchingRole }
135
+ onSaveEditRole = { onSaveEditRole }
136
+ currentRole = { currentRole }
137
+ />
118
138
) : (
119
139
< NoMatchingProfilesResultCard role = { matchingRole } />
120
140
) }
@@ -123,6 +143,7 @@ function SubmitContainer({
123
143
< Progress
124
144
onClick = { ( ) => setAddAnotherOpen ( true ) }
125
145
extraStyleName = { progressStyle }
146
+ isDisabled = { ! buttonClickable }
126
147
buttonLabel = "Continue"
127
148
stages = { stages }
128
149
percentage = "98"
@@ -135,12 +156,14 @@ function SubmitContainer({
135
156
onContinueClick = { openTeamDetails }
136
157
addAnother = { addAnother }
137
158
/>
138
- < TeamDetailsModal
139
- open = { teamDetailsOpen }
140
- onClose = { ( ) => setTeamDetailsOpen ( false ) }
141
- submitForm = { assembleTeam }
142
- addedRoles = { addedRoles }
143
- />
159
+ { teamDetailsOpen && (
160
+ < TeamDetailsModal
161
+ open = { teamDetailsOpen }
162
+ onClose = { ( ) => setTeamDetailsOpen ( false ) }
163
+ submitForm = { assembleTeam }
164
+ addedRoles = { addedRoles }
165
+ />
166
+ ) }
144
167
< ConfirmationModal
145
168
open = { ! ! teamObject }
146
169
onClose = { ( ) => setTeamObject ( null ) }
@@ -156,6 +179,7 @@ SubmitContainer.propTypes = {
156
179
setStages : PT . func ,
157
180
progressStyle : PT . string ,
158
181
addedRoles : PT . array ,
182
+ previousSearchId : PT . string ,
159
183
matchingRole : PT . object ,
160
184
} ;
161
185
0 commit comments