77import React , {
88 useCallback ,
99 useEffect ,
10+ useMemo ,
1011 useLayoutEffect ,
1112 useState ,
1213} from "react" ;
@@ -24,7 +25,7 @@ import ConfirmationModal from "../ConfirmationModal";
2425import { withBusinessAuthentication } from "../../../../hoc/withAuthentication" ;
2526import "./styles.module.scss" ;
2627import { isCustomRole , isUuid , setCurrentStage } from "utils/helpers" ;
27- import { clearSearchedRoles } from "../../actions" ;
28+ import { clearSearchedRoles , editRoleAction } from "../../actions" ;
2829import { postTeamRequest } from "services/teams" ;
2930import NoMatchingProfilesResultCard from "../NoMatchingProfilesResultCard" ;
3031
@@ -33,15 +34,30 @@ function SubmitContainer({
3334 setStages,
3435 progressStyle,
3536 matchingRole,
37+ previousSearchId,
3638 addedRoles,
3739} ) {
3840 const [ addAnotherOpen , setAddAnotherOpen ] = useState ( false ) ;
3941 const [ teamDetailsOpen , setTeamDetailsOpen ] = useState ( true ) ;
4042 const [ teamObject , setTeamObject ] = useState ( null ) ;
4143 const [ requestLoading , setRequestLoading ] = useState ( false ) ;
44+ const [ buttonClickable , setButtonClickable ] = useState ( true ) ;
4245
4346 const dispatch = useDispatch ( ) ;
4447
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+ ) ;
4561 useEffect ( ( ) => {
4662 setCurrentStage ( 2 , stages , setStages ) ;
4763 // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -114,7 +130,11 @@ function SubmitContainer({
114130 return (
115131 < div styleName = "page" >
116132 { ! isCustomRole ( matchingRole ) ? (
117- < ResultCard role = { matchingRole } />
133+ < ResultCard
134+ role = { matchingRole }
135+ onSaveEditRole = { onSaveEditRole }
136+ currentRole = { currentRole }
137+ />
118138 ) : (
119139 < NoMatchingProfilesResultCard role = { matchingRole } />
120140 ) }
@@ -123,6 +143,7 @@ function SubmitContainer({
123143 < Progress
124144 onClick = { ( ) => setAddAnotherOpen ( true ) }
125145 extraStyleName = { progressStyle }
146+ isDisabled = { ! buttonClickable }
126147 buttonLabel = "Continue"
127148 stages = { stages }
128149 percentage = "98"
@@ -135,12 +156,14 @@ function SubmitContainer({
135156 onContinueClick = { openTeamDetails }
136157 addAnother = { addAnother }
137158 />
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+ ) }
144167 < ConfirmationModal
145168 open = { ! ! teamObject }
146169 onClose = { ( ) => setTeamObject ( null ) }
@@ -156,6 +179,7 @@ SubmitContainer.propTypes = {
156179 setStages : PT . func ,
157180 progressStyle : PT . string ,
158181 addedRoles : PT . array ,
182+ previousSearchId : PT . string ,
159183 matchingRole : PT . object ,
160184} ;
161185
0 commit comments