From ca1783a2b66b62bbef4eaa1ab609ab76e3626c7b Mon Sep 17 00:00:00 2001 From: Awais Ansari <79941147+awais-ansari@users.noreply.github.com> Date: Wed, 6 Jul 2022 17:11:37 +0500 Subject: [PATCH] fix: set default value for cohorts dropdown (#208) --- .../posts/post-editor/PostEditor.jsx | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) 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) - && ( - - - - {cohorts.map(cohort => ( - - ))} - - - )} + {canSelectCohort(values.topic) && ( + + + + {cohorts.map(cohort => ( + + ))} + + + )}