diff --git a/src/discussions/posts/post-editor/PostEditor.jsx b/src/discussions/posts/post-editor/PostEditor.jsx index 72e360c1..25003c83 100644 --- a/src/discussions/posts/post-editor/PostEditor.jsx +++ b/src/discussions/posts/post-editor/PostEditor.jsx @@ -124,6 +124,8 @@ function PostEditor({ } dispatch(hidePostEditor()); }; + // null stands for no cohort restriction ("All learners" option) + const selectedCohort = (cohort) => (cohort === 'default' ? null : cohort); const submitForm = async (values) => { if (editExisting) { @@ -135,11 +137,8 @@ function PostEditor({ editReasonCode: values.editReasonCode || undefined, })); } else { - const cohort = canSelectCohort(values.topic) - // null stands for no cohort restriction ("All learners" option) - ? (values.cohort || null) - // if not allowed to set cohort, always undefined, so no value is sent to backend - : undefined; + const cohort = canSelectCohort(values.topic) ? selectedCohort(values.cohort) : undefined; + // if not allowed to set cohort, always undefined, so no value is sent to backend await dispatchSubmit(createNewThread({ courseId, topicId: values.topic, @@ -185,6 +184,7 @@ function PostEditor({ anonymous: allowAnonymous ? false : undefined, anonymousToPeers: allowAnonymousToPeers ? false : undefined, editReasonCode: post?.lastEdit?.reasonCode || '', + cohort: post?.cohort || 'default', }; const validationSchema = Yup.object().shape({ @@ -281,24 +281,24 @@ function PostEditor({ ))} - {canSelectCohort(values.topic) - && ( -