Skip to content

Commit

Permalink
feat: add watchers field to course edit form
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 committed Jul 26, 2023
1 parent 13cbfe5 commit 55cfba0
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 8 deletions.
31 changes: 29 additions & 2 deletions src/components/EditCoursePage/EditCourseForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ import Collapsible from '../Collapsible';
import PriceList from '../PriceList';

import {
PUBLISHED, REVIEWED, EXECUTIVE_EDUCATION_SLUG, COURSE_URL_SLUG_VALIDATION_MESSAGE,
PUBLISHED, REVIEWED, EXECUTIVE_EDUCATION_SLUG, COURSE_URL_SLUG_VALIDATION_MESSAGE, REVIEW_BY_INTERNAL,
} from '../../data/constants';
import {
titleHelp, typeHelp, getUrlSlugHelp, productSourceHelp,
} from '../../helpText';
import { handleCourseEditFail, editCourseValidate, courseTagValidate } from '../../utils/validation';
import {
handleCourseEditFail, editCourseValidate, courseTagValidate, emailValidate,
} from '../../utils/validation';
import {
formatCollaboratorOptions, getDateWithSlashes, getFormattedUTCTimeString, getOptionsData, isPristine,
parseCourseTypeOptions, parseOptions, loadOptions, courseTagObjectsToSelectOptions, getCourseUrlSlugPattern,
Expand Down Expand Up @@ -370,6 +372,30 @@ export class BaseEditCourseForm extends React.Component {
disabled={disabled || !administrator}
optional
/>
{administrator && (
<Field
name="watchers_list"
component={ReduxFormCreatableSelect}
label={(
<FieldLabel
id="watchers.label"
text="Watchers"
helpText={(
<p>
A list of email addresses that will receive
notifications when the course run of the course is published or reviewed.
</p>
)}
optional
/>
)}
isMulti
disabled={!(courseInfo?.data?.course_run_statuses?.includes(REVIEW_BY_INTERNAL) && administrator)}
optional
isCreatable
createOptionValidator={emailValidate}
/>
)}
<div>
<FieldLabel helpText={productSourceHelp} id="productSource" text="Product Source" className="mb-2" />
<div className="mb-3">{parsedProductSource}</div>
Expand Down Expand Up @@ -1091,6 +1117,7 @@ export class BaseEditCourseForm extends React.Component {
disabled={disabled}
optional
/>

{administrator && (
<>
<FieldLabel text="Merchandising Location Restriction" className="mb-2" />
Expand Down
1 change: 1 addition & 0 deletions src/components/EditCoursePage/EditCourseForm.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('BaseEditCourseForm', () => {
skill_names: [],
organization_logo_override: 'http://image.src.small',
organization_short_code_override: 'test short code',
watchers: ['[email protected]'],
location_restriction: {
restriction_type: 'allowlist',
countries: ['AF', 'AX'],
Expand Down
7 changes: 7 additions & 0 deletions src/components/EditCoursePage/EditCoursePage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('EditCoursePage', () => {
const defaultPrice = '77';
const defaultEnd = '2019-08-14T00:00:00Z';
const defaultUpgradeDeadlineOverride = '2019-09-14T00:00:00Z';
const watchers = ['[email protected]'];

const courseInfo = {
data: {
Expand Down Expand Up @@ -161,6 +162,8 @@ describe('EditCoursePage', () => {
skill_names: [],
organization_logo_override_url: 'http://image.src.small',
organization_short_code_override: 'test short code',
watchers,
watchers_list: watchers?.length ? watchers.map(w => ({ label: w, value: w })) : null,
location_restriction: {
restriction_type: 'allowlist',
countries: [
Expand Down Expand Up @@ -384,6 +387,8 @@ describe('EditCoursePage', () => {
},
organization_logo_override_url: 'http://image.src.small',
organization_short_code_override: 'test short code',
watchers,
watchers_list: watchers?.length ? watchers.map(w => ({ label: w, value: w })) : null,
outcome: '<p>Stuff</p>',
prerequisites_raw: '',
prices: {
Expand Down Expand Up @@ -426,6 +431,7 @@ describe('EditCoursePage', () => {
},
organization_logo_override: 'http://image.src.small',
organization_short_code_override: 'test short code',
watchers,
outcome: '<p>Stuff</p>',
prerequisites_raw: '',
prices: {
Expand Down Expand Up @@ -968,6 +974,7 @@ describe('EditCoursePage', () => {
},
organization_logo_override: 'http://image.src.small',
organization_short_code_override: 'test short code',
watchers,
outcome: '<p>Stuff</p>',
prerequisites_raw: '',
prices: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,9 @@ exports[`BaseEditCourseForm override slug format when IS_NEW_SLUG_FORMAT_ENABLED
"type": "8a8f30e1-23ce-4ed3-a361-1325c656b67b",
"uuid": "11111111-1111-1111-1111-111111111111",
"videoSrc": "https://www.video.src/watch?v=fdsafd",
"watchers": Array [
"[email protected]",
],
}
}
editable={false}
Expand Down Expand Up @@ -3521,6 +3524,9 @@ exports[`BaseEditCourseForm renders correctly when submitting for review 1`] = `
"type": "8a8f30e1-23ce-4ed3-a361-1325c656b67b",
"uuid": "11111111-1111-1111-1111-111111111111",
"videoSrc": "https://www.video.src/watch?v=fdsafd",
"watchers": Array [
"[email protected]",
],
}
}
editable={false}
Expand Down Expand Up @@ -5342,6 +5348,9 @@ exports[`BaseEditCourseForm renders html correctly while submitting 1`] = `
"type": "8a8f30e1-23ce-4ed3-a361-1325c656b67b",
"uuid": "11111111-1111-1111-1111-111111111111",
"videoSrc": "https://www.video.src/watch?v=fdsafd",
"watchers": Array [
"[email protected]",
],
}
}
editable={false}
Expand Down Expand Up @@ -5396,6 +5405,9 @@ exports[`BaseEditCourseForm renders html correctly while submitting 1`] = `
"type": "8a8f30e1-23ce-4ed3-a361-1325c656b67b",
"uuid": "11111111-1111-1111-1111-111111111111",
"videoSrc": "https://www.video.src/watch?v=fdsafd",
"watchers": Array [
"[email protected]",
],
}
}
isSubmittingForReview={false}
Expand Down Expand Up @@ -5671,6 +5683,29 @@ exports[`BaseEditCourseForm renders html correctly with administrator being true
pattern="^[a-z0-9_]+(?:-[a-z0-9_]+)*$"
type="text"
/>
<Field
component={[Function]}
createOptionValidator={[Function]}
disabled={true}
isCreatable={true}
isMulti={true}
label={
<FieldLabel
className=""
extraText=""
helpText={
<p>
A list of email addresses that will receive notifications when the course run of the course is published or reviewed.
</p>
}
id="watchers.label"
optional={true}
text="Watchers"
/>
}
name="watchers_list"
optional={true}
/>
<div>
<FieldLabel
className="mb-2"
Expand Down Expand Up @@ -7507,6 +7542,9 @@ exports[`BaseEditCourseForm renders html correctly with administrator being true
"type": "8a8f30e1-23ce-4ed3-a361-1325c656b67b",
"uuid": "11111111-1111-1111-1111-111111111111",
"videoSrc": "https://www.video.src/watch?v=fdsafd",
"watchers": Array [
"[email protected]",
],
}
}
editable={false}
Expand Down Expand Up @@ -7561,6 +7599,9 @@ exports[`BaseEditCourseForm renders html correctly with administrator being true
"type": "8a8f30e1-23ce-4ed3-a361-1325c656b67b",
"uuid": "11111111-1111-1111-1111-111111111111",
"videoSrc": "https://www.video.src/watch?v=fdsafd",
"watchers": Array [
"[email protected]",
],
}
}
isSubmittingForReview={false}
Expand Down Expand Up @@ -9366,6 +9407,9 @@ exports[`BaseEditCourseForm renders html correctly with all data present 1`] = `
"type": "8a8f30e1-23ce-4ed3-a361-1325c656b67b",
"uuid": "11111111-1111-1111-1111-111111111111",
"videoSrc": "https://www.video.src/watch?v=fdsafd",
"watchers": Array [
"[email protected]",
],
}
}
editable={false}
Expand Down Expand Up @@ -9420,6 +9464,9 @@ exports[`BaseEditCourseForm renders html correctly with all data present 1`] = `
"type": "8a8f30e1-23ce-4ed3-a361-1325c656b67b",
"uuid": "11111111-1111-1111-1111-111111111111",
"videoSrc": "https://www.video.src/watch?v=fdsafd",
"watchers": Array [
"[email protected]",
],
}
}
isSubmittingForReview={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ exports[`EditCoursePage renders html correctly 1`] = `
"type": undefined,
"url_slug": undefined,
"videoSrc": undefined,
"watchers": undefined,
"watchers_list": null,
}
}
onSubmit={[Function]}
Expand Down Expand Up @@ -471,6 +473,15 @@ exports[`EditCoursePage renders page correctly with courseInfo 1`] = `
"image": null,
"src": "https://www.video.information/watch?v=cVsQLlk-T0s",
},
"watchers": Array [
"[email protected]",
],
"watchers_list": Array [
Object {
"label": "[email protected]",
"value": "[email protected]",
},
],
},
"error": null,
"isFetching": false,
Expand Down Expand Up @@ -694,6 +705,15 @@ exports[`EditCoursePage renders page correctly with courseInfo 1`] = `
"type": "8a8f30e1-23ce-4ed3-a361-1325c656b67b",
"url_slug": undefined,
"videoSrc": "https://www.video.information/watch?v=cVsQLlk-T0s",
"watchers": Array [
"[email protected]",
],
"watchers_list": Array [
Object {
"label": "[email protected]",
"value": "[email protected]",
},
],
}
}
number="Test101x"
Expand Down Expand Up @@ -976,6 +996,15 @@ exports[`EditCoursePage renders page correctly with courseInfo and courseOptions
"image": null,
"src": "https://www.video.information/watch?v=cVsQLlk-T0s",
},
"watchers": Array [
"[email protected]",
],
"watchers_list": Array [
Object {
"label": "[email protected]",
"value": "[email protected]",
},
],
},
"error": null,
"isFetching": false,
Expand Down Expand Up @@ -1572,6 +1601,15 @@ exports[`EditCoursePage renders page correctly with courseInfo and courseOptions
"type": "8a8f30e1-23ce-4ed3-a361-1325c656b67b",
"url_slug": undefined,
"videoSrc": "https://www.video.information/watch?v=cVsQLlk-T0s",
"watchers": Array [
"[email protected]",
],
"watchers_list": Array [
Object {
"label": "[email protected]",
"value": "[email protected]",
},
],
}
}
number="Test101x"
Expand Down Expand Up @@ -1769,6 +1807,8 @@ exports[`EditCoursePage renders page correctly with courseInfo error 1`] = `
"type": undefined,
"url_slug": undefined,
"videoSrc": undefined,
"watchers": undefined,
"watchers_list": null,
}
}
onSubmit={[Function]}
Expand Down Expand Up @@ -2072,6 +2112,15 @@ exports[`EditCoursePage renders page correctly with courseInfo, courseOptions, a
"image": null,
"src": "https://www.video.information/watch?v=cVsQLlk-T0s",
},
"watchers": Array [
"[email protected]",
],
"watchers_list": Array [
Object {
"label": "[email protected]",
"value": "[email protected]",
},
],
},
"error": null,
"isFetching": false,
Expand Down Expand Up @@ -2736,6 +2785,15 @@ exports[`EditCoursePage renders page correctly with courseInfo, courseOptions, a
"type": "8a8f30e1-23ce-4ed3-a361-1325c656b67b",
"url_slug": undefined,
"videoSrc": "https://www.video.information/watch?v=cVsQLlk-T0s",
"watchers": Array [
"[email protected]",
],
"watchers_list": Array [
Object {
"label": "[email protected]",
"value": "[email protected]",
},
],
}
}
number="Test101x"
Expand Down Expand Up @@ -2949,6 +3007,8 @@ exports[`EditCoursePage renders page correctly with courseInfo, courseOptions, a
"type": undefined,
"url_slug": undefined,
"videoSrc": undefined,
"watchers": undefined,
"watchers_list": null,
}
}
onSubmit={[Function]}
Expand Down Expand Up @@ -3540,6 +3600,8 @@ exports[`EditCoursePage renders page correctly with courseOptions 1`] = `
"type": undefined,
"url_slug": undefined,
"videoSrc": undefined,
"watchers": undefined,
"watchers_list": null,
}
}
onSubmit={[Function]}
Expand Down Expand Up @@ -3737,6 +3799,8 @@ exports[`EditCoursePage renders page correctly with courseOptions error 1`] = `
"type": undefined,
"url_slug": undefined,
"videoSrc": undefined,
"watchers": undefined,
"watchers_list": null,
}
}
onSubmit={[Function]}
Expand Down Expand Up @@ -4019,6 +4083,8 @@ exports[`EditCoursePage renders page correctly with courseRunOptions 1`] = `
"type": undefined,
"url_slug": undefined,
"videoSrc": undefined,
"watchers": undefined,
"watchers_list": null,
}
}
onSubmit={[Function]}
Expand Down Expand Up @@ -4216,6 +4282,8 @@ exports[`EditCoursePage renders page correctly with courseRunOptions error 1`] =
"type": undefined,
"url_slug": undefined,
"videoSrc": undefined,
"watchers": undefined,
"watchers_list": null,
}
}
onSubmit={[Function]}
Expand Down
Loading

0 comments on commit 55cfba0

Please sign in to comment.