@@ -4,14 +4,11 @@ import PropTypes from 'prop-types';
44import { v1 as uuid } from 'uuid' ;
55import { connect , useDispatch } from 'react-redux' ;
66import { isEmpty } from 'lodash' ;
7- import { Button , Notification , Select , TextInput } from 'hds-react' ;
7+ import { Select } from 'hds-react' ;
88import { injectIntl , FormattedMessage } from 'react-intl' ;
9- import classNames from 'classnames' ;
109
11- import Icon from '../../utils/Icon' ;
1210import { createNotificationPayload , NOTIFICATION_TYPES } from '../../utils/notify' ;
1311import * as ProjectsSelector from '../../selectors/projectLists' ;
14- import Phase from './Phase' ;
1512import { hearingShape } from '../../types' ;
1613import {
1714 changeProjectName ,
@@ -22,6 +19,7 @@ import {
2219 changePhase ,
2320} from '../../actions/hearingEditor' ;
2421import { addToast } from '../../actions/toast' ;
22+ import Project from './Project' ;
2523
2624const HearingFormStep5 = ( { errors, hearing, hearingLanguages, language, projects, intl } ) => {
2725 const dispatch = useDispatch ( ) ;
@@ -51,70 +49,6 @@ const HearingFormStep5 = ({ errors, hearing, hearingLanguages, language, project
5149
5250 const onActivePhase = ( phaseId ) => dispatch ( activePhase ( phaseId ) ) ;
5351
54- const renderProject = ( selectedProject ) => {
55- const phasesLength = hearing . project ? hearing . project . phases . length : null ;
56- const errorStyle = ! errors . project_phase_active && phasesLength === 0 ? 'has-error' : null ;
57-
58- return (
59- < div >
60- { selectedProject &&
61- hearingLanguages . map ( ( usedLanguage ) => (
62- < div id = 'projectName' key = { usedLanguage } >
63- < TextInput
64- id = 'projectName'
65- name = 'projectName'
66- label = {
67- < >
68- < FormattedMessage id = 'projectName' /> ({ usedLanguage } )
69- </ >
70- }
71- maxLength = { 100 }
72- value = { selectedProject . title [ usedLanguage ] }
73- onBlur = { ( event ) => onChangeProjectName ( usedLanguage , event . target . value ) }
74- invalid = { ! ! errors . project_title }
75- errorText = { errors . project_title }
76- style = { { marginBottom : 'var(--spacing-s)' } }
77- required
78- />
79- </ div >
80- ) ) }
81- < div className = 'phases-container' >
82- { selectedProject &&
83- selectedProject . phases . map ( ( phase , index ) => {
84- const key = index ;
85-
86- return (
87- < Phase
88- onChange = { onChangePhase }
89- phaseInfo = { phase }
90- key = { key }
91- indexNumber = { index }
92- onDelete = { deletePhase }
93- onActive = { onActivePhase }
94- languages = { hearingLanguages }
95- errors = { errors }
96- />
97- ) ;
98- } ) }
99- </ div >
100- { selectedProject && (
101- < div >
102- < Button className = { classNames ( [ errorStyle , 'kerrokantasi-btn' ] ) } onClick = { addPhase } size = 'small' >
103- < Icon className = 'icon' name = 'plus' /> < FormattedMessage id = 'addProcess' > { ( txt ) => txt } </ FormattedMessage >
104- </ Button >
105- </ div >
106- ) }
107- { ! ! errors . project_phase_active && phasesLength === 0 && (
108- < Notification type = 'error' size = 'small' >
109- { errors . project_phase_active }
110- </ Notification >
111- ) }
112- </ div >
113- ) ;
114- } ;
115-
116- const selectedProject = hearing . project ;
117-
11852 const defaultProjectOptions = [
11953 { value : uuid ( ) , label : intl . formatMessage ( { id : 'noProject' } ) } ,
12054 { value : '' , label : intl . formatMessage ( { id : 'defaultProject' } ) } ,
@@ -129,7 +63,7 @@ const HearingFormStep5 = ({ errors, hearing, hearingLanguages, language, project
12963
13064 const options = [ ...defaultProjectOptions , ...projectsOptions ] ;
13165
132- const projectsInitialValue = selectedProject ?. id ? selectedProject . id : options [ 0 ] ;
66+ const projectsInitialValue = hearing . project ?. id ? hearing . project ? .id : options [ 0 ] ;
13367
13468 return (
13569 < div >
@@ -144,7 +78,16 @@ const HearingFormStep5 = ({ errors, hearing, hearingLanguages, language, project
14478 defaultValue = { projectsInitialValue }
14579 />
14680 </ div >
147- { renderProject ( selectedProject ) }
81+ < Project
82+ hearing = { hearing }
83+ errors = { errors }
84+ hearingLanguages = { hearingLanguages }
85+ onChangeProjectName = { onChangeProjectName }
86+ onChangePhase = { onChangePhase }
87+ deletePhase = { deletePhase }
88+ onActivePhase = { onActivePhase }
89+ addPhase = { addPhase }
90+ />
14891 </ div >
14992 ) ;
15093} ;
0 commit comments