Skip to content

Commit

Permalink
feat: add watchers field
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 committed Jul 21, 2023
1 parent 80b4a1e commit 7a69640
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 2 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 @@ -1091,6 +1093,31 @@ export class BaseEditCourseForm extends React.Component {
disabled={disabled}
optional
/>
{administrator && (
<Field
name="watchers_list"
component={ReduxFormCreatableSelect}
label={(
<FieldLabel
id="watchers.label"
text="Watchers"
helpText={(
<p>
A comma-separated 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}
/>
)}

{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 @@ -967,6 +973,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 @@ -6706,6 +6718,29 @@ exports[`BaseEditCourseForm renders html correctly with administrator being true
requiredHeight={110}
requiredWidth={110}
/>
<Field
component={[Function]}
createOptionValidator={[Function]}
disabled={true}
isCreatable={true}
isMulti={true}
label={
<FieldLabel
className=""
extraText=""
helpText={
<p>
A comma-separated 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}
/>
<FieldLabel
className="mb-2"
extraText=""
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 @@ -693,6 +704,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 @@ -975,6 +995,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 @@ -1570,6 +1599,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 @@ -1767,6 +1805,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 @@ -2070,6 +2110,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 @@ -2733,6 +2782,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 @@ -2946,6 +3004,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 @@ -3537,6 +3597,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 @@ -3734,6 +3796,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 @@ -4016,6 +4080,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 @@ -4213,6 +4279,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
4 changes: 4 additions & 0 deletions src/components/EditCoursePage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ class EditCoursePage extends React.Component {
organization_logo_override: courseData.organization_logo_override_url,
organization_short_code_override:
courseData.organization_short_code_override,
watchers: courseData.watchers_list ? courseData.watchers_list.map((watcher) => watcher.value) : [],
outcome: courseData.outcome,
prerequisites_raw: courseData.prerequisites_raw,
...priceData,
Expand Down Expand Up @@ -615,6 +616,7 @@ class EditCoursePage extends React.Component {
enterprise_subscription_inclusion,
organization_short_code_override,
organization_logo_override_url,
watchers,
},
},
} = this.props;
Expand Down Expand Up @@ -657,9 +659,11 @@ class EditCoursePage extends React.Component {
enterprise_subscription_inclusion,
organization_short_code_override,
organization_logo_override_url,
watchers,
location_restriction: this.buildLocationRestriction(),
in_year_value: this.buildInYearValue(),
tags: topics?.length ? topics.map(t => ({ label: t, value: t })) : null,
watchers_list: watchers?.length ? watchers.map(w => ({ label: w, value: w })) : null,
};
}

Expand Down
Loading

0 comments on commit 7a69640

Please sign in to comment.