11import React , { useEffect , useState } from 'react' ;
22import PropTypes from 'prop-types' ;
3- import { Form } from '@edx /paragon' ;
3+ import { Form } from '@openedx /paragon' ;
44import { FormattedMessage } from '@edx/frontend-platform/i18n' ;
55import { useSelector , useDispatch } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BuildEmailFormExtensible/context' ;
66import { actionCreators as formActions } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BuildEmailFormExtensible/context/reducer' ;
@@ -10,10 +10,11 @@ import './styles.scss';
1010const disableIsHasLearners = [ 'track' , 'cohort' ] ;
1111const recipientsFormDescription = 'A selectable choice from a list of potential email recipients' ;
1212
13- const RecipientsForm = ( { cohorts : additionalCohorts } ) => {
13+ const RecipientsForm = ( { cohorts : additionalCohorts , courseModes } ) => {
1414 const formData = useSelector ( ( state ) => state . form ) ;
1515 const dispatch = useDispatch ( ) ;
1616 const { isEditMode, emailRecipients, isFormSubmitted } = formData ;
17+ const hasCourseModes = courseModes . length > 1 ;
1718
1819 const [ selectedGroups , setSelectedGroups ] = useState ( [ ] ) ;
1920 const hasAllLearnersSelected = selectedGroups . some ( ( group ) => group === 'learners' ) ;
@@ -91,6 +92,24 @@ const RecipientsForm = ({ cohorts: additionalCohorts }) => {
9192 description = { recipientsFormDescription }
9293 />
9394 </ Form . Checkbox >
95+ {
96+ // additional modes
97+ hasCourseModes
98+ && courseModes . map ( ( courseMode ) => (
99+ < Form . Checkbox
100+ key = { `track:${ courseMode . slug } ` }
101+ value = { `track:${ courseMode . slug } ` }
102+ disabled = { hasAllLearnersSelected }
103+ className = "col col-lg-4 col-sm-6 col-12"
104+ >
105+ < FormattedMessage
106+ id = "bulk.email.form.mode.label"
107+ defaultMessage = "Learners in the {courseModeName} Track"
108+ values = { { courseModeName : courseMode . name } }
109+ />
110+ </ Form . Checkbox >
111+ ) )
112+ }
94113 {
95114 // additional cohorts
96115 additionalCohorts
@@ -152,10 +171,17 @@ const RecipientsForm = ({ cohorts: additionalCohorts }) => {
152171
153172RecipientsForm . defaultProps = {
154173 cohorts : [ ] ,
174+ courseModes : [ ] ,
155175} ;
156176
157177RecipientsForm . propTypes = {
158178 cohorts : PropTypes . arrayOf ( PropTypes . string ) ,
179+ courseModes : PropTypes . arrayOf (
180+ PropTypes . shape ( {
181+ slug : PropTypes . string . isRequired ,
182+ name : PropTypes . string . isRequired ,
183+ } ) ,
184+ ) ,
159185} ;
160186
161187export default RecipientsForm ;
0 commit comments