11import { injectIntl , intlShape } from '@edx/frontend-platform/i18n' ;
2- import {
3- Button , Form , TransitionReplace ,
4- } from '@edx/paragon' ;
2+ import { Button , Form , TransitionReplace } from '@edx/paragon' ;
53import PropTypes from 'prop-types' ;
64import React , { useState } from 'react' ;
75import { GroupTypes , TeamSizes } from '../../data/constants' ;
86
97import CollapsableEditor from '../../generic/CollapsableEditor' ;
10- import FormikErrorFeedback from '../../generic/FormikErrorFeedback ' ;
8+ import FormikControl from '../../generic/FormikControl ' ;
119import messages from './messages' ;
1210
1311// Maps a team type to its corresponding intl message
@@ -27,15 +25,14 @@ const TeamTypeNameMessage = {
2725} ;
2826
2927function GroupEditor ( {
30- intl, group, onDelete, onChange, onBlur, fieldNameCommonBase, errors, setFieldError ,
28+ intl, group, onDelete, onChange, onBlur, fieldNameCommonBase, errors,
3129} ) {
3230 const [ isDeleting , setDeleting ] = useState ( false ) ;
3331 const [ isOpen , setOpen ] = useState ( group . id === null ) ;
3432 const initiateDeletion = ( ) => setDeleting ( true ) ;
3533 const cancelDeletion = ( ) => setDeleting ( false ) ;
3634
3735 const handleToggle = ( open ) => setOpen ( Boolean ( errors . name || errors . maxTeamSize || errors . description ) || open ) ;
38- const handleFocus = ( e ) => setFieldError ( e . target . name , undefined ) ;
3936
4037 const formGroupClasses = 'mb-4 mx-2' ;
4138
@@ -45,7 +42,7 @@ function GroupEditor({
4542 ? (
4643 < div className = "d-flex flex-column card rounded mb-3 px-3 py-2 p-4" key = "isDeleting" >
4744 < h3 > { intl . formatMessage ( messages . groupDeleteHeading ) } </ h3 >
48- < p > { intl . formatMessage ( messages . groupDeleteBody ) } </ p >
45+ { intl . formatMessage ( messages . groupDeleteBody ) . split ( '\n' ) . map ( text => < p > { text } </ p > ) }
4946 < div className = "d-flex flex-row justify-content-end" >
5047 < Button variant = "muted" size = "sm" onClick = { cancelDeletion } >
5148 { intl . formatMessage ( messages . cancel ) }
@@ -73,44 +70,31 @@ function GroupEditor({
7370 { intl . formatMessage ( messages . configureGroup ) }
7471 </ div >
7572 ) : (
76- < div className = "d-flex flex-column flex-shrink-1 small" >
77- < span className = "small text-gray-500" > { intl . formatMessage ( TeamTypeNameMessage [ group . type ] . label ) } </ span >
78- < span className = "text-truncate text-black " > { group . name || '<new>' } </ span >
79- < span className = "small text-muted text-gray-500" > { group . description || '<new>' } </ span >
73+ < div className = "d-flex flex-column flex-shrink-1 small mw-100 " >
74+ < div className = "small text-gray-500" > { intl . formatMessage ( TeamTypeNameMessage [ group . type ] . label ) } </ div >
75+ < div className = "h4 text-truncate my-1 " > { group . name } </ div >
76+ < div className = "small text-truncate text- muted text-gray-500" > { group . description } </ div >
8077 </ div >
8178 )
8279 }
8380 >
84- < Form . Group className = { `${ formGroupClasses } mt-2.5` } >
85- < Form . Control
86- className = "pb-2"
87- name = { `${ fieldNameCommonBase } .name` }
88- floatingLabel = { intl . formatMessage ( messages . groupFormNameLabel ) }
89- defaultValue = { group . name }
90- onChange = { onChange }
91- onBlur = { onBlur }
92- onFocus = { handleFocus }
93- />
94- < FormikErrorFeedback name = { `${ fieldNameCommonBase } .name` } >
95- < Form . Text > { intl . formatMessage ( messages . groupFormNameHelp ) } </ Form . Text >
96- </ FormikErrorFeedback >
97- </ Form . Group >
98- < Form . Group className = { formGroupClasses } >
99- < Form . Control
100- className = "pb-2"
101- as = "textarea"
102- rows = { 4 }
103- name = { `${ fieldNameCommonBase } .description` }
104- floatingLabel = { intl . formatMessage ( messages . groupFormDescriptionLabel ) }
105- defaultValue = { group . description }
106- onChange = { onChange }
107- onBlur = { onBlur }
108- onFocus = { handleFocus }
109- />
110- < FormikErrorFeedback name = { `${ fieldNameCommonBase } .description` } >
111- < Form . Text > { intl . formatMessage ( messages . groupFormDescriptionHelp ) } </ Form . Text >
112- </ FormikErrorFeedback >
113- </ Form . Group >
81+ < FormikControl
82+ name = { `${ fieldNameCommonBase } .name` }
83+ value = { group . name }
84+ floatingLabel = { intl . formatMessage ( messages . groupFormNameLabel ) }
85+ help = { intl . formatMessage ( messages . groupFormNameHelp ) }
86+ className = { `${ formGroupClasses } mt-2.5` }
87+ />
88+ < FormikControl
89+ name = { `${ fieldNameCommonBase } .description` }
90+ value = { group . description }
91+ floatingLabel = { intl . formatMessage ( messages . groupFormDescriptionLabel ) }
92+ help = { intl . formatMessage ( messages . groupFormDescriptionHelp ) }
93+ as = "textarea"
94+ rows = { 4 }
95+ style = { { minHeight : '2.5rem' } }
96+ className = { formGroupClasses }
97+ />
11498 < Form . Group className = { formGroupClasses } >
11599 < Form . Label className = "h4 my-3" >
116100 { intl . formatMessage ( messages . groupFormTypeLabel ) }
@@ -135,22 +119,16 @@ function GroupEditor({
135119 ) ) }
136120 </ Form . RadioSet >
137121 </ Form . Group >
138- < Form . Group className = "mx-2" >
139- < Form . Label className = "h4 pb-4" > { intl . formatMessage ( messages . teamSize ) } </ Form . Label >
140- < Form . Control
141- type = "number"
142- name = { `${ fieldNameCommonBase } .maxTeamSize` }
143- floatingLabel = { intl . formatMessage ( messages . groupFormMaxSizeLabel ) }
144- value = { group . maxTeamSize }
145- placeholder = { TeamSizes . DEFAULT }
146- onChange = { onChange }
147- onBlur = { onBlur }
148- onFocus = { handleFocus }
149- />
150- < FormikErrorFeedback name = { `${ fieldNameCommonBase } .maxTeamSize` } >
151- < Form . Text > { intl . formatMessage ( messages . groupFormMaxSizeHelp ) } </ Form . Text >
152- </ FormikErrorFeedback >
153- </ Form . Group >
122+ < FormikControl
123+ type = "number"
124+ name = { `${ fieldNameCommonBase } .maxTeamSize` }
125+ floatingLabel = { intl . formatMessage ( messages . groupFormMaxSizeLabel ) }
126+ value = { group . maxTeamSize }
127+ help = { intl . formatMessage ( messages . groupFormMaxSizeHelp ) }
128+ label = { < Form . Label className = "h4 pb-4" > { intl . formatMessage ( messages . teamSize ) } </ Form . Label > }
129+ className = "mx-2"
130+ placeholder = { TeamSizes . DEFAULT }
131+ />
154132 </ CollapsableEditor >
155133 ) }
156134 </ TransitionReplace >
@@ -177,7 +155,6 @@ GroupEditor.propTypes = {
177155 onDelete : PropTypes . func . isRequired ,
178156 onChange : PropTypes . func . isRequired ,
179157 onBlur : PropTypes . func . isRequired ,
180- setFieldError : PropTypes . func . isRequired ,
181158} ;
182159
183160GroupEditor . defaultProps = {
0 commit comments